BINDING 概述
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 calledsource 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
uint8 numClusterIds;//Number of cluster IDs in the clusterIdList below
uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS];
}BindingEntry_t;
绑定表
1.
2.
3.
4.
5.
typedef struct
uint16 srcIdx;
uint8 srcEP;
uint8 dstGroupMode;
uint16 dstIdx;
uint8 dstEP;
uint8 numClusterIds;
uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS];
zigbee绑定1
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.
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 requests by issuing the zb_AllowBindResponse().Then the zb_BindDeviceRequest()is issued on the source device with a null address.
概述---怎样绑定节点
绑定指的是两个节点在应用层上建立起来的一条逻辑链路。在同一个节点上可以建立多个绑定服务,分别对应不同种类的数据包。此外,绑定也允许有多个目标节点(一对多绑定)。
举个例子,在一个灯光网络中,有多个开关和灯光设备,每一个开关可以控制一个或以上的灯光设备。在这种情况下,需要在每个开关中建立绑定服务。这使得开关中的应用服务在不知道灯光设备确切的目标地址时,可以顺利地向灯光设备发送数据包。
一旦在源节点上建立了绑定,其应用服务即可向目标节点发送数据,而不需指定目标地址了(调用zb_SendDataRequest(),目标地址可用一个无效值0xFFFE代替)。这样,协议栈将会根据数据包的命令标识符,通过自身的绑定表查找到所对应的目标设备地址。
zigbee绑定2
There are 4 ways to build a binding table:
建立一个绑定表格有四种方法可供选择:
l
A.
1)
2)
B.
C.
D.
自动绑定
一、
(1)
(2)
二、
三、
四、
五、
zigbee绑定3
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
任何一个设备或应用服务,都能通过无线信道向网络上的另一个设备发送一个ZDO消息,帮助其建立一个绑定记录。这称为辅助绑定,在消息发向的设备上会建立一个绑定条目。
委托绑定的申请:
任一个应用服务,通过向ZDP_BindReq()[defined in ZDProfile.h]提供绑定记录所需要的应用服务入口参数(地址和端点)以及簇标识号(cluster ID),即可启动委托绑定的申请。第一个参数(消息发送目标地址)是绑定源节点的短地址(即保存绑定记录的节点地址,这是因为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已经打开!
zigbee绑定4
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对相应的应用服务实施绑定。
函数原型:
afStatus_t ZDP_BindReq(zAddrType_t*dstAddr,byte*SourceAddr,
byte SrcEPIntf,byte ClusterID,byte*DestinationAddr,byte DstEPIntf,
byte SecuritySuite);
参数细节:
DstAddr-消息发送地址 (负责绑定的设备地址)
SourceAddr–源节点的64位IEEE地址
SrcEPIntf–源节点应用服务的端点
ClusterID–需要绑定的簇标识符
DestinationAddr–目标节点的64位IEEE地址
DstEPIntf–目标节点应用服务的端点
SecuritySuite-安全机制模式
返回值:
afStatus_t–此函数需要借助AF发送(AF_DataRequest())生成的消息,因此返回值是AF状态值。
zigbee绑定5
Zigbee Device Object End Device Bind Request–2 devices can tell the coordinator that they would like to setup a binding table record.The coordinator will make the match up and create the binding table entries in the 2 devices.Or named Centralized Binding.
Coordinator receives and holds the request until a request from another node is received(16 seconds is the default).
1.Send a ZDO Unbind Request to the first device.The End Device Bind is toggle process,so the unbind is sent first to remove an existing bind entry.
2.Wait for the ZDO Unbind Response,if the response status is ZDP_NO_ENTRY,send a ZDO Bind Request to make the binding entry in the source device.If the response status is ZDP_SUCCESS,move on to the cluster ID for the first device(the unbind removed the entry–toggle).
3.Wait for the ZDO Bind Response.When received,move on to the next cluster ID for the first device.
4.When the first device is done,do the same process with the second device.
5.When the second device is done,send the ZDO End Device Bind Response messages to both the first and second device.
ZigBee设备对象终端节点绑定请求-两个设备可向协调器告知他们想建立一个绑定表记录。协调器通过安排配对并分别在这两个设备上建立绑定表条目,也称集中式绑定。
这一消息将会被协调器接收[ZDP_IncomingData()in ZDProfile.c]和解析[ZDO_ProcessEndDeviceBindReq()in ZDObject.c],然后让回调函数ZDApp_EndDeviceBindReqCB()[in ZDApp.c]调用ZDO_MatchEndDeviceBind()[ZDObject.c]处理这一请求。
1.
2.
3.
4.
5.
注意打开编译选项:REFLECTOR和ZDO_COORDINATOR
zigbee绑定6
ZDApp_SendEndDeviceBindReq()
-Pro:The binding information resides on the network reflector device, saving RAM space on the target devices.
-Pro:The network reflector must be RxOnWhenIdle(always listening to the network).So if one of the bound devices broadcasts that its network address has changed,then the network reflector will update the corresponding binding table entry.Thus,even if the other bound device was sleeping,its subsequent messages to the changed device will still be correctly addressed by the network reflector.
-Con:A device that is bound to more than one other device cannot send a message to one or a subset of its matching devices–the reflector will generate aunicast message to all of the bound devices.
-Con:A sending device cannot receive notification of delivery to the destination device(i.e.the expected result when using the AF_ACK_REQUEST flag.)
-Con:All messages must go thru the network reflector, reducing network bandwidth.
-Pro/Con:A sending device bound to six devices will send one message to the network reflector which will result in the network reflector sending six unicast messages.Consider a network divided into two equal geographic regions,A and B,with the network reflector on the centerline.If the sending device is deep into region A and the receiving devices are deep into region B,then for every message sent, network traffic in region A will be six times less than it would be if the sending device has generated six instead of one trans-network messages.If all devices are nearby each other,deep in one region,then network traffic in that region is very much more than if the sending device could just send single hop messages to the intended recipients.
ZDApp_SendEndDeviceBindReq()
优点:
1.
2.
缺点:
1.
2.
3.
进一步分析:
zigbee绑定7
( Device Application–An application on the device can build or manage a binding table. Another way to enter binding entries on the device is for the application to manage the binding table for itself.
bindAddEntry()–Add entry to binding table
bindRemoveEntry()–Remove entry from binding table
bindRemoveClusterIdFromL
bindAddClusterIdToList()
bindRemoveDev()–Remove all entries with an address reference
bindRemoveSrcDev()
bindUpdateAddr()–Update entries to another address
bindFindExisting()–Find a binding table entry
bindIsClusterIDinList()
bindNumBoundTo()
bindNumOfEntries()–Number of table entries
bindCapacity()–Maximum entries allowed
BindWriteNV()–Update table in NV.
设备的应用服务-设备上的一个应用服务可以建立或者维护一个绑定表。进入设备上绑定条目的另一种方法是由应用服务本身去管理绑定表。
管理绑定表使用的API:
bindAddEntry()–绑定表中加条目
bindRemoveEntry()–绑定表中移除条目
bindRemoveClusterIdFromL
bindAddClusterIdToList()–在一个已有的绑定表条目中加入一个簇标识符
bindRemoveDev()–移除某目标地址的所有条目
bindRemoveSrcDev()–移除某源地址的所有条目
bindUpdateAddr()–更新条目到新的地址
bindFindExisting()–查找一个绑定条目
bindIsClusterIDinList()–在绑定条目中查找一个已有的簇标识符
bindNumBoundTo()–某一地址(源地址或目标地址)绑定条目的个数
bindNumOfEntries()–绑定表条目的个数
bindCapacity()–允许的最大绑定条目数
BindWriteNV()–在NV中保存新的绑定表
zigbee绑定8
Which Binding Method To Use?
我们应该选择哪一种绑定方式?
Automatic
+no user interaction required
+no tool cost
-development time knowledge
-non-configurable
Assisted
+install-time decisions(site-specific knowledge)
+analysis,maintenance,modification,visualization
can be under installers control
-cost of tool
Centralized
+allows user to decide
+cost of tool minimal
-few,if any,configurable parameters
-requires a user interface on each device
Application
+maximum flexibility
-you must write all the code
Some further discussion from TI E2E COMMUNITY
1. The nomenclature "End Device Bind Req" is misleading. This doesn't just apply to end devices... but rather
a. (Bind Req) Device 1 --> Coordinator <--- Device 2 (Bind Req)
Coordinator looks at the cluster contained in the bind req, compares the IEEE of each device, and if the clusters match, and no binding table already exists for these IEEEs then it will send a bind response back to each device.
After step a,
b. Device 1 <--- NWK Addr Req ------ Coordinator ------- NWK addr Req ----> Device 2
c. Device 1 ----> NWK Addr Rsp ---> Coordinator <---- NWK addr Rsp <--- Device 2
d. Device 1 <----- Bind Rsp <----- Coordinator -----> Bind Rsp ----> Device 2
2. Match descriptor is a way of putting the smarts of service discovery on the source device. What happens in this case is the following. NO coordinator involvement is necessary
Device 1 ----> Match Descriptor request (broadcast or unicast) Device 2
Device 1 <---- Match Descriptor response (if clusters, application profile id match) that includes src endpoint, src address <---- Device 2
Device 1 then has to keep a local record of the src endpiont, src address.
Most applications end up using method 2.
来自TI E2E社区的进一步讨论:
一、“终端设备绑定请求”这一命名有误导的嫌疑。这一请求不仅仅适用于终端设备,而且适用于对希望在协调器上绑定的两个设备中匹配的簇实施绑定。一旦这个函数被调用,将假设REFLECTOR这一编译选项在所有希望使用这一服务的节点中都已经打开。具体操作如下:
(1)
协调器首先找出包含在绑定请求中的簇,然后对比每一设备的IEEE地址,如果簇可以匹配,而且这几个设备没有已经存在的绑定表,那他将发送一个绑定应答给每一个设备。
(2)
(3)
(4)
二、“描述符匹配”为源设备的服务发现提供了一种灵巧的方法。下面是具体的操作,这一过程并没有通过协调器。
(1)
(2)
1号设备需要维护一个端点和地址的记录。
许多应用服务最终都会使用第二种方法。