zigbee中常用的结构体

数据发送:

AF_DataRequest //数据发送函数

typedef struct// afAddrType_t;目的地址结构体变量

typedef enum//afAddrMode_t数据传送类型

typedef struct// endPointDesc_t;设备端点描述符

typedef struct// zAddrType_t;地址变量(长地址或者短地址)

typedef struct// aps_Group_t;组结构体

SimpleDescriptionFormat_t;/* 设备的简单描述符 */

数据接收:

typedef struct //afIncomingMSGPacket_t

typedef struct  //afMSGCommandFormat_t;

typedef struct // osal_event_hdr_t;

typedef struct  //afDataConfirm_t;

typedef struct // ZDO_ActiveEndpointRsp_t;

typedef uint16 cId_t;// 命令结构体:... 

 

数据发送:

AF_DataRequest//数据发送函数

AF_DataRequest(

afAddrType_t    *dstAddr,  //目的地址结构体变量(含端点)

endPointDesc_t  *srcEP,       //设备端点描述符(源端点描述)                   

unit16  cID,       //串ID    (命令)         

unit16  len,         //有效数据长度              

unit8   *buf,        //数据

unit8   *transID,              

unit8   *options,              

unit8     radius,

)

例子:

AF_DataRequest( &SampleApp_Flash_DstAddr,

&SampleApp_epDesc,

              SAMPLEAPP_FLASH_CLUSTERID,

               2,

               buffer,

              &SampleApp_TransID,

               AF_DISCV_ROUTE,

              AF_DEFAULT_RADIUS )

 

typedef struct// afAddrType_t;目的地址结构体变量

{

 union

  {

   uint16      shortAddr;

   ZLongAddr_t extAddr;

  }addr;

  afAddrMode_t addrMode;//afAddrMode_t是一个枚举类型模式参数

 byte endPoint;//指定的端点号 端点241—254保留端点 范围 1-240

 uint16 panId;  // used for theINTER_PAN feature

} afAddrType_t;     //目的地址结构体变量(含端点)

 

例:afAddrType_t   SampleApp_Flash_DstAddr;

      /* 设置闪烁命令的目的地址(发送给组1的所有成员)*/

  SampleApp_Flash_DstAddr.addrMode= (afAddrMode_t) afAddrGroup;

 SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;

 SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;

 

typedef  enum//afAddrMode_t数据传送类型

{

afAddrNotPresent  =  AddrNotPresent,    //间接传送(Indirect)

afAddr16Bit  =  Addr16Bit,                   //指定地址单点传送(Unicast)  16位

afAddrGroup  =  AddrGroup,                 //组寻址(Group Addressing)

afAddrBroadcast  =  AddrBroadcast        //广播传送(broadcast)

} afAddrMode_t;//数据传送类型

 

typedef struct// endPointDesc_t;设备端点描述符

{

 byte  endPoint;

 byte *task_id;          // Pointer to location of theApplication task ID.

 SimpleDescriptionFormat_t *simpleDesc;        //设备简单描述符

 afNetworkLatencyReq_t  latencyReq;

} endPointDesc_t;//设备端点描述符

例:

      endPointDesc_tSampleApp_epDesc;

      /* 填充端点描述符 */

  SampleApp_epDesc.endPoint =SAMPLEAPP_ENDPOINT;

  SampleApp_epDesc.task_id =&SampleApp_TaskID;

  SampleApp_epDesc.simpleDesc

            =(SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;

  SampleApp_epDesc.latencyReq= noLatencyReqs;

 

typedef struct// zAddrType_t;地址变量(长地址或者短地址)

{

 union

  {

   uint16         shortAddr;

   ZLongAddr_t   extAddr;

  }addr;

 byte addrMode;

} zAddrType_t;  //地址变量(长地址或者短地址)

 

typedef struct// aps_Group_t;组结构体

{

 uint16 ID;                      // Unique to this table

 uint8  name[APS_GROUP_NAME_LEN];// Human readable name of group

} aps_Group_t;  //组结构体

 

 

SimpleDescriptionFormat_t;/*设备的简单描述符 */

 

typedef struct

{

  byte EndPoint;                              //EP ID (EP=End Point)

  uint16 AppProfId;                  // profile ID(剖面ID)

  uint16 AppDeviceId;               // Device ID

  byte AppDevVer:4;                //Device Version 0x00 为 Version 1.0

  byte Reserved:4;                     // AF_V1_SUPPORT uses for AppFlags:4.

  byte AppNumInClusters;                //终端支持的输入簇的个数

  cId_t*pAppInClusterList;         //指向输入Cluster ID列表的指针

  byte AppNumOutClusters;         //输出簇的个数

  cId_t *pAppOutClusterList;     //指向输出Cluseter ID列表的指针

} SimpleDescriptionFormat_t;

例子:

const SimpleDescriptionFormat_tSampleApp_SimpleDesc =

{

 SAMPLEAPP_ENDPOINT,             //  端点号

 SAMPLEAPP_PROFID,                 // Profile ID

 SAMPLEAPP_DEVICEID,               //  设备ID

  SAMPLEAPP_DEVICE_VERSION,        // 设备版本

 SAMPLEAPP_FLAGS,                  //  标识

 SAMPLEAPP_MAX_CLUSTERS,         // 输入簇的数量

 (cId_t *)SampleApp_ClusterList,                //  输入簇列表

 SAMPLEAPP_MAX_CLUSTERS,          //  输出簇的数量

 (cId_t *)SampleApp_ClusterList                  //  输出簇列表

};

 

数据接收:

typedef struct  //afIncomingMSGPacket_t

{

 osal_event_hdr_t  hdr;     /* OSAL Message header */

 uint16  groupId;           /* Message's group ID - 0 if not set*/

 uint16  clusterId;         /* Message's cluster ID */

 afAddrType_t  srcAddr;     /* Source Address, if endpoint isSTUBAPS_INTER_PAN_EP,

                               it's an InterPANmessage */

 uint16  macDestAddr;       /* MAC header destination short address*/

 uint8  endPoint;           /* destination endpoint */

 uint8  wasBroadcast;       /* TRUE if network destination was abroadcast address */

 uint8  LinkQuality;        /* The link quality of the receiveddata frame */

 uint8  correlation;        /* The raw correlation value of thereceived data frame */

 int8   rssi;               /* The received RF power inunits dBm */

 uint8  SecurityUse;        /* deprecated */

 uint32 timestamp;         /*receipt timestamp from MAC */

 afMSGCommandFormat_t  cmd; /*Application Data */

} afIncomingMSGPacket_t;

//afIncomingMSGPacket_t  gtwRxFromNode;

 

// Generalized MSG Command Format

typedef struct  // afMSGCommandFormat_t;

{

 byte   TransSeqNumber;

 uint16 DataLength;              // Number of bytes in TransData

 byte  *Data;

} afMSGCommandFormat_t;

 

typedef struct //osal_event_hdr_t; 

{

 uint8  event;

 uint8  status;

} osal_event_hdr_t;       

 

 

typedef struct  //afDataConfirm_t;

{

 osal_event_hdr_t hdr;

 byte endpoint;

 byte transID;

}afDataConfirm_t;

 

typedef struct // ZDO_ActiveEndpointRsp_t;

{

 uint8   status;

 uint16  nwkAddr;   // Network address of interest

 uint8   cnt;

 uint8   epList[];

} ZDO_ActiveEndpointRsp_t;

 

 

typedef uint16  cId_t;//命令结构体:

// Simple Description Format Structure

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
下面是一个简单的示例代码,使用 Zigbee 网络控制灯的亮度。 ```c #include <stdio.h> #include "contiki.h" #include "dev/leds.h" #include "dev/button-sensor.h" #include "net/rime/rime.h" #include "net/rime/mesh.h" PROCESS(zigbee_light_process, "ZigBee Light Process"); AUTOSTART_PROCESSES(&zigbee_light_process); static struct mesh_conn mesh; // Zigbee Mesh 接收回调函数 static void recv_mesh(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops) { printf("Received message from %d.%d: %s\n", from->u8[0], from->u8[1], (char *)packetbuf_dataptr()); // 如果接收到消息为 "ON",则打开灯 if (strcmp((char *)packetbuf_dataptr(), "ON") == 0) leds_on(LEDS_ALL); // 如果接收到消息为 "OFF",则关闭灯 else if (strcmp((char *)packetbuf_dataptr(), "OFF") == 0) leds_off(LEDS_ALL); } // Zigbee Mesh 发送回调函数 static const struct mesh_callbacks mesh_callbacks = {recv_mesh}; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(zigbee_light_process, ev, data) { PROCESS_EXITHANDLER(mesh_close(&mesh);) PROCESS_BEGIN(); // 初始化 Zigbee Mesh 网络 mesh_open(&mesh, 132, &mesh_callbacks); // 注册按键事件回调函数 SENSORS_ACTIVATE(button_sensor); while (1) { // 如果按下按键,则向 Zigbee Mesh 网络发送 "ON" 消息 if (ev == sensors_event && data == &button_sensor) { packetbuf_copyfrom("ON", 3); mesh_send(&mesh, &rimeaddr_null); } // 延时 1 秒 etimer_set(&et, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } PROCESS_END(); } ``` 在上面的示例代码,我们使用了 Contiki 操作系统和 Contiki-NG 的网络协议栈,通过 Zigbee Mesh 网络控制灯的亮度。 首先,我们定义了一个 `mesh` 结构体,用于表示 Zigbee Mesh 网络连接。然后,我们实现了 `recv_mesh` 回调函数,用于处理接收到的消息。在该回调函数,我们判断接收到的消息是否为 "ON" 或 "OFF",分别打开或关闭 LED 灯。 接下来,在 `PROCESS_THREAD` 函数,我们初始化 Zigbee Mesh 网络,注册按键事件回调函数,并使用一个循环来检测按键事件。如果检测到按键事件,则向 Zigbee Mesh 网络发送 "ON" 消息。我们还使用了 `etimer` 函数来实现延时。 这只是一个简单的示例代码,你可以根据自己的需求进行修改和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值