[zigbee] zcl read attributes

//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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值