前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Zigbee协议栈组播通信

Zigbee协议栈组播通信

作者头像
得野
发布2020-02-18 23:02:31
1.1K0
发布2020-02-18 23:02:31
举报
文章被收录于专栏:我得去远方我得去远方

1、在Zigbee网络中组播通信,模块可以分组来标记,发送模块的组号和接受模块的组号相对应,那么这些模块就可以拿到无线数据包。

2、分组中组编号是2个字节,如0x0001、0x0002。

3、发送的模块按照组的方式发送,需要目标模块的组编号,端点,簇。

4、一个组可以关联多个端点,同一个端点也可以关联多个组。

终端节点(发送):

ZZApp.c中

代码语言:javascript
复制
  if ( events & ZZApp_MY_EVT )
  {
    if(P0_1 == 0)
    {
       char theMessageData[] = "HELLO WORLD!";
       ZZApp_DstAddr.addrMode = (afAddrMode_t)AddrGroup;//组播形式
       ZZApp_DstAddr.addr.shortAddr = 0x0001;//接受端的组
       // Take the first endpoint, Can be changed to search through endpoints
       ZZApp_DstAddr.endPoint = 10;//接受端的端口

       AF_DataRequest( &ZZApp_DstAddr, &ZZApp_epDesc,
                       0x0001,//接受端的簇
                       (byte)osal_strlen( theMessageData ) + 1,
                       (byte *)&theMessageData,
                       &ZZApp_TransID,
                       AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
       P1_0 = ~P1_0;
    }
    if(P2_0 == 0)
    {
      char theMessageData[] = "hello world!";
       ZZApp_DstAddr.addrMode = (afAddrMode_t)AddrGroup;//组播形式
       ZZApp_DstAddr.addr.shortAddr = 0x0002;//接受端的组
       // Take the first endpoint, Can be changed to search through endpoints
       ZZApp_DstAddr.endPoint = 10;//接受端的端口

       AF_DataRequest( &ZZApp_DstAddr, &ZZApp_epDesc,
                       0x0001,//接受端的簇
                       (byte)osal_strlen( theMessageData ) + 1,
                       (byte *)&theMessageData,
                       &ZZApp_TransID,
                       AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
       P1_1 = ~P1_1;
    }
    return (events ^ ZZApp_MY_EVT);
  }
协调器(接受):

ZZApp.c定义#include "aps_groups.h"头文件 定义两个组

代码语言:javascript
复制
aps_Group_t ZZApp_Group1;
aps_Group_t ZZApp_Group2;

编写事件

代码语言:javascript
复制
  if ( events & ZZApp_MY_EVT )
  {
    if(P0_1 == 0)
    {
      LCD_P8x16Str(4, 4, "groupId 0x0001");
      aps_RemoveGroup(10,0x0002);//取消关联 10端口和组0x0002

      ZZApp_Group1.ID = 0x0001; //定义组0x0001
      aps_AddGroup(10, &ZZApp_Group1 ); //关联 10端口和组0x0001
    }
    if(P2_0 == 0)
    {
      LCD_P8x16Str(4, 4, "groupId 0x0002");
      aps_RemoveGroup(10,0x0001);//取消关联 10端口和组0x0001

      ZZApp_Group2.ID = 0x0002;//定义组0x0002
      aps_AddGroup(10, &ZZApp_Group2 );//关联 10端口和组0x0002
    }
    return (events ^ ZZApp_MY_EVT);
  }

接受数据

代码语言:javascript
复制
void ZZApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
  if(pkt->groupId==0x0001)//组
  {
    if(pkt->endPoint==10)//端点
    {
      switch(pkt->clusterId)//簇
      {
        case 0x0001:LCD_P8x16Str(8, 2, pkt->cmd.Data);
                    //D1  P1_0
                    P1SEL &= ~0x01;
                    P1DIR |= 0x01;
                    P1_0 = ~P1_0;
                    break;
      }
    }
  }
  if(pkt->groupId==0x0002)//组
  {
    if(pkt->endPoint==10)//端点
    {
      switch(pkt->clusterId)//簇
      {
        case 0x0001:LCD_P8x16Str(8, 2, pkt->cmd.Data);
                    //D2 P1_1
                    P1SEL &= ~0x02;
                    P1DIR |= 0x02;
                    P1_1 = ~P1_1;
                    break;
      }
    }
  }
}
相关函数:
代码语言:javascript
复制
#include "aps_groups.h"//头文件

aps_Group_t SampleApp_Group; //定义组

extern ZStatus_t aps_AddGroup( uint8 endpoint, aps_Group_t *group ); //关联端点和组
extern uint8 aps_RemoveGroup( uint8 endpoint, uint16 groupID );//取消关联的端点和组
extern void aps_RemoveAllGroup( uint8 endpoint );//取消所有关联的端点和组
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-02-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 我得去远方 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 协调器(接受):
  • 相关函数:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档