ZCL Commands#
API for runtime subscription to ZCL commands.
Following a brief usage example that demonstrate how to subscribe to the ZCL "Level Control" cluster commands, client side, with no manufacturer ID. In this example we only handle only "Stop" command. The subscribed callback must return a value of:
EMBER_ZCL_STATUS_SUCCESS if the received ZCL command was handled.
EMBER_ZCL_STATUS_UNSUP_COMMAND if the received ZCL command was not handled.
void my_zcl_command_handler(sl_service_opcode_t opcode,
sl_service_function_context_t *context)
{
assert(opcode == SL_SERVICE_FUNCTION_TYPE_ZCL_COMMAND);
EmberAfClusterCommand *cmd = (EmberAfClusterCommand *)context->data;
switch (cmd->commandId) {
case ZCL_STOP_COMMAND_ID:
{
// ZCL command structs and parsing functions are implemented in the
// generated zap-cluster-command-parser.[c,h] files.
sl_zcl_level_control_cluster_stop_command_t cmd_data;
if (zcl_decode_level_control_cluster_stop_command(cmd, &cmd_data)
!= EMBER_ZCL_STATUS_SUCCESS) {
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
}
// Handle the command here
// Send a default response back to the client
emberAfSendDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
return EMBER_ZCL_STATUS_SUCCESS;
}
}
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
}
void app_init(void)
{
sl_zigbee_subscribe_to_zcl_commands(ZCL_LEVEL_CONTROL_CLUSTER_ID,
0xFFFF, // not manufacturer specific
ZCL_DIRECTION_SERVER_TO_CLIENT,
my_zcl_command_handler);
}
API#
Runtime subscription to specific incoming ZCL commands.
API Documentation#
sl_zigbee_subscribe_to_zcl_commands#
sl_status_t sl_zigbee_subscribe_to_zcl_commands (uint16_t cluster_id, uint16_t manufacturer_id, uint8_t direction, sl_service_function_t service_function)
Runtime subscription to specific incoming ZCL commands.
N/A | cluster_id | The cluster ID of the ZCL messages to subscribe to. |
N/A | manufacturer_id | The manufacturer ID if any. If not set, a value of 0xFFFF should be passed in. |
N/A | direction | A value of ZCL_DIRECTION_CLIENT_TO_SERVER or ZCL_DIRECTION_SERVER_TO_CLIENT specifying the side (client or server) of the ZCL messages to subscribe to. |
N/A | service_function | A sl_service_function_t function pointer specifying the function to be invoked when an incoming ZCL command matches the criteria specified in this API. |
Returns
A sl_status_t value of:
SL_STATUS_OK - If the subscription was successful.
SL_STATUS_INVALID_PARAMETER - If one or more passed parameters are invalid.
SL_STATUS_ALLOCATION_FAILED - If the system failed to allocate the necessary data structures.
2066
of file app/framework/include/af.h