果对于目的地址能找到有效的路由表条目,信息包将会被传递到该条目中所存储的下一个hop地址;如果找不到有效的路由表条目,路由探测功能将会被启动,信息包将会被缓存直到发现一个新的路由信息。
ZigBee End Device不会执行任何路由函数,它只是简单的将信息传送给前面的可以执行路由功能的父设备。因此,如果End Device想发送信息给另外一个End Device,在发送信息之间将会启动路由探测功能,找到相应的父路由节点。
2.8 ZigBee四种绑定方式在Z-Stack中的应用
http://blog.ednchina.com/Jam/253891/message.aspx KuangJunBin:本文是作者根据TI Z-Stack开发文档,ZigBee Specification-2007,《Zigbee Wireless Networking》等英文资料整合和翻译而成,采用中英双语对照方便读者理解,文中翻译不当之处,望广大同行不吝赐教。推广ZigBee技术,提高国内电子行业的国际影响力,是我们无线通讯工程师的愿景。本文欢迎转载,请保留作者信息和出处,作为支持我继续努力前行的动力,谢谢!
E-mail:kuangjunbin@gmail.com
In the Zigbee 2006 release,the binding mechanism is implemented in all devices and is called source binding. Binding allows an application to send a packet without knowing the destination address,the APS layer determines the destination address from its binding table,and then forwards the message on to the destination application(or multiple applications)or group.
ZigBee2006版本中规定,在全部节点中实现绑定机制,并将其称为源绑定。绑定机制允许一个应用服务在不知道目标地址的情况下向对方(的应用服务)发送数据包。发送时使用的目标地址将由应用支持子层从绑定表中自动获得,从而能使消息顺利被目标节点的一个或多个应用服务,乃至分组接收。
Binding Table
1.Defined in RAM,but can be saved in Flash if the NV_RESTORE compiler option is used
2.Stored on source node(REFLECTOR compiler option required) 3.Entries map messages to their intended destination 4.Each entry in the binding table contains the following: typedef struct {
uint16 srcIdx;//Source index uint8 srcEP;//Source endpoint
uint8 dstGroupMode;//Specifies normal or group addressing uint16 dstIdx;//Destination index or group address uint8 dstEP;//Destination endpoint
第 21 页 共 107 页
uint8 numClusterIds;//Number of cluster IDs in the clusterIdList below uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS]; }BindingEntry_t;
绑定表
1. 绑定表存放的位置是内存中预先定义的块,如果编译选项NV_RESTORE被激活,也能
保存在Flash里。
2. 绑定表放置在源节点(需要激活编译选项REFLECTOR)。 3. 绑定表的条目把需要发送的消息映射到它们的目标地址上。 4. 绑定表中每个条目包括以下内容: 5. 绑定表条目结构体的定义 typedef struct {
uint16 srcIdx; //源地址索引 uint8 srcEP; //源端点
uint8 dstGroupMode; //指定寻址模式 uint16 dstIdx; //目标地址索引或者分组号 uint8 dstEP; //目标端点
uint8 numClusterIds; //在簇标识符表中簇标识符的个数
uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS]; //簇标识符表 }BindingEntry_t;
Simple Description --- How to bind devices
A binding is a logical link between two devices at the application layer. Multiple bindings can be created on a device, one for each type of data packet. In addition, a binding may have more than one destination device(one-to-many bindings).
For example,in a lighting network with multiple switches and lights,each switch will control one or more light.In that case,a binding should be created in each switch.This allows the application to send the data packets without knowing the actual destination address.
Once a binding is created on the source device,the application can send data without specifying a destination address(in the call to zb_SendDataRequest(),the invalid address-0xFFFE should be used as the destination).This will cause the stack to look up the destination in its internal binding table based on the command identifier of the packet.
There can be more than one destination in the binding entry.In that case,the stack will automatically send a copy of the packet to each destination specified in the binding entry. Also,if the NV_RESTORE compile option is enabled when building the image,the stack will save the binding entries to non-volatile ram This is useful in the device has an accidental reset(or if the batteries need to be changed on the device),the device can recover automatically without the user having to setup the bindings again.
There are two mechanisms available to configure device bindings.If the extended address of the destination device is known,the zb_BindDeviceRequest()can be to create a binding entry. If the extended address is not known,a―push button‖strategy may be employed.In this case,the destination device is first put in a state where it will respond to match requ
第 22 页 共 107 页
ests by issuing the zb_AllowBindResponse().Then the zb_BindDeviceRequest()is issued on the source device with a null address.
In addition,bindings can be setup by using an external commissioning tool.Note that bindings can only be created between―complementary‖devices.That is,the binding will only succeed if both devices have registered the same command_id in their simple descriptor structures and one device has the command as an―output‖while the other device has it as an―input‖.
概述---怎样绑定节点
绑定指的是两个节点在应用层上建立起来的一条逻辑链路。在同一个节点上可以建立多个绑定服务,分别对应不同种类的数据包。此外,绑定也允许有多个目标节点(一对多绑定)。
举个例子,在一个灯光网络中,有多个开关和灯光设备,每一个开关可以控制一个或以上的灯光设备。在这种情况下,需要在每个开关中建立绑定服务。这使得开关中的应用服务在不知道灯光设备确切的目标地址时,可以顺利地向灯光设备发送数据包。
一旦在源节点上建立了绑定,其应用服务即可向目标节点发送数据,而不需指定目标地址了(调用zb_SendDataRequest(),目标地址可用一个无效值0xFFFE代替)。这样,协议栈将会根据数据包的命令标识符,通过自身的绑定表查找到所对应的目标设备地址。 在绑定表的条目中,有时会有多个目标端点。这使得协议栈自动地重复发送数据包到绑定表指定的各个目标地址。同时,如果在编译目标文件时,编译选项NV_RESTORE被打开,协议栈将会把绑定条目保存在非易失性存储器里。因此当意外重启(或者节点电池耗尽需要更换)等突发情况的发生时,节点能自动恢复到掉电前的工作状态,而不需要用户重新设置绑定服务。
配置设备绑定服务,有两种机制可供选择。如果目标设备的扩展地址(64位地址)已知,可通过调用zb_BindDeviceRequest()建立绑定条目。如果目标设备的扩展地址未知,可实施一个“按键”策略实现绑定。这时,目标设备将首先进入一个允许绑定的状态,并通过zb_AllowBindResponse()对配对请求作出响应。然后,在源节点中执行zb_BindDeviceRequest()(目标地址设为无效)可实现绑定。
此外,使用节点外部的委托工具(通常是协调器)也可实现绑定服务。请注意,绑定服务只能在“互补”设备之间建立。那就是,只有分别在两个节点的简单描述结构体(simple descriptor structure)中,同时注册了相同的命令标识符(command_id)并且方向相反(一个属于输出指令“output”,另一个属于输入指令“input”),才能成功建立绑定。
There are 4 ways to build a binding table: 建立一个绑定表格有四种方法可供选择:
? Automatic Binding
A. Sending device broadcasts a―personal ad‖on the network with: 1) Address,Profile ID,Cluster Lists
2) Match Description Request-ZDP_MatchDescReq() B. Compatible devices respond
C. Response handled and validated by the ZDO
D. Sender application stores binding record in binding table
第 23 页 共 107 页
自动绑定
一、 负责发送消息的设备在网络上广播带有如下参数的“个人公告”(Personal Advert
isement):
(1) 地址,配置文件标识符,簇集合列表;
(2) 描述符匹配请求- ZDP_MatchDescReq()。 二、 匹配的设备会作出响应。 三、 由ZDO处理和验证响应。
四、 负责发送消息的设备建立绑定表并保存绑定记录。 五、 这种方法有时也称“服务发现”,“自动找寻”或者“自动匹配”。
? Zigbee Device Object Bind Request–a commissioning tool can tell the device to m
ake a binding record,or named Assisted Binding.
Any device or application can send a ZDO message to another device(over the air)to build a binding record for that other device in the network.This is called Assisted Binding and it will create a binding entry for the sending device.
The Commissioning Application
An application can do this by calling ZDP_BindReq()[defined in ZDProfile.h]with 2 applications(addresses and endpoints)and the cluster ID wanted in the binding record.The first parameter(target dstAddr)is the short address of the binding’s source address(where the binding record will be stored).
Make sure you have the feature enabled in ZDConfig.h[ZDO_BIND_UNBIND_REQUEST].
You can use ZDP_UnbindReq()with the same parameters to remove the binding record.
The target device will send back a Zigbee Device Object Bind or Unbind Response message which the ZDO code will parse and notify ZDApp.c by calling ZDApp_BindRsp()or ZDApp_UnbindRsp()with the status of the action.
For the Bind Response,the status returned from the coordinator will be ZDP_SUCCESS,ZDP_TABLE_FULL or ZDP_NOT_SUPPORTED.
For the Unbind Response, the status returned from the coordinator will be ZDP_SUCCESS,ZDP_NO_ENTRY or ZDP_NOT_SUPPORTED.
External device initiated binding(―external‖meaning not a participant of the resultant binding)
External device application calls ZDP_BindReq()with 2 applications(addresses and endpoints)and the cluster ID to bin
The first parameter is where the binding record will be stored Make sure you have REFLECTOR compile flag enabled
ZigBee设备对象绑定请求-一种告诉目标设备建立绑定记录的委托工具,也称辅助绑定。
任何一个设备或应用服务,都能通过无线信道向网络上的另一个设备发送一个ZDO消息,帮助其建立一个绑定记录。这称为辅助绑定,在消息发向的设备上会建立一个绑定条目。
委托绑定的申请:
任一个应用服务,通过向ZDP_BindReq()[defined in ZDProfile.h]提供绑定记录所需要的应用服务入口参数(地址和端点)以及簇标识号(cluster ID),即可启动委托绑
第 24 页 共 107 页
定的申请。第一个参数(消息发送目标地址)是绑定源节点的短地址(即保存绑定记录的节点地址,这是因为ZDP需委托应用框架AF辅助实现绑定,如果节点本身是REFLECTOR,并且希望保存绑定记录,则此消息发送的目标地址就是本地的AF,这与目标节点的地址DestinationAddr of Receiving device不同)。
注意事项:
确保[ZDConfig.h]中ZDO_BIND_UNBIND_REQUEST特性已经打开! 你可以通过ZDP_UnbindReq()(使用相同参数)来移除绑定记录。
被请求辅助绑定的目标设备会返回的ZDO申请绑定或者解除绑定的应答消息。此ZDO消息会被解析并通过调用ZDApp_BindRsp()或ZDApp_UnbindRsp()告知ZDApp.c此次请求的结果。
对于申请绑定的应答消息,从协调器返回的状态可能有ZDP_SUCCESS,ZDP_TABLE_FULL or ZDP_NOT_SUPPORTED。
对于解除绑定的应答消息,从协调器返回的状态可能有ZDP_SUCCESS,ZDP_NO_ENTRY or ZDP_NOT_SUPPORTED。
绑定是由外部的设备发起(“外部”的意思是发起绑定的不是绑定的对象之一)。
外部设备应用程序以两个应用服务(地址和端点)和簇标识符作为参数调用ZDP_BindReq ()发起绑定。第一个参数就是绑定记录保存的设备地址。
确保编译选项REFLECTOR已经打开!
ZDP_BindReq()
This is actually a macro that calls ZDP_BindUnbindReq().This call will build and send a Bind Request.Use this function to request the Zigbee Coordinator to bind application based on clusterID. Prototype
afStatus_t ZDP_BindReq(zAddrType_t*dstAddr,byte*SourceAddr, byte SrcEPIntf,byte ClusterID,byte*DestinationAddr,byte DstEPIntf, byte SecuritySuite); Parameter Details
DstAddr-The destination address. (the binding’s source address) SourceAddr–64 bit IEEE address of the device generating the messages. SrcEPIntf–endpoint/interface of the application generating the messages. ClusterID–cluster ID of the messages to bind.
DestinationAddr–64 bit IEEE address of the device receiving the messages. DstEPIntf–endpoint/interface of the application receiving the messages. SecuritySuite-Type of security wanted on the message. Return
afStatus_t–This function uses AF to send the message,so the status values are AF status values defined in ZStatus_t in ZComDef.h.
函数解析:
ZDP_BindReq()实际上是调用ZDP_BindUnbindReq()的一个宏。这一调用会产生并发送一个绑定的请求,使得ZigBee协调器根据簇标识号clusterID对相应的应用服务实施绑定。 函数原型:
第 25 页 共 107 页