//For your application (device2), the interesting attribute is :
// *** On/Off Cluster Attributes ***
{
ZCL_CLUSTER_ID_GEN_ON_OFF,
{ // Attribute record
ATTRID_ON_OFF,
ZCL_DATATYPE_UINT8,
ACCESS_CONTROL_READ,
(void *)&zclSampleLight_OnOff
}
},
/*This defines the attribute "OnOff" of cluster "Generic On/Off" in read access and gives the pointer to the variable in which you can find the status.
Below, there's the definition of clusters implemented in input and output :*/
const cId_t zclSampleLight_InClusterList[ZCLSAMPLELIGHT_MAX_INCLUSTERS] =
{
...
ZCL_CLUSTER_ID_GEN_ON_OFF,
};
/*And below there's a SimpleDescriptionFormat_t structure that describe the device type and gives the in and out clusters list.
May be you've already seen this so I'll directly jump to the read process (device1).
In you main source file, you should have functions :
zclyourapp_ProcessIncomingMsg
zclyourapp_ProcessInReadRspCmd
See the SampleLight example for the whole process.
The only thing they don't show you in this example is how to read an attribute. Reading an attribute is done in an asynchronous way since you don't want Device1 to be stuck waiting for Device2 answer.
For the read :
*/
afAddrType_t addr;
addr.endPoint = APP_ENDPOINT;
addr.addrMode = (afAddrMode_t) afAddr16Bit;
addr.addr.shortAddr = device2_shortaddr;
zclReadCmd_t readCmd;
readCmd.numAttr = 1;
readCmd.attrID[0] = 0; // Attribute ID of OnOff in Cluster Gen On/Off is 0 (see ZigBee Cluster Library spec)
zcl_SendRead(APP_ENDPOINT, &addr, ZCL_CLUSTER_ID_GEN_ON_OFF, &readCmd, ZCL_FRAME_CLIENT_SERVER_DIR, TRUE, 0);
//When the answer is received, the Zstack sends it to your ProcessIncomingMsg and your receive it through :
static uint8 zclyourapp_ProcessInReadRspCmd(zclIncomingMsg_t *pInMsg)
{
zclReadRspCmd_t * readRspCmd;
readRspCmd = (zclReadRspCmd_t *) pInMsg->attrCmd;
switch(pInMsg->clusterId)
{
case ZCL_CLUSTER_ID_GEN_ON_OFF:
{
uint8 onoff = * ((uint8 *) readRspCmd->attrList[0].data);
// And that's OK !
}
break;
}
return TRUE;
}
[zigbee] zcl read attributes
最新推荐文章于 2020-11-12 16:47:41 发布