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、接收:接收节点调用协议栈的无线数据接收函数,实现无线数据接收。
是不是看上去很简单啊,其实协议栈很多都封装好了,下面我们大概看看无线发送函数:

afStatus_ t AF_ DataRequest(    afAddrType_ t *dstAddr,endPointDesc_ t *srcEP,uint16 cID,uint16 len,uint8 *buf,uint8 *transID,uint8 options,uint8radius )

用户调用该函数即可实现数据的无线数据的发送,此函数中有8个参数,用户需要将每个参数的含义理解以后,才能熟练使用该函数进行无线数据通信的目的。现在只讲其中最重要的两个参数,其它参数不需要死记硬背,以后用多了自然就记住了。

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 协议栈相关推荐

  1. zigbee协议栈学习(二)

    协议栈规范的 ID号可以通过查询设备发送的 beacon 帧获得.在设备加入网络之前,首先 需要确认协议栈规范的 ID."特定网络"规范 ID号为0: ZigBee协议栈规范的 I ...

  2. ZigBee协议栈简介和流程

    ZigBee协议栈实际上就是ZigBee协议的API接口 一般步骤为: 1.组网:调用协议栈的组网函数.加入网络函数,实现网络的建立与节点的加入 2.发送:发送节点调用协议栈的无线数据发送函数,实现无 ...

  3. ZIGBEE通讯-7.ZigBee协议栈简介

    想要学习协议栈,必须先知道协议是什么.协议定义的是一系列的通信标准,通信双方需要共同按照这一标准进行正常的数据收发,而协议栈是协议的具体实现形式,通俗的理解为用代码实现的函数库,以便于开发人员调用. ...

  4. ZigBee协议栈浅显解读(一)

    目前ZigBee开发主要用的是TI的CC2530.CC2530内部集成看增强型的51所以对于只学过51的小白入门不成问题. 本篇文章我只会介绍ZigBee的协议栈. 我们打开ZigBee协议栈后可以加 ...

  5. Zigbee协议栈ZStack构架

     协议栈版本信息: ZigBee2006\ZStack-1.4.3-1.2.1 1.ZStack协议栈构架 Zigbee协议栈就是将各个层定义的协议都集合在一起,以函数的形式实现,并给用户提供一些 ...

  6. zigbee协议栈ADC采集外部电压

    ADC 由于最近在做一个项目,其中一个步骤是需要CC2530片内ADC采集外设的电压值,三天反思不得其解,终于解决了这个问题. zigbee协议栈是有错误的,稍后我会写出来 ADC支持14位模数转换, ...

  7. CC2530下ZigBee协议栈中添加BH1750数字光照传感器

    项目里需要获得光照强度,之前用的是光敏电阻,但是光敏电阻实在不精确,换用BH1750数字光照传感器.网上购买后,送的资料都是单片机的,移植到ZigBee协议栈里面,时序有些问题,在网上找的一些资料,很 ...

  8. CC2530/Zigbee协议栈外部中断配置详解

    CC2530/Zigbee协议栈配置外部中断 一.I/O端口 二.配置寄存器 三.中断处理函数 一.I/O端口 1.在CC2530芯片中,其I/O口用作通用 I/O 时,引脚可以组成 3 个 8 位端 ...

  9. zigbee协议栈初使用(三)无线数据传输

    zigbee协议栈初使用(三)无线数据传输 本次使用协议栈例程广播通信完成,本文记录网蜂<Zigbee实战演练>学习总结 一.发送部分   打开SampleApp.c找到 uint16 S ...

  10. ZigBee协议栈Zstack介绍

    文中所讲述的协议栈是基于ZigBee2006\Zstack-1.4.3-1.2.1 1.ZSTACK协议栈的架构 ZigBee协议栈就是将各个层定义的协议都集合在一起,以函数的形式实现,并给用户提供一 ...

最新文章

  1. leetcode刷题之树(2)
  2. linux常用指令总结一~~
  3. Expression Blend实例中文教程(6) - 项目控件和用户交互控件快速入门
  4. luogu P1220 关路灯
  5. Python结合selenium自动领取无忧币的脚本
  6. 数据集:高考录取分数
  7. Openvswitch手册(7): Interfaces
  8. Primer设计PCR引物的方法,在线引物设计网站汇总整理
  9. 数据库备份软件带邮件发送
  10. DAVE笔记--Micrium uc-Probo Oscilloscope调试
  11. userdel: user xxx is currently used by process xxx
  12. John Gaar “Slow Rollin” WA47 WA87 WA14麦克风
  13. 第五人格为什么服务器维护中,《第五人格》提前停服原因和不删档测试说明
  14. 腾讯Bugly,简单实用的崩溃日志收集
  15. 自动驾驶L1至L5智能化程度分级
  16. 微信小程序毕业设计题目音乐播放器+后台管理系统|前后分离VUE.js
  17. 腾讯企业邮箱使用简单说明
  18. 跟ChatGPT,聊聊ChatGPT
  19. [Wpf] . [Theme] 重构/Themes/Generic.xaml 创建一个Custom Control的典型做法
  20. 设计一个串行数据检测电路. 当连续出现4个和4个以上的1时, 检测输出信号为1, 其余情况下的输出信号为0(设计1111序列检测电路)

热门文章

  1. 用PLC和触摸屏设计用户可编程的控制项目
  2. 数据库知识点汇总(最全!!)
  3. axure android 原型设计工具,知乎和Quora高分APP原型设计工具推荐
  4. MATPOWER工具本质原理解析
  5. 将新项目上传到svn
  6. 基于Python的DELMIA二次开发(三):人体建模
  7. 上周热点回顾(5.8-5.14)
  8. 在线摩尔斯密码加密解密工具
  9. 【JAVA】poi操作,excel读取数据。
  10. 标准为先、产业当道,这次大会“探云”深刻……