4.5.3 Parsing the Response Payload
In the callback function for a general cluster command’s response, the application must first check the status of the command’s execution. Parsing the response payload is needed in case of:
- Successful execution of the
read attributes
command - Error in execution of a
write attributes
command for several attributes at once (the payload contains IDs of the attributes that the writing operation has failed for)
For the write attributes response, the success status means that all attributes were written successfully, while the error status means that some attributes were not written. In the latter case, the response payload contains a separate status report for each attribute. For more details, refer to the Zigbee Cluster Library Specification (07-5123).
The write attributesʼ response indicates successful writing of all attributes with a success status, while an error status signals that the system failed to write some attributes. When this occurs, the response payload provides a separate status report for each attribute. For more details, refer to the Zigbee Cluster Library Specification (07-5123).
To process the response payload, the application must configure an instance of ZCL_NextElement_t type and use the ZCL_GetNextElement() function to extract subsequent attribute records:
- Define a variable of ZCL_NextElement_t type and a variable of the ZCL_ WriteAttributeResp_t type (for read attributes response) or of the ZCL_WriteAttributeResp_t type (for write attributes response).
- Define a variable of type
ZCL_NextElement_t
.ZCL_NextElement_t element;
- Define a pointer variable for the read attribute response of type
ZCL_ReadAttributeResp_t
.ZCL_ ReadAttributeResp_t *temp = NULL;
- Define a pointer variable for the write attribute response of type
ZCL_WriteAttributeResp_t
.ZCL_ WriteAttributeResp_t *temp = NULL;
- Define a variable of type
- The user can configure the element in the following way:
element.payloadLength = resp->responseLength; element.payload = resp->responsePayload; element.content = NULL;
For the read attributes response:For the write attributes response:element.id = ZCL_READ_ATTRIBUTES_RESPONSE_COMMAND_ID;
element.id = ZCL_WRITE_ATTRIBUTES_RESPONSE_COMMAND_ID;
- For each requested attribute, repeat the following steps:
- Call ZCL_GetNextElement()(&element).
- Cast
element.content
to ZCL_ ReadAttributeResp_t* for read attributes response and to ZCL_ WriteAttributeResp_t* for write attribute response. - Access the value as
*(<AttrType>*)value
or check the id and status fields (the status field describes the result of read attributes command).
ZCL_GetNextElement()(&element); temp = (ZCL_ ReadAttributeResp_t *) element.content; if (ZCL_SUCCESS_STATUS == temp->status) { uint64_t value = *(uint64_t*)temp->value; //Process the received value }
- Check the return value of the ZCL_GetNextElement(). After the function reads the last element from the payload, it returns
ZCL_END_PAYLOAD_REACHED_STATUS
.