读取cc2530节点的设备类型、协调器、路由器、终端。

建立网络、加入网络流程分析

   协调器节点:在1-10  实验8 网络通信实验2 组播通信中

  1.  while(MSGpkt)  
  2.    {  
  3.      switch(MSGpkt->hdr.event)  
  4.     {  
  5.     case ZDO_STATE_CHANGE:  //建立网络后,设置事件     
  6.       GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//???????  
  7.       if(GenericApp_NwkState==DEV_ZB_COORD)//把该节点已初始化为协调器,则执行下面的  
  8.       {  
  9.        HalLedBlink(HAL_LED_2,0,50,500);    //LED2 闪烁   
  10.        aps_AddGroup(GENERICAPP_ENDPOINT,&GenericApp_Group);  //建立网路后,加入组。  
  11.        osal_start_timerEx(GenericApp_TaskID,SEND_TO_ALL_EVENT,5000);  
  12.       }  

  路由器节点: 在1-10  实验8 网络通信实验2 组播通信中

  1.  while(MSGpkt)  
  2.     {  
  3.       switch(MSGpkt->hdr.event)  
  4.       { 
  5.     case ZDO_STATE_CHANGE:   //加入网络后,加入族中  
  6.       GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//读取节点的设备类型   
  7.       if(GenericApp_NwkState==DEV_ROUTER)  
  8.       {  
  9.         aps_AddGroup(GENERICAPP_ENDPOINT,&GenericApp_Group); //加入组中  
  10.       }  
  11.       break;  

终端节点:1-5   实验4   串口通信2

  1.     while(MSGpkt)  
  2.     {  
  3.       switch(MSGpkt->hdr.event)  
  4.       {  
  5.     case ZDO_STATE_CHANGE:  
  6.       GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//读取节点的设备类型  
  7.       if(GenericApp_NwkState==DEV_END_DEVICE)  
  8.       {  
  9.         //当中断节点加入网络后使用osal_set_envent()函数设置SEND_DATA_EVENT事件,当事件发生时,执行事件处理函数  
  10.         osal_set_event(GenericApp_TaskID,SEND_DATA_EVENT);//??????????????????????????  
  11.       }  
  12.       break; 

而上面的 GenericApp_NwkState是devStates_t GenericApp_NwkState;这样定义的,用于//保存节点状态   

[cpp] view plain copy
 
  1. typedef enum  
  2. {  
  3.   DEV_HOLD,               // Initialized - not started automatically  
  4.   DEV_INIT,               // Initialized - not connected to anything  
  5.   DEV_NWK_DISC,           // Discovering PAN's to join  
  6.   DEV_NWK_JOINING,        // Joining a PAN  
  7.   DEV_NWK_REJOIN,         // ReJoining a PAN, only for end devices  
  8.   DEV_END_DEVICE_UNAUTH,  // Joined but not yet authenticated by trust center  
  9.   DEV_END_DEVICE,         // Started as device after authentication  
  10.   DEV_ROUTER,             // Device joined, authenticated and is a router  
  11.   DEV_COORD_STARTING,     // Started as Zigbee Coordinator  
  12.   DEV_ZB_COORD,           // Started as Zigbee Coordinator  
  13.   DEV_NWK_ORPHAN          // Device has lost information about its parent..  
  14. } devStates_t;  

刚开始时,都是在GenericApp_Init()函数中将GenericApp_NwkState=DEV_INIT。然后再通过哪几步转到为上面三种情况DEV_ZB_COORD、DEV_ROUTER、DEV_END_DEVICE中的一种。

TI协议栈是半开源的,网络层代码并不开源。运行于端口0的ZDO负责应用层用户程序和网络层之间的通信。

网络层的建立过程是由ZDO来实现的。网络建立后应用层会接受到ZDO_STATE_CHANGE消息。使用下面语句就可以读取当前网络的状态。

GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//读取节点的设备类型  

原文地址:https://www.cnblogs.com/yihujiu/p/5690390.html