文章源于郑州新双恒信息技术有限公司资料,为尊重劳动者,转载请注明出处。

发送数据时调用

AF_DataRequest( afAddrType_t *dstAddr, endPointDesc_t *srcEP, uint16 cID, uint16 len, uint8 *buf, uint8 *transID, uint8 options, uint8 radius ); 函数即可,AF_DataRequest 函数最终调用APSDE_DataReq 原语,而我们只需要了解 AF_DataRequest 函数的参数,就可非常灵活的以各种方式来发送数据。

AF_DataRequest 函数的调用会触发afDataConfirm(...)函数,数据的发送结果也由 afDataConfirm(...)函数返回.而AF_DataRequest函数返回的值并不是真正的发送结果。 4.3.1函数参数说明 *dstAddr --发送目的地址+端点地址和传送模式 *srcEP --源(答复或确认)终端的描述(比如操作系统中任务ID 等)源EP cID --被Profile 指定的有效的集群号 len --发送数据长度 *buf --发送数据缓冲区 *transID --任务ID 号 options --有效位掩码的发送选项 radius --传送跳数,通常设置为AF_DEFAULT_RADIUS 其中

4.3.1.1 afAddrType_t *dstAddr typedef struct

{

 union { uint16 shortAddr; //短地址 }

addr; afAddrMode_t addrMode; //传送模式

byte endPoint; //端点号 } afAddrType_t;

4.3.1.2 endPointDesc_t *srcEP typedef struct {

byte endPoint; //端点号

byte *task_id; //那一个任务的端点号

SimpleDescriptionFormat_t *simpleDesc;//简单的端点描述

afNetworkLatencyReq_t latencyReq; } endPointDesc_t;

4.1.3.3 SimpleDescriptionFormat_t typedef struct {

byte EndPoint; //EP

uint16 AppProfId; //应用规范ID

uint16 AppDeviceId; //特定规范ID 的设备类型

byte AppDevVer:4; //特定规范ID 的设备的版本

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

byte AppNumInClusters; //输入簇ID 的个数

cId_t *pAppInClusterList; //输入簇ID 的列表

byte AppNumOutClusters; //输出簇ID 的个数

cId_t *pAppOutClusterList; //输出簇ID 的列表

} SimpleDescriptionFormat_t;

4.1.3.4 uint16 cID ClusterID --具体应用串ID

4.1.3.5 uint8 options 发送模式选项有如下选项

#define AF_FRAGMENTED 0x01

#define AF_ACK_REQUEST 0x10

#define AF_DISCV_ROUTE 0x20

#define AF_EN_SECURITY 0x40

#define AF_SKIP_ROUTING 0x80

       其中AF_ACK_REQUEST 为发送后需要接收方的确认

4.1.3.6

      uint8 radius 传输跳数或传输半径,默认值为10 4.3.2广播发送 广播发送时,分为三种广播,如果想使用广播发送,则只需将dstAddr-> addrMode 设为 AddrBroadcast,dstAddr->addr->shortAddr 设置为相应的广播类型即可。

     具体的定义如下: NWK_BROADCAST_SHORTADDR_DEVALL(0xFFFF)——数据包将被传送到网络上的所有设备,包括 睡眠中的设备。对于睡眠中的设备,数据包将被保留在其父亲节点直到查询到它,或者消息 超时。

NWK_BROADCAST_SHORTADDR_DEVRXON(0xFFFD)——数据包将被传送到网络上的所有在空闲时 打开接收的设备(RXONWHENIDLE),也就是说,除了睡眠中的所有设备。 NWK_BROADCAST_SHORTADDR_DEVZCZR(0xFFFC)——数据包发送给所有的路由器,包括协调器。

4.3.3组播发送 如果设备想传输数据到某一组设备,那么只需将dstAddr-> addrMode 设为AddrGroup, dstAddr->addr->shortAddr 设置为相应的组ID 即可。

代码如下:

// Setup for the flash command's destination address - Group 1

SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup; SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;

SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;

// Fill out the endpoint description.

SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;

SampleApp_epDesc.task_id = &SampleApp_TaskID;

SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;

SampleApp_epDesc.latencyReq = noLatencyReqs;

根据上面代码的配置,然后使用AF_DataRequest()函数来进行组播发送。

4.3.4点对点的发送 点对点的传输需要知道目标设备的短地址, 需要将dstAddr-> addrMode 设为 Addr16Bit,dstAddr->addr->shortAddr 设置为目标设备的短地址即可。 代码如下:

SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddr16Bit;

SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;

SampleApp_Flash_DstAddr.addr.shortAddr = 0x00;

// Fill out the endpoint description.

SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;

SampleApp_epDesc.task_id = &SampleApp_TaskID;

SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;

SampleApp_epDesc.latencyReq = noLatencyReqs;

根据上面代码的配置,然后使用AF_DataRequest()函数来进行点对点发送。

posted on 2016-02-21 12:10  farbeyond  阅读(1877)  评论(0编辑  收藏  举报