读取cc2530节点的设备类型、协调器、路由器、终端。
建立网络、加入网络流程分析
协调器节点:在1-10 实验8 网络通信实验2 组播通信中
- while(MSGpkt)
- {
- switch(MSGpkt->hdr.event)
- {
- case ZDO_STATE_CHANGE: //建立网络后,设置事件
- GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//???????
- if(GenericApp_NwkState==DEV_ZB_COORD)//把该节点已初始化为协调器,则执行下面的
- {
- HalLedBlink(HAL_LED_2,0,50,500); //LED2 闪烁
- aps_AddGroup(GENERICAPP_ENDPOINT,&GenericApp_Group); //建立网路后,加入组。
- osal_start_timerEx(GenericApp_TaskID,SEND_TO_ALL_EVENT,5000);
- }
路由器节点: 在1-10 实验8 网络通信实验2 组播通信中
- while(MSGpkt)
- {
- switch(MSGpkt->hdr.event)
- {
- case ZDO_STATE_CHANGE: //加入网络后,加入族中
- GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//读取节点的设备类型
- if(GenericApp_NwkState==DEV_ROUTER)
- {
- aps_AddGroup(GENERICAPP_ENDPOINT,&GenericApp_Group); //加入组中
- }
- break;
终端节点:1-5 实验4 串口通信2
- while(MSGpkt)
- {
- switch(MSGpkt->hdr.event)
- {
- case ZDO_STATE_CHANGE:
- GenericApp_NwkState=(devStates_t)(MSGpkt->hdr.status);//读取节点的设备类型
- if(GenericApp_NwkState==DEV_END_DEVICE)
- {
- //当中断节点加入网络后使用osal_set_envent()函数设置SEND_DATA_EVENT事件,当事件发生时,执行事件处理函数
- osal_set_event(GenericApp_TaskID,SEND_DATA_EVENT);//??????????????????????????
- }
- break;
而上面的 GenericApp_NwkState是devStates_t GenericApp_NwkState;这样定义的,用于//保存节点状态
- typedef enum
- {
- DEV_HOLD, // Initialized - not started automatically
- DEV_INIT, // Initialized - not connected to anything
- DEV_NWK_DISC, // Discovering PAN's to join
- DEV_NWK_JOINING, // Joining a PAN
- DEV_NWK_REJOIN, // ReJoining a PAN, only for end devices
- DEV_END_DEVICE_UNAUTH, // Joined but not yet authenticated by trust center
- DEV_END_DEVICE, // Started as device after authentication
- DEV_ROUTER, // Device joined, authenticated and is a router
- DEV_COORD_STARTING, // Started as Zigbee Coordinator
- DEV_ZB_COORD, // Started as Zigbee Coordinator
- DEV_NWK_ORPHAN // Device has lost information about its parent..
- } 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);//读取节点的设备类型