14.2.3.5.3 Parsing the response payload
In the callback function for a general cluster command’s response, the application should first check the status of the command’s execution . Parsing 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 will contain IDs of attributes for which writing operation has failed)
For the write attributes response the success status means that all attributes have been written successfully, while the error status means that some attributes have not been written. In the latter case the response payload contains a separate status report for each attribute (Refer ZCL specification).
To process the response payload, the application should 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). For
example:
ZCL_NextElement_t element;
andZCL_ ReadAttributeResp_t *temp = NULL;
orZCL_ WriteAttributeResp_t *temp = NULL;
- Configure element in the following
way:
element.payloadLength = resp->responseLength; element.payload = resp->responsePayload; element.content = NULL;
For read attributes response:For 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 value returned by ZCL_GetNextElement(). When the last element from the payload is read, the function returns ZCL_END_PAYLOAD_REACHED_STATUS.