5.1.7.3.7 ZCL_PutNextElement Function

Syntax

ZCL_Status_t ZCL_PutNextElement(ZCL_NextElement_t *element);

Description

This function adds an element to the outgoing command payload.

This function enables simplification of the creation of valid payloads for general commands, including reading and writing attributes. A single command can involve actions on several attributes, so the overall payload must contain pieces corresponding to each attribute.

To facilitate the payload, the user must supply a buffer and the associated content. The function, then, performs two critical operations:
  • Writes the content in a correct way to the buffer
  • Calculates the overall payload length

The function then passes the buffer and the payload length as parameters to the ZCL_AttributeReq() function. The following example code provides more details:

ZCL_NextElement_t element;
ZCL_ReadAttributeReq_t readAttrReqElement;
ZCL_Request_t readAttrReq;
uint8_t buffer[BUFFER_SIZE];
element.payloadLength = 0;
element.payload = buffer;
element.id = ZCL_READ_ATTRIBUTES_COMMAND_ID;
element.content = &readAttrReqElement;
readAttrReqElement = ATTRIBUTE_ID1; //Set to the ID of the first attribute
ZCL_PutNextElement(&element);
readAttrReqElement = ATTRIBUTE_ID2; //Set to the ID of the second attribute
ZCL_PutNextElement(&element);
readAttrReq.requestLength = element.payloadLength;
readAttrReq.requestPayload = buffer;
...
Note: The usage can differ depending on the command’s type.
Input Parameters
Parameter NameDescription
elementInformation about payload and element [out] status of the operation
ZCL_SUCCESS_STATUS (0x00)The system successfully wrote an element to the payload; it can now add more elements.
ZCL_END_PAYLOAD_REACHED_STATUS (0xFD)The system wrote an element successfully, and the payload is full; cannot add more elements.
ZCL_INVALID_PARAMETER_STATUS (0xFF)The argument is NULL.
Return Type and Values
  • None