![Simple API协议应用程序分析_第1页](http://file2.renrendoc.com/fileroot_temp3/2021-12/1/393fa87b-7f11-4f9c-8760-67276321eda7/393fa87b-7f11-4f9c-8760-67276321eda71.gif)
![Simple API协议应用程序分析_第2页](http://file2.renrendoc.com/fileroot_temp3/2021-12/1/393fa87b-7f11-4f9c-8760-67276321eda7/393fa87b-7f11-4f9c-8760-67276321eda72.gif)
![Simple API协议应用程序分析_第3页](http://file2.renrendoc.com/fileroot_temp3/2021-12/1/393fa87b-7f11-4f9c-8760-67276321eda7/393fa87b-7f11-4f9c-8760-67276321eda73.gif)
![Simple API协议应用程序分析_第4页](http://file2.renrendoc.com/fileroot_temp3/2021-12/1/393fa87b-7f11-4f9c-8760-67276321eda7/393fa87b-7f11-4f9c-8760-67276321eda74.gif)
![Simple API协议应用程序分析_第5页](http://file2.renrendoc.com/fileroot_temp3/2021-12/1/393fa87b-7f11-4f9c-8760-67276321eda7/393fa87b-7f11-4f9c-8760-67276321eda75.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、无线Zigbee网络协议栈BasicRF API说明Basic RF协议 其采用IEEE802.15.4MAC协议兼容的数据与应答数据包(分组),但不提供完整的MAC层支持,只用于两个节点之间的通信。它是IEEE802.15.4协议标准的子集:(1) 不支持网络匹配、扫描和信标(2) 无协调器和端设备等的分类,支持点对点通信,通信节点对等(3) 不支持数据包(分组)重传Basic RF的应用(以下函数的定义和功能具体说明,参考swru214a - CC2530软件实例用户手册.pdf文件)1 启动(1) 确保开发板上外围接口和无线电接口初始化,调用halBoardInit()函数完成(2) 创
2、建basicRfCfg_t数据结构体,并初始化其成员变量;(3) 调用basicRfInit()对数据包(分组)协议进行初始化。2 发送数据(1) 创建一个发送缓冲区,最大为103字节;(2) 调用basicRfSendPacket()函数发送数据,检测函数返回值获取发送状态;3 接收数据(1) 调用basicRfPacketIsReady()函数,等待数据接收(2) 调用basicRfReceive()函数来接收数据包,并负责分配一个足够大的缓冲区来存储数据包信息,其中2个字节用来存储RSSI值(接收信号强度值)。数据结构typedef struct uint16 myAddr; 短地址 u
3、int16 panId; 所在域网ID uint8 channel; 通信信道 uint8 ackRequest; 应答请求设置(True或False); #ifdef SECURITY_CCM 安全设定(可选) uint8* securityKey; uint8* securityNonce; #endif basicRfCfg_t; 操作流程HalBoardInit()初始化节点硬件外围接口和通信接口basicRfInit()初始化数据包结构及通信设置basicRfSendPacket()发送数据basicRfReceive()接收数据basicRfPacketIsReady()接收数据b
4、asicRfCfg_t结构发送接收无线Zigbee网络协议栈Simple API分析网络设备类型:(1) 协调器协调器是启动Zigbee网络的设备,它是网络中的一个设备,其选择信道和网络标号ID,然后启动网络。协调器可选用作为辅助安全设置和网络中应用层的绑定。协调器的主要作用是启动和配置网络,当网络建立完成后,协调器的操作和路由器类似。基于Zigbee网络的分布式特性,网络的后继操作不再依靠协调器。(2) 路由器路由器主要有两个作用:(1)允许其他设备加入网络;(2)多调通信;(3)辅助电池供电的子设备通信。通常情况下,路由器需要时时激活运行,因此需要主电源供电。(3) 端点设备Zigbee
5、Stack API:寻址方式:(1) 长地址(64bit),又名MAC地址,Extended 地址,物理地址(2) 短地址(16bit),又名网络地址,逻辑地址怎样是一台设备加入网络 网络中每台设备都具有一组配置参数,分为网络参数和设备参数。同一网络中的设备必须配置相同的网络参数,而设备参数可因功能各异而不相同。ZCD_NV_LOGICAL_TYPEZCD_NV_CHANLISTZCD_NV_PANID协调器路由器端设备组建网络加入网络加入网络怎样绑定设备绑定是网络设备在应用层中的逻辑连接。(1) 若绑定对象的长地址已知,采用zb_BindDevice()函数建立绑定(2) 若绑定对象的长地址
6、未知,目标设备通过zb_AllowBindResponse()函数处于等待绑定状态,源设备启动zb_BindDevice()函数建立绑定。 注意:绑定只能创建在两个互补设备之间,即它们必须在描述器中注册有相同的命令ID,而且一个为输出,另一个为输入。怎样开发一个私有的应用(1) 划分应用中的设备类型(2) 划分应用中设备中相互交换的命令,并为命令赋予一个标识号ID(3) 针对每个命令,划分出设备对其是输入还是输出(4) 为每个设备建立一个描述结构(5) 为每个命令确定消息格式(6) 为每个设备编写应用程序(7) 确定一个绑定策略以便设备能够正确交换分组Switch收集器SenSor控制器路由器
7、/协调器端设备端设备路由器/协调器Zigbee网络应用实例流程控制器作为协调器启动网络控制器允许绑定zb_AllowBind()开关端设备请求建立绑定zb_BindDevice()控制器收到绑定请求处理zb_AllowBindConfirm()开关端设备绑定建立完成处理zb_BindConfirm()开关端设备发送数据zb_SendDataRequest()控制器接收数据处理zb_ReceiveDataIndication()zmain.c文件int main( void ) / Turn off interrupts osal_int_disable( INTS_ALL ); 关闭中断 /
8、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 InitBoard( OB_COLD ); 初始化节点板 / Initialze HAL drivers HalDriverInit(); 初始化驱动 / 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(); 操作系统初始
10、化 / 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_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 ); 启动看门狗#endif osal_start_system(); / No Return from here /启动系统 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 定义设备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 定义命令ID#define TOGG
13、LE_LIGHT_CMD_ID 1#define SENSOR_REPORT_CMD_ID 2#endif / SIMPLE_APP_HSimpleSwitch.cpp/ Application States 应用程序状态#define APP_INIT 0 / Initial state#define APP_START 1 / Device has started/joined network/ Application osal event identifiers 操作系统层事件ID#define MY_START_EVT 0x0001/* * TYPEDEFS */* * LOCAL V
14、ARIABLES */static uint8 myAppSeqNumber = 0; 应用程序序号static uint8 myAppState = APP_INIT; 应用程序状态static uint8 myStartRetryDelay = 10; 起动重试延时/* * GLOBAL VARIABLES */ Inputs and Outputs for Switch device /定义设备的输入输出命令数#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 /定义设备描述结构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 ) /操作系统事件处理 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; /设备逻辑类型 zb_WriteConfiguration(ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType); /写入配置参数 / Do more configuration if necessary and then restart device with auto-start bit set zb_ReadConfiguration( ZCD_NV_STARTUP_OPTION, sizeof(uint8), &startOptions ); /读取配置参数 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(); /系统复位 else / Send the command to toggle light /传输数据 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"超值系列"对比CC1101被删除的功能如下: Forward error correction (FEC) and inter
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 三讲三心申请书
- Review Module练习英语四年级下册-外研版(一起)(含答案)
- 履约保证金申请书
- 2025年江西赣州发展投资控股集团有限责任公司招聘笔试参考题库附带答案详解
- 电工材料的教育培训与知识普及
- 部编版:2022年七年级《道德A卷》下册第八章试卷以及答案
- 油服岗位模拟题+参考答案
- 新建某市文冠果生物质能源林种植基地可行性研究报告
- N3外科模拟考试题与答案
- 2025年中国果蔬加工行业市场调研分析及投资战略咨询报告
- 焊口外观检查记录
- 18-《护理心理学》课程标准
- Y2系列电机样本
- 市域社会治理现代化解决方案
- 高考英语单词3500分类记忆(精编版)
- 许慎《说文解字》(全文)
- 我国应急通信保障能力评估体系探究(金)
- 井控-井口套管头装置⑥课件
- 施工质量管理体系与保证措施方案
- 变配电室受电方案
- 译林版五下英语1-3单元电子稿
评论
0/150
提交评论