4.5.1 Sending a General Cluster Command

To send general cluster commands, use the ZCL_AttributeReq() function with a pointer to an instance of the ZCL_Request_t type as its argument. The structure behind the pointer includes the following:
  • Complete destination specification (device address, destination endpoint, cluster ID and more)
  • Command ID
  • Source endpoint ID
  • Payload length
  • Payload itself

In additon, the argument contains the defaultResponse field for configuring default response bit. Set this field to ZCL_FRAME_CONTROL_ENABLE_DEFAULT_RESPONSE to ensure that the destination sends a ZCL default response command, except for commands that already require a command-specific ZCL response (for example, read attribute command). A special callback function indicates the reception of unsolicited default responses.

The following code is an explanation of how to implement the ZCL_AttributeReq() function with an example:
ZCL_Request_t zclReq; //In the global scope
...
zclReq.id = …; // specify command ID, e.g. ZCL_READ_ATTRIBUTES_COMMAND_ID
zclReq.endpointId = APP_ENDPOINT_LIGHT; //Source application endpoint
zclReq.ZCL_Notify = ZCL_AttributeResp; //The callback function
 
//Setting destination address
zclReq.dstAddressing.addrMode = APS_NO_ADDRESS; //Use binding
zclReq.dstAddressing.profileId = PROFILE_ID;
zclReq.dstAddressing.clusterId = ONOFF_CLUSTER_ID;
zclReq.dstAddressing.clusterSide = ZCL_CLUSTER_SIDE_SERVER;
 
//Disable default response (won’t be sent for commands with specific ZCL response)
//but can be enabled for requests w/o response (e.g. attribute reports)
zclReq.defaultResponse = ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RESPONSE;
 
zclReq.requestLength = …; // specify payload length
zclReq.requestPayload = …; // point to payload memory
 
//execute the request 
ZCL_AttributeReq(&zclReq);
Note: The example does not demonstrate how to populate the req.requestLength and req.requestPayload fields. To simplify the process of filling and parsing the payload, as well as accurately calculating its length, the ZCL component offers the ZCL_PutNextElement() function. Use this utility to ensure these fields are correctly set within the ZCL_Request_t structure.