判断网络状态:
一、
1、extern devStates_t devState;(在ZDApp.h中声明)
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;
2、HAL_LED_3灯的状态。
亮表示设备成为Coo(ZDO_NetworkFormationConfirmCB函数)或者Route(ZDO_StartRouterConfirmCB函数)成功、加网成功(ZDO_JoinConfirmCB函数),
闪烁表示失败。在ZDApp.c文件中设值。
二、
1、在主task中注册ZDO_STATE_CHANGE消息的事件函数。
2、在消息事件相应函数中可以获取新状态,用于判断设备状态。
uint16 ***_event_loop(()
{
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( ***_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
case ZDO_STATE_CHANGE:
***_NwkState = (devStates_t)(MSGpkt->hdr.status);
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( ***_TaskID );
}
// Return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
}
注意:只有EndDevice设备才能判断是否是孤儿节点,router设备是不能的
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
都一样的,协议里边实现的!
一周热门 更多>