ZDO_NWK_DISC_CNF 网络发现
if (devState != DEV_NWK_DISC) //如果设备的网络状态不是发现网络
{
}
#if !defined ( ZDO_COORDINATOR ) || defined ( SOFT_START )
#if defined ( MANAGED_SCAN )
// ZDO_SUCCESS确实发现网络了,那么就加入吧。可以分为两种方式加入
else if ( (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status == ZDO_SUCCESS) && (zdoDiscCounter > NUM_DISC_ATTEMPTS) )
#else
else if ( (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status == ZDO_SUCCESS) && (zdoDiscCounter++ > NUM_DISC_ATTEMPTS) )
#endif
{
//如果是首次加入,就直接加入!
if ( devStartMode == MODE_JOIN )
{
devState = DEV_NWK_JOINING;
ZDApp_NodeProfileSync((ZDO_NetworkDiscoveryCfm_t *)msgPtr);
if ( NLME_JoinRequest( ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->extendedPANID,
BUILD_UINT16( ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->panIdLSB, ((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->panIdMSB ),
((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->logicalChannel,
ZDO_Config_Node_Descriptor.CapabilityFlags ) != ZSuccess )
{
ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
+ ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))) );
}
}
//如果是再次加入,就rejion吧……
else if ( devStartMode == MODE_REJOIN )
{
devState = DEV_NWK_REJOIN;
if ( NLME_ReJoinRequest() != ZSuccess )
{
ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
+ ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))) );
}
}
//下面这个情况我就不明白是什么了,放到这里以后看
if ( ZDO_Config_Node_Descriptor.CapabilityFlags & CAPINFO_RCVR_ON_IDLE )
{
// The receiver is on, turn network layer polling off.
NLME_SetPollRate( 0 );
NLME_SetQueuedPollRate( 0 );
NLME_SetResponseRate( 0 );
}
}
else
{
//剩下的就是没有发现网络了,有一种情况就是协调器第一次没有发现网络,所以下面基本就是判断一个设备在没有发现网络能否以协调器启迪哦那个了……
#if defined ( SOFT_START ) && !defined ( VIRTKEY_SOFT_START )
//因为定义了SOFT_START,所以可以启动作为路由器的
#if defined ( MANAGED_SCAN )
if ( (softStartAllowCoord)
&& (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status != ZDO_SUCCESS )
&& (zdoDiscCounter > NUM_DISC_ATTEMPTS) )
#else
if ( (softStartAllowCoord)
&& (((ZDO_NetworkDiscoveryCfm_t *)msgPtr)->hdr.status != ZDO_SUCCESS )
&& (zdoDiscCounter++ > NUM_DISC_ATTEMPTS) )
#endif
{
ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_COORDINATOR;
devStartMode = MODE_HARD;
}
else if ( continueJoining == FALSE )
{
devState = DEV_HOLD; //如果不让加入 continueJoining == FALSE,则将设备状态挂起,等待触发
osal_stop_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT );
break; // Don't init
}
#endif
#if defined ( MANAGED_SCAN )
ZDApp_NetworkInit( MANAGEDSCAN_DELAY_BETWEEN_SCANS );
#else
if ( continueJoining )
{
ZDApp_NetworkInit( (uint16)(BEACON_REQUEST_DELAY //如果可以就初始化,调用start网络函数
+ ((uint16)(osal_rand()& BEACON_REQ_DELAY_MASK))) );
}
#endif
}
#endif // !ZDO_COORDINATOR
break;