[Zigbee]Z-stack Zed 失去節點之後的流程

1.終端節點在丟失父節點後會進入ZDO_SyncIndicationCB,然後執行ZDO_StartDevice以及NLME_OrphanJoinRequest重新加入網絡。

第一步:

void ZDO_SyncIndicationCB( uint8 type, uint16 shortAddr )
{
  (void)shortAddr;  // Remove this line if this parameter is used.

  if ( ZSTACK_END_DEVICE_BUILD
    || (ZSTACK_ROUTER_BUILD && BUILD_FLEXABLE && ((_NIB.CapabilityFlags & ZMAC_ASSOC_CAPINFO_FFD_TYPE) == 0)))
  {
    if ( type == 1 && retryCnt == 0 )
    {
      // We lost contact with our parent.  Clear the neighbor Table.
      nwkNeighborInitTable();
      
      //If we are Factory new, then report fail on association
      if(!bdb_isDeviceNonFactoryNew())
      {
        bdb_nwkAssocAttemt(FALSE);
      }
#if (ZG_BUILD_ENDDEVICE_TYPE)
      else
      {
        //We lost our parent
        bdb_parentLost();
      }
#endif
    }
  }
}
第二步:在bdb_parentLost();中會進入bdb_reportCommissioningState

            uint8 temp = FALSE;
            //If fail, then restore poll rate
            NLME_SetPollRate(POLL_RATE);
            bdbAttributes.bdbCommissioningStatus = BDB_COMMISSIONING_NO_NETWORK;
            bdbCommissioningModeMsg.bdbCommissioningMode = BDB_COMMISSIONING_NWK_STEERING;
            bdbCommissioningProcedureState.bdbCommissioningState = BDB_COMMISSIONING_STATE_START_RESUME;
            bdbAttributes.bdbCommissioningMode &= ~BDB_COMMISSIONING_MODE_NWK_STEERING;
            
            //Turn off the radio
            ZMacSetReq(ZMacRxOnIdle, &temp);
            //Set the device to FN, to start as new for subsequent attempts
            bdb_setFN();
            NLME_ResetRequest();
            ZDApp_ChangeState( DEV_HOLD );
            
            //Free the list of nwk discovered
            while(pBDBListNwk)
            {
              bdb_nwkDescFree(pBDBListNwk);
            }
第三步:在UINT16 ZDApp_event_loop( uint8 task_id, UINT16 events )

         
UINT16 ZDApp_event_loop( uint8 task_id, UINT16 events )
 if( events & ZDO_REJOIN_BACKOFF )
  {
    if( devState == DEV_NWK_BACKOFF )
    {
      ZDApp_ChangeState(DEV_NWK_DISC);
      // Restart scan for rejoin
      ZDApp_StartJoiningCycle();
      osal_start_timerEx( ZDAppTaskID, ZDO_REJOIN_BACKOFF, zgDefaultRejoinScan );
    }
    else
    {
      // Rejoin backoff, silent period
      ZDApp_ChangeState(DEV_NWK_BACKOFF);
      ZDApp_StopJoiningCycle();
      osal_start_timerEx( ZDAppTaskID, ZDO_REJOIN_BACKOFF, zgDefaultRejoinBackoff );
    }




發佈了67 篇原創文章 · 獲贊 22 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章