zigbee zcl规范及其协议栈实现3 读取服务器端属性值

zigbee zcl规范及其协议栈实现2   中有介绍 对通用命令的处理,按照那个思路和信息流程添加读取服务器端属性值的功能
客户端samplesw想要知道与自己的12号端点SAMPLESW_ENDPOINT 绑定的那个节点samplelight(的13号端点)的硬件版本和厂商名字,这两个属性zcl都有规定,
属于zcl general 的ZCL_CLUSTER_ID_GEN_BASIC
A
1.首先服务器samplelight端需要配置这个属性,代码中已经写过,位于
函数zclSampleLight_Init里注册了属性表,
zcl_registerAttrList( SAMPLELIGHT_ENDPOINT, SAMPLELIGHT_MAX_ATTRIBUTES, zclSampleLight_Attrs );
属性表zclSampleLight_Attrs 配置了属性ATTRID_BASIC_ZCL_VERSION和ATTRID_BASIC_MANUFACTURER_NAME,属于ZCL_CLUSTER_ID_GEN_BASIC
  {
    ZCL_CLUSTER_ID_GEN_BASIC,
    { // Attribute record
      ATTRID_BASIC_ZCL_VERSION,
      ZCL_DATATYPE_UINT8,
      ACCESS_CONTROL_READ,
      (void *)&zclSampleLight_ZCLVersion
    }
  },
  {
    ZCL_CLUSTER_ID_GEN_BASIC,
    { // Attribute record
      ATTRID_BASIC_MANUFACTURER_NAME,
      ZCL_DATATYPE_CHAR_STR,
      ACCESS_CONTROL_READ,
      (void *)zclSampleLight_ManufacturerName
    }
  },

2. InClusters里必须添加对clusterid ZCL_CLUSTER_ID_GEN_BASIC的支持
#define ZCLSAMPLELIGHT_BINDINGLIST       2
static cId_t bindingInClusters[ZCLSAMPLELIGHT_BINDINGLIST] =
{
  ZCL_CLUSTER_ID_GEN_ON_OFF,
  ZCL_CLUSTER_ID_GEN_BASIC
};

3 .在申请绑定搞定的时候,使用bindingInClusters作为参数,代码中已经实现

    ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
                           SAMPLELIGHT_ENDPOINT,
                           ZCL_HA_PROFILE_ID,
                           ZCLSAMPLELIGHT_BINDINGLIST, bindingInClusters,
                           0, NULL,   // No Outgoing clusters to bind
                           TRUE );


B
1.客户端samplesw使用与服务器对应的cluster列表
#define ZCLSAMPLESW_BINDINGLIST      2
static cId_t bindingOutClusters[ZCLSAMPLESW_BINDINGLIST] =
{
  ZCL_CLUSTER_ID_GEN_ON_OFF,
  ZCL_CLUSTER_ID_GEN_BASIC
};
2.在申请绑定的时候使用bindingOutClusters作为参数,代码中已经实现
    dstAddr.addrMode = afAddr16Bit;
    dstAddr.addr.shortAddr = 0;   // Coordinator makes the match
    ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
                           SAMPLESW_ENDPOINT,
                           ZCL_HA_PROFILE_ID,
                           0, NULL,   // No incoming clusters to bind
                           ZCLSAMPLESW_BINDINGLIST,bindingOutClusters,
                           TRUE );
3.在某个地方执行以下代码,即申请读取zclSampleSw_DstAddr的下面两个属性 (zcl_SendRead()中会自动指定ZCL_FRAME_TYPE_PROFILE_CMD)
   zclReadCmd_t readcmd;
   ZStatus_t st;
   readcmd.numAttr=2;
   readcmd.attrID[0]=ATTRID_BASIC_ZCL_VERSION;
   readcmd.attrID[1]=ATTRID_BASIC_MANUFACTURER_NAME;
   st= zcl_SendRead( SAMPLESW_ENDPOINT, &zclSampleSw_DstAddr,
                               /*ZCL_CLUSTER_ID_GEN_ON_OFF*/ZCL_CLUSTER_ID_GEN_BASIC,  &readcmd,
                               ZCL_FRAME_CLIENT_SERVER_DIR,  false, 0 );

C
服务器会收到信息,触发zclCmdTable[ZCL_CMD_READ]函数即zclProcessInReadCmd函数,此函数自动读取相关属性返回给客户端,通过函数zcl_SendReadRsp(),命令是ZCL_CMD_READ_RSP

D
客户端,samplesw收到信息后触发zclCmdTable[ZCL_CMD_READ_RSP]函数即zclSendMsg函数,此函数会将这个消息以ZCL_INCOMING_MSG事件发给上层任务去处理,前提是上层任务使用zcl_registerForMsg注册过,而在samplesw在init中已经注册过。

在客户端,samplesw任务中处理之
        case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );->zclSampleSw_ProcessInReadRspCmd
          break;
//属性返回处理
static uint8 zclSampleSw_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
{
  zclReadRspCmd_t *readRspCmd;
  uint8 i;

  readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  for (i = 0; i < readRspCmd->numAttr; i++)
  {
     uint8 str[6];
    // Notify the originator of the results of the original read attributes
    // attempt and, for each successfull request, the value of the requested
    // attribute
    /*
    if(i==0)
    {
       uint8  ii=*readRspCmd->attrList[i].data;
       _itoa(ii,str,10);
       HalLcdWriteString(str,2);
    }
    */
    if(i==1)
    {
      uint8* pp=readRspCmd->attrList[i].data;
      HalLcdWriteString(pp,2);
    }
  }
  return TRUE;
}


posted on 2013-03-17 15:32  _song  阅读(2687)  评论(1编辑  收藏  举报