协议栈2.5.1a ,一个协调器,两个路由器,9个终端,抓包发现两个路由器帮忙转发终端的数据给协调器,路由器自己的数据却没有发给协调器,目前推测原因是: 路由器帮忙转发终端的数据,操作系统无暇发送自己的数据给协调器。
抓包文件如下:
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
#include "OSAL.h" #include "AF.h" #include "ZDApp.h" #include "ZDObject.h" #include "ZDProfile.h" #include "Coordinator.h" #include "DebugTrace.h" //#if !defined( WIN32 ) #include "OnBoard.h" //#endif /* HAL */ #include "hal_lcd.h" #include "hal_adc.h" #include "hal_led.h" #include "hal_key.h" #include "hal_uart.h" #include "ds18b20A1.h" #include "ds18b20A2.h" #include "ds18b20A3.h" #include "ds18b20A4.h" #include "ds18b20A5.h" #include "TempQueue.h" #define SEND_JOIN_EVENT 0x0001 #define SEND_PERIODIC_MSG_EVT 0x0002 #define SEND_PERIODIC_MSG_EVT0 0x0008 const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] = { GENERICAPP_CLUSTERID, GENERICAPP_PERIODIC_CLUSTERID }; const SimpleDescriptionFormat_t GenericApp_SimpleDesc = { GENERICAPP_ENDPOINT, GENERICAPP_PROFID, GENERICAPP_DEVICEID, GENERICAPP_DEVICE_VERSION, GENERICAPP_FLAGS, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList, GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList }; endPointDesc_t GenericApp_epDesc; byte GenericApp_TaskID; devStates_t GenericApp_NwkState; byte GenericApp_TransID; void SendRespons(void); ///发送函数 void SendInfo1(void); void SendInfo2(void); ///发送函数 void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt ); unsigned short sqrt(unsigned long a); unsigned short ADcollecter(int HAL_ADC_CHANNEL); int nl_abs(int x); void GenericApp_Init( uint8 task_id ) { GenericApp_NwkState = DEV_INIT; GenericApp_TaskID = task_id; GenericApp_TransID = 0; GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT; GenericApp_epDesc.task_id = &GenericApp_TaskID; GenericApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc; GenericApp_epDesc.latencyReq = noLatencyReqs; afRegister( &GenericApp_epDesc ); // P0SEL &= 0x0f ; P0SEL &= 0x0f ; //0000 1111 让P0_4567处于普通IO口 P1SEL &= 0xfb ; //1111 1011 让P1_2处于普通IO口状态 halUARTCfg_t uartConfig; uartConfig.configured=TRUE; uartConfig.baudRate=HAL_UART_BR_115200; uartConfig.flowControl=FALSE; uartConfig.callBackFunc=0; HalUARTOpen(0,&uartConfig); } uint16 GenericApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t *MSGpkt; if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case ZDO_STATE_CHANGE: GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( (GenericApp_NwkState == DEV_ROUTER) || (GenericApp_NwkState == DEV_END_DEVICE) ) { osal_set_event(GenericApp_TaskID,SEND_PERIODIC_MSG_EVT); } break; case AF_INCOMING_MSG_CMD: GenericApp_MessageMSGCB( MSGpkt ); break; default: break; } osal_msg_deallocate( (uint8 *)MSGpkt ); MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID ); } return (events ^ SYS_EVENT_MSG); } if ( events & SEND_JOIN_EVENT ) { SendRespons(); return (events ^ SEND_JOIN_EVENT); } if ( events & SEND_PERIODIC_MSG_EVT) ////发送数据给协调器 { SendInfo1(); osal_start_timerEx( GenericApp_TaskID, SEND_PERIODIC_MSG_EVT, SEND_PERIODIC_MSG_TIMEOUT ); return (events ^ SEND_PERIODIC_MSG_EVT); } return 0; } void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { switch ( pkt->clusterId ) { case GENERICAPP_CLUSTERID: if( (pkt->cmd.Data[0]=='S')&&(pkt->cmd.Data[1]=='T')&&(pkt->cmd.Data[2]=='A')&&(pkt->cmd.Data[3]=='R') && (pkt->cmd.Data[4]=='T') ) { osal_start_timerEx( GenericApp_TaskID, SEND_PERIODIC_MSG_EVT, SEND_PERIODIC_MSG_TIMEOUT ); } else if ( (pkt->cmd.Data[0]=='S')&&(pkt->cmd.Data[1]=='T')&&(pkt->cmd.Data[2]=='O')&&(pkt->cmd.Data[3]=='P')) { osal_stop_timerEx( GenericApp_TaskID, SEND_PERIODIC_MSG_EVT); } break; case GENERICAPP_PERIODIC_CLUSTERID: break; } } void SendRespons(void) { char TheMassageRespons[]="JOIN"; afAddrType_t my_DstAddr; my_DstAddr.addrMode=(afAddrMode_t)Addr16Bit; my_DstAddr.endPoint = GENERICAPP_ENDPOINT; my_DstAddr.addr.shortAddr = 0x0000; AF_DataRequest( &my_DstAddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 4, (uint8*)TheMassageRespons, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); } unsigned short sqrt(unsigned long a) { unsigned long rem = 0; unsigned long root = 0; unsigned long divisor = 0; for(int i=0; i<16; i++) { root <<= 1; rem = ((rem << 2) + (a >> 30)); a <<= 2; divisor = (root<<1) + 1; if(divisor <= rem) { rem -= divisor; root++; } } return (unsigned short)(root); } int nl_abs(int x) { if (x > 0)return x; return -x; } unsigned short ADcollecter(int HAL_ADC_CHANNEL) { int16 ADten0[100]={0}; int16 Sum0 = 0; int16 avag0 = 0; int16 fSum0 = 0; int16 calc_value0 = 0; int16 ADten00[100]={0}; int16 new_buffer0[100]={0}; for(int i=0;i<100;i++) { ADten0[i]=HalAdcRead( HAL_ADC_CHANNEL, HAL_ADC_RESOLUTION_14 ); Sum0+=ADten0[i]; } avag0 = Sum0 / 100; for(int i=0;i<100;i++) { ADten00[i]=HalAdcRead( HAL_ADC_CHANNEL, HAL_ADC_RESOLUTION_14 ); //sum1+=ADten1[i]; } for(int i=0; i<100; i++) { new_buffer0[i] = nl_abs(ADten0[i] - avag0-1965); fSum0+=new_buffer0[i]; } calc_value0 = fSum0/100; return calc_value0; } void SendInfo1(void) { TH_TL1(); TempElem infoA1; int y11 = 0; //判断循环次数 int y12 = 0; int y13 = 0; int y14 = 0; int y21 = 0; //判断循环次数 int y22 = 0; int y23 = 0; int y24 = 0; int y31 = 0; int y32 = 0; //判断循环次数 int y33 = 0; int y34 = 0; int y41 = 0; //判断循环次数 int y42 = 0; int y43 = 0; int y44 = 0; float temp1; unsigned short temp11, temp12,temp14, tempA151; float temp13,temp15,temp16,temp17,temp18,temp19,temp110,temp111; float temp2; unsigned short temp21, temp22,temp24, tempA251; float temp23,temp25,temp26,temp27,temp28,temp29,temp210,temp211; float temp3; unsigned short temp31, temp32,temp34, tempA351; float temp33,temp35,temp36,temp37,temp38,temp39,temp310,temp311; float temp4; unsigned short temp41, temp42,temp44, tempA451; float temp43,temp45,temp46,temp47,temp48,temp49,temp410,temp411; int flag11=0; //有效数据标志位,便于查找bug int flag12=0; int flag13=0; int flag14=0; int flag15=0; int flag21=0; //有效数据标志位,便于查找bug int flag22=0; int flag23=0; int flag24=0; int flag25=0; int flag31=0; //有效数据标志位,便于查找bug int flag32=0; int flag33=0; int flag34=0; int flag35=0; int flag41=0; //有效数据标志位,便于查找bug int flag42=0; int flag43=0; int flag44=0; int flag45=0; /* 第1个传感器 */ while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA1(); check_value=Ds18b20_CheckA1(); if(check_value==0) { Temp_testA1(); Temp0[i]=tempA1; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.FirstTemp[0]='w'; infoA1.FirstTemp[1]='r'; infoA1.FirstTemp[2]='o'; infoA1.FirstTemp[3]='n'; infoA1.FirstTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.FirstTemp[0]='i'; infoA1.FirstTemp[1]='n'; infoA1.FirstTemp[2]='v'; infoA1.FirstTemp[3]='a'; infoA1.FirstTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp1 = Temp_use[y] *0.0625; tempA1 = temp1 * 100; infoA1.FirstTemp[0]=tempA1/1000+48; infoA1.FirstTemp[1]=tempA1/100%10+48; infoA1.FirstTemp[2]='.'; infoA1.FirstTemp[3]=tempA1/10%10+48; infoA1.FirstTemp[4]=tempA1%10+48; break; } } /* 第2个传感器 */ while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA2(); check_value=Ds18b20_CheckA2(); if(check_value==0) { Temp_testA2(); Temp0[i]=tempA2; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.SecondTemp[0]='w'; infoA1.SecondTemp[1]='r'; infoA1.SecondTemp[2]='o'; infoA1.SecondTemp[3]='n'; infoA1.SecondTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.SecondTemp[0]='i'; infoA1.SecondTemp[1]='n'; infoA1.SecondTemp[2]='v'; infoA1.SecondTemp[3]='a'; infoA1.SecondTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp2 = Temp_use[y] *0.0625; tempA2 = temp2 * 100; infoA1.SecondTemp[0]=tempA2/1000+48; infoA1.SecondTemp[1]=tempA2/100%10+48; infoA1.SecondTemp[2]='.'; infoA1.SecondTemp[3]=tempA2/10%10+48; infoA1.SecondTemp[4]=tempA2%10+48; break; } } /* 第3个传感器 */ while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA3(); check_value=Ds18b20_CheckA3(); if(check_value==0) { Temp_testA3(); Temp0[i]=tempA3; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.ThirdTemp[0]='w'; infoA1.ThirdTemp[1]='r'; infoA1.ThirdTemp[2]='o'; infoA1.ThirdTemp[3]='n'; infoA1.ThirdTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.ThirdTemp[0]='i'; infoA1.ThirdTemp[1]='n'; infoA1.ThirdTemp[2]='v'; infoA1.ThirdTemp[3]='a'; infoA1.ThirdTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp3 = Temp_use[y] *0.0625; tempA3 = temp3 * 100; infoA1.ThirdTemp[0]=tempA3/1000+48; infoA1.ThirdTemp[1]=tempA3/100%10+48; infoA1.ThirdTemp[2]='.'; infoA1.ThirdTemp[3]=tempA3/10%10+48; infoA1.ThirdTemp[4]=tempA3%10+48; break; } } /* 第4个传感器 */ while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA4(); check_value=Ds18b20_CheckA4(); if(check_value==0) { Temp_testA4(); Temp0[i]=tempA4; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.FourthTemp[0]='w'; infoA1.FourthTemp[1]='r'; infoA1.FourthTemp[2]='o'; infoA1.FourthTemp[3]='n'; infoA1.FourthTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.FourthTemp[0]='i'; infoA1.FourthTemp[1]='n'; infoA1.FourthTemp[2]='v'; infoA1.FourthTemp[3]='a'; infoA1.FourthTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp4 = Temp_use[y] *0.0625; tempA4 = temp4 * 100; infoA1.FourthTemp[0]=tempA4/1000+48; infoA1.FourthTemp[1]=tempA4/100%10+48; infoA1.FourthTemp[2]='.'; infoA1.FourthTemp[3]=tempA4/10%10+48; infoA1.FourthTemp[4]=tempA4%10+48; break; } } //////////////////////////////////////////////////// osal_start_timerEx( GenericApp_TaskID, SEND_PERIODIC_MSG_EVT0, SEND_PERIODIC_MSG_TIMEOUT0 ); TH_TL2(); /* 第5个传感器 */ while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA1(); check_value=Ds18b20_CheckA1(); if(check_value==0) { Temp_testA1(); Temp0[i]=tempA1; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.FifthTemp[0]='w'; infoA1.FifthTemp[1]='r'; infoA1.FifthTemp[2]='o'; infoA1.FifthTemp[3]='n'; infoA1.FifthTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.FifthTemp[0]='i'; infoA1.FifthTemp[1]='n'; infoA1.FifthTemp[2]='v'; infoA1.FifthTemp[3]='a'; infoA1.FifthTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp1 = Temp_use[y] *0.0625; tempA1 = temp1 * 100; infoA1.FifthTemp[0]=tempA1/1000+48; infoA1.FifthTemp[1]=tempA1/100%10+48; infoA1.FifthTemp[2]='.'; infoA1.FifthTemp[3]=tempA1/10%10+48; infoA1.FifthTemp[4]=tempA1%10+48; break; } } // while (1) // { // // Temp_testA1(); // tempA151= tempA1&0xf800; // //tempA151=tempA151>>11; //将前五位移到后五位 // if((tempA151==63488)||(tempA151==0)) //用于判断前五位是否一样 // // { // // if(tempA1==0xFFFF) // { // infoA1.FifthTemp[0]='w'; // infoA1.FifthTemp[1]='r'; // infoA1.FifthTemp[2]='o'; // infoA1.FifthTemp[3]='n'; // infoA1.FifthTemp[4]='g'; // break; // } // // // else if(tempA151==63488) // { // // //前五位均为1时 ,数据为负数 // temp11=~tempA1; // tempA1=temp11+1; //此处为原码 // temp1 = tempA1 * 0.0625; // // if(temp1 <=30) // { // tempA1 = temp1 * 100; // flag11=1; // break; // } // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // // { // MicroWait(1000); // } // // Temp_testA1(); // temp12=~tempA1; // tempA1=temp12+1; // temp13 = tempA1 * 0.0625; // for (int i=0;i<500;i++) //延时0.5秒 // { // MicroWait(1000); // } // // Temp_testA1(); // temp14=~tempA1; // tempA1=temp14+1; // temp15 = tempA1 * 0.0625; // // temp16= temp13 -temp1; // temp17= temp15 -temp1; // // if ( -5 <= temp16 && temp16<=5&&-5 <= temp17&& temp17<=5 ) // { // y11 = 0; // tempA1= temp1 * 100; // flag12=1; // break; // } // else // { // // for (int i=0;i<500;i++) //延时0.5秒 // { // MicroWait(1000); // } // // y11 += 1; // // if ( y11 >= 10) // { // flag12=0; // break; // } // // } // // } // // // } // else if(tempA151==0) // { // // temp1 = tempA1 * 0.0625; // // y12 = 0; // // if(temp1 <= 50) // { // tempA1 = temp1 * 100; // flag13=1; // break; // } // // // // // else if (tempA1==0x0550) //删除出现电源线断开出现85的情况 // { // y14 += 1; // // if (y14 >= 20) // { // // infoA1.FifthTemp[0]='w'; // infoA1.FifthTemp[1]='r'; // infoA1.FifthTemp[2]='o'; // infoA1.FifthTemp[3]='n'; // infoA1.FifthTemp[4]='g'; // break; // } // // } // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // { // MicroWait(1000); // } // // Temp_testA1(); // temp18=tempA1*0.0625; // // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // Temp_testA1(); // temp19=tempA1*0.0625; // // temp110=temp18-temp1; // temp111=temp19-temp1; // if (-5 <= temp110 && temp110<=5&&-5 <= temp111&& temp111<=5 ) // { // y12 = 0; // tempA1 = temp1 * 100; // flag14=1; // break; // } // else // { // // for (int i=0;i<500;i++) //延时0.5秒 // // { // // MicroWait(1000); // } // // y12 += 1; // // if (y12 >= 10) // { // flag14=0; // break; // } // // } // } // } // // // } // // // // else // { // // for (int i=0;i< 500;i++) //延时0.5秒 // { // MicroWait(1000); // } // // y13 += 1; // // if (y13 >= 20) // { // flag15=0; // break; // } // // } // // // // } // // // // // if(flag11||flag12||flag13||flag14||flag15) // { // infoA1.FifthTemp[0]=tempA1/1000+48; // infoA1.FifthTemp[1]=tempA1/100%10+48; // infoA1.FifthTemp[2]='.'; // infoA1.FifthTemp[3]=tempA1/10%10+48; // infoA1.FifthTemp[4]=tempA1%10+48; // } // else // { // infoA1.FifthTemp[0]='w'; // infoA1.FifthTemp[1]='r'; // infoA1.FifthTemp[2]='o'; // infoA1.FifthTemp[3]='n'; // infoA1.FifthTemp[4]='g'; // } // /* 第六个传感器 */ // while (1) // { // // Temp_testA2(); // tempA251= tempA2&0xf800; // //tempA151=tempA151>>11; //将前五位移到后五位 // if((tempA251==63488)||(tempA251==0)) //用于判断前五位是否一样 // // { // // if(tempA2==0xFFFF) // { // infoA1.SixthTemp[0]='w'; // infoA1.SixthTemp[1]='r'; // infoA1.SixthTemp[2]='o'; // infoA1.SixthTemp[3]='n'; // infoA1.SixthTemp[4]='g'; // break; // } // // // else if(tempA251==63488) // { // // //前五位均为1时 ,数据为负数 // temp21=~tempA2; // tempA2=temp21+1; //此处为原码 // temp2 = tempA2 * 0.0625; // // if(temp2 <= 30) // { // tempA2 = temp2 * 100; // flag21=1; // break; // } // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // // { // MicroWait(1000); // } // // Temp_testA2(); // temp22=~tempA2; // tempA2=temp22+1; // temp23 = tempA2 * 0.0625; // // for (int i=0;i<500;i++) //延时0.5秒 // { // MicroWait(1000); // } // // Temp_testA2(); // temp24=~tempA2; // tempA2=temp24+1; // temp25 = tempA2 * 0.0625; // // temp26= temp23 -temp2; // temp27= temp25 -temp2; // // if (-5 <= temp26 && temp26<=5&&-5 <= temp27&& temp27<=5 ) // { // y21 = 0; // tempA2= temp2 * 100; // flag22=1; // break; // } // else // { // // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // y21 += 1; // // if (y21 >= 10) // { // flag22=0; // break; // } // } // // // } // // // // // } // // else if(tempA251==0) // { // // temp2 = tempA2 * 0.0625; // // y22 = 0; // // if(temp2 <= 50) // { // tempA2 = temp2 * 100; // flag23=1; // break; // } // // // else if (tempA2==0x0550) //删除出现电源线断开出现85的情况 // { // y24 += 1; // // if (y24 >= 20) // { // // infoA1.SixthTemp[0]='w'; // infoA1.SixthTemp[1]='r'; // infoA1.SixthTemp[2]='o'; // infoA1.SixthTemp[3]='n'; // infoA1.SixthTemp[4]='g'; // break; // } // // } // // // // // // // // // // // // // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // // } // // Temp_testA2(); // temp28=tempA2*0.0625; // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // Temp_testA2(); // temp29=tempA2*0.0625; // // temp210=temp28-temp2; // temp211=temp29-temp2; // if (-5 <= temp210 && temp210<=5&&-5 <= temp211&& temp211<=5 ) // { // y22 = 0; // tempA2 = temp2 * 100; // flag24=1; // break; // } // else // { // // // for (int i=0;i<500;i++) //延时0.5秒 // // { // MicroWait(1000); // } // // // y22 += 1; // // if (y22 >= 10) // { // flag24=0; // break; // } // // } // // } // // } // // // } // // // // else // { // // for (int i=0;i< 500;i++) //延时0.5秒 // // { // // MicroWait(1000); // } // // y23 += 1; // // if (y23 >= 20) // { // flag25=0; // break; // } // // // } // // // // } // // // if(flag21||flag22||flag23||flag24||flag25) // { // infoA1.SixthTemp[0]=tempA2/1000+48; // infoA1.SixthTemp[1]=tempA2/100%10+48; // infoA1.SixthTemp[2]='.'; // infoA1.SixthTemp[3]=tempA2/10%10+48; // infoA1.SixthTemp[4]=tempA2%10+48; // } // else // { // infoA1.SixthTemp[0]='w'; // infoA1.SixthTemp[1]='r'; // infoA1.SixthTemp[2]='o'; // infoA1.SixthTemp[3]='n'; // infoA1.SixthTemp[4]='g'; // } // while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA2(); check_value=Ds18b20_CheckA2(); if(check_value==0) { Temp_testA2(); Temp0[i]=tempA2; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.SixthTemp[0]='w'; infoA1.SixthTemp[1]='r'; infoA1.SixthTemp[2]='o'; infoA1.SixthTemp[3]='n'; infoA1.SixthTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.SixthTemp[0]='i'; infoA1.SixthTemp[1]='n'; infoA1.SixthTemp[2]='v'; infoA1.SixthTemp[3]='a'; infoA1.SixthTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp2 = Temp_use[y] *0.0625; tempA2 = temp2 * 100; infoA1.SixthTemp[0]=tempA2/1000+48; infoA1.SixthTemp[1]=tempA2/100%10+48; infoA1.SixthTemp[2]='.'; infoA1.SixthTemp[3]=tempA2/10%10+48; infoA1.SixthTemp[4]=tempA2%10+48; break; } } while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA3(); check_value=Ds18b20_CheckA3(); if(check_value==0) { Temp_testA3(); Temp0[i]=tempA3; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.SeventhTemp[0]='w'; infoA1.SeventhTemp[1]='r'; infoA1.SeventhTemp[2]='o'; infoA1.SeventhTemp[3]='n'; infoA1.SeventhTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.SeventhTemp[0]='i'; infoA1.SeventhTemp[1]='n'; infoA1.SeventhTemp[2]='v'; infoA1.SeventhTemp[3]='a'; infoA1.SeventhTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp3 = Temp_use[y] *0.0625; tempA3 = temp3 * 100; infoA1.SeventhTemp[0]=tempA3/1000+48; infoA1.SeventhTemp[1]=tempA3/100%10+48; infoA1.SeventhTemp[2]='.'; infoA1.SeventhTemp[3]=tempA3/10%10+48; infoA1.SeventhTemp[4]=tempA3%10+48; break; } } /* 第八个传感器 */ // while (1) // { // // // Temp_testA4(); // tempA451= tempA4&0xf800; // //tempA151=tempA151>>11; //将前五位移到后五位 // if((tempA451==63488)||(tempA451==0)) //用于判断前五位是否一样 // // { // // if(tempA4==0xFFFF) // { // infoA1.EighthTemp[0]='w'; // infoA1.EighthTemp[1]='r'; // infoA1.EighthTemp[2]='o'; // infoA1.EighthTemp[3]='n'; // infoA1.EighthTemp[4]='g'; // break; // } // // // else if(tempA451==63488) // { // // //前五位均为1时 ,数据为负数 // temp41=~tempA4; // tempA4=temp41+1; //此处为原码 // temp4 = tempA4 * 0.0625; // // if(temp4 <= 30) // { // tempA4 = temp4 * 100; // flag41=1; // break; // } // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // // { // // MicroWait(1000); // } // // Temp_testA4(); // temp42=~tempA4; // tempA4=temp42+1; // temp43 = tempA4 * 0.0625; // // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // Temp_testA4(); // temp44=~tempA4; // tempA4=temp44+1; // temp45 = tempA4 * 0.0625; // // temp46= temp43 -temp4; // temp47= temp45 -temp4; // // if (-5 <= temp46 && temp46<=5&&-5 <= temp47 && temp47<=5 ) // { // y41 = 0; // tempA4= temp4 * 100; // flag42=1; // break; // } // else // { // // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // y41 += 1; // // if (y41 >= 10) // { // flag42=0; // break; // } // } // // // } // // // // // } // else if(tempA451==0) // { // // temp4 = tempA4 * 0.0625; // // y42 = 0; // // if(temp4 <= 50) // { // tempA4 = temp4 * 100; // flag43=1; // break; // } // // else if (tempA4==0x0550) //删除出现电源线断开出现85的情况 // { // y44 += 1; // // if (y44 >= 20) // { // // infoA1.EighthTemp[0]='w'; // infoA1.EighthTemp[1]='r'; // infoA1.EighthTemp[2]='o'; // infoA1.EighthTemp[3]='n'; // infoA1.EighthTemp[4]='g'; // break; // } // // } // // // // else // { // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // // } // // Temp_testA4(); // temp48=tempA4*0.0625; // for (int i=0;i<500;i++) //延时0.5秒 // { // // MicroWait(1000); // } // // Temp_testA4(); // temp49=tempA4*0.0625; // // temp410=temp48-temp4; // temp411=temp49-temp4; // if (-5 <= temp410 && temp410<=5&&-5 <= temp411&& temp411<=5 ) // { // y42 = 0; // tempA4 = temp4 * 100; // flag44=1; // break; // } // else // { // // // for (int i=0;i<500;i++) //延时0.5秒 // // { // // MicroWait(1000); // } // // // y42 += 1; // // if (y42 >= 10) // { // flag44=0; // break; // } // } // } // } // // // } // // // // else // { // // for (int i=0;i< 500;i++) //延时0.5秒 // // { // // MicroWait(1000); // } // // y43 += 1; // // if (y43 >= 20) // { // flag45=0; // break; // } // // // } // // // // } // // // if(flag41||flag42||flag43||flag44||flag45) // { // infoA1.EighthTemp[0]=tempA4/1000+48; // infoA1.EighthTemp[1]=tempA4/100%10+48; // infoA1.EighthTemp[2]='.'; // infoA1.EighthTemp[3]=tempA4/10%10+48; // infoA1.EighthTemp[4]=tempA4%10+48; // } // else // { // infoA1.EighthTemp[0]='w'; // infoA1.EighthTemp[1]='r'; // infoA1.EighthTemp[2]='o'; // infoA1.EighthTemp[3]='n'; // infoA1.EighthTemp[4]='g'; // } // // // while(1) { int count1=0; int count2=0; int count3=0; int count4=0; unsigned short T1; unsigned short T2; int check_value; unsigned short Temp0[5]={0,0,0,0,0}; unsigned short Temp0_5[5]={0,0,0,0,0}; unsigned short Temp_use[5]={0,0,0,0,0}; /*********开始采集5次数据*****/ for(int i=0;i<5;i++) //开始采集5次数据 { Ds18b20_RestA4(); check_value=Ds18b20_CheckA4(); if(check_value==0) { Temp_testA4(); Temp0[i]=tempA4; Temp0_5[i]= Temp0[i]&0xf800; count1++; } else { count2++;} } /************5次采集完成************/ if(count2==5) { infoA1.EighthTemp[0]='w'; infoA1.EighthTemp[1]='r'; infoA1.EighthTemp[2]='o'; infoA1.EighthTemp[3]='n'; infoA1.EighthTemp[4]='g'; break; } else { for(int j=0;j<count1;j++) { if ( (Temp0_5[j]==0)||(Temp0_5[j]==63488)) { if ( Temp0_5[j]==0) //正数 { Temp_use[j]=Temp0[j]; count3++; } else //负数 { T1=~Temp0[j]; T2=T1+1; Temp_use[j]=T2; count3++; } } else { count4++; if(count4==count3){ infoA1.EighthTemp[0]='i'; infoA1.EighthTemp[1]='n'; infoA1.EighthTemp[2]='v'; infoA1.EighthTemp[3]='a'; infoA1.EighthTemp[4]='l'; break; } } } //进行冒泡排序 for(int k=1;k<count3;k++) //总共比较 count3-1 次 { for(int m=0;m<count3-k;m++) { if(Temp_use[m]>Temp_use[m+1]) { unsigned short x=Temp_use[m]; Temp_use[m]=Temp_use[m+1]; Temp_use[m+1]=x; } } } //排序完成 int y=count3/2; //取出数组中间值 temp4 = Temp_use[y] *0.0625; tempA4 = temp4 * 100; infoA1.EighthTemp[0]=tempA4/1000+48; infoA1.EighthTemp[1]=tempA4/100%10+48; infoA1.EighthTemp[2]='.'; infoA1.EighthTemp[3]=tempA4/10%10+48; infoA1.EighthTemp[4]=tempA4%10+48; break; } } //////////////////////////////////////////////////////////////// APCFG |= 0x0f; // p0.1 0.2 0.3 0.0设置为adc功能 HalAdcInit(); HalAdcSetReference ( HAL_ADC_REF_AVDD ); int16 calc_value0 = 0; int16 calc_value1 = 0; int16 calc_value2 = 0; int16 calc_value3 = 0; calc_value0=ADcollecter(HAL_ADC_CHANNEL_0); infoA1.FirstAD[0]=calc_value0/1000+48; infoA1.FirstAD[1]=calc_value0%1000/100+48; infoA1.FirstAD[2]=calc_value0%100/10+48; infoA1.FirstAD[3]=calc_value0%10+48; calc_value1 = ADcollecter(HAL_ADC_CHANNEL_1); infoA1.SecondAD[0]=calc_value1/1000+48; infoA1.SecondAD[1]=calc_value1%1000/100+48; infoA1.SecondAD[2]=calc_value1%100/10+48; infoA1.SecondAD[3]=calc_value1%10+48; calc_value2 = ADcollecter(HAL_ADC_CHANNEL_2); infoA1.ThirdAD[0]=calc_value2/1000+48; infoA1.ThirdAD[1]=calc_value2%1000/100+48; infoA1.ThirdAD[2]=calc_value2%100/10+48; infoA1.ThirdAD[3]=calc_value2%10+48; calc_value3 = ADcollecter(HAL_ADC_CHANNEL_3); infoA1.FourthAD[0]=calc_value3/1000+48; infoA1.FourthAD[1]=calc_value3%1000/100+48; infoA1.FourthAD[2]=calc_value3%100/10+48; infoA1.FourthAD[3]=calc_value3%10+48; infoA1.DeviceNumber[0]='0'; infoA1.DeviceNumber[1]='7'; afAddrType_t my_DstAddr; my_DstAddr.addrMode=(afAddrMode_t)Addr16Bit; my_DstAddr.endPoint = GENERICAPP_ENDPOINT; my_DstAddr.addr.shortAddr = 0x0000; AF_DataRequest( &my_DstAddr, &GenericApp_epDesc, GENERICAPP_PERIODIC_CLUSTERID, 58, (uint8*)&infoA1, &GenericApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); }
发送函数是void SendInfo1(void);
周期性事件以及事件函数:
if ( events & SEND_PERIODIC_MSG_EVT) ////发送数据给协调器
{
SendInfo1();
osal_start_timerEx( GenericApp_TaskID, SEND_PERIODIC_MSG_EVT,
SEND_PERIODIC_MSG_TIMEOUT );
return (events ^ SEND_PERIODIC_MSG_EVT);
}