ZigBee四种绑定方式在Z-Stack中的应用(转)
本文是作者根据TI Z-Stack开发文档,ZigBee Specification-2007,《Zigbee Wireless Networking》等英文资料整合和翻译而成,采用中英双语对照方便读者理解,文中翻译不当之处,望广大同行不吝赐教。推广ZigBee技术,提高国 内电子行业的国际影响力,是我们无线通讯工程师的愿景。
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
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];
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代替)。这样,协议栈将会根据数据包的命令标识符,通过自身的绑定表查找到所对应的目标设备地址。
There are 4 ways to build a binding table:
建立一个绑定表格有四种方法可供选择:
l
A.
1)
2)
B.
C.
D.
自动绑定
一、
(1)
(2)
二、
三、
四、
五、
l
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已经打开!
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状态值。
l
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设备对象终端节点绑定请求-两个设备可向协调器告知他们想建立一个绑定表记录。协调器通过安排配对并分别在这两个设备上建立绑定表条目,也称集中式绑定。