CC2530学习(八)Zigbee点播、组播、广播

本文详细介绍了如何在CC2530上使用Z-stack实现Zigbee的点播、组播和广播通信。从创建设备地址结构体、初始化结构、处理函数的创建和修改,到实际的现象观察,逐步展示了三种通信方式的具体操作步骤。
摘要由CSDN通过智能技术生成

首先打开Profile下的AF.h文件(Application Framework,应用程序框架),我们可以看到枚举类型afAddrMode_t里面的枚举,分别有几种地址模式选择。我们主要关注afAddr16Bit、afAddrGroup和afAddrBroadcast这三种地址模式

typedef enum
{
   
  afAddrNotPresent = AddrNotPresent,//不出现
  afAddr16Bit      = Addr16Bit,//16位地址 点播方式
  afAddr64Bit      = Addr64Bit,//64位地址 点播方式
  afAddrGroup      = AddrGroup,//组播方式
  afAddrBroadcast  = AddrBroadcast//广播方式
} afAddrMode_t;

在这里插入图片描述

一、点播

(一)、创建设备地址结构体

首先打开SampleApp项目,打开SampleApp.c文件,模仿示例的初始化过程,创建关于点播的地址结构体变量afAddrType_t SampleAPP_Point_To_Point_DstAddr

在这里插入图片描述

我们查看结构体afAddrType_t的定义处可以发现它的内部结构,除了包含地址类型还包括地址、端点属性和PANID等。

typedef struct
{
   
  union
  {
   
    uint16      shortAddr;
    ZLongAddr_t extAddr;
  } addr;
  afAddrMode_t addrMode;//地址类型,这里选择使用哪种方式通信
  uint8 endPoint;
  uint16 panId;  // used for the INTER_PAN feature
} afAddrType_t;
(二)、初始化设备地址结构体

接着就是初始化这个结构体了,顺藤摸瓜我们发现示例是在SampleApp_Init()函数内部进行初始化的,所以我们可以在其后紧跟着点播地址结构体的初始化。

  //Point To Point
  SampleAPP_Point_To_Point_DstAddr.addrMode = (afAddrMode_t)afAddr16Bit;//点播
  SampleAPP_Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleAPP_Point_To_Point_DstAddr.addr.shortAddr = 0x0000;//发送给协调器

在这里插入图片描述

(三)、创建点播处理函数

在上一篇文章说到过SampleApp_ProcessEvent()函数内会有一个间隔一段时间(interval time)执行一次的事件

  // Send a message out - This event is generated by a timer
  //  (setup in SampleApp_Init()).
  if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT )//间隔发送信息事件
  {
   
    // Send the periodic message
    //SampleApp_SendPeriodicMessage();//广播
    SampleApp_SendPointToPointMessage();//点播
    
    // Setup to send message again in normal period (+ a little jitter)
    osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT,
        (
  • 11
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值