您的位置:首页 > 其它

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

2014-06-30 17:26 302 查看
凡是组网,必然涉及到单播,组播,广播这几个概念。

这几个概念的含义一目了然。这节主要关注怎么在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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  zigbee 无线 数据