Zigbee組播的實現
按照SampleApp實驗,組播的實現需要如下步驟:1.宣告一個組物件aps_Group_t SampleApp_Group;
typedef struct
{
uint16 ID; // Unique to this table
uint8 name[APS_GROUP_NAME_LEN]; // Human readable name of group
} aps_Group_t;2.對aps_Group_t結構體賦值,示例如下:// By default, all devices start out in Group 1SampleApp_Group.ID = 0x0003;
//void * osal_memcpy(void *dst,const void GENERIC *src,unsigned int len)
3.設定通訊的目標地址,示例如下:// Setup for the flash command's destination address - Group 1
//afAddrType_t SampleApp_Flash_DstAddr;
typedef struct
{
union
{
uint16 shortAddr;
ZLongAddr_t extAddr;
} addr;
afAddrMode_t addrMode;
uint8 endPoint;
uint16 panId; // used for the INTER_PAN feature
} afAddrType_t;SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;
// Register the endpoint description with the AFafRegister( &SampleApp_epDesc );5.在本任務裡將端點加入到組中,示例如下:aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
extern ZStatus_t aps_AddGroup( uint8 endpoint, aps_Group_t *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 );}