Zigbee协议栈(CC2530开发板):绑定


原文地址: Zigbee协议栈(CC2530开发板)    原文作者: 江淮一士

GenericApp实验

绑定是协调器与终端或者终端与终端之间相互传输数据一种方法。绑定之后,网络内设备之间就可以互相传递数据了。

1.协调器通过广播方式与网络内所有终端建立绑定

uint16 bind_req(uint8 task_id,uint16 events)//终端请求与协调器绑定
{
 zAddrType_t dstAddr;
  
//********** 广播方式 终端 能够与网络内所有设备绑定,包括协调器和其它终端**  
     dstAddr.addrMode = AddrBroadcast;
     dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
//*************************************************************************     
     
      ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
                        GENERICAPP_PROFID,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        FALSE );
     
      osal_start_timerEx(bind_TaskID,5,2000);
 
 return 0;
}

 

这是我建立的一个任务,可以通过定时器触发此任务,绑定成功后可以停止该定时器。绑定成功后,协调器就可以通过广播方式发送数据给所有终端了。

 

2.终端与协调器绑定

只需要对上述函数稍作修改就可以啦

如下所示:

uint16 bind_req(uint8 task_id,uint16 events)//终端请求与协调器绑定
{
 zAddrType_t dstAddr;
 
//*******  只与协调器绑定 *************
      dstAddr.addrMode = Addr16Bit;
      dstAddr.addr.shortAddr = 0x0000; // Coordinator
//*************************************     
 
//********** 广播方式 终端 能够与网络内所有设备绑定,包括协调器和其它终端** 
//      dstAddr.addrMode = AddrBroadcast;
//      dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
//*************************************************************************     
     
      ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
                        GENERICAPP_PROFID,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        FALSE );
     
      osal_start_timerEx(bind_TaskID,5,2000);
 
 return 0;
}

 

以上介绍了两种绑定方法。实现绑定以后,互传数据就随心所欲啦。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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 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版本中规定,在全部节点中实现绑定机制,并将其称为源绑定绑定机制允许一个应用服务在不知道目标地址的情况下向对方(的应用服务)发送数据包。发送时使用的目标地址将由应用支持子层(APS)从绑定表中自动获得,从而能使消息顺利被目标节点的一个或多个应用服务,乃至分组接收。 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. 绑定表存放的位置是内存中预先定义的RAM块,如果编译选项NV_RESTORE被激活,也能保存在Flash里。 2. 绑定表放置在源节点(需要激活编译选项REFLECTOR)。 3. 绑定表的条目把需要发送的消息映射到它们的目标地址上。 4. 绑定表中每个条目(entry)包括以下内容: 绑定表条目结构体的定义

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值