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.

修改一下status change,可以检测入网失败。

在ZDApp.c中,新创建一个函数

/*********************************************************************
 * @fn          ZDApp_CountinueJoin()
 *
 * @brief       countinue join after a fail-joining
 *
 * @param       none
 *
 * @return      none
 */
void ZDApp_CountinueJoin(void)
{
  devState = DEV_INIT;
  osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );
  if(continueJoining)
  {
    ZDApp_NetworkInit( (uint16)(NWK_START_DELAY
                                + ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))));
  }
}

全局搜索有ZDApp_NetworkInit( (uint16)(NWK_START_DELAY+ ((uint16)(osal_rand()& EXTENDED_JOINING_RANDOM_MASK))))的调用,并替换为该函数。

在原先有if(countinueJoining)的地方,连同if(countinueJoining)全部替换为

          if((zdoDiscCounter > NUM_DISC_ATTEMPTS) && (NULL == pChosenNwk))
          {
#ifdef BLACK_LIST
            // Reset the black list as this when no wpan can be found
            zgBlackListInit( TRUE );
#endif
            zdoDiscCounter = 0;
            ZDApp_CountinueJoin();
          }
          else
          {
            zdoDiscCounter++;
#if defined ( MANAGED_SCAN )
            ZDApp_NetworkInit( MANAGEDSCAN_DELAY_BETWEEN_SCANS );
#else
            ZDApp_NetworkInit( (uint16)(BEACON_REQUEST_DELAY 
                                        + ((uint16)(osal_rand()& BEACON_REQ_DELAY_MASK))) );
            
#endif
          }

这样,就可以在status change中判断节点是否掉线,是否不能入网。只要检测到DEV_INIT,就说明上次入网失败。TI原版协议栈是基于每次入网必成功的思路,无法检测到入网失败的情况。配合黑名单使用,可以把入网失败的PANID加入黑名单中。