html5 访问组播数据,ZStack单播组播广播具体操作与原理资料整理

// 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.对数据的处理与单播的实现一样

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值