Simple API協(xié)議應(yīng)用程序分析_第1頁(yè)
Simple API協(xié)議應(yīng)用程序分析_第2頁(yè)
Simple API協(xié)議應(yīng)用程序分析_第3頁(yè)
Simple API協(xié)議應(yīng)用程序分析_第4頁(yè)
Simple API協(xié)議應(yīng)用程序分析_第5頁(yè)
已閱讀5頁(yè),還剩10頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、無(wú)線Zigbee網(wǎng)絡(luò)協(xié)議棧BasicRF API說(shuō)明Basic RF協(xié)議 其采用IEEE802.15.4MAC協(xié)議兼容的數(shù)據(jù)與應(yīng)答數(shù)據(jù)包(分組),但不提供完整的MAC層支持,只用于兩個(gè)節(jié)點(diǎn)之間的通信。它是IEEE802.15.4協(xié)議標(biāo)準(zhǔn)的子集:(1) 不支持網(wǎng)絡(luò)匹配、掃描和信標(biāo)(2) 無(wú)協(xié)調(diào)器和端設(shè)備等的分類,支持點(diǎn)對(duì)點(diǎn)通信,通信節(jié)點(diǎn)對(duì)等(3) 不支持?jǐn)?shù)據(jù)包(分組)重傳Basic RF的應(yīng)用(以下函數(shù)的定義和功能具體說(shuō)明,參考swru214a - CC2530軟件實(shí)例用戶手冊(cè).pdf文件)1 啟動(dòng)(1) 確保開發(fā)板上外圍接口和無(wú)線電接口初始化,調(diào)用halBoardInit()函數(shù)完成(2) 創(chuàng)

2、建basicRfCfg_t數(shù)據(jù)結(jié)構(gòu)體,并初始化其成員變量;(3) 調(diào)用basicRfInit()對(duì)數(shù)據(jù)包(分組)協(xié)議進(jìn)行初始化。2 發(fā)送數(shù)據(jù)(1) 創(chuàng)建一個(gè)發(fā)送緩沖區(qū),最大為103字節(jié);(2) 調(diào)用basicRfSendPacket()函數(shù)發(fā)送數(shù)據(jù),檢測(cè)函數(shù)返回值獲取發(fā)送狀態(tài);3 接收數(shù)據(jù)(1) 調(diào)用basicRfPacketIsReady()函數(shù),等待數(shù)據(jù)接收(2) 調(diào)用basicRfReceive()函數(shù)來(lái)接收數(shù)據(jù)包,并負(fù)責(zé)分配一個(gè)足夠大的緩沖區(qū)來(lái)存儲(chǔ)數(shù)據(jù)包信息,其中2個(gè)字節(jié)用來(lái)存儲(chǔ)RSSI值(接收信號(hào)強(qiáng)度值)。數(shù)據(jù)結(jié)構(gòu)typedef struct uint16 myAddr; 短地址 u

3、int16 panId; 所在域網(wǎng)ID uint8 channel; 通信信道 uint8 ackRequest; 應(yīng)答請(qǐng)求設(shè)置(True或False); #ifdef SECURITY_CCM 安全設(shè)定(可選) uint8* securityKey; uint8* securityNonce; #endif basicRfCfg_t; 操作流程HalBoardInit()初始化節(jié)點(diǎn)硬件外圍接口和通信接口basicRfInit()初始化數(shù)據(jù)包結(jié)構(gòu)及通信設(shè)置basicRfSendPacket()發(fā)送數(shù)據(jù)basicRfReceive()接收數(shù)據(jù)basicRfPacketIsReady()接收數(shù)據(jù)b

4、asicRfCfg_t結(jié)構(gòu)發(fā)送接收無(wú)線Zigbee網(wǎng)絡(luò)協(xié)議棧Simple API分析網(wǎng)絡(luò)設(shè)備類型:(1) 協(xié)調(diào)器協(xié)調(diào)器是啟動(dòng)Zigbee網(wǎng)絡(luò)的設(shè)備,它是網(wǎng)絡(luò)中的一個(gè)設(shè)備,其選擇信道和網(wǎng)絡(luò)標(biāo)號(hào)ID,然后啟動(dòng)網(wǎng)絡(luò)。協(xié)調(diào)器可選用作為輔助安全設(shè)置和網(wǎng)絡(luò)中應(yīng)用層的綁定。協(xié)調(diào)器的主要作用是啟動(dòng)和配置網(wǎng)絡(luò),當(dāng)網(wǎng)絡(luò)建立完成后,協(xié)調(diào)器的操作和路由器類似?;赯igbee網(wǎng)絡(luò)的分布式特性,網(wǎng)絡(luò)的后繼操作不再依靠協(xié)調(diào)器。(2) 路由器路由器主要有兩個(gè)作用:(1)允許其他設(shè)備加入網(wǎng)絡(luò);(2)多調(diào)通信;(3)輔助電池供電的子設(shè)備通信。通常情況下,路由器需要時(shí)時(shí)激活運(yùn)行,因此需要主電源供電。(3) 端點(diǎn)設(shè)備Zigbee

5、Stack API:尋址方式:(1) 長(zhǎng)地址(64bit),又名MAC地址,Extended 地址,物理地址(2) 短地址(16bit),又名網(wǎng)絡(luò)地址,邏輯地址怎樣是一臺(tái)設(shè)備加入網(wǎng)絡(luò) 網(wǎng)絡(luò)中每臺(tái)設(shè)備都具有一組配置參數(shù),分為網(wǎng)絡(luò)參數(shù)和設(shè)備參數(shù)。同一網(wǎng)絡(luò)中的設(shè)備必須配置相同的網(wǎng)絡(luò)參數(shù),而設(shè)備參數(shù)可因功能各異而不相同。ZCD_NV_LOGICAL_TYPEZCD_NV_CHANLISTZCD_NV_PANID協(xié)調(diào)器路由器端設(shè)備組建網(wǎng)絡(luò)加入網(wǎng)絡(luò)加入網(wǎng)絡(luò)怎樣綁定設(shè)備綁定是網(wǎng)絡(luò)設(shè)備在應(yīng)用層中的邏輯連接。(1) 若綁定對(duì)象的長(zhǎng)地址已知,采用zb_BindDevice()函數(shù)建立綁定(2) 若綁定對(duì)象的長(zhǎng)地址

6、未知,目標(biāo)設(shè)備通過(guò)zb_AllowBindResponse()函數(shù)處于等待綁定狀態(tài),源設(shè)備啟動(dòng)zb_BindDevice()函數(shù)建立綁定。 注意:綁定只能創(chuàng)建在兩個(gè)互補(bǔ)設(shè)備之間,即它們必須在描述器中注冊(cè)有相同的命令I(lǐng)D,而且一個(gè)為輸出,另一個(gè)為輸入。怎樣開發(fā)一個(gè)私有的應(yīng)用(1) 劃分應(yīng)用中的設(shè)備類型(2) 劃分應(yīng)用中設(shè)備中相互交換的命令,并為命令賦予一個(gè)標(biāo)識(shí)號(hào)ID(3) 針對(duì)每個(gè)命令,劃分出設(shè)備對(duì)其是輸入還是輸出(4) 為每個(gè)設(shè)備建立一個(gè)描述結(jié)構(gòu)(5) 為每個(gè)命令確定消息格式(6) 為每個(gè)設(shè)備編寫應(yīng)用程序(7) 確定一個(gè)綁定策略以便設(shè)備能夠正確交換分組Switch收集器SenSor控制器路由器

7、/協(xié)調(diào)器端設(shè)備端設(shè)備路由器/協(xié)調(diào)器Zigbee網(wǎng)絡(luò)應(yīng)用實(shí)例流程控制器作為協(xié)調(diào)器啟動(dòng)網(wǎng)絡(luò)控制器允許綁定zb_AllowBind()開關(guān)端設(shè)備請(qǐng)求建立綁定zb_BindDevice()控制器收到綁定請(qǐng)求處理zb_AllowBindConfirm()開關(guān)端設(shè)備綁定建立完成處理zb_BindConfirm()開關(guān)端設(shè)備發(fā)送數(shù)據(jù)zb_SendDataRequest()控制器接收數(shù)據(jù)處理zb_ReceiveDataIndication()zmain.c文件int main( void ) / Turn off interrupts osal_int_disable( INTS_ALL ); 關(guān)閉中斷 /

8、Initialization for board related stuff such as LEDs HAL_BOARD_INIT(); 板載硬件初始化 / Make sure supply voltage is high enough to run zmain_vdd_check(); 檢測(cè)節(jié)點(diǎn)電壓(自定義函數(shù)) / Initialize board I/O InitBoard( OB_COLD ); 初始化節(jié)點(diǎn)板 / Initialze HAL drivers HalDriverInit(); 初始化驅(qū)動(dòng) / Initialize NV System osal_nv_init( NULL

9、 ); / Initialize the MAC ZMacInit(); 初始化MAC / Determine the extended address zmain_ext_addr(); 確定外部地址 / Initialize basic NV items zgInit(); #ifndef NONWK / Since the AF isn't a task, call it's initialization routine afInit();#endif / Initialize the operating system osal_init_system(); 操作系統(tǒng)初始

10、化 / Allow interrupts osal_int_enable( INTS_ALL ); 啟動(dòng)中斷 / Final board initialization InitBoard( OB_READY ); 初始化板 / Display information about this device zmain_dev_info(); 顯示設(shè)備信息 /* Display the device info on the LCD */#ifdef LCD_SUPPORTED zmain_lcd_init();#endif#ifdef WDT_IN_PM1 /* If WDT is used, th

11、is is a good place to enable it. */ WatchDogEnable( WDTIMX ); 啟動(dòng)看門狗#endif osal_start_system(); / No Return from here /啟動(dòng)系統(tǒng) return 0; / Shouldn't get here. / main()simpleAPP.h#ifndef SIMPLE_APP_H#define SIMPLE_APP_H#define MY_PROFILE_ID 0x0F10#define MY_ENDPOINT_ID 0x02/ Define devices#define DEV

12、_ID_SWITCH 1 定義設(shè)備ID#define DEV_ID_CONTROLLER 2 #define DEV_ID_SENSOR 3#define DEV_ID_COLLECTOR 4#define DEVICE_VERSION_SWITCH 1#define DEVICE_VERSION_CONTROLLER 1#define DEVICE_VERSION_SENSOR 1#define DEVICE_VERSION_COLLECTOR 1/ Define the Command ID's used in this application 定義命令I(lǐng)D#define TOGG

13、LE_LIGHT_CMD_ID 1#define SENSOR_REPORT_CMD_ID 2#endif / SIMPLE_APP_HSimpleSwitch.cpp/ Application States 應(yīng)用程序狀態(tài)#define APP_INIT 0 / Initial state#define APP_START 1 / Device has started/joined network/ Application osal event identifiers 操作系統(tǒng)層事件ID#define MY_START_EVT 0x0001/* * TYPEDEFS */* * LOCAL V

14、ARIABLES */static uint8 myAppSeqNumber = 0; 應(yīng)用程序序號(hào)static uint8 myAppState = APP_INIT; 應(yīng)用程序狀態(tài)static uint8 myStartRetryDelay = 10; 起動(dòng)重試延時(shí)/* * GLOBAL VARIABLES */ Inputs and Outputs for Switch device /定義設(shè)備的輸入輸出命令數(shù)#define NUM_OUT_CMD_SWITCH 1#define NUM_IN_CMD_SWITCH 0typedef struct byte EndPoint; uint1

15、6 AppProfId; uint16 AppDeviceId; byte AppDevVer:4; byte Reserved:4; / AF_V1_SUPPORT uses for AppFlags:4. byte AppNumInClusters; cId_t *pAppInClusterList; byte AppNumOutClusters; cId_t *pAppOutClusterList; SimpleDescriptionFormat_t;/ List of output and input commands for Switch device /命令列表const cId_

16、t zb_OutCmdListNUM_OUT_CMD_SWITCH = TOGGLE_LIGHT_CMD_ID;/ Define SimpleDescriptor for Switch device /定義設(shè)備描述結(jié)構(gòu)const SimpleDescriptionFormat_t zb_SimpleDesc = MY_ENDPOINT_ID, / Endpoint MY_PROFILE_ID, / Profile ID DEV_ID_SWITCH, / Device ID DEVICE_VERSION_SWITCH, / Device Version 0, / Reserved NUM_IN_

17、CMD_SWITCH, / Number of Input Commands (cId_t *) NULL, / Input Command List NUM_OUT_CMD_SWITCH, / Number of Output Commands (cId_t *) zb_OutCmdList / Output Command List;/* * fn zb_HandleOsalEvent * * brief The zb_HandleOsalEvent function is called by the operating * system when a task event is set

18、* * param event - Bitmask containing the events that have been set * * return none */void zb_HandleOsalEvent( uint16 event ) /操作系統(tǒng)事件處理 if ( event & MY_START_EVT ) zb_StartRequest(); /* * fn zb_HandleKeys * * brief Handles all key events for this device. * * param shift - true if in shift/alt. *

19、param keys - bit field for key events. Valid entries: * EVAL_SW4 * EVAL_SW3 * EVAL_SW2 * EVAL_SW1 * * return none */void zb_HandleKeys( uint8 shift, uint8 keys ) uint8 startOptions; uint8 logicalType; / Shift is used to make each button/switch dual purpose. /雙功能按鍵處理 if ( shift ) if ( keys & HAL_

20、KEY_SW_1 ) if ( keys & HAL_KEY_SW_2 ) if ( keys & HAL_KEY_SW_3 ) if ( keys & HAL_KEY_SW_4 ) else if ( keys & HAL_KEY_SW_1 ) if ( myAppState = APP_INIT ) / In the init state, keys are used to indicate the logical mode. / The Switch device is always an end-device logicalType = ZG_DEVIC

21、ETYPE_ENDDEVICE; /設(shè)備邏輯類型 zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType); /寫入配置參數(shù) / Do more configuration if necessary and then restart device with auto-start bit set zb_ReadConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); /讀取配置參數(shù) startOptions = Z

22、CD_STARTOPT_AUTO_START; zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); zb_SystemReset(); else / Initiate a binding with null destination /建立綁定 zb_BindDevice(TRUE, TOGGLE_LIGHT_CMD_ID, NULL); if ( keys & HAL_KEY_SW_2 ) if ( myAppState = APP_INIT ) / In the init

23、state, keys are used to indicate the logical mode. / The Switch device is always an end-device logicalType = ZG_DEVICETYPE_ENDDEVICE; zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType); zb_ReadConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); startOpt

24、ions = ZCD_STARTOPT_AUTO_START; zb_WriteConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); zb_SystemReset(); /系統(tǒng)復(fù)位 else / Send the command to toggle light /傳輸數(shù)據(jù) zb_SendDataRequest( 0xFFFE, TOGGLE_LIGHT_CMD_ID, 0, (uint8 *)NULL, myAppSeqNumber, 0, 0 ); if ( keys & HAL_KEY_S

25、W_3 ) / Remove all existing bindings /刪除綁定 zb_BindDevice(FALSE, TOGGLE_LIGHT_CMD_ID, NULL); if ( keys & HAL_KEY_SW_4 ) /* * fn zb_StartConfirm * * brief The zb_StartConfirm callback is called by the ZigBee stack * after a start request operation completes * * param status - The status of the sta

26、rt operation. Status of * ZB_SUCCESS indicates the start operation completed * successfully. Else the status is an error code. * * return none */void zb_StartConfirm( uint8 status ) / If the device sucessfully started, change state to running if ( status = ZB_SUCCESS ) myAppState = APP_START; else /

27、 Try again later with a delay osal_start_timerEx( sapi_TaskID, MY_START_EVT, myStartRetryDelay ); /* * fn zb_SendDataConfirm * * brief The zb_SendDataConfirm callback function is called by the * ZigBee after a send data operation completes * * param handle - The handle identifying the data transmiss

28、ion. * status - The status of the operation. * * return none */void zb_SendDataConfirm( uint8 handle, uint8 status )/* * fn zb_BindConfirm * * brief The zb_BindConfirm callback is called by the ZigBee stack * after a bind operation completes. * * param commandId - The command ID of the binding being

29、 confirmed. * status - The status of the bind operation. * * return none */void zb_BindConfirm( uint16 commandId, uint8 status ) if ( ( status = ZB_SUCCESS ) && ( myAppState = APP_START ) ) / Turn on LED 1 HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); /* * fn zb_AllowBindConfirm * * brief Indicat

30、es when another device attempted to bind to this device * * param * * return none */void zb_AllowBindConfirm( uint16 source )/* * fn zb_FindDeviceConfirm * * brief The zb_FindDeviceConfirm callback function is called by the * ZigBee stack when a find device operation completes. * * param searchType

31、- The type of search that was performed. * searchKey - Value that the search was executed on. * result - The result of the search. * * return none */void zb_FindDeviceConfirm( uint8 searchType, uint8 *searchKey, uint8 *result )/* * fn zb_ReceiveDataIndication * * brief The zb_ReceiveDataIndication c

32、allback function is called * asynchronously by the ZigBee stack to notify the application * when data is received from a peer device. * * param source - The short address of the peer device that sent the data * command - The commandId associated with the data * len - The number of bytes in the pData

33、 parameter * pData - The data sent by the peer device * * return none */void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData )The following features are removed from the Value Line chips versus CC1101:CC110L"超值系列"對(duì)比CC1101被刪除的功能如下: Forward error correction (FEC) and inter

溫馨提示

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

評(píng)論

0/150

提交評(píng)論