微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > 射频无线通信设计 > ZigBee四种绑定方式在Z-Stack中的应用(转)

ZigBee四种绑定方式在Z-Stack中的应用(转)

时间:10-02 整理:3721RD 点击:



本文是作者根据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. 绑定表存放的位置是内存中预先定义的块,如果编译选项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 requests 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:

建立一个绑定表格有四种方法可供选择:

l 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

自动绑定

一、 负责发送消息的设备在网络上广播带有如下参数的“个人公告”(Personal Advertisement):

(1) 地址,配置文件标识符,簇集合列表;

(2) 描述符匹配请求- ZDP_MatchDescReq()。

二、 匹配的设备会作出响应。

三、 由ZDO处理和验证响应。

四、 负责发送消息的设备建立绑定表并保存绑定记录。

五、 这种方法有时也称“服务发现”,“自动找寻”或者“自动匹配”。

l Zigbee Device Object Bind Request–a commissioning tool can tell the device to make 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),即可启动委托绑定的申请。第一个参数(消息发送目标地址)是绑定源节点的短地址(即保存绑定记录的节点地址,这是因为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 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.

This mechanism uses a button press or other similar action at the selected devices to bind within a specific timeout period. The End Device Bind Request messages are collected at the coordinator within the timeout period and a resulting Binding Table entry is created based on the agreement of profile ID and cluster ID. The default end device binding timeout(APS_DEFAULT_MAXBINDING_TIME)is 16 seconds(defined in nwk_globals.h),but can be changed if added to f8wConfig.cfg.

You’ll notice that all sample applications have a function that handles key events[for example, TransmitApp_HandleKeys()in TransmitApp.c].This function calls ZDApp_SendEndDeviceBindReq()[in ZDApp.c],which gathers all the information for the application’s endpoint and calls ZDP_EndDeviceBindReq()[ZDProfile.c]to send the message to the coordinator.Or,as in SampleLight and SampleSwitch,ZDP_EndDeviceBindReq()is called directly with only the cluster IDs relevant to the lamp On/Off functions.

The coordinator will receive[ZDP_IncomingData()in ZDProfile.c]and parse [ZDO_ProcessEndDeviceBindReq()in ZDObject.c]the message and call ZDApp_EndDeviceBindReqCB()[in ZDApp.c],which calls ZDO_MatchEndDeviceBind()[ZDObject.c] to process the request.

Coordinator receives and holds the request until a request from another node is received(16 seconds is the default).

When the coordinator receives 2 matching End Device Bind Requests,it will start the process of creating source binding entries in the requesting devices.The coordinator follows the following process,assuming matches were found in the ZDO End Device Bind Requests:

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设备对象终端节点绑定请求-两个设备可向协调器告知他们想建立一个绑定表记录。协调器通过安排配对并分别在这两个设备上建立绑定表条目,也称集中式绑定。

这一机制规定在指定的时限内,通过按键或者其他类似动作对指定的设备实施绑定。在规定的时限内,协调器负责收集终端设备绑定请求消息,然后根据相同的配置 文件标识号和簇标识号建立相应的绑定表格条目。默认的终端节点绑定时限(APS_DEFAULT_MAXBINDING_TIME)是16秒(在 nwk_globals.h中定义),若要修改可在f8wConfig.cfg中新增数值。

所有例子的应用服务中都有一个响应按键事件的函数(例如,TransmitApp.c中的TransmitApp_HandleKeys())。这一响应 函数调用ZDApp_SendEndDeviceBindReq()[在 ZDApp.c中]收集该应用服务端点的所有信息,然后再调用ZDP_EndDeviceBindReq()[在ZDProfile.c中]把信息发送给 协调器。或者,像SampleLight和SampleSwitch例程中,按键后直接调用ZDP_EndDeviceBindReq(),仅把

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top