// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
3.在需要发送数据的地方,执行如下代码:
if ( AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
(byte)osal_strlen( theMessageData ) + 1,
(byte *)&theMessageData,
&GenericApp_TransID,
AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
// Successfully requested to be sent.
}
else
{
// Error occurred in request to send.
}
注意GENERICAPP_CLUSTERID必须为对方的输入cluster,且两方的简单描述符中的profileID必须一致
4.在接收设备任务循环中检测AF_INCOMING_MSG_CMD事件:
afIncomingMSGPacket_t结构的数据包进行处理
afIncomingMSGPacket_t结构如下:
typedef struct
{
osal_event_hdr_t hdr;
uint16 groupId;
uint16 clusterId;
afAddrType_t srcAddr;
byte endPoint;
byte wasBroadcast;
byte LinkQuality;
byte SecurityUse;
uint32 timestamp;
afMSGCommandFormat_t cmd;
} afIncomingMSGPacket_t;
其中afMSGCommandFormat_t结构如下:
typedef struct
{
byte TransSeqNumber;
uint16 DataLength; // Number of bytes in TransData
byte *Data;
} afMSGCommandFormat_t;
提取出Data即可
---------------------------------------------------------------------------
组播:按照SampleApp实验,组播的实现需要如下步骤:
1.声明一个组对象aps_Group_tSampleApp_Group;
2.对aps_Group_t结构体赋值,示例如下:
// By default, all devices start out in Group 1
SampleApp_Group.ID = 0x0003;
osal_memcpy( SampleApp_Group.name, "Group 3", 7 );
3.设定通信的目标地址,示例如下:
// 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;
4.注册端点描述符,示例如下:
// 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;
// Register the endpoint description with the AF
afRegister( &SampleApp_epDesc );
5.在本任务里将端点加入到组中,示例如下:
aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
6.按照组播地址向对方发送数据,示例如下:
if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_PERIODIC_CLUSTERID,
1,
(uint8*)&SampleAppPeriodicCounter,
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
}
else
{
// Error occurred in request to send.
}
通信时候,发送设备的输出cluster设定为接收设备的输入cluster,另外profileID设定相同,即可通信
7.对数据的处理与单播的实现一样
8.若要把一个设备加入到组中的端点从组中移除,调用aps_RemoveGroup即可,示例如下:
aps_Group_t *grp;
grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
if ( grp )
{
// Remove from the group
aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
}
---------------------------
广播:按照SampleApp,执行如下步骤即可
1.声明afAddrType_t 的变量SampleApp_Periodic_DstAddr;
2.设定目标地址变量为广播地址,示例如下:
SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;
3.进行数据发送,示例如下:
if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_PERIODIC_CLUSTERID,
1,
(uint8*)&SampleAppPeriodicCounter,
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
}
else
{
// Error occurred in request to send.
}
通信时候,发送设备的输出cluster设定为接收设备的输入cluster,另外profileID设定相同,即可通信 4.对数据的处理与单播的实现一样