在zstack中,分为广播、组播及点对点的通讯,其中组播是对终端进行分类管理,类似将一个协调器与一部分终端定义了一个组号,这一堆是1组,那一堆是2组,数据的传输只在组内进行,其它的组外的设备不响应额外的数据。在协调器中的代码大概如下:
GenericApp_DstAddr.addrMode = ( afAddrMode_t )AddrGroup; //组播
GenericApp_DstAddr.endPoint = GENERICAPP_ENDPOINT;
GenericApp_DstAddr.addr.shortAddr = 0x0002;//发给组内节点
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= ( SimpleDescriptionFormat_t * )&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
// Register for all key events - This app will handle all key events
RegisterForKeys( GenericApp_TaskID );
// By default, all devices start out in Group 1
GenericApp_Group.ID = 0x0002;//组号
GenericApp_Group.name[0] = 7;
osal_memcpy( &(GenericApp_Group.name[1]), "group 1", 7);//设定组名
aps_AddGroup( GENERICAPP_ENDPOINT, &GenericApp_Group );//把该组登记添加到APS中
在终端的使用稍有不同:
GenericApp_DstAddr.addrMode = ( afAddrMode_t )Addr16Bit; //点播
GenericApp_DstAddr.endPoint = GENERICAPP_ENDPOINT;
GenericApp_DstAddr.addr.shortAddr = 0x0000;//发送给协调器
// Fill out the endpoint description.
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= ( SimpleDescriptionFormat_t * )&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
GenericApp_Group.ID = 0x0002;//组号
GenericApp_Group.name[0] = 7;
osal_memcpy( &(GenericApp_Group.name[1]), "group 1", 7);//设定组名
aps_AddGroup( GENERICAPP_ENDPOINT, &GenericApp_Group );//把该组登记添加到APS中
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
在一个pan中,协调器的地址为0x0000,所以在终端中的shortAddr设置为0x0000,查询过的资料中,有的将这个值也设置成了组ID,经测试不能调通;按以上代码中的方式,是可以运行的,需要将其分为不同的组,可以直接改动这个group_id就可以了,如0x0003、0x0005都是可以的。
做为一个老菜鸟,有些东西理解的并不好,目前还在学习中,感谢多年来在优快云中得到的帮助,碰到的问题以后也会在这里记一下,提示自己,也希望能帮到他人。