This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

fixing zcl_SendReportCmd function to report Attribute Value needs being accessed by ReadWriteCB.

Other Parts Discussed in Thread: CC2530, Z-STACK, CC2538

 The current function zcl_SendReportCmd could not access Attribute Value that is accessed only by ReadWriteCB. But I think it can be fixed like this.

ZStatus_t zcl_SendReportCmdEx( uint8 srcEP, afAddrType_t *dstAddr,
                             uint16 clusterID, zclReportCmd_t *reportCmd,
                             uint8 direction, uint8 disableDefaultRsp, uint8 seqNum, uint8 isReqFromApp)
{
  uint16 dataLen = 0;
  uint8 *buf;
  ZStatus_t status;
  uint8 i;

  // calculate the size of the command
  for ( i = 0; i < reportCmd->numAttr; i++ )
  {
    zclReport_t *reportRec = &(reportCmd->attrList[i]);

    dataLen += 2 + 1; // Attribute ID + data type

    // Attribute Data
    //dataLen += zclGetAttrDataLength( reportRec->dataType, reportRec->attrData );
    if( reportRec->attrData ) //( statusRec->data != NULL )
    {
      dataLen += zclGetAttrDataLength( reportRec->dataType, reportRec->attrData );
    }
    else
    {
      dataLen += zclGetAttrDataLengthUsingCB( srcEP, clusterID, reportRec->attrID );
    }
  }

  buf = zcl_mem_alloc( dataLen );
  if ( buf != NULL )
  {
    // Load the buffer - serially
    uint8 *pBuf = buf;

    for ( i = 0; i < reportCmd->numAttr; i++ )
    {
      zclReport_t *reportRec = &(reportCmd->attrList[i]);

      *pBuf++ = LO_UINT16( reportRec->attrID );
      *pBuf++ = HI_UINT16( reportRec->attrID );
      *pBuf++ = reportRec->dataType;

      //pBuf = zclSerializeData( reportRec->dataType, reportRec->attrData, pBuf );
      if ( reportRec->attrData != NULL )
      {
        // Copy attribute data to the buffer to be sent out
        pBuf = zclSerializeData( reportRec->dataType, reportRec->attrData, pBuf );
      }
      else
      {
        uint16 dataLen;

        // Read attribute data directly into the buffer to be sent out
        zclReadAttrDataUsingCB( srcEP, clusterID, reportRec->attrID, pBuf, &dataLen );
        pBuf += dataLen;
      }
    }
    if(isReqFromApp)
    {
      status = zcl_SendCommand( srcEP, dstAddr, clusterID, ZCL_CMD_REPORT, FALSE,
                                direction, disableDefaultRsp, 0, seqNum, dataLen, buf );
    }
    else
    {
      status = zcl_StackSendCommand( srcEP, dstAddr, clusterID, ZCL_CMD_REPORT, FALSE,
                                direction, disableDefaultRsp, 0, seqNum, dataLen, buf );
    }
    zcl_mem_free( buf );
  }
  else
  {
    status = ZMemError;
  }

  return ( status );
}