zigbee組網(wǎng)過程.doc_第1頁
zigbee組網(wǎng)過程.doc_第2頁
zigbee組網(wǎng)過程.doc_第3頁
zigbee組網(wǎng)過程.doc_第4頁
zigbee組網(wǎng)過程.doc_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

int main( void ) / Initialize the operating system osal_init_system(); /初始化操作系統(tǒng) .OSAL.cuint8 osal_init_system( void ) / Initialize the system tasks. osalInitTasks(); / 初始化任務(wù) OSAL_SampleLight.cvoid osalInitTasks( void ) uint8 taskID = 0; ZDApp_Init( taskID+ ); zcl_Init( taskID+ ); zclSampleLight_Init( taskID+ ); ZDApp.cvoid ZDApp_Init( uint8 task_id ) ZDAppTaskID = task_id; ZDAppNwkAddr.addrMode = Addr16Bit;/地址模式為16bit短地址 ZDAppNwkAddr.addr.shortAddr = INVALID_NODE_ADDR;/短地址=0xFFFE (void)NLME_GetExtAddr(); /API函數(shù),用于得到64bit IEEE地址 afRegister( (endPointDesc_t *)&ZDApp_epDesc ); /為設(shè)備注冊端點(diǎn)0描述符 ZDO_Init(); /初始化ZDO 物件,并且設(shè)置設(shè)備 if ( devState != DEV_HOLD ) / 無HOLD_AUTO_START此項(xiàng)預(yù)編譯,所以devState = DEV_INIT ZDOInitDevice( 0 ); ZDApp_RegisterCBs();/注冊ZDO 消息,只有注冊了的消息才能以ZDO_CB_MSG 消息的形式發(fā)送給指定的任務(wù) ZDApp.cuint8 ZDOInitDevice( uint16 startDelay )uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;/0x01,初始化該設(shè)備新的網(wǎng)絡(luò)狀態(tài) #if defined ( NV_RESTORE ) networkStateNV = ZDApp_ReadNetworkRestoreState(); /讀出存儲(chǔ)的網(wǎng)絡(luò)狀態(tài) if ( networkStateNV = ZDO_INITDEV_RESTORED_NETWORK_STATE ) networkStateNV = ZDApp_RestoreNetworkState(); runtimeChannel = (uint32) (1L hdr.event )case ZDO_STATE_CHANGE:zclSampleLight_NwkState = (devStates_t)(MSGpkt-hdr.status);if ( (zclSampleLight_NwkState = DEV_ZB_COORD) |(zclSampleLight_NwkState = DEV_ROUTER) |(zclSampleLight_NwkState = DEV_END_DEVICE) )#ifdef LEDif (IsOffline)IsOffline = false; osal_stop_timerEx(zclSampleLight_TaskID, SAMPLELIGHT_OFFLINE_EVT);HAL_TURN_ON_LED1();路由器入網(wǎng)ZDObject.c void ZDO_StartDevice( byte logicalType, devStartModes_t startMode, byte beaconOrder, byte superframeOrder ) devState = DEV_NWK_DISC; ret = NLME_NetworkDiscoveryRequest( zgDefaultChannelList, zgDefaultStartingScanDuration ); 當(dāng)網(wǎng)絡(luò)層執(zhí)行加入網(wǎng)絡(luò)后,將給予ZDO層反饋信息:ZDApp.cZStatus_t ZDO_NetworkDiscoveryConfirmCB( byte ResultCount,networkDesc_t *NetworkList ) ZDApp_SendMsg( ZDAppTaskID,ZDO_NWK_DISC_CNF,sizeof(ZDO_NetworkDiscoveryCfm_t), (byte *)&msg );ZDApp.c void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr )switch ( msgPtr-event ) case ZDO_NWK_DISC_CNF: ZDApp_ChangeState( DEV_NWK_JOINING );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 ) ZDApp.c void ZDO_JoinConfirmCB( uint16 PanId, ZStatus_t Status ) ?ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_JOIN_IND, sizeof(osal_event_hdr_t), (byte*)NULL );ZDApp.c void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr ) switch ( msgPtr-event ) case ZDO_NWK_JOIN_IND: ZDApp_ProcessNetworkJoin(); break; ZDApp.c void ZDApp_ProcessNetworkJoin( void ) if ( (devState = DEV_NWK_JOINING) | (devState = DEV_NWK_ORPHAN) &(ZDO_Config_Node_Descriptor.LogicalType = NODETYPE_ROUTER) )if ( nwkStatus = ZSuccess ) osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );NLME_StartRouterRequest( 0, 0, false );ZDApp.c UINT16 ZDApp_event_loop( byte task_id, UINT16 events ) . if ( events & ZDO_STATE_CHANGE_EVT )/ZDO狀態(tài)改變事件 ZDO_UpdateNwkStatus( devState ); ZDObject.c void ZDO_UpdateNwkStatus( devStates_t state ) if (pItem-epDesc-endPoint != ZDO_EP)zdoSendStateChangeMsg(state, *(pItem-epDesc-task_id);ZDAppNwkAddr.addr.shortAddr = NLME_GetShortAddr();(void)NLME_GetExtAddr(); / Load the saveExtAddr pointer.終端入網(wǎng) ZDObject.c void ZDO_StartDevice( byte logicalType, devStartModes_t startMode, byte beaconOrder, byte superframeOrder ) devState = DEV_NWK_DISC; ret = NLME_NetworkDiscoveryRequest( zgDefaultChannelList, zgDefaultStartingScanDuration ); 當(dāng)網(wǎng)絡(luò)層執(zhí)行加入網(wǎng)絡(luò)后,將給予ZDO層反饋信息ZDApp.c ZStatus_t ZDO_NetworkDiscoveryConfirmCB( byte ResultCount,networkDesc_t *NetworkList ) ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_DISC_CNF,sizeof(ZDO_NetworkDiscoveryCfm_t), (byte *)&msg ); ZDApp.c void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr ) switch (msgPtr-event)case ZDO_NWK_DISC_CNF: 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 ) ZDApp.c void ZDO_JoinConfirmCB( uint16 PanId, ZStatus_t Status ) ZDApp_SendMsg( ZDAppTaskID, ZDO_NWK_JOIN_IND, sizeof(osal_event_hdr_t), (byte*)NULL );ZDApp.c void ZDApp_ProcessOSALMsg( osal_event_hdr_t *msgPtr ) switch ( msgPtr-event ) case ZDO_NWK_JOIN_IND: ZDApp_ProcessNetworkJoin(); ZDApp.c void ZDApp_ProcessNetworkJoin( void ) osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT ) ZDApp.c UINT16 ZDApp_event_loop( byte task_id, UINT16 events ) if ( events & ZDO_STATE_CHANGE_EVT )/ZDO狀態(tài)改變事件 ZDO_UpdateNwkStatus( devState ); ZDObject.c void ZDO_UpdateNwkStatus( devStates_t state ) while (pItem != NULL)if (pItem-epDesc-endPoint != ZDO_EP)zdoSendStateChangeMsg(state, *(pItem-epDesc-task_id);pItem = pItem-nextDesc;ZDAppNwkAddr.addr.shortAddr = NLME_GetShortAddr();(void)NLME_GetExtAddr(); / Load the saveExtAddr pointer.zcl_samplelight.cuint16 zclSampleLight_event_loop( uint8 task_id, uint16 events )case ZDO_STATE_CHANGE:zclSampleLight_NwkState = (devStates_t)(MS

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論