ZigBee教程

上传人:gbs****77 文档编号:10080117 上传时间:2020-04-09 格式:DOC 页数:135 大小:852.50KB
返回 下载 相关 举报
ZigBee教程_第1页
第1页 / 共135页
ZigBee教程_第2页
第2页 / 共135页
ZigBee教程_第3页
第3页 / 共135页
点击查看更多>>
资源描述
ZigBee 学习之 1 点灯 我用的编译环境是 IARfor51 7 30B 再介绍一下我的开发板的情况 ZigBee 模块用的是 CC2430 这块芯片是一款 Soc 的芯片 集成了 8051 内核和 ZigBee 射频部分 只要很少的外部电路就可以搭建一个射频模块 因为其中的是 8051 的内核 所有对于熟悉 8051 系列的同学们来说 基本的一些操作就很简单了 这里我们在温习一下 顺便对 CC2430 芯片进行一下熟悉 嵌入式的一大特点是其底层的软件和硬件紧密相关 如果没有数字电路的知识 那么作起 来是很困难的 我们先介绍一下基本的管脚分配情况 P0 的 2 和 3 接到了一个 232 电压转换芯片上 可以用来和 PC 进行通信 LCD RST LCD CS 接的是 LCD 的复位和片选端 这里我用到的 LCD 是兼容 PCD8544 的 NOkia5110 的 LCD 为 SPI 总线 LCD 84X48 点阵 CC2430 MOSI CC2430 CLK 都接到 LCD 上了 P1 0 接到一个调试 LED 上面 为高电平点亮 下面的第一个实验就很简单了 我们只要把 P1 0 配置为通用 IO 输出方式 然后从这里输出高电平 那么就可以点亮这个 LED 了 用到的寄存器为 P1 配置寄存器 P1SEL P1 方向寄存器 P1DIR 程序如下 include define DEBUG LED P1 0 void delay unsigned int n 26 cycles delay while n asm NOP void LEDInit P1SEL P1 0 defined General purpose I O P1DIR 0X01 P1 0 defined Output main LEDInit while 1 DEBUG LED 1 Led light delay 50000 DEBUG LED 0 delay 50000 编译通过以后就用 TI 的官方工具 SmartRF Flash Programmer 将生成的 HEX 文件 烧录到 CC2430 吧 激动的时刻 呵 呵如果点亮了这个小小的 LED 那么恭喜你 你的硬件因该是没有问的了 一个小小的胜利后我们就有更多的勇气和信 心前进咯 ZigBee 学习之 2 SPI void LCD IOInit P0SEL P0DIR 0X03 P1SEL P1DIR 0XF0 void LCD WriteOneByte uchar data uchar i 0 for i 0 i 8 i LCD SCK 0 if data i else LCD SIN 0 LCD SCK 1 void LCD WriteMByte uchar data uint num while num LCD WriteOneByte data data void LCD Init LCD nCS 0 delay 100 LCD nRES 0 delay 100 LCD nRES 1 delay 100 LCD DnC 0 LCD WriteOneByte 0 x21 LCD WriteOneByte 0 xC8 LCD WriteOneByte 0 x06 LCD WriteOneByte 0 x13 LCD WriteOneByte 0 x20 LCD WriteOneByte 0 x0C LCD DnC 1 main uint i 0 uchar Hello 0 x00 0 x7E 0 x10 0 x10 0 x7E 0 x00 H 0 6 X 8 楷体 GB2312 0 x00 0 x7E 0 x52 0 x52 0 x42 0 x00 E 1 6 X 8 楷体 GB2312 0 x42 0 x7E 0 x42 0 x40 0 x40 0 x00 L 2 6 X 8 楷体 GB2312 0 x42 0 x7E 0 x42 0 x40 0 x40 0 x00 L 3 6 X 8 楷体 GB2312 0 x00 0 x3C 0 x42 0 x42 0 x3C 0 x00 O 4 6 X 8 楷体 GB2312 LCD IOInit LCD Init for i 0 i 30 i LCD WriteOneByte Hello i LCD WriteMByte Hello 30 LCD nCS 1 下面是采用 SPI 总线方式控制 LCD 显示的例子 This file is applicable to Eshine EXBEE DK V1 Function LCD test the LCD use SPI BUS The SPI BUS occupation P1 USART1 ALT 2 InPut OutPut Created longfan 2010 1 10 Modify include periodef h include font h include TestBMP h include void delay uint n 26 cycles delay while n asm NOP void LEDInit P1SEL P1 0 defined General purpose I O P1DIR 0X01 P1 0 defined Output DEBUG LED 1 LED light up Initial P1 USART1 SPI void SPIInit U1 P1 void PERCFG 0X02 USART1 alt 2 P1 P1SEL 0XE0 P1 ISP P1 4 LCD DnC defined general IO P2SEL 0X40 USART1 has priority U1GCR 0 x20 MSB first Negative clock polarity Data is output on MOSI on the falling edge of CLK U1GCR 19 MAX Baud rate 17 falling edge U1BAUD 0 UTX1IF 0 Clear interrupt P1 USART1 SPI Send One Byte void SPI SendOne U1 P1 uchar data U1DBUF data while UTX1IF UTX1IF 0 P1 USART1 SPI Send Multily Byte void SPI Send U1 P1 uchar data uint length while length SPI SendOne U1 P1 data data length 1 LCD Use SPI BUS Set the first display piex When after call this function can direct call SPI data output function 0 X 83 0 Y 5 void SPI LCDSetPos uchar X uchar Y LCD DnC 0 SPI SendOne U1 P1 0 x80 X SPI SendOne U1 P1 0 x40 Y LCD DnC 1 LCD Use SPI BUS Clear the LCD Display and its RAM void SPI ClearLCD uint i SPI LCDSetPos 0 0 for i 0 i 504 i SPI SendOne U1 P1 0 LCD Use SPI BUS Send one LCD Command void SPI LCDWriteOneComm uchar command LCD DnC 0 SPI SendOne U1 P1 command LCD Use SPI BUS Send More than one LCD Command void SPI LCDWriteMulComm uchar command uchar num LCD DnC 0 SPI Send U1 P1 command num LCD Use SPI BUS Send More than one data void SPI LCDWriteData uchar data uchar length LCD DnC 1 SPI Send U1 P1 data length LCD Use SPI BUS Display a english character Without set position The inverse argument control the inverse video mode When use font library call this function to display InPut character The character want to display inverse Inverse video mode 1 or not 0 OutPut Created longfan 2010 1 10 Modify void SPI LCDWriteChar uchar character uchar inverse uchar line LCD DnC 1 if inverse for line 0 line 6 line SPI SendOne U1 P1 font6x8 character 32 line else SPI Send U1 P1 uchar font6x8 character 32 6 LCD Use SPI BUS Display a english character at X Y The inverse argument control the inverse video mode When use font library call this function to display InPut character The character want to display X Y The position want to display inverse Inverse video mode 1 or not 0 OutPut Created longfan 2010 1 10 Modify void SPI LCDDISPChar uchar character uchar X uchar Y uchar inverse uchar line SPI LCDSetPos X Y if inverse for line 0 line 6 line SPI SendOne U1 P1 font6x8 character 32 line else SPI Send U1 P1 uchar font6x8 character 32 6 LCD Use SPI BUS Display a english string at X Y void SPI LCDWriteEnString uchar EnString uchar X uchar Y uchar inverse uchar line SPI LCDSetPos X Y while EnString uchar chara EnString chara 32 if inverse for line 0 line 6 line SPI SendOne U1 P1 font6x8 chara line else SPI Send U1 P1 uchar font6x8 chara 6 EnString LCD Use SPI BUS Draw a AREA use Horizontal thus the High pixel must be a multiple of 8 When use dot matrix to display use this function InPut data The dot matrix of the data want to display X Y The position want to display wide high The pixel of wide and high OutPut Created longfan 2010 1 10 Modify void SPI LCDDrawArea H uchar data uchar X uchar Y uchar wide uchar high uchar row uchar i SPI LCDSetPos X Y Set position row high 8 calculate the row number for i 0 ipacketLength payloadLength BASIC RF PACKET OVERHEAD SIZE pConfig 为基本配置数据结构 typedef struct uint16 myAddr uint16 panId uint8 channel uint8 ackRequest basicRfCfg t pHdr frameControlField pConfig ackRequest BASIC RF FCF ACK BASIC RF FCF NOACK fcf pConfig ackRequest BASIC RF FCF ACK BASIC RF FCF NOACK 分别得到 16 位数的低 8 位和高 8 位 define HI UINT16 a uint16 a 8 pHdr fcf1 HI UINT16 fcf 得到数据序列 pHdr seqNumber txState txSeqNumber pHdr panId pConfig panId pHdr destAddr destAddr pHdr srcAddr pConfig myAddr ifdef SECURITY CCM Add security to FCF length and security header pHdr fcf0 BASIC RF SEC ENABLED FCF BM L pHdr packetLength PKT LEN MIC pHdr packetLength BASIC RF AUX HDR LENGTH pHdr securityControl SECURITY CONTROL pHdr frameCounter 0 LO UINT16 LO UINT32 txState frameCounter pHdr frameCounter 1 HI UINT16 LO UINT32 txState frameCounter pHdr frameCounter 2 LO UINT16 HI UINT32 txState frameCounter pHdr frameCounter 3 HI UINT16 HI UINT32 txState frameCounter endif Make sure bytefields are network byte order 这里把大的字节放到了前面 但有不是完全按从大到小的顺序排列字节 不知道为什么 UINT16 HTON pHdr panId UINT16 HTON pHdr destAddr UINT16 HTON pHdr srcAddr 1 字节长度 2 字节 FCF 1 字节序列 2 字节 PanID 2 字节目的地址 2 字节源地址 10 return BASIC RF HDR SIZE fn basicRfBuildMpdu brief Builds mpdu MAC header payload according to IEEE 802 15 4 frame format param destAddr Destination short address pPayload pointer to buffer with payload payloadLength length of payload buffer return uint8 length of mpdu 构造 MPDU static uint8 basicRfBuildMpdu uint16 destAddr uint8 pPayload uint8 payloadLength uint8 hdrLength n txMpdu 是定义 txMpdu BASIC RF MAX PAYLOAD SIZE BASIC RF PACKET OVERHEAD SIZE 1 hdrLength basicRfBuildHeader txMpdu destAddr payloadLength 将有效载荷数据放入 MPDU 单元中 for n 0 n0 pData RFD length 读取 MPDU 的长度 Read payload length halRfReadRxBuf 指定 MPDU 的长度字节的高位默认固定为 0 所以去掉高位 得到长度真实值 pHdr packetLength Ignore MSB Is this an acknowledgment packet Only ack packets may be 5 bytes in total if pHdr packetLength BASIC RF ACK PACKET SIZE 如果只有 5 个字节长度 则此帧为应答帧 Read the packet halRfReadRxBuf Make sure byte fields are changed from network to host byte order UINT16 NTOH pHdr panId UINT16 NTOH pHdr destAddr UINT16 NTOH pHdr srcAddr ifdef SECURITY CCM UINT32 NTOH pHdr frameCounter endif rxi ackRequest pHdr fcf0 条过 RSSI 指到 CRC 校验 Read the status word and check for CRC OK pStatusWord rxMpdu 4 Indicate the successful ACK reception if CRC and sequence number OK if pStatusWord 1 No it is data else It is assumed that the radio rejects packets with invalid length Subtract the number of bytes in the frame overhead to get actual payload rxi length pHdr packetLength BASIC RF PACKET OVERHEAD SIZE ifdef SECURITY CCM rxi length BASIC RF AUX HDR LENGTH BASIC RF LEN MIC authStatus halRfReadRxBufSecure else halRfReadRxBuf endif Make sure byte fields are changed from network to host byte order UINT16 NTOH pHdr panId UINT16 NTOH pHdr destAddr UINT16 NTOH pHdr srcAddr ifdef SECURITY CCM UINT32 NTOH pHdr frameCounter endif rxi ackRequest pHdr fcf0 Read the source address rxi srcAddr pHdr srcAddr Read the packet payload rxi pPayload rxMpdu BASIC RF HDR SIZE Read the FCS to get the RSSI and CRC pStatusWord rxi pPayload rxi length ifdef SECURITY CCM pStatusWord BASIC RF LEN MIC endif rxi rssi pStatusWord 0 Notify the application about the received data packet if the CRC is OK Throw packet if the previous packet had the same sequence number if pStatusWord 1 else if pHdr fcf0 endif rxi seqNumber pHdr seqNumber Enable RX frame done interrupt again halIntOff halRfEnableRxInterrupt GLOBAL FUNCTIONS fn basicRfInit brief Initialise basic RF datastructures Sets channel short address and PAN id in the chip and configures interrupt on packet reception param pRfConfig pointer to BASIC RF CONFIG struct This struct must be allocated by higher layer txState file scope variable that keeps tx state info rxi file scope variable info extracted from the last incoming frame return none 几个重要的底层函数 RF 初始化 调用 hal rf c 中的函数 uint8 halRfInit void uint8 i turning on power to analog part of radio and waiting for voltage regulator 模拟稳压器上电 延时 250uS 上电 RFPWR 0 x04 等待 ADI RADIO PD 为 0 也可以通过检测中断标志 RFIF IRQ RREG ON 为 1 来等待稳压 器稳定 while RFPWR 根据需要设置 RF 功能 自动 CRC 自动应答 0 x03 Setting for AUTO CRC and AUTOACK MDMCTRL0L AUTO CRC AUTO ACK 打开自动收发转换 接收包后 12 个符号超时 接受应答包控制 Turning on AUTO TX2RX FSMTC1 FSMTC1 当 SRXON 发送时包接收不终止 Turning off abortRxOnSrxon FSMTC1 FIFO 门限设为最大值 127 Set FIFOP threshold to maximum IOCFG0 0 x7F 增益这部分没看懂 好像是用来优化的 tuning adjustments for optimal radio performance details available in datasheet RXCTRL0H 0 x32 RXCTRL0L 0 xF5 Turning on receiver to get output from IF ADC ISRXON halMcuWaitUs 1 运行随机数发生器 Enable random generator ADCCON1 for i 0 i channel 设置短地址和 PAN id Write the short address and the PAN ID to the CC2520 RAM halRfSetShortAddr pConfig myAddr halRfSetPanId pConfig panId if security is enabled write key and nonce ifdef SECURITY CCM basicRfSecurityInit pConfig endif 设置接收中断函数 在 hal types h 中有中断函数的定义 define HAL ISR FUNC DECLARATION f v PRAGMA vector v near func interrupt void f void define HAL ISR FUNC PROTOTYPE f v PRAGMA vector v near func interrupt void f void define HAL ISR FUNCTION f v HAL ISR FUNC PROTOTYPE f v HAL ISR FUNC DECLARATION f v 可以看出 HAL ISR FUNCTION f v 其实就定义了中断函数了 然后中断函数如下 HAL ISR FUNCTION macMcuRfIsr RF VECTOR uint8 rfim uint8 x HAL INT LOCK x rfim RFIM if RFIF Execute the custom ISR S1CON 0 RFIF HAL INT UNLOCK x 进入中断后会检查中断类型 然后执行 pfISR 指针指向的中断函数 typedef void ISR FUNC PTR void 定义中断服务程序的函数指针 static ISR FUNC PTR pfISR NULL void halRfRxInterruptConfig ISR FUNC PTR pf uint8 x HAL INT LOCK x pfISR pf HAL INT UNLOCK x define HAL INT LOCK x st x EA EA 0 define HAL INT UNLOCK x st EA x 中断锁 实际上就是在操作之前关闭总的中断 等操作完成后再打开中断 避免产生不必要 的中断 Set up receive interrupt received data or acknowlegment halRfRxInterruptConfig basicRfRxFrmDoneIsr 开所有中断 halIntOn return SUCCESS fn basicRfSendPacket brief Send packet param destAddr destination short address pPayload pointer to payload buffer This buffer must be allocated by higher layer length length of payload txState file scope variable that keeps tx state info mpdu file scope variable Buffer for the frame to send return basicRFStatus t SUCCESS or FAILED 发送函数 uint8 halRfTransmit void uint8 status ISTXON Sending Waiting for transmission to finish while RFIF RFIF IRQ TXDONE status SUCCESS return status uint8 basicRfSendPacket uint16 destAddr uint8 pPayload uint8 length uint8 mpduLength uint8 status 打开接收 define FLUSH RX FIFO st ISFLUSHRX ISFLUSHRX void halRfReceiveOn void 发送 CPS 指令 FLUSH RX FIFO ISRXON Turn on receiver if its not on if txState receiveOn halRfReceiveOn Check packet length length min length BASIC RF MAX PAYLOAD SIZE 等待传输完成 void halRfWaitTransceiverReady void while RFSTATUS We ll enter RX automatically so just wait until we can be sure that the ack reception should have finished The timeout consists of a 12 symbol turnaround time the ack packet duration and a small margin BASIC RF SYMBOL DURATION 为 0 5us 因为 2MChip s 的速度是固定的 halMcuWaitUs 12 BASIC RF SYMBOL DURATION BASIC RF ACK DURATION 2 BASIC RF SYMBOL DURATION 10 If an acknowledgment has been received by RxFrmDoneIsr the ackReceived flag should be set status txState ackReceived SUCCESS FAILED else status SUCCESS Turn off the receiver if it should not continue to be enabled if txState receiveOn halRfReceiveOff if status SUCCESS txState txSeqNumber ifdef SECURITY CCM halRfIncNonceTx Increment nonce value endif return status fn basicRfPacketIsReady brief Check if a new packet is ready to be read by next higher layer param none return uint8 TRUE if a packet is ready to be read by higher layer 检查包是否已准备好被上层读取 uint8 basicRfPacketIsReady void return rxi isReady fn basicRfReceive brief Copies the payload of the last incoming packet into a buffer param pRxData pointer to data buffer to fill This buffer must be allocated by higher layer len Number of bytes to read in to buffer rxi file scope variable holding the information of the last incoming packet return uint8 number of bytes actually copied into buffer uint8 basicRfReceive uint8 pRxData uint8 len int16 pRssi Accessing shared variables this is a critical region Critical region start halIntOff memcpy pRxData rxi pPayload min rxi length len if pRssi NULL if rxi rssi 128 pRssi rxi rssi halRfGetRssiOffset else pRssi rxi rssi 256 halRfGetRssiOffset rxi isReady FALSE halIntOn Critical region end return min rxi length len fn basicRfGetRssi brief Copies the payload of the last incoming packet into a buffer param none return int8 RSSI value int8 basicRfGetRssi void if rxi rssi asdu 解析 Bind rsp Unbind rsp 或 End Device Bind rsp 消息 a 指向要解析的消息的指针 ZDO MgmNwkDiscRsp t ZDO ParseMgmNwkDiscRsp zdoIncomingMsg t inMsg 解析 Mgmt NWK Disc rsp 消息 ZDO MgmtLqiRsp t ZDO ParseMgmtLqiRsp zdoIncomingMsg t inMsg ZDO MgmtRtgRsp t ZDO ParseMgmtRtgRsp zdoIncomingMsg t inMsg ZDO MgmtBindRsp t ZDO ParseMgmtBindRsp zdoIncomingMsg t inMsg define ZDO ParseMgmtDirectJoinRsp a uint8 a asdu define ZDO ParseMgmtLeaveRsp a uint8 a asdu define ZDO ParseMgmtPermitJoinRsp a uint8 a asdu ZDO UserDescRsp t ZDO ParseUserDescRsp zdoIncomingMsg t inMsg void ZDO ParseServerDiscRsp zdoIncomingMsg t inMsg ZDO ServerDiscRsp t pRsp 解析 Server Discovery rsp 消息 void ZDO ParseEndDeviceBindReq zdoIncomingMsg t inMsg ZDEndDeviceBind t bindReq void ZDO ParseBindUnbindReq zdoIncomingMsg t inMsg ZDO BindUnbindReq t pReq define ZDO ParseUserDescConf a uint8 a asdu void ZDO ParseDeviceAnnce zdoIncomingMsg t inMsg ZDO DeviceAnnce t pAnnce ZDO MgmtNwkUpdateNotify t ZDO ParseMgmtNwkUpdateNotify zdoIncomingMsg t inMsg ZigBee 学习之 15 ZStack API 解读 3 应用框架 AF 应用框架层是应用道 APS 层的 OTA 数据接口 此层也接收数据消息的终端多路复用器 AF 为应用提供以下功能 终端 Endpoint 管理 发送和接收数据 哈哈 这里的函数应该就是我们经常要用到的函数了 终端管理 每个设备都是 Zigbee 中的节点 每个节点有长地址和短地址 短地址被其他设备用来发送数据 每个节点又 241 个终端 0 保留 1 240 可分配给应用 每个终端可以独立设置地址 当设 备发送数据时必须指定目标设备的短地址和接收终端 一个应用必须注册一个或多个终端用来 接收或者发送数据 简单描述符 SimpleDescriptionFormat t 每个终端都必须有一个 Zigbee 简单描述 这些描述对 Zigbee 网络刻画了这个终端 其他设备 可以询问这个终端以知道这个设备的类型 typedef struct byte EndPoint uint16 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 EndPoint 终端号 1 240 这是节点的子地址 用来接收数据 AppProfId 定义了这个终端上支持的 Profile ID 剖面 ID ID 最好遵循由 ZigBee 联盟的分 配 AppDeviceId 终端支持的设备 ID ID 最好遵循 ZigBee 联盟的分配 AppDevVer 此终端上设备执行的设备描述的版本 0 x00 为 Version 1 0 Reserved 保留 AppNumInClusters 终端支持的输入簇数目 pAppInClusterList 指向输入 Cluster ID 列表的指针 AppNumOutClusters 终端支持的输出簇数目 pAppOutClusterList 指向输出 Cluster ID 列表的指针 终端描述符 endPointDesc t 节点中的每一个终端都必须有一个终端描述符 typedef struct byte endPoint byte task id Pointer to location of the Application task ID SimpleDescriptionFormat t simpleDesc afNetworkLatencyReq t latencyReq endPointDesc t task id 任务 ID 指针 当接收到消息时 此任务 ID 将指示消息传递目的 接收到的消息是以 OSAL 消息形式包装的 将发送到一个任务 simpleDesc 指向这个终端的 ZigBee 简单描述 latencyReq 必须用 noLatencyReqs 来填充 afStatus t afRegister endPointDesc t epDesc 为设备注册一个新的终端 epDesc 指向终端描述符 返回值 afStatus t 若成功则返回 ZSuccess 否则返回 ZComDef h 中定义的错误 epList t afRegisterExtended endPointDesc t epDesc pDescCB descFn 在上面函数功能的基础上增加了回调函数 当终端的简单描述符被查询时将调用此回调函数 这样应有就可以动态改变简单描述符而不用 RAM ROM 来储存描述符了 descFn 回调函数指针 相关函数必须为简单描述符分配足够的空间 填充简单描述符 然后返 回指向简单描述符的指针 调用者将释放为描述符分配空间 epList 指向终端列表元件的指针 如果失败则为 NULL endPointDesc t afFindEndPointDesc byte endPoint 从一个终端找到终端描述符 endPoint 要寻找的终端描述符的终端号 endPointDesc t 指向终端描述符的指针 若失败则为 NULL byte afFindSimpleDesc SimpleDescriptionFormat t ppDesc byte EP 从一个终端找到终端描述符 若返回值非零则必须调用 osal mem free 来释放描述符的内存占 用 ppDesc 指向指向简单描述符的指针 EP 终端简单描述符需要 uint8 afGetMatch uint8 ep 默认情况下 设备将响应 ZDO 匹配描述符请求 用这个函数来获得 ZDO 匹配描述符应答的设 置 ep 用来获得 ZDO 匹配描述符响应行为的终端 返回值 TRUE 允许响应 FALSE 不允许或者终端未找到 uint8 afSetMatch uint8 ep uint8 action 默认情况下 设备将响应 ZDO 匹配描述符 可以用这个函数来改变这个行为 比如 ep 为 1 action 为 FALSE ZDO 将不响应终端 1 的 ZDO 匹配面述符请求 ep 用来获得 ZDO 匹配描述符响应行为的终端 action TRUE 允许响应 FALSE 不允许或者终端未找到 返回值 TRUE 成功 FALSE 失败或者终端未找到 byte afNumEndPoints void 查找已注册的终端数目 返回此设备上已注册的终端数目 包括终端 0 void afEndPoints byte epBuf byte skipZDO 返回包含已注册的终端的一个数组 epBuf 指向存放终端的数组 每个终端占一个字节 skipZDO 设置为 TRUE 则不包含 ZDO 终端 终端 0 发送数据 afStatus t AF DataRequest afAddrType t dstAddr endPointDesc t srcEP uint16 cID uint16 len uint8 buf uint8 transID uint8 options uint8 radius dstAddr 目标地址指针 afAddrNotPresent 由反射器 邦定源 也即路由器或者协调器 指定 afAddrGroup 发送到组 afAddrBroadcast 发送广播消息 afAddr16Bit 直接发送到节点 单播 srcEP 发送终端的终端描述符指针 cID 簇 ID cluster ID 如同消息 ID 并且在剖面 profile 中各不相同 len 要发送的字节数 buf 指向要发送的数据缓存的指针 transID 事务序列号指针 如果消息缓存发送 这个函数将增加这个数字 options 发送选项 可以由下面一项 或几项相或得到 AF ACK REQUEST 0 x10 要求 APS 应答 这是应用层的应答 支在直接发送 单播 时使用 AF DISCV ROUTE 0 x20 总要包含这个选项 AF SKIP ROUTING 0 x80 设置这个选项将导致设备跳过路由而直接发送消息 终点设备将不 向其父亲发送消息 在直接发送 单播 和广播消息时很好用 radius 最大的跳数 用默认值 AF DEFAULT RADIUS afStatus t 成功则为 ZSuccess defined in ZComDef h 否则 Errors defined in ZComDef h uint8 afDataReqMTU afDataReqMTU t fields 找出基于输入参数的最大可发送字节数 返回能发送的最大字节数 fields 要发送的消息类型参数 typedef struct uint8 kvp APSDE DataReqMTU t aps afDataReqMTU t kvp 设为 false typedef struct uint8 secure APSDE DataReqMTU t aps secure 设为 false 如果在一个安全网络中此位将自动设置 ZigBee 学习之 16 ZStack API 解读 4 应用支持子层 APS 应用支持子层提供如下管理功能 邦定表管理 组表管理 快速地址查找 除了管理功能外 APS 还提供数据服务 只是应用不能访问数据服务 应用需要通过 AF 数据 接口 AF DataRequest 来发送数据 如果要使用邦定表函数需要包含 BindingTable h 头文件 邦定表管理 请注意 绑定服务只能在 互补 设备之间建立 那就是 只有分别在两个节点的简单描述结构 体 simple descriptor structure 中 同时注册了相同的命令标识符 command id 并且方向相 反 一个属于输出指令 output 另一个属于输入指令 input 才能成功建立绑定 APS 邦定表是在静态 RAM 中定义的一张表 定义在 nwk globals c 中 表的大小可以通过 f8wConfig cfg 中的 NWK MAX BINDING ENTRIES 和 MAX BINDING CLUSTER IDS 莱配 置 只有定义了 REFLECTOR 或者 COORDINATOR BINDING 才能包含此表 用 REFLECTOR 编译选项来支持 APS 层的源邦定 邦定表结构 BindingEntry t typedef struct uint16 srcIdx Address Manager index uint8 srcEP uint8 dstGroupMode Destination address type 0 Normal address index 1 Group address uint16 dstIdx This field is used in both modes group and non group to save NV and RAM space dstGroupMode 0 Address Manager index dstGroupMode 1 Group Address uint8 dstEP uint8 numClusterIds uint16 clusterIdList MAX BINDING CLUSTER IDS Don t use MAX BINDING CLUSTERS ID when using the clusterIdList field Use gMAX BINDING CLUSTER IDS BindingEntry t srcIdx 源地址 绑定记录的源地址 的地址管理器索引 地址管理器保存着源地址的 IEEE 地 址和短地址 srcEP 源终端 dstGroupMode 目的地址类型 0 普通地址 1 组地址 dstIdx 若 dstGroupMode 为 0 则包含目的地址的地址管理器索引 若 dstGroupMode 为 1 则 包含目的组地址 dstEP 目的终端 numClusterIds clusterIdList 中的入口数目 clusterIdList 簇 ID 列表 列表的最大数目定义由 MAX BINDING CLUSTER IDS f8wConfig cfg 指定 邦定表维护 BindingEntry t bindAddEntry zAddrType t srcAddr byte srcEpInt zAddrType t dstAddr byte dstEpInt byte numClusterIds uint16 clusterIds 在邦定表中增加一个入口 由于每个入口可以有多个 cluster ID 所以此函数有可能仅仅在已有邦 定条目上增加 cluster ID srcAddr 邦定记录源地址 为 Addr16Bit 或者 Addr64Bit 的 addr 数据结构 srcEpInt 邦定记录源终端 dstAddr 邦定记录目的地址 为 Addr16Bit Addr64Bit 或 AddrGroup addrMode 若为 Ad
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!