关注zigbee(五)--单播,组播,广播

凡是组网,必然涉及到单播,组播,广播这几个概念。

这几个概念的含义一目了然。这节主要关注怎么在zigbee中实现单播,组播,广播。

回到 afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,
                           uint16 cID, uint16 len, uint8 *buf, uint8 *transID,
                           uint8 options, uint8 radius )

的第一个参数afAddrType_t *dstAddr, 是什么类型的消息,由这个参数决定。

typedef struct
{
  union
  {
    uint16      shortAddr;
    ZLongAddr_t extAddr;
  } addr;
  afAddrMode_t addrMode;   //决定了数据发送模式,这个值为 afAddr16Bit表示单播, afAddrGroup 是组播, afAddrBroadcast 是广播
  uint8 endPoint;
  uint16 panId;  // used for the INTER_PAN feature
} afAddrType_t;

除了设置addrMode,目的地址还需要设置 shortAddr,它是节点的网络地址,如协调器为0x0000。

单播

将目的地址设置成单播形式即可。

    Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
    Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
    Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器

组播

使用组播方式,难点是如何加入特定的组。 组播的要素(见结构体aps_Group_t)为 组播ID, 组播名字。

typedef struct
{
  uint16 ID;                       // Unique to this table
  uint8  name[APS_GROUP_NAME_LEN]; // Human readable name of group
} aps_Group_t;

然后调用aps_AddGroup,将端口加入组播组。

  如  // By default, all devices start out in Group 1
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );


广播

使用广播通信时,shortAddr的网络地址可以为0xffff, 0xfffd, 0xfffc

0xffff 表示数据在全网广播,包括处于休眠的节点;

0xfffd 表示数据包只发往处于active的节点,不发往处于休眠的节点;

0xfffc表示数据包发往网络中的所有路由器节点。

如:

  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值