協(xié)調(diào)器自啟動模式_第1頁
協(xié)調(diào)器自啟動模式_第2頁
協(xié)調(diào)器自啟動模式_第3頁
協(xié)調(diào)器自啟動模式_第4頁
協(xié)調(diào)器自啟動模式_第5頁
已閱讀5頁,還剩11頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、使用的協(xié)議棧版本信息:ZigBee2006ZStack-1.4.3-1.2.1Zigbee網(wǎng)絡(luò)設(shè)備啟動流程一協(xié)調(diào)器(自啟動模式)一以SampleApp的協(xié)調(diào)器為例.1、協(xié)調(diào)器預(yù)編譯信息通過 project-options-c/c+compiler-extraOptions可以看至U協(xié)調(diào)器所帶的配置文件為:-f $PROJ_DIR$ ToolsCC2430DBf8wCoord .cfg I-f $PROJ_DIR$ ToolsCC2430DBf8wConfig .cfg即編譯了 ZDO_COORDINATOR 和 RTR_NWK通過 project-options-c/c+compiler-Pr

2、eprocessor-Defined symbols可以看到協(xié)調(diào)器預(yù)編譯包含了:CC2430EB; ZTOOL_P1; MT_TASK; LCD_SUPPORTED=DEBUG; MANAGED_SCAN沒有編譯 HOLD_AUTO_START 和 SOFT_START2、具體流程main()-osal_init_system()-osalInitTasks()-ZDApp_Init()進入 ZDApp_Init()函數(shù):*void ZDApp_Init( byte task_id ) 一 一uint8 capabilities;/ Save the task IDZDAppTaskID =

3、task_id;/ Initialize the ZDO global device short address storageZDAppNwkAddr.addrMode = Addr16Bit;ZDAppNwkAddr.addr .shortAddr =INVALID_NODE_ADDR; /OxFFFE(void)NLME_GetExtAddr(); / Load the saveExtAddr pointer./ Check for manualHold Auto Start檢測到有手工設(shè)置SW_1則會設(shè)置devState = DEV_HOLD,從而避開網(wǎng)絡(luò)初始化ZDAppCheckFo

4、rHoldKey();II Initialize ZDO items and setup the device - type of device to createZDO_lnit(); 通過判斷預(yù)編譯來開啟一些函數(shù)功能II Register the endpoint description with the AFII This task doesnt have a Simple description, but we still needII to register the endpoint.afRegister( (endPointDesc_t *)& ZDApp_epDesc );#if

5、 defined( ZDO_USERDESC_RESPONSE )ZDApp_InitUserDesc();#endif II ZDO_USERDESC_RESPONSEII set broadcast address mask to support broadcast filtering NLME_GetRequest(nwkCapabilityInfo, 0, & capabilities);NLME_SetBroadcastFilter( capabilities );II Start the device?if ( devState != DEV_HOLD )ZDOInitDevice

6、( 0 );elseII Blink LED to indicate HOLD_STARTHalLedBlink ( HAL_LED_4, 0, 50, 500 );ZDApp_RegisterCBs(); _*協(xié)調(diào)器沒有編譯HOLD_AUTO_START,也沒有手工設(shè)置SW_1,初始化 devState = DEV_INIT(參見基本問題說明 3).因此直接在ZDApp_Init() 中進入ZDOInitDevice( 0 )開啟設(shè)備.*uint8 ZDOInitDevice( uint16 startDelay )初始化設(shè)備網(wǎng)絡(luò)狀態(tài)為ZDO_INITDEV_NEW_NETWORK_STAT

7、E:新的網(wǎng)絡(luò)狀態(tài)/可能意味著ZCD_NV_STARTUP_OPTION 不能恢復(fù),或沒有任何網(wǎng)絡(luò)狀態(tài)恢復(fù)uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE; uint16 extendedDelay = 0;devState = DEV_INIT; / Remove the Hold state/ Initialize leave control logicII函數(shù)讀取 NV 項目 ZCD_NV_LEAVE_CTRL 的值,ZDApp_LeaveCtrl指向這個值ZDApp_LeaveCtrlInit();II Check leave co

8、ntrol reset settingsZDApp_LeaveCtrlStartup( & devState, & startDelay );II Leave may make the hold state come backII以上兩個函數(shù)設(shè)置了對設(shè)備離開時的控制,如果有延時則延時,沒有則II把設(shè)備狀態(tài)設(shè)為 DEV_HOLDif ( devState = DEV_HOLD )ZDO_INITDEV_LEAVE_NOT_STARTED:該設(shè)備沒有在網(wǎng)絡(luò)中,下次調(diào)用才啟用return ( ZDO_INITDEV_LEAVE_NOT_STARTED );II Dont join -(one tim

9、e).#if defined ( NV_RESTORE )II Get Keypad directly to see if a reset nv is needed II Hold down the SW_BYPASS_NV key (defined in OnBoard h)II while booting引導(dǎo))to skip past NV Restore.if ( HalKeyRead() = SW_BYPASS_NV )IISW_BYPASS_NV按鍵處于按下狀態(tài)時,則避開網(wǎng)絡(luò)層的NV存儲networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE; I

10、I設(shè)備網(wǎng)絡(luò)狀態(tài)為新的網(wǎng)絡(luò)狀態(tài)elseII Determine if NV should be restored/函數(shù)返回的設(shè)備網(wǎng)絡(luò)狀態(tài)要么是新的網(wǎng)絡(luò)狀態(tài);要么是恢復(fù)的網(wǎng)絡(luò)狀態(tài);以此來確定要不要讀取NV里相應(yīng)條目來恢復(fù)網(wǎng)絡(luò)先前狀態(tài)networkStateNV = ZDApp_ReadNetworkRestoreState(); _如果設(shè)備的網(wǎng)絡(luò)狀態(tài)為恢復(fù)的網(wǎng)絡(luò)狀態(tài)if ( networkStateNV = ZDO_INITDEV_RESTORED_NETWORK_STATE )/恢復(fù)設(shè)備先前的網(wǎng)絡(luò)狀態(tài)參數(shù)并且設(shè)置 devStartMode = MODE_RESUME!networkStateNV

11、 = ZDApp_RestoreNetworkState(); _else /如果設(shè)備的網(wǎng)絡(luò)狀態(tài)為新的網(wǎng)絡(luò)狀態(tài) ,在下面進行處理II Wipe out(清除)the network state in NVNLME_InitNV();NLME_SetDefaultNV(); 設(shè)置默認(rèn) NV 條目#endifII如果設(shè)備的網(wǎng)絡(luò)狀態(tài)為新的網(wǎng)絡(luò)狀態(tài)if ( networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE ) II根據(jù)預(yù)編譯來設(shè)置設(shè)備新的網(wǎng)絡(luò)狀態(tài)參數(shù)ZDAppDetermineDeviceType();II Only delay if joining net

12、work - not restoring network state extendedDelay = (uint16)(NWK_START_DELAY + startDelay) + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK);II Initialize device security ZDApp_SecInit( networkStateNV );II Trigger the network start ZDApp_NetworkInit( extendedDelay );return ( networkStateNV );*分兩種情況:(1)如

13、果協(xié)調(diào)器預(yù)編譯了 NV_RESTORE,且函數(shù)ZDApp_ReadNetworkRestoreState()返回值為ZDO_INITDEV_RESTORED_NETWORK_STATE,貝 V進入ZDApp_RestoreNetworkState()里設(shè)置ZDO_Config_Node_Descriptor .LogicalType = NODETYPE_COORDINATOR 和 devStartMode = MODE_RESUME. *uint8 ZDApp_RestoreNetworkState( void ) _/ Are we a coordinator/設(shè)備的網(wǎng)絡(luò)狀態(tài)為恢復(fù)的網(wǎng)絡(luò)狀

14、態(tài)則進入這個函數(shù)進行恢復(fù)先判斷如果短地址為0則設(shè)置設(shè)備邏輯類型為協(xié)調(diào)器且devStartMode = MODE_RESUMEII否貝V設(shè)置 devStartMode = MODE_RESUMEZDAppNwkAddr .addr .shortAddr = NLME_GetShortAddr();if ( ZDAppNwkAddr.addr.shortAddr = 0 ) II女口果短地址是 0,即協(xié)調(diào)器ZDO_Config_Node_Descriptor.LogicalType =NODETYPE_COORDINATOR; /! devStartMode = MODE_RESUME; IIMO

15、DE_RESUME!* (2)如果協(xié)調(diào)器沒有預(yù)編譯 NV_RESTORE,networkStateNV=ZDO_INITDEV_NEW_NETWORK_STATE,但由于協(xié)調(diào)器編譯了ZDO_COORDINATOR 而沒有編譯 SOFT_START,因此 ZDAppDetermineDeviceType()不起作用因此 ZDO_Config_Node_Descriptor.LogicalType 禾口 devStartMode 這兩個關(guān) 鍵參數(shù)保持初始化時的值:ZDO_Config_Node_Descriptor .LogicalType =NODETYPE_COORDINATOR( 見基本問題

16、說明 6) devStartMode = MODE_HARD(見基本問題說明 4) 對于協(xié)調(diào)器,這兩種情況最終都是確定兩個關(guān)鍵設(shè)備網(wǎng)絡(luò)狀態(tài)參數(shù)的值 對本例的SampleApp的協(xié)調(diào)器,沒有編譯NV_RESTORE,因此屬于情況(2).然后調(diào)用ZDApp_NetworkInit()啟動網(wǎng)絡(luò):*void ZDApp_NetworkInit( uint16 delay ) _if ( delay )/ Wait awhile before starting the deviceosal_start_timerEx( ZDAppTaskID, ZDO_NETWORK_INIT, delay );els

17、e osal_set_event( ZDAppTaskID, ZDO_NETWORK_INIT );*通過觸發(fā)ZDAppTaskID的ZDO_NETWORK_INIT事件來看下對ZDO_NETWORK_INIT事件的處理:*UINT16 ZDApp_event_loop( byte task_id, UINT16 events )if ( events & ZDO_NETWORK_INIT )/ Initialize apps and start the networkdevState = DEV_INIT;ZDO_StartDevice( (uint8)ZDO_Config_Node_Des

18、criptor .LogicalTyp e, devStartMode,DEFAULT_BEACON_ORDER,DEFAULT_SUPERFRAME_ORDER );/ Return unprocessed eventsreturn (events A ZDO_NETWORK_INIT); * 可以看到調(diào)用了ZDO_StartDevice( (uint8)ZDO_Config_Node_Descriptor.LogicalType, devStartMode,DEFAULT_BEACON_ORDER, DEFAULT_SUPERFRAME_ORDER );這里設(shè)備網(wǎng)絡(luò)狀態(tài)參數(shù):ZDO_Con

19、fig_Node_Descriptor .LogicalType =NODETYPE_COORDINATORdevStartMode = MODE_HARD且協(xié)調(diào)器編譯了 ZDO_COORDINATOR*void ZDO_StartDevice( byte logicalType, devStartModes_t startMode, byte beaconOrder, byte superframeOrder )ZStatus_t ret;ret = ZUnsupportedMode;#if defined(ZDO_COORDINATOR)if ( logicalType = NODETYP

20、E_COORDINATOR )if ( startMode = MODE_HARD )MODE_HARDdevState = DEV_COORD_STARTING; /Started as Zigbee Coordinator建網(wǎng)ret = NLME_NetworkFormationRequest( zgConfigPANID, zgDefaultChannelList,zgDefaultStartingScanDuration, beaconOrder,superframeOrder, false );else if ( startMode = MODE_RESUME ) MODE_RESU

21、ME/ Just start the coordinator devState = DEV_COORD_STARTING; ret = NLME_StartRouterRequest( beaconOrder, beaconOrder, false );else/錯誤,未知啟動模式#if defined( LCD_SUPPORTED ) HalLcdWriteScreen( StartDevice ERR, MODE unknown); ClearScreen();Print8(HAL_LCD_LINE_1,10,StartDevice ERR,1); Print8(HAL_LCD_LINE_

22、2,10,MODE unknown,;#endif#endif / !ZDO_COORDINATOR#if !defined ( ZDO_COORDINATOR ) | defined( SOFT_START )if ( logicalType = NODETYPE_ROUTER | logicalType = NODETYPE_DEVICE )if ( (startMode = MODE_JOIN) | (startMode = MODE_REJOIN) devState = DEV_NWK_DISC; /Discovering PANs to join#if defined( MANAGE

23、D_SCAN ) ZDOManagedScan_Next(); ret =NLME_NetworkDiscoveryRequest( managedScanChannelMask, BEACON_ORDER_15_MSEC );#elseret = NLME_NetworkDiscoveryRequest( zgDefaultChannelList, zgDefaultStartingScanDuration );#endifelse if ( startMode = MODE_RESUME ) /MODE_RESUME 恢復(fù) if ( logicalType = NODETYPE_ROUTE

24、R )ZMacScanCnf_t scanCnf; devState = DEV_NWK_ORPHAN;scanCnf.hdr .Status = ZSUCCESS; scanCnf.ScanType = ZMAC_ORPHAN_SCAN; scanCnf.UnscannedChannels = 0;scanCnf.ResultListSize = 0;nwk_ScanJoiningOrphan(&scanCnf);ret = ZSuccess;elsedevState = DEV_NWK_ORPHAN; 孤兒ret = NLME_OrphanJoinRequest( zgDefaultCha

25、nnelList, zgDefaultStartingScanDuration );else#if defined( LCD_SUPPORTED )II HalLcdWriteScreen( StartDevice ERR, MODE unknown); Print8(HAL_LCD_LINE_1,10,StartDevice ERR,1); Print8(HAL_LCD_LINE_2,10,MODE unknown,;#endifII#endif II!ZDO COORDINATOR | SOFT_START if ( ret != ZSuccess )osal_start_timerEx(

26、ZDAppTaskID, ZDO_NETWORK_INIT, NWK_RETRY_DELAY );*通過參數(shù)可知協(xié)調(diào)器調(diào)用NLME_NetworkFormationRequest( zgConfigPANID, zgDefaultChannelList,zgDefaultStartingScanDuration, beaconOrder, superframeOrder, false )進行網(wǎng)絡(luò)的組建.而對NLME_NetworkFormationRequest()的調(diào)用會產(chǎn)生一個回調(diào)函數(shù)ZDO_NetworkFormationConfirmCB()(見主要函數(shù)說明 3),來看下:*void

27、ZDO_NetworkFormationConfirmCB( ZStatus_t Status ) 一 一#if defined(ZDO_COORDINATOR) nwkStatus = (byte)Status; if ( Status = ZSUCCESS ) / LED on shows Coordinator startedHalLedSet ( HAL_LED_3, HAL_LED_MODE_ON );/ LED off forgets HOLD_AUTO_STARTHalLedSet (HAL_LED_4, HAL_LED_MODE_OFF);#if defined ( ZBIT

28、)SIM_SetColor(0xd0ffd0);#endifif ( devState = DEV_HOLD )/ Began with HOLD_AUTO_START devState = DEV_COORD_STARTING;#if defined(BLINK_LEDS)elseHalLedSet ( HAL_LED_3, HAL_LED_MODE_FLASH );/ FlashLED to show failure#endifosal_set_event( ZDAppTaskID, ZDO_NETWORK_START );#endif /ZDO_COORDINATOR*如果Status返

29、回ZSUCCESS,建立網(wǎng)絡(luò)成功,通過一些燈亮來來指示;不成功則通過閃爍燈來指示最后觸發(fā)任務(wù)ZDAppTaskID的ZDO_NETWORK_START 事件,看下對 ZDO_NETWORK_START 的處理:*#if defined (RTR_NWK)if ( events & ZDO_NETWORK_START )ZDApp_NetworkStartEvt();II Return unprocessed events return (events A ZDO_NETWORK_START);*調(diào)用了 ZDApp_NetworkStartEvt()*void ZDApp_NetworkStar

30、tEvt( void ) _if ( nwkStatus = ZSuccess )/網(wǎng)絡(luò)建立成功/ Successfully started a ZigBee networkif ( devState = DEV_COORD_STARTING )devState = DEV_ZB_COORD; osal_pwrmgr_device( PWRMGR_ALWAYS_ON );osal_set_event( ZDAppTaskID, ZDO_STATE_CHANGE_EVT );else/網(wǎng)絡(luò)建立不成功,則增加能量閥值重新建網(wǎng)/ Try again with a higher energy thre

31、shold !if ( ( NLME_GetEnergyThreshold() + ENERGY_SCAN_INCREMENT ) epDesc-endPoint != ZDO_EP ) _msgPtr = (osal_event_hdr_t *)osal_msg_allocate( bufLen );if ( msgPtr )msgPtr-event = ZDO_STATE_CHANGE; / Command ID msgPtr-status = (byte)state;osal_msg_send( *(epDesc-epDesc-task_id), (byte *)msgPtr )/ 發(fā)往

32、應(yīng)用任務(wù)epDesc = epDesc-nextDesc;*對SampleApp的協(xié)調(diào)器來說,這里觸發(fā)應(yīng)用任務(wù)SampleApp_TasklD的 ZDO_STATE_CHANGE 事件,看下對 ZDO_STATE_CHANGE 的處理:*case ZDO_STATE_CHANGE:SampleApp_NwkState = (devStates_t)(MSGpkt-hdr.status); / 獲取設(shè)備當(dāng)前狀態(tài)if ( (SampleApp_NwkState = DEV_ZB_COORD)| (SampleApp_NwkState = DEV_rOuTER)| (SampleApp_NwkState = DEV_E

溫馨提示

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

評論

0/150

提交評論