zigbee mesh组网 怎样读出路由节点的收包数量?或者是转发包的数量。
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.
网上有个前辈说,在代码收到并处理无线数据的地方开个计数器,每次运行到这里就加1,这个方法行得通吗?
您好,我把代码加在黄色背景部分(两处均试过),来统计收包数量 h ,发现随着路由节点的子节点数量增加,路由节点的 h 的增加速率并没有改变,这是为什么?问题出在哪?以下为部分代码。感谢解答
uint16 i = 0;
uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
{
 uint8 Display_Buf[6] = {0};
 uint16 shortAddr = 0;
 uint16 shortAddrNew = 0; 
 uint16 PANID=0;
 uint16 parentshortAddr = 0;
 uint16 parentshortAddrNew = 0;
uint16 h;
afIncomingMSGPacket_t *MSGpkt;
 
 (void)task_id; // Intentionally unreferenced parameter
if ( events & SYS_EVENT_MSG ) /*系统消息事件*/
 {
 
 h=i;
 num_to_str(h, Display_Buf, 4 , 16); 
 Gui_DrawFont_GBK16(0,96,BLACK,YELLOW,Display_Buf);
 i++;
 
 MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
 while ( MSGpkt ) /*调用数据接收函数接收数据.2*/
 {
 switch ( MSGpkt->hdr.event ) /*判断具体事件*/
 { 
 // Received when a key is pressed
 case KEY_CHANGE:
 SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
 break; /*如果为按键事件,调用案件处理函数.3*/
// Received when a messages is received (OTA) for this endpoint
 case AF_INCOMING_MSG_CMD:
 HAL_TOGGLE_LED1(); /*?*/
 SampleApp_MessageMSGCB( MSGpkt );
 
// h=i;
// num_to_str(h,Display_Buf, 4 , 16); 
// Gui_DrawFont_GBK16(0,96,BLACK,YELLOW,Display_Buf);
// i++;
 
 
 
 break; /*如果为数据接收事件,调用数据接收函数.3*/
// Received whenever the device changes state in the network
 case ZDO_STATE_CHANGE:
 SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
 if ( (SampleApp_NwkState == DEV_ZB_COORD)
 ||(SampleApp_NwkState == DEV_ROUTER)
 || (SampleApp_NwkState == DEV_END_DEVICE) ) /*如果为网络状态改变事件,则判断网络类型.5*/
 {
if(SampleApp_NwkState == DEV_END_DEVICE)
 {
 Gui_DrawFont_GBK16(0,16,RED,CYAN," EndDevice ");
 Gui_DrawFont_GBK16(0,48,BLACK,YELLOW,"ShortAddr: ");
 Gui_DrawFont_GBK16(0,64,BLACK,YELLOW, "Temp:");
 Gui_DrawFont_GBK16(0,80,BLACK,YELLOW, "parentSA:");
 
 
 } 
 else if(SampleApp_NwkState == DEV_ZB_COORD)
 { 
 Gui_DrawFont_GBK16(0,16,RED,CYAN," CooDevice ");
 }
 else
 {
 Gui_DrawFont_GBK16(0,16,RED,CYAN," RouterDevice ");
 Gui_DrawFont_GBK16(0,48,BLACK,YELLOW,"ShortAddr: ");
 Gui_DrawFont_GBK16(0,64,BLACK,YELLOW, "parentSA:");
 }
 
 
 if ( (SampleApp_NwkState == DEV_ROUTER)
 || (SampleApp_NwkState == DEV_END_DEVICE) )
 { 
 
 //显示设备地址shortAddr
 zb_GetDeviceInfo(ZB_INFO_SHORT_ADDR, &shortAddr);
 shortAddrNew = LO_UINT16(shortAddr) << 8; 
 shortAddrNew = HI_UINT16(shortAddr) |shortAddrNew; 
 num_to_str(shortAddrNew, Display_Buf, 4 , 16); 
 Gui_DrawFont_GBK16(94,48,BLACK,YELLOW,Display_Buf);
 
 
 //显示父节点
 zb_GetDeviceInfo(ZB_INFO_PARENT_SHORT_ADDR, &parentshortAddr);
 parentshortAddrNew = LO_UINT16(parentshortAddr) << 8; 
 parentshortAddrNew = HI_UINT16(parentshortAddr) |parentshortAddrNew; 
 num_to_str(parentshortAddrNew, Display_Buf, 4 , 16); 
 Gui_DrawFont_GBK16(94,80,BLACK,YELLOW,Display_Buf);
 
 
 
 // Start sending the periodic message in a regular interval.
 osal_start_timerEx( SampleApp_TaskID,
 SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
 SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); /*调用定时函数,进行定时事件处理.3*/
 
 }
 //显示PANID
 zb_GetDeviceInfo(ZB_INFO_PAN_ID, &PANID);
 num_to_str(PANID, Display_Buf, 4 , 16); 
 Gui_DrawFont_GBK16(94,32,BLACK,YELLOW,Display_Buf); 
 
 }
 else
 {
 // Device is no longer in the network
 }
 break;
default:
 break;
 }
// Release the memory
 osal_msg_deallocate( (uint8 *)MSGpkt ); /*释放空间*/
// Next - if one is available
 MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); /*调用数据接收函数接收数据*/
 
 h=i;
 num_to_str(h,Display_Buf, 4 , 16); 
 Gui_DrawFont_GBK16(0,96,BLACK,YELLOW,Display_Buf);
 i++;
 
 }
// return unprocessed events返回未处理的事件
 return (events ^ SYS_EVENT_MSG);
 }
// Send a message out - This event is generated by a timer发送消息-此事件由计时器生成
 // (setup in SampleApp_Init()).
 if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) /*如果为定时事件,进行定时事件处理*/
 {
 // Send the periodic message
 // SampleApp_SendPeriodicMessage();
 // HalUARTWrite(0,"UartInit OK\n", sizeof("UartInit OK\n"));//提示信息
 
 if(SampleApp_NwkState == DEV_ROUTER)
 {
 //sendDummyReport();
 sendReport();
 osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
 (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); /*循环调用定时函数.2*/ 
 }
 else{
 DHT11_TEST();
 sendReport();
 
 num_to_str(ucharT_data_H, Display_Buf, 4 , 10 ); 
 Gui_DrawFont_GBK16(94,64,BLACK,YELLOW, Display_Buf);
 // Setup to send message again in normal period (+ a little jitter)
 osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
 (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal_rand() & 0x00FF)) ); /*循环调用定时函数.2*/
// HAL_TOGGLE_LED1();
 // HAL_TOGGLE_LED2();
 }
 // return unprocessed events
 return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT);
 }
// Discard unknown events
 return 0;
}