Zigbee 协议栈
Zigbee 協議棧
- 平臺
- 協議棧對我們的作用
- 怎么使用協議棧
- 協議棧的安裝、編譯與下載
- Components (部件)
- Documents (文件)
- Projects (項目例子)
- Tools (工具)
- App 應用層目錄
- HAL :硬件層目錄
- MAC:MAC層目錄
- MT
- NWK :網絡層目錄
- APS層庫的函數接口。
- OSAL :協議棧的操作系統。
- Profile : Application framework
- Security:安全層目錄
- Services :地址處理函數目錄
- Tools :工程配置目錄
- ZDO : ZDO目錄
- ZMac: MAC層目錄
- ZMain:主函數目錄
- Output :輸出文件目錄
- 協議棧應用開發相關函數
- OSAL(Operating System Abstraction Layer)
- int main( void )
- osal_init_system()
- osalInitTasks()
- osal_start_system()
- osal_run_system();
- SampleApp_ Init()
- SampleApp_ ProcessEvent()
- void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
- void SampleApp_SendPeriodicMessage( void )
- void SampleApp_SendFlashMessage( uint16 flashTime )
- AF_DataRequest()
平臺
協議 TI ZStack-CC2530-2.5.1a
協議棧對我們的作用
協議棧是協議的實現,可以理解為代碼,函數庫, 供上層應用調用,協議較底下的層與應用是相互獨立的。商業化的協議棧就是給你寫好了底層的代碼, 符合協議標準,提供給你一個功能模塊給你調用。你需要關心的就是你的應用邏輯,數據從哪里到哪里,怎么存儲,處理;還有系統里的設備之間的通信順序什么的,當你的應用需要數據通信時, 調用組網函數給你組建你想要的網絡;當你想從一個設備發數據到另一個設備時, 調用無線數據發送函數;當然,接收端就調用接收函數;當你的設備沒事干的時候,你就調用睡眠函數;要干活的時候就調用喚醒函數。所以當你做具體應用時,不需要關心協議棧是怎么寫的,里面的每條代碼是什么意思。除非你要做協議研究。每個廠商的協議棧有區別,也就是函數名稱和參數可能有區別,這個要看具體的例子、說明文檔。
怎么使用協議棧
舉個例子,用戶實現-個簡單的無線數據通信時的一 般步驟:
1、組網:調用協議棧的組網函數、加入網絡函數,實現網絡的建立與節點的加入。
2、發送:發送節點調用協議棧的無線數據發送函數,實現無線數據發送。
3、接收:接收節點調用協議棧的無線數據接收函數,實現無線數據接收。
是不是看上去很簡單啊,其實協議棧很多都封裝好了,下面我們大概看看無線發送函數:
用戶調用該函數即可實現數據的無線數據的發送,此函數中有8個參數,用戶需要將每個參數的含義理解以后,才能熟練使用該函數進行無線數據通信的目的?,F在只講其中最重要的兩個參數,其它參數不需要死記硬背,以后用多了自然就記住了。
uint16 len,//發送數據的長度; uint8 *buf,//指向存放發送數據的緩沖區的指針。至于調用該函數后,如何初始化硬件進行數據發送等工作,用戶不需要關心, ZigBee協議棧己經將所需要的工作做好了,我們只需要調用相應的API函數即可,而不必關心具體實現細節??雌饋硎遣皇呛芎唵文?是不是有動手試試的沖動。先別急還要先安裝ZigBee協議棧才能進行開發調試呢,下面就動手安裝ZigBee協議棧吧。
協議棧的安裝、編譯與下載
去TI官網下載 ZStack-CC2530-2.5.1a.exe 進行安裝,路徑你可以選擇默認,同樣你也可以選擇你想要安裝的位置。也許有人就困惑了,裝完之后不是應該有個桌面圖標的么?其實所謂的安裝協議棧只是把一些文件解壓到你安裝的目錄下。
Components (部件)
顧名思義這個是放我們的庫的文件夾,里面放了一些我們用到的ZDO,driver , hal , zcl等庫的代碼
Documents (文件)
這個不用說大家都知道是放TI的開發文檔的,里面很多都是講述協議棧的API的有空時可以看看
Projects (項目例子)
這個文件夾放的是TI協議棧的例子程序,一個個例子程序都是以一個個project的形式給我們的,學好這些例子程序里面的一兩個,基本你能做事情了。
Tools (工具)
這個文件夾是放T|的例子程序的一些上位機之類的程序,作為工具使用。
用IAR打開 \ZStack-2.5.1a\Projects\zstack\Samples\SampleApp\CC2530DB\SampleApp.eww
App 應用層目錄
這是用戶創建各種不同工程的區域,在這個目錄中包含了應用層的內容和這個項目的主要內容。
HAL :硬件層目錄
包含有與硬件相
關的配置和驅動及操作函數。
MAC:MAC層目錄
包含了MAC層的參數配置文件及其MAC的LIB庫的函數接口文件。
MT
實現通過串口可控制各層并與各層進行直接交互
NWK :網絡層目錄
包含網絡層配置參數文件網絡層庫的函數接口文件及
APS層庫的函數接口。
OSAL :協議棧的操作系統。
Profile : Application framework
應用框架層目錄包含AF層處理函數文件。應用框架層是應用程序和APS層的無線數據接口。
Security:安全層目錄
包含安全層處理函數.比如加密函數等
Services :地址處理函數目錄
包括地址模式的定義及地址處理函數。
Tools :工程配置目錄
包括空間劃分及Z-Stack相關配置信息。
ZDO : ZDO目錄
ZMac: MAC層目錄
包括MAC層參數配置及MAC層LB庫函數回調處理函數.
ZMain:主函數目錄
包括入口函數及硬件配置文件。
Output :輸出文件目錄
由IAR IDE自動生成。
協議棧應用開發相關函數
OSAL(Operating System Abstraction Layer)
中文解釋操作系統抽象層。它可以看做是一種機制,一種任務分配資源的機制,從而形成 了一個簡單多任務的操作系統。
int main( void )
在ZMain.c
/********************************************************************** @fn main* @brief First function called after startup.* @return don't care*/ int main( void ) {// Turn off interrupts //關閉所有中斷osal_int_disable( INTS_ALL );// Initialization for board related stuff such as LEDs //初始化系統時鐘HAL_BOARD_INIT();// Make sure supply voltage is high enough to run //檢查芯片電壓是否正常zmain_vdd_check();// Initialize board I/O //初始化IO , LED、Timer 等InitBoard( OB_COLD );// Initialze HAL drivers //初始化芯片各硬件模塊HalDriverInit();// Initialize NV System//初始化Flash存儲器osal_nv_init( NULL );// Initialize the MAC //初始化MAC層ZMacInit();// Determine the extended address //確定IEEE 64位地址zmain_ext_addr();#if defined ZCL_KEY_ESTABLISH// Initialize the Certicom certificate information.zmain_cert_init(); #endif// Initialize basic NV items//初始化非易失變量zgInit();#ifndef NONWK// Since the AF isn't a task, call it's initialization routineafInit(); #endif// Initialize the operating system//初始化操作系統osal_init_system();// Allow interrupts//使能全部中斷osal_int_enable( INTS_ALL );// Final board initialization//最終板載初始化InitBoard( OB_READY );// Display information about this device//顯示設備信息zmain_dev_info();/* Display the device info on the LCD */ #ifdef LCD_SUPPORTEDzmain_lcd_init(); //初始化LCD #endif#ifdef WDT_IN_PM1/* If WDT is used, this is a good place to enable it. */WatchDogEnable( WDTIMX ); #endifosal_start_system(); // No Return from here//執行操作系統return 0; // Shouldn't get here. } // main()osal_init_system()
右鍵 go to definition of…
/********************************************************************** @fn osal_init_system** @brief** This function initializes the "task" system by creating the* tasks defined in the task table (OSAL_Tasks.h).** @param void** @return SUCCESS*/ uint8 osal_init_system( void ) {// Initialize the Memory Allocation Systemosal_mem_init();// Initialize the message queueosal_qHead = NULL;// Initialize the timersosalTimerInit();// Initialize the Power Management Systemosal_pwrmgr_init();// Initialize the system tasks.osalInitTasks();// Setup efficient search for the first free block of heap.osal_mem_kick();return ( SUCCESS ); }osalInitTasks()
// The order in this table must be identical to the task initialization calls below in osalInitTask. const pTaskEventHandlerFn tasksArr[] = {macEventLoop,nwk_event_loop,Hal_ProcessEvent, #if defined( MT_TASK )MT_ProcessEvent, #endifAPS_event_loop, #if defined ( ZIGBEE_FRAGMENTATION )APSF_ProcessEvent, #endifZDApp_event_loop, #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )ZDNwkMgr_event_loop, #endifSampleApp_ProcessEventa };const uint8 tasksCnt = sizeof( tasksArr ) / sizeof( tasksArr[0] ); uint16 *tasksEvents;/********************************************************************** FUNCTIONS*********************************************************************//********************************************************************** @fn osalInitTasks** @brief This function invokes the initialization function for each task.** @param void** @return none*/ void osalInitTasks( void ) //任務初始化函數在OSAL. SampleApp.c文件中{uint8 taskID = 0;// 分配內存,返回指向緩沖區的指針tasksEvents = (uint16 *)osal_mem_alloc( sizeof( uint16 ) * tasksCnt);// 設置所分配的內存空間單元值為0osal_memset( tasksEvents, 0, (sizeof( uint16 ) * tasksCnt));// 任務優先級由高向低依次排列,高優先級對應taskID 的值反而小macTaskInit( taskID++ ); //macTaskInit(0) ,用戶不需考慮nwk_init( taskID++ ); //nwk_init(1),用戶不需考慮Hal_Init( taskID++ ); //Hal_Init(2) ,用戶需考慮 #if defined( MT_TASK )MT_TaskInit( taskID++ ); #endifAPS_Init( taskID++ ); //APS_Init(3) ,用戶不需考慮 #if defined ( ZIGBEE_FRAGMENTATION )APSF_Init( taskID++ ); #endifZDApp_Init( taskID++ ); //ZDApp_Init(4) ,用戶需考慮 #if defined ( ZIGBEE_FREQ_AGILITY ) || defined ( ZIGBEE_PANID_CONFLICT )ZDNwkMgr_Init( taskID++ ); #endif///************************************關鍵函數//用戶創建的任務SampleApp_Init( taskID ); // SampleApp_Init _Init(5) ,用戶需考慮 ///************************************}SampleApp_ Init()是我們應用協議棧例程的必要函數,用戶通常在這里初始化自己的
東西。
osal_start_system()
/********************************************************************** @fn osal_start_system** @brief** This function is the main loop function of the task system (if* ZBIT and UBIT are not defined). This Function doesn't return.** @param void** @return none*/ void osal_start_system( void ) { #if !defined ( ZBIT ) && !defined ( UBIT )for(;;) // Forever Loop #endif{osal_run_system();} }osal_run_system();
/********************************************************************** @fn osal_run_system** @brief** This function will make one pass through the OSAL taskEvents table* and call the task_event_processor() function for the first task that* is found with at least one event pending. If there are no pending* events (all tasks), this function puts the processor into Sleep.** @param void** @return none*/ void osal_run_system( void ) {uint8 idx = 0;osalTimeUpdate(); //掃描哪個事件被觸發了,然后置相應的標志位Hal_ProcessPoll(); //輪詢TIMER與UART/*A do statement executes a statement one or more times, while its test-context expression has a **nonzero** value:dostatementwhile (test); *///得到待處理的最高優先級任務索引1號idxdo {if (tasksEvents[idx]) // Task is highest priority that is ready.{break;}} while (++idx < tasksCnt);if (idx < tasksCnt){uint16 events;halIntState_t intState;HAL_ENTER_CRITICAL_SECTION(intState);// 進入臨界區,保護events = tasksEvents[idx];//提取需要處理的任務中的事件tasksEvents[idx] = 0; // Clear the Events for this task.tasksEvents[idx] = 0; //清除本次任務的事件HAL_EXIT_CRITICAL_SECTION(intState);activeTaskID = idx;events = (tasksArr[idx])( idx, events );//通過指針調用任務處理函數,關鍵activeTaskID = TASK_NO_TASK;HAL_ENTER_CRITICAL_SECTION(intState);tasksEvents[idx] |= events; // Add back unprocessed events to the current task.//保存未處理的事件HAL_EXIT_CRITICAL_SECTION(intState);//退出臨界區} #if defined( POWER_SAVING )else // Complete pass through all task events with no activity?{osal_pwrmgr_powerconserve(); // Put the processor/system into sleep} #endif/* Yield in case cooperative scheduling is being used. */ #if defined (configUSE_PREEMPTION) && (configUSE_PREEMPTION == 0){osal_task_yield();} #endif }SampleApp_ Init()
用戶應用任務初始化函數
/********************************************************************** @fn SampleApp_Init** @brief Initialization function for the Generic App Task.* This is called during initialization and should contain* any application specific initialization (ie. hardware* initialization/setup, table initialization, power up* notificaiton ... ).** @param task_id - the ID assigned by OSAL. This ID should be* used to send messages and set timers.** @return none*/ void SampleApp_Init( uint8 task_id ) { SampleApp_TaskID = task_id; //osal分配的任務ID隨著用戶添加任務的增多而改變SampleApp_NwkState = DEV_INIT;//設備狀態設定為ZDO層中定義的初始化狀態/*設備狀態設定為ZDO層中定義的初始化狀態初始化應用設備的網絡類型, 設備類型的改變都要產生一個事件一_ZDO_ STATE_ CHANGE ,從字面理解為ZDO狀態發生了改變。所以在設備初始化的時候一定要把它初始化為什么狀態都沒有。那么它就要去檢測整個環境,看是否能重新建立或者加入存在的網絡。但是有一種情況例外,就是當NV_ RESTORE被設置的候( NV_ RESTORE是把信息保存在非易失存儲器中),那么當設備斷電或者某種意外重啟時,由于網絡狀態存儲在非易失存儲器中,那么此時就只需要恢復其網絡狀態,而不需要重新建立或者加入網絡了.這里需要設置NV RESTORE宏定義。*/SampleApp_TransID = 0; //消息發送ID(多消息時有順序之分)// Device hardware initialization can be added here or in main() (Zmain.c).// If the hardware is application specific - add it here.// If the hardware is other parts of the device add it in main().#if defined ( BUILD_ALL_DEVICES )// The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START// We are looking at a jumper (defined in SampleAppHw.c) to be jumpered// together - if they are - we will start up a coordinator. Otherwise,// the device will start as a router.if ( readCoordinatorJumper() )zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;elsezgDeviceLogicalType = ZG_DEVICETYPE_ROUTER; #endif // BUILD_ALL_DEVICES//該段的意思是,如果設置了HOLD_AUTO_START宏定義,將會在啟動芯片的時候會暫停啟動 //流程,只有外部觸發以后才會啟動芯片。其實就是需要一個按鈕觸發它的啟動流程。 #if defined ( HOLD_AUTO_START )// HOLD_AUTO_START is a compile option that will surpress ZDApp// from starting the device and wait for the application to// start the device.ZDOInitDevice(0); #endif// Setup for the periodic message's destination address 設置發送數據的方式和目的地址尋址模式// Broadcast to everyone 發送模式:廣播發送SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;//廣播SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; //指定端點號SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;//指定目的網絡地址為廣播地址// Setup for the flash command's destination address - Group 1 組播發送SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; //組尋址SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT; //指定端點號SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;//組號0x0001// Fill out the endpoint description. 定義本設備用來通信的APS層端點描述符SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT; //指定端點號SampleApp_epDesc.task_id = &SampleApp_TaskID; //SampleApp 描述符的任務IDSampleApp_epDesc.simpleDesc= (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;//SampleApp簡單描述符SampleApp_epDesc.latencyReq = noLatencyReqs; //延時策略 /*向AF層登記描述符,登記endpoint description 到AF,要對該應用進行初始化并在AF //進行登記,告訴應用層有這么一個EP已經開通可以使用,那么下層要是有關于該應用的信 //息或者應用要對下層做哪些操作,就自動得到下層的配合*/// Register the endpoint description with the AFafRegister( &SampleApp_epDesc ); //向AF層登記描述符// Register for all key events - This app will handle all key eventsRegisterForKeys( SampleApp_TaskID ); // 登記所有的按鍵事件// By default, all devices start out in Group 1SampleApp_Group.ID = 0x0001;//組號osal_memcpy( SampleApp_Group.name, "Group 1", 7 );//設定組名aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );//把該組登記添加到APS中#if defined ( LCD_SUPPORTED )HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 ); //如果支持LCD,顯示提示信息 #endif }SampleApp_ ProcessEvent()
用戶應用任務的事件處理函數
/********************************************************************** @fn SampleApp_ProcessEvent** @brief Generic Application Task event processor. This function* is called to process all events for the task. Events* include timers, messages and any other user defined events.** @param task_id - The OSAL assigned task ID.* @param events - events to process. This is a bit map and can* contain more than one event.** @return none*/ //用戶應用任務的事件處理函數 uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) {afIncomingMSGPacket_t *MSGpkt;(void)task_id; // Intentionally unreferenced parameterif ( events & SYS_EVENT_MSG ) //接收系統消息再進行判斷{//接收屬于本應用任務SampleApp的消息,以SampleApp_TaskID標記MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );while ( MSGpkt ){switch ( MSGpkt->hdr.event ){// Received when a key is pressedcase KEY_CHANGE://按鍵事件SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );break;// Received when a messages is received (OTA) for this endpointcase AF_INCOMING_MSG_CMD://接收數據事件,調用函數AF_DataRequest()接收數據SampleApp_MessageMSGCB( MSGpkt );//調用回調函數對收到的數據進行處理break;// Received whenever the device changes state in the networkcase ZDO_STATE_CHANGE://只要網絡狀態發生改變,就通過ZDO_STATE_CHANGE事件通知所有的任務。//同時完成對協調器,路由器,終端的設置SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);//if ( (SampleApp_NwkState == DEV_ZB_COORD)//實驗中協調器只接收數據所以取消發送事件if ( (SampleApp_NwkState == DEV_ROUTER) || (SampleApp_NwkState == DEV_END_DEVICE) ){// Start sending the periodic message in a regular interval.//這個定時器只是為發送周期信息開啟的,設備啟動初始化后從這里開始//觸發第一個周期信息的發送,然后周而復始下去osal_start_timerEx( SampleApp_TaskID,SAMPLEAPP_SEND_PERIODIC_MSG_EVT,SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );}else{// Device is no longer in the network}break;default:break;}// Release the memory 事件處理完了,釋放消息占用的內存osal_msg_deallocate( (uint8 *)MSGpkt );// Next - if one is available 指針指向下一個放在緩沖區的待處理的事件,//返回while ( MSGpkt )重新處理事件,直到緩沖區沒有等待處理事件為止MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );}// return unprocessed events 返回未處理的事件return (events ^ SYS_EVENT_MSG);} /********************************************************************** @fn SampleApp_ProcessEvent** @brief Generic Application Task event processor. This function* is called to process all events for the task. Events* include timers, messages and any other user defined events.** @param task_id - The OSAL assigned task ID.* @param events - events to process. This is a bit map and can* contain more than one event.** @return none*/ //用戶應用任務的事件處理函數 uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) {afIncomingMSGPacket_t *MSGpkt;(void)task_id; // Intentionally unreferenced parameterif ( events & SYS_EVENT_MSG ) //接收系統消息再進行判斷{//接收屬于本應用任務SampleApp的消息,以SampleApp_TaskID標記MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );while ( MSGpkt ){switch ( MSGpkt->hdr.event ){// Received when a key is pressedcase KEY_CHANGE://按鍵事件SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );break;// Received when a messages is received (OTA) for this endpointcase AF_INCOMING_MSG_CMD://接收數據事件,調用函數AF_DataRequest()接收數據SampleApp_MessageMSGCB( MSGpkt );//調用回調函數對收到的數據進行處理break;// Received whenever the device changes state in the networkcase ZDO_STATE_CHANGE://只要網絡狀態發生改變,就通過ZDO_STATE_CHANGE事件通知所有的任務。//同時完成對協調器,路由器,終端的設置SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status);//if ( (SampleApp_NwkState == DEV_ZB_COORD)//實驗中協調器只接收數據所以取消發送事件if ( (SampleApp_NwkState == DEV_ROUTER) || (SampleApp_NwkState == DEV_END_DEVICE) ){// Start sending the periodic message in a regular interval.//這個定時器只是為發送周期信息開啟的,設備啟動初始化后從這里開始//觸發第一個周期信息的發送,然后周而復始下去osal_start_timerEx( SampleApp_TaskID,SAMPLEAPP_SEND_PERIODIC_MSG_EVT,SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT );}else{// Device is no longer in the network}break;default:break;}// Release the memory 事件處理完了,釋放消息占用的內存osal_msg_deallocate( (uint8 *)MSGpkt );// Next - if one is available 指針指向下一個放在緩沖區的待處理的事件,//返回while ( MSGpkt )重新處理事件,直到緩沖區沒有等待處理事件為止MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );}// return unprocessed events 返回未處理的事件return (events ^ SYS_EVENT_MSG);}void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
/********************************************************************** LOCAL FUNCTIONS*//********************************************************************** @fn SampleApp_MessageMSGCB** @brief Data message processor callback. This function processes* any incoming data - probably from other devices. So, based* on cluster ID, perform the intended action.** @param none** @return none*/ //接收數據,參數為接收到的數據 void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) {uint16 flashTime;byte buf[3]; switch ( pkt->clusterId ) //判斷簇ID{case SAMPLEAPP_PERIODIC_CLUSTERID: //收到廣播數據osal_memset(buf, 0 , 3);osal_memcpy(buf, pkt->cmd.Data, 2); //復制數據到緩沖區中if(buf[0]=='D' && buf[1]=='1') //判斷收到的數據是否為"D1" {HalLedBlink(HAL_LED_1, 0, 50, 500);//如果是則Led1間隔500ms閃爍 #if defined(ZDO_COORDINATOR) //協調器收到"D1"后,返回"D1"給終端,讓終端Led1也閃爍SampleApp_SendPeriodicMessage(); #endif}else{HalLedSet(HAL_LED_1, HAL_LED_MODE_ON); }break;case SAMPLEAPP_FLASH_CLUSTERID: //收到組播數據flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] );HalLedBlink( HAL_LED_4, 4, 50, (flashTime / 4) );break;} }void SampleApp_SendPeriodicMessage( void )
分析發送周期信息
void SampleApp_SendPeriodicMessage( void ) {byte SendData[3]="D1";// 調用AF_DataRequest將數據無線廣播出去if( AF_DataRequest( &SampleApp_Periodic_DstAddr,//發送目的地址+端點地址和傳送模式&SampleApp_epDesc,//源(答復或確認)終端的描述(比如操作系統中任務ID等)源EPSAMPLEAPP_PERIODIC_CLUSTERID, //被Profile指定的有效的集群號2, // 發送數據長度SendData,// 發送數據緩沖區&SampleApp_TransID, // 任務ID號AF_DISCV_ROUTE, // 有效位掩碼的發送選項AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) //傳送跳數,通常設置為AF_DEFAULT_RADIUS{}else{HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);// Error occurred in request to send.} }void SampleApp_SendFlashMessage( uint16 flashTime )
/********************************************************************** @fn SampleApp_SendFlashMessage** @brief Send the flash message to group 1.** @param flashTime - in milliseconds** @return none*/ void SampleApp_SendFlashMessage( uint16 flashTime ) //此實驗沒有用到,后面再分析 {uint8 buffer[3];buffer[0] = (uint8)(SampleAppFlashCounter++);buffer[1] = LO_UINT16( flashTime );buffer[2] = HI_UINT16( flashTime );if ( AF_DataRequest( &SampleApp_Flash_DstAddr, &SampleApp_epDesc,SAMPLEAPP_FLASH_CLUSTERID,3,buffer,&SampleApp_TransID,AF_DISCV_ROUTE,AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ){}else{// Error occurred in request to send.} }AF_DataRequest()
/********************************************************************** @fn AF_DataRequest** @brief Common functionality for invoking APSDE_DataReq() for both* SendMulti and MSG-Send.** input parameters** @param *dstAddr - Full ZB destination address: Nwk Addr + End Point.* @param *srcEP - Origination (i.e. respond to or ack to) End Point Descr.* @param cID - A valid cluster ID as specified by the Profile.* @param len - Number of bytes of data pointed to by next param.* @param *buf - A pointer to the data bytes to send.* @param *transID - A pointer to a byte which can be modified and which will* be used as the transaction sequence number of the msg.* @param options - Valid bit mask of Tx options.* @param radius - Normally set to AF_DEFAULT_RADIUS.** output parameters** @param *transID - Incremented by one if the return value is success.** @return afStatus_t - See previous definition of afStatus_... types.*/ uint8 AF_DataRequestDiscoverRoute = TRUE; afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,uint16 cID, uint16 len, uint8 *buf, uint8 *transID,uint8 options, uint8 radius )東西很多,慢慢來吧
總結
以上是生活随笔為你收集整理的Zigbee 协议栈的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LCD12864(ST7565P)字符汉
- 下一篇: 数学建模学习笔记(六):排队论模型