z-stack 数据传输AF层application frame

前面已经把z-stack里面的操作系统的基本原理搞懂了,紧接着的任务就是深入了解,不同设备之间是如何进行数据传输的。(个人习惯喜欢自顶而下的学习方式)

AF层是application通过空中向APS层传输数据的接口,它包括从通过aps层和NEW层空中传输数据的功能函数。它也能接收数据。AF层的功能:终端管理和数据收发。

在zigbee中每个设备看做一个节点(node),每个node有长地址和短地址,短地址被其他node用来传输数据,每个node可以有240个应用终点(endpoint,每个endpoint又要用地址来分开,device发送任务的时候。一个应用必须注册一个或多个endpoint来接收和发送数据。(来自ti的API的数据手册的资料)这说明z-stack数据传输的最小单位是endpoint。

下面看看AF层是如何对ENDPOINT进行管理的呢?

每个zigbee的endpoint有simple description,SimpleDescriptionFormat_t的结构体定义如下:

typedef struct
{
byte EndPoint;                               //endpoint的编号,也可以理解成地址1-240
uint16 AppProfId;                          //应用规范号,从zigbee联盟里面获得
uint16 AppDeviceId;                     //设备ID,这个endpoint的设备ID,也是从zigbee联盟里面获得。这里的device指的是CC2430节点后面接的设备,不是指CC2430本身。
byte AppDevVer:4;                  //设备描述的版本号,
byte Reserved:4; // AF_V1_SUPPORT uses for AppFlags:4.
byte AppNumInClusters;           //输入簇的数目
cId_t *pAppInClusterList;          //输入簇表的首地址,指针
byte AppNumOutClusters;        //输出簇的数目
cId_t *pAppOutClusterList;       //输出簇的首地址,指针
} SimpleDescriptionFormat_t;

endpoint描述结构:endPointDesc_t

typedef struct
{
byte endPoint;                                      //endpoint的编号,也可以理解成地址1-240(难以理解为什么要出现两个endpoint)byte *task_id;                                       // Pointer to location of the Application task ID.Task  ID pointer. When               a message is received, this task ID will be used to
SimpleDescriptionFormat_t  *simpleDesc;   //上面的结构体,这里是结构体嵌套结构体
afNetworkLatencyReq_t  latencyReq;           //充满没有潜伏时间的回复
} endPointDesc_t;

看了结构体,我们再看看功能函数

afRegister()用来注册一个新的endpoint到一个设备(device)上也就是(node)。

函数的原型(prototype)

afStatus_t afRegister( endPointDesc_t *epDesc );

epDesc是指向设备描述结构体的指针。

返回值是状态也就是Zsuccess 或者是Zfaules

接着还有一些endpoint管理的函数这里就不一一讲了。

终于到发送数据了。

发送数据的函数是 AF_DataRequest()
                           Call this function to send data.
              Prototype原型
afStatus_t AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP,
                                             uint16 cID, uint16 len, uint8 *buf, uint8 *transID,
                                             uint8 options, uint8 radius );参数超多
Parameter Details(参数详解:)
dstAddr – Destination address pointer. 目标地址指针
The address mode in this structure must be either: 它有四种形式

1。afAddrNotPresent tolet the reflector (source binding) figure out the destination address;

2。afAddrGroup to send to a group;

3。afAddrBroadcast to send a broadcast message;

4。afAddr16Bit to send directly (unicast) to a node.

srcEP – Endpoint Descriptor pointer of the sending endpoint.//发送设备的描述结构体的地址
cID – Cluster ID – the message’s cluster ID is like a message ID and is unique with in the profile.//簇ID
len – number of bytes in the buf field. The number of bytes to send.//发送数据buff的长度
buf – buffer pointer of data to send.//buff指针
transID – transaction sequence number pointer. This number will be incremented by this function if the message
is buffered to be sent.//序列数的指针
options – the options to send this message are to be OR’d into this field are:

AF_FRAGMENTED       0x01       Not to be used.
AF_ACK_REQUEST      0x10       APS Ack requested. This is an application level
                                                     acknowledgement – meaning that the destination
                                                     device will acknowledge the message. Only used on
                                                      messages send direct (unicast).//目标设备收到将会回复
AF_DISCV_ROUTE       0x20        Should always be included.//发现路由
AF_EN_SECURITY        0x40         Not needed.
AF_SKIP_ROUTING       0x80         Setting this option will cause the device to skip routing and try to send the message                                          directly End devices will not send the message to its parent first. Good for only                                                   direct (unicast) andbroadcast messages.//直接发送到目的设备,不发送到他的父节点

radius –Maximum number of hops 最大跳数

奇怪,怎么AF层里面只有发送的函数没有接收的函数。经过,鄙人不懈的努力,终于找到数据接收的函数。原来在ZDO层里面。

一个应用通过用ZDO_RegisterForZDOMsg()注册能从空中接收任何信息。
ZDO_RegisterForZDOMsg()
Call this function to request an over-the-air message. A copy of the message will be sent to a task in an OSAL
message. The task receiving the message can either parse the message themselves or call a ZDO Parser function to
parse the message. Only response messages have a ZDO Parser function.
After registering for a message, and the message is received (OTA), the message is sent to the application/task as a
ZDO_CB_MSG (OSAL Msg). The body of the message (zdoIncomingMsg_t – defined in ZDProfile.h) contains the
OTA message.

程序原型(prototype)

ZStatus_t ZDO_RegisterForZDOMsg( uint8 taskID, uint16 clusterID );
参数详解(Parameter Details)
taskID – the application’s task ID. This will be used to send the OSAL message.
clusterID – the over the air message’s clusterID that you would like to receive (example: NWK_addr_rsp).
These are defined in ZDProfile.h.
Return
ZStatus_t –status values defined in ZStatus_t in ZComDef.h,可惜在z-stack里面没有找到,而且,NEW层和MAC层没有给出源文件


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值