diff --git a/components/esp_matter/esp_matter_client.cpp b/components/esp_matter/esp_matter_client.cpp index c6f1901fa..0c2b780c2 100644 --- a/components/esp_matter/esp_matter_client.cpp +++ b/components/esp_matter/esp_matter_client.cpp @@ -12,29 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include +#include #include - -#include #include -#if CONFIG_ESP_MATTER_ENABLE_DATA_MODEL -#include -#include "app/CASESessionManager.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "app/CommandPathParams.h" #include "app/CommandSender.h" #include "app/InteractionModelEngine.h" -#endif // CONFIG_ESP_MATTER_ENABLE_DATA_MODEL using namespace chip::app::Clusters; -using chip::BitMask; using chip::DeviceProxy; -using chip::FabricInfo; -using chip::kInvalidEndpointId; using chip::OperationalDeviceProxy; -using chip::OperationalSessionSetup; using chip::ScopedNodeId; -using chip::Server; using chip::SessionHandle; using chip::Callback::Callback; using chip::Messaging::ExchangeManager; @@ -44,47 +47,47 @@ static const char *TAG = "esp_matter_client"; namespace esp_matter { namespace client { -static command_callback_t client_command_callback = NULL; -static group_command_callback_t client_group_command_callback = NULL; -static void *command_callback_priv_data; +static request_callback_t client_request_callback = NULL; +static group_request_callback_t client_group_request_callback = NULL; +static void *request_callback_priv_data; static bool initialize_binding_manager = false; -esp_err_t set_command_callback(command_callback_t callback, group_command_callback_t g_callback, void *priv_data) +esp_err_t set_request_callback(request_callback_t callback, group_request_callback_t g_callback, void *priv_data) { - client_command_callback = callback; - client_group_command_callback = g_callback; - command_callback_priv_data = priv_data; + client_request_callback = callback; + client_group_request_callback = g_callback; + request_callback_priv_data = priv_data; return ESP_OK; } void esp_matter_connection_success_callback(void *context, ExchangeManager &exchangeMgr, const SessionHandle &sessionHandle) { - command_handle_t *cmd_handle = static_cast(context); - if (!cmd_handle) { - ESP_LOGE(TAG, "Failed to call connect_success_callback since the command handle is NULL"); + request_handle_t *req_handle = static_cast(context); + if (!req_handle) { + ESP_LOGE(TAG, "Failed to call connect_success_callback since the request handle is NULL"); return; } ESP_LOGI(TAG, "New connection success"); // Only unicast binding needs to establish the connection - if (client_command_callback) { + if (client_request_callback) { OperationalDeviceProxy device(&exchangeMgr, sessionHandle); - client_command_callback(&device, cmd_handle, command_callback_priv_data); + client_request_callback(&device, req_handle, request_callback_priv_data); } - chip::Platform::Delete(cmd_handle); + chip::Platform::Delete(req_handle); } void esp_matter_connection_failure_callback(void *context, const ScopedNodeId &peerId, CHIP_ERROR error) { - command_handle_t *cmd_handle = static_cast(context); + request_handle_t *req_handle = static_cast(context); ESP_LOGI(TAG, "New connection failure"); - if (cmd_handle) { - chip::Platform::Delete(cmd_handle); + if (req_handle) { + chip::Platform::Delete(req_handle); } } esp_err_t connect(case_session_mgr_t *case_session_mgr, uint8_t fabric_index, uint64_t node_id, - command_handle_t *cmd_handle) + request_handle_t *req_handle) { if (!case_session_mgr) { return ESP_ERR_INVALID_ARG; @@ -92,27 +95,26 @@ esp_err_t connect(case_session_mgr_t *case_session_mgr, uint8_t fabric_index, ui static Callback success_callback(esp_matter_connection_success_callback, NULL); static Callback failure_callback(esp_matter_connection_failure_callback, NULL); - command_handle_t *context = chip::Platform::New(cmd_handle); + request_handle_t *context = chip::Platform::New(req_handle); if (!context) { ESP_LOGE(TAG, "failed to alloc memory for the command handle"); return ESP_ERR_NO_MEM; } success_callback.mContext = static_cast(context); failure_callback.mContext = static_cast(context); - case_session_mgr->FindOrEstablishSession(ScopedNodeId(node_id, fabric_index), &success_callback, - &failure_callback); + case_session_mgr->FindOrEstablishSession(ScopedNodeId(node_id, fabric_index), &success_callback, &failure_callback); return ESP_OK; } -esp_err_t group_command_send(uint8_t fabric_index, command_handle_t *cmd_handle) +esp_err_t group_request_send(uint8_t fabric_index, request_handle_t *req_handle) { - if (!cmd_handle) { + if (!req_handle) { ESP_LOGE(TAG, "command handle is null"); return ESP_ERR_NO_MEM; } - if (client_group_command_callback) { - client_group_command_callback(fabric_index, cmd_handle, command_callback_priv_data); + if (client_group_request_callback) { + client_group_request_callback(fabric_index, req_handle, request_callback_priv_data); } return ESP_OK; @@ -121,20 +123,35 @@ esp_err_t group_command_send(uint8_t fabric_index, command_handle_t *cmd_handle) static void esp_matter_command_client_binding_callback(const EmberBindingTableEntry &binding, OperationalDeviceProxy *peer_device, void *context) { - command_handle_t *cmd_handle = static_cast(context); - if (!cmd_handle) { + request_handle_t *req_handle = static_cast(context); + if (!req_handle) { ESP_LOGE(TAG, "Failed to call the binding callback since command handle is NULL"); return; } if (binding.type == MATTER_UNICAST_BINDING && peer_device) { - if (client_command_callback) { - cmd_handle->endpoint_id = binding.remote; - client_command_callback(peer_device, cmd_handle, command_callback_priv_data); + if (client_request_callback) { + if (req_handle->type == INVOKE_CMD) { + req_handle->command_path.mFlags.Set(chip::app::CommandPathFlags::kEndpointIdValid); + req_handle->command_path.mFlags.Clear(chip::app::CommandPathFlags::kGroupIdValid); + req_handle->command_path.mEndpointId = binding.remote; + } else if (req_handle->type == WRITE_ATTR || req_handle->type == READ_ATTR || + req_handle->type == SUBSCRIBE_ATTR) { + req_handle->attribute_path.mEndpointId = binding.remote; + } else if (req_handle->type == READ_EVENT || req_handle->type == SUBSCRIBE_EVENT) { + req_handle->event_path.mEndpointId = binding.remote; + } + client_request_callback(peer_device, req_handle, request_callback_priv_data); } } else if (binding.type == MATTER_MULTICAST_BINDING && !peer_device) { - if (client_group_command_callback) { - cmd_handle->group_id = binding.groupId; - client_group_command_callback(binding.fabricIndex, cmd_handle, command_callback_priv_data); + if (client_group_request_callback) { + if (req_handle->type == INVOKE_CMD) { + req_handle->command_path.mFlags.Set(chip::app::CommandPathFlags::kGroupIdValid); + req_handle->command_path.mFlags.Clear(chip::app::CommandPathFlags::kEndpointIdValid); + req_handle->command_path.mGroupId = binding.groupId; + } else { + return; + } + client_group_request_callback(binding.fabricIndex, req_handle, request_callback_priv_data); } } } @@ -142,19 +159,30 @@ static void esp_matter_command_client_binding_callback(const EmberBindingTableEn static void esp_matter_binding_context_release(void *context) { if (context) { - chip::Platform::Delete(static_cast(context)); + chip::Platform::Delete(static_cast(context)); } } -esp_err_t cluster_update(uint16_t local_endpoint_id, command_handle_t *cmd_handle) +esp_err_t cluster_update(uint16_t local_endpoint_id, request_handle_t *req_handle) { - command_handle_t *context = chip::Platform::New(cmd_handle); + request_handle_t *context = chip::Platform::New(req_handle); if (!context) { - ESP_LOGE(TAG, "failed to alloc memory for the command handle"); + ESP_LOGE(TAG, "failed to alloc memory for the request handle"); return ESP_ERR_NO_MEM; } + chip::ClusterId notified_cluster_id = chip::kInvalidClusterId; + if (req_handle->type == INVOKE_CMD) { + notified_cluster_id = req_handle->command_path.mClusterId; + } else if (req_handle->type == WRITE_ATTR || req_handle->type == READ_ATTR || req_handle->type == SUBSCRIBE_ATTR) { + notified_cluster_id = req_handle->attribute_path.mClusterId; + } else if (req_handle->type == READ_EVENT || req_handle->type == SUBSCRIBE_EVENT) { + notified_cluster_id = req_handle->event_path.mClusterId; + } + if (notified_cluster_id == chip::kInvalidClusterId) { + return ESP_ERR_INVALID_ARG; + } if (CHIP_NO_ERROR != - chip::BindingManager::GetInstance().NotifyBoundClusterChanged(local_endpoint_id, cmd_handle->cluster_id, + chip::BindingManager::GetInstance().NotifyBoundClusterChanged(local_endpoint_id, notified_cluster_id, static_cast(context))) { chip::Platform::Delete(context); ESP_LOGE(TAG, "failed to notify the bound cluster changed"); @@ -190,30 +218,15 @@ void binding_init() { initialize_binding_manager = true; } -} // namespace client -#if CONFIG_ESP_MATTER_ENABLE_DATA_MODEL -namespace cluster { -using client::peer_device_t; - -static void send_command_success_callback(void *context, const chip::app::DataModel::NullObjectType &data) -{ - ESP_LOGI(TAG, "Send command success"); -} - -static void send_command_failure_callback(void *context, CHIP_ERROR error) -{ - ESP_LOGI(TAG, "Send command failure: err: %" CHIP_ERROR_FORMAT, error.Format()); -} - -namespace custom { -namespace command { +namespace interaction { +namespace invoke { using command_data_tag = chip::app::CommandDataIB::Tag; using chip::TLV::ContextTag; using chip::TLV::TLVWriter; -esp_err_t send_command(void *ctx, peer_device_t *remote_device, const CommandPathParams &command_path, +esp_err_t send_request(void *ctx, peer_device_t *remote_device, const CommandPathParams &command_path, const char *command_data_json_str, custom_command_callback::on_success_callback_t on_success, custom_command_callback::on_error_callback_t on_error, const Optional &timed_invoke_timeout_ms, const Optional &response_timeout) @@ -273,7 +286,7 @@ esp_err_t send_command(void *ctx, peer_device_t *remote_device, const CommandPat return ESP_OK; } -esp_err_t send_group_command(const uint8_t fabric_index, const CommandPathParams &command_path, +esp_err_t send_group_request(const uint8_t fabric_index, const CommandPathParams &command_path, const char *command_data_json_str) { if (!command_path.mFlags.Has(chip::app::CommandPathFlags::kGroupIdValid)) { @@ -281,7 +294,8 @@ esp_err_t send_group_command(const uint8_t fabric_index, const CommandPathParams return ESP_ERR_INVALID_ARG; } chip::Transport::OutgoingGroupSession session(command_path.mGroupId, fabric_index); - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); + chip::Messaging::ExchangeManager *exchange_mgr = + chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); auto command_sender = chip::Platform::MakeUnique(nullptr, exchange_mgr); if (command_sender == nullptr) { ESP_LOGE(TAG, "No memory for command sender"); @@ -313,1431 +327,316 @@ esp_err_t send_group_command(const uint8_t fabric_index, const CommandPathParams } return ESP_OK; } -} // namespace command -} // namespace custom -namespace on_off { -namespace command { - -esp_err_t send_on(peer_device_t *remote_device, uint16_t remote_endpoint_id) -{ - OnOff::Commands::On::Type command_data; - - chip::Controller::OnOffCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_on(uint8_t fabric_index, uint16_t group_id) -{ - OnOff::Commands::On::Type command_data; - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_off(peer_device_t *remote_device, uint16_t remote_endpoint_id) -{ - OnOff::Commands::Off::Type command_data; - - chip::Controller::OnOffCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_off(uint8_t fabric_index, uint16_t group_id) -{ - OnOff::Commands::Off::Type command_data; - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_toggle(peer_device_t *remote_device, uint16_t remote_endpoint_id) -{ - OnOff::Commands::Toggle::Type command_data; - - chip::Controller::OnOffCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_toggle(uint8_t fabric_index, uint16_t group_id) -{ - OnOff::Commands::Toggle::Type command_data; - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -} // namespace command -} // namespace on_off - -namespace level_control { -namespace command { - -esp_err_t send_move(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::Move::Type command_data; - command_data.moveMode = (LevelControl::MoveMode)move_mode; - command_data.rate.SetNonNull(rate); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, uint8_t option_mask, - uint8_t option_override) -{ - LevelControl::Commands::Move::Type command_data; - command_data.moveMode = (LevelControl::MoveMode)move_mode; - command_data.rate.SetNonNull(rate); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_level(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t level, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::MoveToLevel::Type command_data; - command_data.level = level; - command_data.transitionTime.SetNonNull(transition_time); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_level(uint8_t fabric_index, uint16_t group_id, uint8_t level, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::MoveToLevel::Type command_data; - command_data.level = level; - command_data.transitionTime.SetNonNull(transition_time); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_level_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t level, - uint16_t transition_time) -{ - LevelControl::Commands::MoveToLevelWithOnOff::Type command_data; - command_data.level = level; - command_data.transitionTime.SetNonNull(transition_time); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_level_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t level, - uint16_t transition_time) -{ - LevelControl::Commands::MoveToLevelWithOnOff::Type command_data; - command_data.level = level; - command_data.transitionTime.SetNonNull(transition_time); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint8_t rate) -{ - LevelControl::Commands::MoveWithOnOff::Type command_data; - command_data.moveMode = (LevelControl::MoveMode)move_mode; - command_data.rate.SetNonNull(rate); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate) -{ - LevelControl::Commands::MoveWithOnOff::Type command_data; - command_data.moveMode = (LevelControl::MoveMode)move_mode; - command_data.rate.SetNonNull(rate); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::Step::Type command_data; - command_data.stepMode = (LevelControl::StepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime.SetNonNull(transition_time); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::Step::Type command_data; - command_data.stepMode = (LevelControl::StepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime.SetNonNull(transition_time); - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint8_t step_size, uint16_t transition_time) -{ - LevelControl::Commands::StepWithOnOff::Type command_data; - command_data.stepMode = (LevelControl::StepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime.SetNonNull(transition_time); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time) -{ - LevelControl::Commands::StepWithOnOff::Type command_data; - command_data.stepMode = (LevelControl::StepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime.SetNonNull(transition_time); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_stop(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t option_mask, - uint8_t option_override) -{ - LevelControl::Commands::Stop::Type command_data; - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_stop(uint8_t fabric_index, uint16_t group_id, uint8_t option_mask, uint8_t option_override) -{ - LevelControl::Commands::Stop::Type command_data; - command_data.optionsMask.SetRaw(option_mask); - command_data.optionsOverride.SetRaw(option_override); - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_stop_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id) -{ - LevelControl::Commands::Stop::Type command_data; - - chip::Controller::LevelControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_stop_with_on_off(uint8_t fabric_index, uint16_t group_id) -{ - LevelControl::Commands::Stop::Type command_data; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -} // namespace command -} // namespace level_control - -namespace color_control { -namespace command { - -esp_err_t send_move_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveHue::Type command_data; - command_data.moveMode = (ColorControl::HueMoveMode)move_mode; - command_data.rate = rate; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_hue(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveHue::Type command_data; - command_data.moveMode = (ColorControl::HueMoveMode)move_mode; - command_data.rate = rate; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint8_t rate, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveSaturation::Type command_data; - command_data.moveMode = (ColorControl::SaturationMoveMode)move_mode; - command_data.rate = rate; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveSaturation::Type command_data; - command_data.moveMode = (ColorControl::SaturationMoveMode)move_mode; - command_data.rate = rate; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t hue, uint8_t direction, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToHue::Type command_data; - command_data.hue = hue; - command_data.direction = (ColorControl::HueDirection)direction; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_hue(uint8_t fabric_index, uint16_t group_id, uint8_t hue, uint8_t direction, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToHue::Type command_data; - command_data.hue = hue; - command_data.direction = (ColorControl::HueDirection)direction; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_hue_and_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t hue, - uint8_t saturation, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::MoveToHueAndSaturation::Type command_data; - command_data.hue = hue; - command_data.saturation = saturation; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_hue_and_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t hue, - uint8_t saturation, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::MoveToHueAndSaturation::Type command_data; - command_data.hue = hue; - command_data.saturation = saturation; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t saturation, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToSaturation::Type command_data; - command_data.saturation = saturation; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t saturation, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToSaturation::Type command_data; - command_data.saturation = saturation; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::StepHue::Type command_data; - command_data.stepMode = (ColorControl::HueStepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step_hue(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::StepHue::Type command_data; - command_data.stepMode = (ColorControl::HueStepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint8_t step_size, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::StepSaturation::Type command_data; - command_data.stepMode = (ColorControl::SaturationStepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::StepSaturation::Type command_data; - command_data.stepMode = (ColorControl::SaturationStepMode)step_mode; - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t color_x, - uint16_t color_y, uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToColor::Type command_data; - command_data.colorX = color_x; - command_data.colorY = color_y; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_color(uint8_t fabric_index, uint16_t group_id, uint16_t color_x, uint16_t color_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToColor::Type command_data; - command_data.colorX = color_x; - command_data.colorY = color_y; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, int16_t rate_x, int16_t rate_y, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveColor::Type command_data; - command_data.rateX = rate_x; - command_data.rateY = rate_y; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_color(uint8_t fabric_index, uint16_t group_id, int16_t rate_x, int16_t rate_y, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveColor::Type command_data; - command_data.rateX = rate_x; - command_data.rateY = rate_y; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, int16_t step_x, int16_t step_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::StepColor::Type command_data; - command_data.stepX = step_x; - command_data.stepY = step_y; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step_color(uint8_t fabric_index, uint16_t group_id, int16_t step_x, int16_t step_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::StepColor::Type command_data; - command_data.stepX = step_x; - command_data.stepY = step_y; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_to_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t color_temperature_mireds, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToColorTemperature::Type command_data; - command_data.colorTemperatureMireds = color_temperature_mireds; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_to_color_temperature(uint8_t fabric_index, uint16_t group_id, - uint16_t color_temperature_mireds, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override) -{ - ColorControl::Commands::MoveToColorTemperature::Type command_data; - command_data.colorTemperatureMireds = color_temperature_mireds; - command_data.transitionTime = transition_time; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_stop_move_step(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::StopMoveStep::Type command_data; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_stop_move_step(uint8_t fabric_index, uint16_t group_id, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::StopMoveStep::Type command_data; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_move_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint16_t rate, uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::MoveColorTemperature::Type command_data; - command_data.moveMode = static_cast(move_mode); - command_data.rate = rate; - command_data.colorTemperatureMinimumMireds = color_temperature_minimum_mireds; - command_data.colorTemperatureMaximumMireds = color_temperature_maximum_mireds; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_move_color_temperature(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint16_t rate, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::MoveColorTemperature::Type command_data; - command_data.moveMode = static_cast(move_mode); - command_data.rate = rate; - command_data.colorTemperatureMinimumMireds = color_temperature_minimum_mireds; - command_data.colorTemperatureMaximumMireds = color_temperature_maximum_mireds; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_step_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint16_t step_size, uint16_t transition_time, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::StepColorTemperature::Type command_data; - command_data.stepMode = static_cast(step_mode); - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.colorTemperatureMinimumMireds = color_temperature_minimum_mireds; - command_data.colorTemperatureMaximumMireds = color_temperature_maximum_mireds; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Controller::ColorControlCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_step_color_temperature(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, - uint16_t step_size, uint16_t transition_time, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override) -{ - ColorControl::Commands::StepColorTemperature::Type command_data; - command_data.stepMode = static_cast(step_mode); - command_data.stepSize = step_size; - command_data.transitionTime = transition_time; - command_data.colorTemperatureMinimumMireds = color_temperature_minimum_mireds; - command_data.colorTemperatureMaximumMireds = color_temperature_maximum_mireds; - command_data.optionsMask = option_mask; - command_data.optionsOverride = option_override; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -} // namespace command -} // namespace color_control - -namespace identify { -namespace command { -esp_err_t send_identify(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t identify_time) -{ - Identify::Commands::Identify::Type command_data; - command_data.identifyTime = identify_time; - - chip::Controller::IdentifyCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t group_send_identify(uint8_t fabric_index, uint16_t group_id, uint16_t identify_time) -{ - Identify::Commands::Identify::Type command_data; - command_data.identifyTime = identify_time; - - chip::Messaging::ExchangeManager *exchange_mgr = chip::app::InteractionModelEngine::GetInstance()->GetExchangeManager(); - - chip::Controller::InvokeGroupCommandRequest(exchange_mgr, fabric_index, group_id, command_data); - return ESP_OK; -} - -esp_err_t send_trigger_effect(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t effect_identifier, - uint8_t effect_variant) -{ - Identify::Commands::TriggerEffect::Type command_data; - command_data.effectIdentifier = Identify::EffectIdentifierEnum(effect_identifier); - command_data.effectVariant = Identify::EffectVariantEnum(effect_variant); - - chip::Controller::IdentifyCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace identify - -namespace group_key_management { -namespace command { - -esp_err_t send_keyset_write(peer_device_t *remote_device, uint16_t remote_endpoint_id, - group_keyset_struct &group_keyset) -{ - GroupKeyManagement::Commands::KeySetWrite::Type command_data; - command_data.groupKeySet = group_keyset; - - chip::Controller::GroupKeyManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_keyset_read(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t keyset_id, - keyset_read_callback keyset_read_cb) -{ - GroupKeyManagement::Commands::KeySetRead::Type command_data; - command_data.groupKeySetID = keyset_id; - - chip::Controller::GroupKeyManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, keyset_read_cb, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace group_key_management - -namespace groups { -namespace command { - -esp_err_t send_add_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, char *group_name, - add_group_callback add_group_cb) -{ - Groups::Commands::AddGroup::Type command_data; - command_data.groupID = group_id; - command_data.groupName = chip::CharSpan(group_name, strnlen(group_name, 16)); - - chip::Controller::GroupsCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, add_group_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_view_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - view_group_callback view_group_cb) -{ - Groups::Commands::ViewGroup::Type command_data; - command_data.groupID = group_id; - - chip::Controller::GroupsCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, view_group_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_remove_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - remove_group_callback remove_group_cb) -{ - Groups::Commands::RemoveGroup::Type command_data; - command_data.groupID = group_id; - - chip::Controller::GroupsCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, remove_group_cb, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace groups - -namespace scenes_management { -namespace command { - -esp_err_t send_add_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, uint8_t scene_id, - uint16_t transition_time, char *scene_name, extension_field_sets &efs, - add_scene_callback add_scene_cb) -{ - ScenesManagement::Commands::AddScene::Type command_data; - command_data.groupID = group_id; - command_data.sceneID = scene_id; - command_data.transitionTime = transition_time; - command_data.sceneName = chip::CharSpan(scene_name, strnlen(scene_name, 16)); - command_data.extensionFieldSets = efs; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, add_scene_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_view_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, view_scene_callback view_scene_cb) -{ - ScenesManagement::Commands::ViewScene::Type command_data; - command_data.groupID = group_id; - command_data.sceneID = scene_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, view_scene_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_remove_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, remove_scene_callback remove_scene_cb) -{ - ScenesManagement::Commands::RemoveScene::Type command_data; - command_data.groupID = group_id; - command_data.sceneID = scene_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, remove_scene_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_remove_all_scenes(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - remove_all_scenes_callback remove_all_scenes_cb) -{ - ScenesManagement::Commands::RemoveAllScenes::Type command_data; - command_data.groupID = group_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, remove_all_scenes_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_store_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, store_scene_callback store_scene_cb) -{ - ScenesManagement::Commands::StoreScene::Type command_data; - command_data.groupID = group_id; - command_data.sceneID = scene_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, store_scene_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_recall_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id) -{ - ScenesManagement::Commands::RecallScene::Type command_data; - command_data.groupID = group_id; - command_data.sceneID = scene_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_get_scene_membership(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - get_scene_membership_callback get_scene_membership_cb) -{ - ScenesManagement::Commands::GetSceneMembership::Type command_data; - command_data.groupID = group_id; - - chip::Controller::ScenesManagementCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, get_scene_membership_cb, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace scenes_management - -namespace thermostat { -namespace command { - -esp_err_t send_setpoint_raise_lower(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t mode, - uint8_t amount) -{ - Thermostat::Commands::SetpointRaiseLower::Type command_data; - command_data.mode = chip::app::Clusters::Thermostat::SetpointRaiseLowerModeEnum(mode); - command_data.amount = amount; - - chip::Controller::ThermostatCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_set_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t num_of_tras_for_seq, uint8_t day_of_week_for_seq, uint8_t mode_for_seq, - transitions &trans) -{ - Thermostat::Commands::SetWeeklySchedule::Type command_data; - command_data.numberOfTransitionsForSequence = num_of_tras_for_seq; - command_data.dayOfWeekForSequence.SetRaw(day_of_week_for_seq); - command_data.modeForSequence.SetRaw(mode_for_seq); - command_data.transitions = trans; - - chip::Controller::ThermostatCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_get_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t day_to_return, - uint8_t mode_to_return, get_weekly_schedule_callback get_weekly_schedule_cb) -{ - Thermostat::Commands::GetWeeklySchedule::Type command_data; - command_data.daysToReturn.SetRaw(day_to_return); - command_data.modeToReturn.SetRaw(mode_to_return); - - chip::Controller::ThermostatCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, get_weekly_schedule_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id) -{ - Thermostat::Commands::ClearWeeklySchedule::Type command_data; - - chip::Controller::ThermostatCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace thermostat - -namespace door_lock { -namespace command { - -esp_err_t send_lock_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::LockDoor::Type command_data; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_unlock_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::UnlockDoor::Type command_data; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_unlock_with_timeout(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timeout, - uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::UnlockWithTimeout::Type command_data; - command_data.timeout = timeout; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_set_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t week_day_index, - uint16_t user_index, uint8_t days_mask, uint8_t start_hour, uint8_t start_minute, - uint8_t end_hour, uint8_t end_minute) -{ - DoorLock::Commands::SetWeekDaySchedule::Type command_data; - command_data.weekDayIndex = week_day_index; - command_data.userIndex = user_index; - command_data.daysMask.SetRaw(days_mask); - command_data.startHour = start_hour; - command_data.startMinute = start_minute; - command_data.endHour = end_hour; - command_data.endMinute = end_minute; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_get_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t week_day_index, - uint16_t user_index, get_week_day_schedule_callback success_cb) -{ - DoorLock::Commands::GetWeekDaySchedule::Type command_data; - command_data.weekDayIndex = week_day_index; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t week_day_index, uint16_t user_index) -{ - DoorLock::Commands::ClearWeekDaySchedule::Type command_data; - command_data.weekDayIndex = week_day_index; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_set_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t year_day_index, - uint16_t user_index, uint32_t local_start_time, uint32_t local_end_time) -{ - DoorLock::Commands::SetYearDaySchedule::Type command_data; - command_data.yearDayIndex = year_day_index; - command_data.userIndex = user_index; - command_data.localStartTime = local_start_time; - command_data.localEndTime = local_end_time; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_get_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t year_day_index, - uint16_t user_index, get_year_day_schedule_callback success_cb) -{ - DoorLock::Commands::GetYearDaySchedule::Type command_data; - command_data.yearDayIndex = year_day_index; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t year_day_index, uint16_t user_index) -{ - DoorLock::Commands::ClearYearDaySchedule::Type command_data; - command_data.yearDayIndex = year_day_index; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_set_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index, - uint32_t local_start_time, uint32_t local_end_time, uint8_t operating_mode) -{ - DoorLock::Commands::SetHolidaySchedule::Type command_data; - command_data.holidayIndex = holiday_index; - command_data.localStartTime = local_start_time; - command_data.localEndTime = local_end_time; - command_data.operatingMode = DoorLock::OperatingModeEnum(operating_mode); - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_get_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index, - get_holiday_schedule_callback success_cb) -{ - DoorLock::Commands::GetHolidaySchedule::Type command_data; - command_data.holidayIndex = holiday_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index) -{ - DoorLock::Commands::ClearHolidaySchedule::Type command_data; - command_data.holidayIndex = holiday_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_set_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t operation_type, - uint16_t user_index, char *user_name, uint32_t user_unique_id, uint8_t user_status, - uint8_t user_type, uint8_t credential_rule, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::SetUser::Type command_data; - command_data.operationType = DoorLock::DataOperationTypeEnum(operation_type); - command_data.userIndex = user_index; - if (user_name) { - command_data.userName = chip::app::DataModel::MakeNullable(chip::CharSpan(user_name, strlen(user_name))); - } - command_data.userUniqueID = chip::app::DataModel::MakeNullable(user_unique_id); - command_data.userStatus = chip::app::DataModel::MakeNullable(DoorLock::UserStatusEnum(user_status)); - command_data.userType = chip::app::DataModel::MakeNullable(DoorLock::UserTypeEnum(user_type)); - command_data.credentialRule = chip::app::DataModel::MakeNullable(DoorLock::CredentialRuleEnum(credential_rule)); - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_get_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t user_index, - get_user_callback success_cb) -{ - DoorLock::Commands::GetUser::Type command_data; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t user_index, - uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::ClearUser::Type command_data; - command_data.userIndex = user_index; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_set_credential(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t operation_type, - credential_struct credential, uint8_t *credential_data, size_t credential_len, - uint16_t user_index, uint8_t user_status, uint8_t user_type, - set_credential_callback success_cb, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::SetCredential::Type command_data; - command_data.operationType = DoorLock::DataOperationTypeEnum(operation_type); - command_data.credential = credential; - command_data.credentialData = chip::ByteSpan(credential_data, credential_len); - command_data.userIndex = chip::app::DataModel::MakeNullable(user_index); - command_data.userStatus = chip::app::DataModel::MakeNullable(DoorLock::UserStatusEnum(user_status)); - command_data.userType = chip::app::DataModel::MakeNullable(DoorLock::UserTypeEnum(user_type)); - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_get_credential_status(peer_device_t *remote_device, uint16_t remote_endpoint_id, - credential_struct &credential, get_credential_status_callback success_cb) -{ - DoorLock::Commands::GetCredentialStatus::Type command_data; - command_data.credential = credential; - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, success_cb, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_clear_credential(peer_device_t *remote_device, uint16_t remote_endpoint_id, - credential_struct &credential, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::ClearCredential::Type command_data; - command_data.credential = chip::app::DataModel::MakeNullable(credential); - - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; -} - -esp_err_t send_unbolt_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t *pin_code, - size_t pin_code_len, uint16_t timed_invoke_timeout_ms) -{ - DoorLock::Commands::UnboltDoor::Type command_data; - if (pin_code) { - command_data.PINCode = chip::MakeOptional(chip::ByteSpan(pin_code, pin_code_len)); +} // namespace invoke + +using chip::SubscriptionId; +using chip::app::ConcreteDataAttributePath; +using chip::app::EventHeader; +using chip::app::ReadPrepareParams; +using chip::app::StatusIB; +using chip::app::DataVersionFilterIBs::Builder; +using chip::TLV::TLVReader; +using chip::TLV::TLVWriter; + +class client_deleter_read_callback : public ReadClient::Callback { +public: + client_deleter_read_callback(ReadClient::Callback &callback) + : m_callback(callback) + { } - chip::Controller::DoorLockCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - chip::MakeOptional(timed_invoke_timeout_ms)); - return ESP_OK; - return ESP_ERR_NOT_SUPPORTED; -} +private: + void OnReportBegin() override { m_callback.OnReportBegin(); } + void OnReportEnd() override { m_callback.OnReportEnd(); } + void OnError(CHIP_ERROR aError) override { m_callback.OnError(aError); } -} // namespace command -} // namespace door_lock + void OnAttributeData(const ConcreteDataAttributePath &aPath, TLVReader *apData, const StatusIB &aStatus) override + { + m_callback.OnAttributeData(aPath, apData, aStatus); + } -namespace window_covering { -namespace command { + void OnEventData(const EventHeader &aEventHeader, TLVReader *apData, const StatusIB *apStatus) override + { + m_callback.OnEventData(aEventHeader, apData, apStatus); + } -esp_err_t send_up_or_open(peer_device_t *remote_device, uint16_t remote_endpoint_id) + void OnDone(ReadClient *apReadClient) override + { + m_callback.OnDone(apReadClient); + chip::Platform::Delete(apReadClient); + chip::Platform::Delete(this); + } + + void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override + { + m_callback.OnSubscriptionEstablished(aSubscriptionId); + } + + CHIP_ERROR OnResubscriptionNeeded(ReadClient *apReadClient, CHIP_ERROR aTerminationCause) override + { + return m_callback.OnResubscriptionNeeded(apReadClient, aTerminationCause); + } + + void OnDeallocatePaths(chip::app::ReadPrepareParams &&aReadPrepareParams) override + { + m_callback.OnDeallocatePaths(std::move(aReadPrepareParams)); + } + + CHIP_ERROR OnUpdateDataVersionFilterList(Builder &aDataVersionFilterIBsBuilder, + const chip::Span &aAttributePaths, + bool &aEncodedDataVersionList) override + { + return m_callback.OnUpdateDataVersionFilterList(aDataVersionFilterIBsBuilder, aAttributePaths, + aEncodedDataVersionList); + } + + CHIP_ERROR GetHighestReceivedEventNumber(chip::Optional &aEventNumber) override + { + return m_callback.GetHighestReceivedEventNumber(aEventNumber); + } + + void OnUnsolicitedMessageFromPublisher(ReadClient *apReadClient) override + { + m_callback.OnUnsolicitedMessageFromPublisher(apReadClient); + } + + void OnCASESessionEstablished(const SessionHandle &aSession, ReadPrepareParams &aSubscriptionParams) override + { + m_callback.OnCASESessionEstablished(aSession, aSubscriptionParams); + } + + ReadClient::Callback &m_callback; +}; + +namespace read { + +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams *attr_path, size_t attr_path_size, + EventPathParams *event_path, size_t event_path_size, ReadClient::Callback &callback) { - WindowCovering::Commands::UpOrOpen::Type command_data; + if (!remote_device->GetSecureSession().HasValue() || remote_device->GetSecureSession().Value()->IsGroupSession()) { + ESP_LOGE(TAG, "Invalid Session Type"); + return ESP_ERR_INVALID_ARG; + } + if ((!attr_path || attr_path_size == 0) && (!event_path || event_path_size == 0)) { + ESP_LOGE(TAG, "Invalid attribute path and event path"); + return ESP_ERR_INVALID_ARG; + } + ReadPrepareParams params(remote_device->GetSecureSession().Value()); + params.mpAttributePathParamsList = attr_path; + params.mAttributePathParamsListSize = attr_path_size; + params.mpEventPathParamsList = event_path; + params.mEventPathParamsListSize = event_path_size; + params.mpDataVersionFilterList = nullptr; + params.mDataVersionFilterListSize = 0; + params.mIsFabricFiltered = false; - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); + auto client_deleter_callback = chip::Platform::MakeUnique(callback); + if (!client_deleter_callback) { + ESP_LOGE(TAG, "Failed to allocate memory for client deleter callback"); + return ESP_ERR_NO_MEM; + } + auto client = chip::Platform::MakeUnique(chip::app::InteractionModelEngine::GetInstance(), + remote_device->GetExchangeManager(), *client_deleter_callback, + ReadClient::InteractionType::Read); + if (!client) { + ESP_LOGE(TAG, "Failed to allocate memory for ReadClient"); + return ESP_ERR_NO_MEM; + } + + if (client->SendRequest(params) != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to send read request"); + return ESP_FAIL; + } + // The memory will be released when OnDone() is called + client.release(); + client_deleter_callback.release(); return ESP_OK; } -esp_err_t send_down_or_close(peer_device_t *remote_device, uint16_t remote_endpoint_id) +} // namespace read + +namespace subscribe { + +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams *attr_path, size_t attr_path_size, + EventPathParams *event_path, size_t event_path_size, uint16_t min_interval, + uint16_t max_interval, bool keep_subscription, bool auto_resubscribe, + ReadClient::Callback &callback) { - WindowCovering::Commands::DownOrClose::Type command_data; + if (!remote_device->GetSecureSession().HasValue() || remote_device->GetSecureSession().Value()->IsGroupSession()) { + ESP_LOGE(TAG, "Invalid Session Type"); + return ESP_ERR_INVALID_ARG; + } + if ((!attr_path || attr_path_size == 0) && (!event_path || event_path_size == 0)) { + ESP_LOGE(TAG, "Invalid attribute path and event path"); + return ESP_ERR_INVALID_ARG; + } + ReadPrepareParams params(remote_device->GetSecureSession().Value()); + params.mpAttributePathParamsList = attr_path; + params.mAttributePathParamsListSize = attr_path_size; + params.mpEventPathParamsList = event_path; + params.mEventPathParamsListSize = event_path_size; + params.mpDataVersionFilterList = nullptr; + params.mDataVersionFilterListSize = 0; + params.mIsFabricFiltered = false; + params.mMinIntervalFloorSeconds = min_interval; + params.mMaxIntervalCeilingSeconds = max_interval; + params.mKeepSubscriptions = keep_subscription; - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); + auto client_deleter_callback = chip::Platform::MakeUnique(callback); + if (!client_deleter_callback) { + ESP_LOGE(TAG, "Failed to allocate memory for client deleter callback"); + return ESP_ERR_NO_MEM; + } + auto client = chip::Platform::MakeUnique(chip::app::InteractionModelEngine::GetInstance(), + remote_device->GetExchangeManager(), *client_deleter_callback, + ReadClient::InteractionType::Subscribe); + if (!client) { + ESP_LOGE(TAG, "Failed to allocate memory for ReadClient"); + return ESP_ERR_NO_MEM; + } + + CHIP_ERROR err = CHIP_NO_ERROR; + if (auto_resubscribe) { + err = client->SendAutoResubscribeRequest(std::move(params)); + } else { + err = client->SendRequest(params); + } + if (err != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to send subcribe request"); + return ESP_FAIL; + } + // The memory will be released when OnDone() is called + client.release(); + client_deleter_callback.release(); return ESP_OK; } -esp_err_t send_stop_motion(peer_device_t *remote_device, uint16_t remote_endpoint_id) +} // namespace subscribe + +namespace write { +static constexpr size_t k_encoded_buf_size = chip::kMaxAppMessageLen; + +class client_deleter_write_callback : public WriteClient::Callback { +public: + client_deleter_write_callback(WriteClient::Callback &callback) + : m_callback(callback) + { + } + void OnResponse(const WriteClient *apWriteClient, const ConcreteDataAttributePath &aPath, + StatusIB attributeStatus) override + { + m_callback.OnResponse(apWriteClient, aPath, attributeStatus); + } + + void OnError(const WriteClient *apWriteClient, CHIP_ERROR aError) override + { + m_callback.OnError(apWriteClient, aError); + } + + void OnDone(WriteClient *apWriteClient) override + { + m_callback.OnDone(apWriteClient); + chip::Platform::Delete(apWriteClient); + chip::Platform::Delete(this); + } + +private: + WriteClient::Callback &m_callback; +}; + +static esp_err_t encode_attribute_value(uint8_t *encoded_buf, size_t encoded_buf_size, const char *attr_val_json_str, + TLVReader &out_reader) { - WindowCovering::Commands::StopMotion::Type command_data; + TLVWriter writer; + uint32_t encoded_len = 0; + TLVReader reader; + esp_err_t err = ESP_OK; - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); + writer.Init(encoded_buf, encoded_buf_size); + if ((err = json_to_tlv(attr_val_json_str, writer, chip::TLV::AnonymousTag())) != ESP_OK) { + ESP_LOGE(TAG, "Failed to parse attribute value"); + return err; + } + if (writer.Finalize() != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to finalize tlv writer"); + return ESP_FAIL; + } + encoded_len = writer.GetLengthWritten(); + reader.Init(encoded_buf, encoded_len); + if (reader.Next() != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to read next"); + return ESP_FAIL; + } + if (reader.GetType() != chip::TLV::TLVType::kTLVType_Structure) { + ESP_LOGE(TAG, "The TLV type must be structure"); + return ESP_ERR_INVALID_ARG; + } + if (reader.OpenContainer(out_reader) != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to open container"); + return ESP_FAIL; + } + if (out_reader.Next() != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to read next"); + return ESP_FAIL; + } return ESP_OK; } -esp_err_t send_go_to_lift_value(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t lift_value) +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams &attr_path, + const char *attr_val_json_str, WriteClient::Callback &callback, + const chip::Optional &timeout_ms) { - WindowCovering::Commands::GoToLiftValue::Type command_data; - command_data.liftValue = lift_value; + esp_err_t err = ESP_OK; + if (!remote_device->GetSecureSession().HasValue() || remote_device->GetSecureSession().Value()->IsGroupSession()) { + ESP_LOGE(TAG, "Invalid Session Type"); + return ESP_ERR_INVALID_ARG; + } + if (attr_path.HasWildcardEndpointId()) { + ESP_LOGE(TAG, "Endpoint Id Invalid"); + return ESP_ERR_INVALID_ARG; + } - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); + ConcreteDataAttributePath path(attr_path.mEndpointId, attr_path.mClusterId, attr_path.mAttributeId); + + auto client_deleter_callback = chip::Platform::MakeUnique(callback); + if (!client_deleter_callback) { + ESP_LOGE(TAG, "Failed to allocate memory for client deleter callback"); + return ESP_ERR_NO_MEM; + } + auto write_client = chip::Platform::MakeUnique(remote_device->GetExchangeManager(), + client_deleter_callback.get(), timeout_ms, false); + if (!write_client) { + ESP_LOGE(TAG, "Failed to allocate memory for WriteClient"); + return ESP_ERR_NO_MEM; + } + chip::Platform::ScopedMemoryBuffer encoded_buf; + encoded_buf.Alloc(k_encoded_buf_size); + if (!encoded_buf.Get()) { + ESP_LOGE(TAG, "Failed to alloc memory for encoded_buf"); + return ESP_ERR_NO_MEM; + } + TLVReader attr_val_reader; + err = encode_attribute_value(encoded_buf.Get(), k_encoded_buf_size, attr_val_json_str, attr_val_reader); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to encode attribute value to a TLV reader"); + return err; + } + if (write_client->PutPreencodedAttribute(path, attr_val_reader) != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to put pre-encoded attribute value to WriteClient"); + return ESP_FAIL; + } + if (write_client->SendWriteRequest(remote_device->GetSecureSession().Value()) != CHIP_NO_ERROR) { + ESP_LOGE(TAG, "Failed to Send Write Request"); + return ESP_FAIL; + } + // Release the write_client and client deleter callback as it will be managed by the client deleter callback + write_client.release(); + client_deleter_callback.release(); return ESP_OK; } -esp_err_t send_go_to_lift_percentage(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t lift_percent100ths_value) -{ - WindowCovering::Commands::GoToLiftPercentage::Type command_data; - command_data.liftPercent100thsValue = static_cast(lift_percent100ths_value); - - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_go_to_tilt_value(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t tilt_value) -{ - WindowCovering::Commands::GoToTiltValue::Type command_data; - command_data.tiltValue = tilt_value; - - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -esp_err_t send_go_to_tilt_percentage(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t tilt_percent100ths_value) -{ - WindowCovering::Commands::GoToTiltPercentage::Type command_data; - command_data.tiltPercent100thsValue = static_cast(tilt_percent100ths_value); - - chip::Controller::WindowCoveringCluster cluster(*remote_device->GetExchangeManager(), - remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback); - return ESP_OK; -} - -} // namespace command -} // namespace window_covering - -namespace administrator_commissioning { -namespace command { - -esp_err_t send_open_commissioning_window(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t commissioning_timeout, chip::MutableByteSpan &pake_passcode_verifier, - uint16_t discriminator, uint32_t iterations, chip::MutableByteSpan &salt, - uint16_t timed_interaction_timeout_ms) -{ - AdministratorCommissioning::Commands::OpenCommissioningWindow::Type command_data; - command_data.commissioningTimeout = commissioning_timeout; - command_data.PAKEPasscodeVerifier = pake_passcode_verifier; - command_data.discriminator = discriminator; - command_data.iterations = iterations; - command_data.salt = salt; - - chip::Controller::AdministratorCommissioningCluster cluster( - *remote_device->GetExchangeManager(), remote_device->GetSecureSession().Value(), remote_endpoint_id); - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - timed_interaction_timeout_ms); - return ESP_OK; -} - -esp_err_t send_open_basic_commissioning_window(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t commissioning_timeout, uint16_t timed_interaction_timeout_ms) -{ - AdministratorCommissioning::Commands::OpenBasicCommissioningWindow::Type command_data; - command_data.commissioningTimeout = commissioning_timeout; - - chip::Controller::AdministratorCommissioningCluster cluster( - *remote_device->GetExchangeManager(), remote_device->GetSecureSession().Value(), remote_endpoint_id); - - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - timed_interaction_timeout_ms); - return ESP_OK; -} - -esp_err_t send_revoke_commissioning(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t timed_interaction_timeout_ms) -{ - AdministratorCommissioning::Commands::RevokeCommissioning::Type command_data; - - chip::Controller::AdministratorCommissioningCluster cluster( - *remote_device->GetExchangeManager(), remote_device->GetSecureSession().Value(), remote_endpoint_id); - - cluster.InvokeCommand(command_data, NULL, send_command_success_callback, send_command_failure_callback, - timed_interaction_timeout_ms); - return ESP_OK; -} - -} // namespace command -} // namespace administrator_commissioning - -} // namespace cluster -#endif // CONFIG_ESP_MATTER_ENABLE_DATA_MODEL - +} // namespace write +} // namespace interaction +} // namespace client } // namespace esp_matter diff --git a/components/esp_matter/esp_matter_client.h b/components/esp_matter/esp_matter_client.h index 82f4d4765..2be2b88d0 100644 --- a/components/esp_matter/esp_matter_client.h +++ b/components/esp_matter/esp_matter_client.h @@ -19,24 +19,28 @@ #include namespace esp_matter { -namespace cluster { -using client::peer_device_t; - -/** Custom command send APIs - * - * They can be used for all the commands of all the clusters, including the custom clusters. - */ -namespace custom { -namespace command { +namespace client { +namespace interaction { using chip::Optional; +using chip::app::AttributePathParams; using chip::app::CommandPathParams; using chip::app::CommandSender; using chip::app::ConcreteCommandPath; +using chip::app::EventPathParams; +using chip::app::ReadClient; using chip::app::StatusIB; +using chip::app::WriteClient; using chip::Messaging::ExchangeManager; using chip::System::Clock::Timeout; using chip::TLV::TLVReader; +using client::peer_device_t; + +/** Command invoke APIs + * + * They can be used for all the commands of all the clusters, including the custom clusters. + */ +namespace invoke { class custom_command_callback final : public chip::app::CommandSender::Callback { public: @@ -96,380 +100,42 @@ private: void *context; }; -esp_err_t send_command(void *ctx, peer_device_t *remote_device, const CommandPathParams &command_path, +esp_err_t send_request(void *ctx, peer_device_t *remote_device, const CommandPathParams &command_path, const char *command_data_json_str, custom_command_callback::on_success_callback_t on_success, custom_command_callback::on_error_callback_t on_error, const Optional &timed_invoke_timeout_ms, const Optional &response_timeout = chip::NullOptional); -esp_err_t send_group_command(const uint8_t fabric_index, const CommandPathParams &command_path, +esp_err_t send_group_request(const uint8_t fabric_index, const CommandPathParams &command_path, const char *command_data_json_str); +} // namespace invoke -} // namespace command -} // namespace custom - -/** Specific command send APIs +/** Attribute/event read API * - * If some standard command is not present here, it can be added. + * It can be used for reading all the attributes/events of all the clusters, including the custom clusters. */ - -namespace on_off { -namespace command { -esp_err_t send_off(peer_device_t *remote_device, uint16_t remote_endpoint_id); -esp_err_t send_on(peer_device_t *remote_device, uint16_t remote_endpoint_id); -esp_err_t send_toggle(peer_device_t *remote_device, uint16_t remote_endpoint_id); -esp_err_t group_send_off(uint8_t fabric_index, uint16_t group_id); -esp_err_t group_send_on(uint8_t fabric_index, uint16_t group_id); -esp_err_t group_send_toggle(uint8_t fabric_index, uint16_t group_id); -} // namespace command -} // namespace on_off - -namespace level_control { -namespace command { -esp_err_t send_move(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_to_level(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t level, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_to_level_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t level, - uint16_t transition_time); -esp_err_t send_move_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint8_t rate); -esp_err_t send_step(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_step_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint8_t step_size, uint16_t transition_time); -esp_err_t send_stop(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t option_mask, - uint8_t option_override); -esp_err_t send_stop_with_on_off(peer_device_t *remote_device, uint16_t remote_endpoint_id); -esp_err_t group_send_move(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, uint8_t option_mask, - uint8_t option_override); -esp_err_t group_send_move_to_level(uint8_t fabric_index, uint16_t group_id, uint8_t level, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_to_level_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t level, - uint16_t transition_time); -esp_err_t group_send_move_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate); -esp_err_t group_send_step(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_step_with_on_off(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time); -esp_err_t group_send_stop(uint8_t fabric_index, uint16_t group_id, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_stop_with_on_off(uint8_t fabric_index, uint16_t group_id); -} // namespace command -} // namespace level_control - -namespace color_control { -namespace command { -esp_err_t send_move_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint8_t rate, uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_to_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t hue, uint8_t direction, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_to_hue_and_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t hue, - uint8_t saturation, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override); -esp_err_t send_move_to_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t saturation, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_step_hue(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_step_saturation(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint8_t step_size, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override); -esp_err_t send_move_to_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t color_x, - uint16_t color_y, uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, int16_t rate_x, int16_t rate_y, - uint8_t option_mask, uint8_t option_override); -esp_err_t send_step_color(peer_device_t *remote_device, uint16_t remote_endpoint_id, int16_t step_x, int16_t step_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t send_move_to_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t color_temperature_mireds, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override); -esp_err_t send_stop_move_step(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t option_mask, - uint8_t option_override); -esp_err_t send_move_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t move_mode, - uint16_t rate, uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override); -esp_err_t send_step_color_temperature(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t step_mode, - uint16_t step_size, uint16_t transition_time, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override); - -esp_err_t group_send_move_hue(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint8_t rate, - uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_to_hue(uint8_t fabric_index, uint16_t group_id, uint8_t hue, uint8_t direction, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_to_hue_and_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t hue, - uint8_t saturation, uint16_t transition_time, uint8_t option_mask, - uint8_t option_override); -esp_err_t group_send_move_to_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t saturation, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_step_hue(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_step_saturation(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, uint8_t step_size, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_to_color(uint8_t fabric_index, uint16_t group_id, uint16_t color_x, uint16_t color_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_color(uint8_t fabric_index, uint16_t group_id, int16_t rate_x, int16_t rate_y, - uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_step_color(uint8_t fabric_index, uint16_t group_id, int16_t step_x, int16_t step_y, - uint16_t transition_time, uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_move_to_color_temperature(uint8_t fabric_index, uint16_t group_id, - uint16_t color_temperature_mireds, uint16_t transition_time, - uint8_t option_mask, uint8_t option_override); -esp_err_t group_send_stop_move_step(uint8_t fabric_index, uint16_t group_id, uint8_t option_mask, - uint8_t option_override); -esp_err_t group_send_move_color_temperature(uint8_t fabric_index, uint16_t group_id, uint8_t move_mode, uint16_t rate, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override); -esp_err_t group_send_step_color_temperature(uint8_t fabric_index, uint16_t group_id, uint8_t step_mode, - uint16_t step_size, uint16_t transition_time, - uint16_t color_temperature_minimum_mireds, - uint16_t color_temperature_maximum_mireds, uint8_t option_mask, - uint8_t option_override); - -} // namespace command -} // namespace color_control - -namespace identify { -namespace command { -esp_err_t send_identify(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t identify_time); - -esp_err_t group_send_identify(uint8_t fabric_index, uint16_t group_id, uint16_t identify_time); - -esp_err_t send_trigger_effect(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t effect_identifier, - uint8_t effect_variant); -} // namespace command -} // namespace identify - -namespace group_key_management { -namespace command { -using group_keyset_struct = chip::app::Clusters::GroupKeyManagement::Structs::GroupKeySetStruct::Type; -using keyset_read_callback = - void (*)(void *, const chip::app::Clusters::GroupKeyManagement::Commands::KeySetRead::Type::ResponseType &); - -esp_err_t send_keyset_write(peer_device_t *remote_device, uint16_t remote_endpoint_id, - group_keyset_struct &group_keyset); - -esp_err_t send_keyset_read(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t keyset_id, - keyset_read_callback read_callback); - -} // namespace command -} // namespace group_key_management - -namespace groups { -namespace command { -using add_group_callback = void (*)(void *, - const chip::app::Clusters::Groups::Commands::AddGroup::Type::ResponseType &); -using view_group_callback = void (*)(void *, - const chip::app::Clusters::Groups::Commands::ViewGroup::Type::ResponseType &); -using remove_group_callback = void (*)(void *, - const chip::app::Clusters::Groups::Commands::RemoveGroup::Type::ResponseType &); - -esp_err_t send_add_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, char *group_name, - add_group_callback add_group_cb); - -esp_err_t send_view_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - view_group_callback view_group_cb); - -esp_err_t send_remove_group(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - remove_group_callback remove_group_cb); - -} // namespace command -} // namespace groups - -namespace scenes_management { -namespace command { - -using extension_field_sets = chip::app::DataModel::List; -using add_scene_callback = void (*)(void *, - const chip::app::Clusters::ScenesManagement::Commands::AddScene::Type::ResponseType &); -using view_scene_callback = void (*)(void *, - const chip::app::Clusters::ScenesManagement::Commands::ViewScene::Type::ResponseType &); -using remove_scene_callback = void (*)(void *, - const chip::app::Clusters::ScenesManagement::Commands::RemoveScene::Type::ResponseType &); -using remove_all_scenes_callback = - void (*)(void *, const chip::app::Clusters::ScenesManagement::Commands::RemoveAllScenes::Type::ResponseType &); -using store_scene_callback = void (*)(void *, - const chip::app::Clusters::ScenesManagement::Commands::StoreScene::Type::ResponseType &); -using get_scene_membership_callback = - void (*)(void *, const chip::app::Clusters::ScenesManagement::Commands::GetSceneMembership::Type::ResponseType &); - -esp_err_t send_add_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, uint8_t scene_id, - uint16_t transition_time, char *scene_name, extension_field_sets &efs, - add_scene_callback add_scene_cb); - -esp_err_t send_view_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, view_scene_callback view_scene_cb); - -esp_err_t send_remove_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, remove_scene_callback remove_scene_cb); - -esp_err_t send_remove_all_scenes(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - remove_all_scenes_callback remove_all_scenes_cb); - -esp_err_t send_store_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id, store_scene_callback store_scene_cb); - -esp_err_t send_recall_scene(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - uint8_t scene_id); - -esp_err_t send_get_scene_membership(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t group_id, - get_scene_membership_callback get_scene_membership_cb); - -} // namespace command -} // namespace scenes_management - -namespace thermostat { -namespace command { - -using transitions = - chip::app::DataModel::List; - -using get_weekly_schedule_callback = - void (*)(void *, const chip::app::Clusters::Thermostat::Commands::GetWeeklySchedule::Type::ResponseType &); - -esp_err_t send_setpoint_raise_lower(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t mode, - uint8_t amount); - -esp_err_t send_set_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t num_of_tras_for_seq, uint8_t day_of_week_for_seq, uint8_t mode_for_seq, - transitions &trans); - -esp_err_t send_get_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t day_to_return, - uint8_t mode_to_return, get_weekly_schedule_callback get_weekly_schedule_cb); - -esp_err_t send_clear_weekly_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id); - -} // namespace command -} // namespace thermostat - -namespace door_lock { -namespace command { - -using get_week_day_schedule_callback = - void (*)(void *, const chip::app::Clusters::DoorLock::Commands::GetWeekDaySchedule::Type::ResponseType &); - -using get_year_day_schedule_callback = - void (*)(void *, const chip::app::Clusters::DoorLock::Commands::GetYearDaySchedule::Type::ResponseType &); - -using get_holiday_schedule_callback = - void (*)(void *, const chip::app::Clusters::DoorLock::Commands::GetHolidaySchedule::Type::ResponseType &); - -using get_user_callback = void (*)(void *, - const chip::app::Clusters::DoorLock::Commands::GetUser::Type::ResponseType &); - -using set_credential_callback = - void (*)(void *, const chip::app::Clusters::DoorLock::Commands::SetCredential::Type::ResponseType &); - -using get_credential_status_callback = - void (*)(void *, const chip::app::Clusters::DoorLock::Commands::GetCredentialStatus::Type::ResponseType &); - -using credential_struct = chip::app::Clusters::DoorLock::Structs::CredentialStruct::Type; - -esp_err_t send_lock_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timed_invoke_timeout_ms); - -esp_err_t send_unlock_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timed_invoke_timeout_ms); - -esp_err_t send_unlock_with_timeout(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t timeout, - uint16_t timed_invoke_timeout_ms); - -esp_err_t send_set_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t week_day_index, - uint16_t user_index, uint8_t days_mask, uint8_t start_hour, uint8_t start_minute, - uint8_t end_hour, uint8_t end_minute); - -esp_err_t send_get_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t week_day_index, - uint16_t user_index, get_week_day_schedule_callback success_cb); - -esp_err_t send_clear_week_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t week_day_index, uint16_t user_index); - -esp_err_t send_set_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t year_day_index, - uint16_t user_index, uint32_t local_start_time, uint32_t local_end_time); - -esp_err_t send_get_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t year_day_index, - uint16_t user_index, get_year_day_schedule_callback success_cb); - -esp_err_t send_clear_year_day_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint8_t year_day_index, uint16_t user_index); - -esp_err_t send_set_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index, - uint32_t local_start_time, uint32_t local_end_time, uint8_t operating_mode); - -esp_err_t send_get_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index, - get_holiday_schedule_callback success_cb); - -esp_err_t send_clear_holiday_schedule(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t holiday_index); - -esp_err_t send_set_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t operation_type, - uint16_t user_index, char *user_name, uint32_t user_unique_id, uint8_t user_status, - uint8_t user_type, uint8_t credential_rule, uint16_t timed_invoke_timeout_ms); - -esp_err_t send_get_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t user_index, - get_user_callback success_cb); - -esp_err_t send_clear_user(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t user_index, - uint16_t timed_invoke_timeout_ms); - -esp_err_t send_set_credential(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t operation_type, - credential_struct credential, uint8_t *credential_data, size_t credential_len, - uint16_t user_index, uint8_t user_status, uint8_t user_type, - set_credential_callback success_cb, uint16_t timed_invoke_timeout_ms); - -esp_err_t send_get_credential_status(peer_device_t *remote_device, uint16_t remote_endpoint_id, - credential_struct &credential, get_credential_status_callback success_cb); - -esp_err_t send_clear_credential(peer_device_t *remote_device, uint16_t remote_endpoint_id, - credential_struct &credential, uint16_t timed_invoke_timeout_ms); - -esp_err_t send_unbolt_door(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint8_t *pin_code, - size_t pin_code_len, uint16_t timed_invoke_timeout_ms); - -} // namespace command -} // namespace door_lock - -namespace window_covering { -namespace command { - -esp_err_t send_up_or_open(peer_device_t *remote_device, uint16_t remote_endpoint_id); - -esp_err_t send_down_or_close(peer_device_t *remote_device, uint16_t remote_endpoint_id); - -esp_err_t send_stop_motion(peer_device_t *remote_device, uint16_t remote_endpoint_id); - -esp_err_t send_go_to_lift_value(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t lift_value); - -esp_err_t send_go_to_lift_percentage(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t lift_percent100ths_value); - -esp_err_t send_go_to_tilt_value(peer_device_t *remote_device, uint16_t remote_endpoint_id, uint16_t tilt_value); - -esp_err_t send_go_to_tilt_percentage(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t tilt_percent100ths_value); - -} // namespace command -} // namespace window_covering - -namespace administrator_commissioning { -namespace command { - -esp_err_t send_open_commissioning_window(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t commissioning_timeout, chip::MutableByteSpan &pake_passcode_verifier, - uint16_t discriminator, uint32_t iterations, chip::MutableByteSpan &salt, - uint16_t timed_interaction_timeout_ms); - -esp_err_t send_open_basic_commissioning_window(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t commissioning_timeout, uint16_t timed_interaction_timeout_ms); - -esp_err_t send_revoke_commissioning(peer_device_t *remote_device, uint16_t remote_endpoint_id, - uint16_t timed_interaction_timeout_ms); - -} // namespace command -} // namespace administrator_commissioning - -} // namespace cluster +namespace read { +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams *attr_path, size_t attr_path_size, + EventPathParams *event_path, size_t event_path_size, ReadClient::Callback &callback); +} // namespace read + +/** Attribute write API + * + * It can be used for writing all the attributes of all the clusters, including the custom clusters. + */ +namespace write { +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams &attr_path, + const char *attr_val_json_str, WriteClient::Callback &callback, + const chip::Optional &timeout_ms); +} // namespace write + +namespace subscribe { +esp_err_t send_request(client::peer_device_t *remote_device, AttributePathParams *attr_path, size_t attr_path_size, + EventPathParams *event_path, size_t event_path_size, uint16_t min_interval, + uint16_t max_interval, bool keep_subscription, bool auto_resubscribe, + ReadClient::Callback &callback); +} // namespace subscribe + +} // namespace interaction +} // namespace client } // namespace esp_matter diff --git a/components/esp_matter/esp_matter_core.h b/components/esp_matter/esp_matter_core.h index 7adf13d28..ab66ebb6a 100644 --- a/components/esp_matter/esp_matter_core.h +++ b/components/esp_matter/esp_matter_core.h @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include using chip::app::ConcreteCommandPath; using chip::DeviceLayer::ChipDeviceEvent; @@ -832,23 +835,44 @@ uint32_t get_id(event_t *event); /* Client APIs */ namespace client { -/** Command handle as the input when calling `connect()` or `cluster_update()` +/** Client request types + */ +typedef enum { + INVOKE_CMD = 0, + READ_ATTR = 1, + READ_EVENT = 2, + WRITE_ATTR = 3, + SUBSCRIBE_ATTR = 4, + SUBSCRIBE_EVENT = 5, +} request_type_t; + +/** Request handle as the input when calling `connect()` or `cluster_update()` * */ -typedef struct command_handle { +typedef struct request_handle { + request_type_t type; union { - uint16_t endpoint_id; - uint16_t group_id; + chip::app::AttributePathParams attribute_path; + chip::app::EventPathParams event_path; + chip::app::CommandPathParams command_path; }; - uint32_t cluster_id; - uint32_t command_id; - void *command_data; - command_handle() : endpoint_id(chip::kInvalidEndpointId), cluster_id(chip::kInvalidClusterId), - command_id(chip::kInvalidCommandId), command_data(NULL){} - command_handle(struct command_handle* cmd) : endpoint_id(cmd->endpoint_id), cluster_id(cmd->cluster_id), - command_id(cmd->command_id), command_data(cmd->command_data) {} -} command_handle_t; + /* This could be the command data field when the request type is INVOKE_CMD, + * or the attribute value data when the request type is WRITE_ATTR. + */ + void *request_data; + request_handle() : type(INVOKE_CMD), request_data(NULL) {} + request_handle(struct request_handle* req) : type(req->type), request_data(req->request_data) + { + if (req->type == INVOKE_CMD) { + command_path = req->command_path; + } else if (req->type == WRITE_ATTR || req->type == READ_ATTR || req->type == SUBSCRIBE_ATTR) { + attribute_path = req->attribute_path; + } else if (req->type == READ_EVENT || req->type == SUBSCRIBE_EVENT) { + event_path = req->event_path; + } + } +} request_handle_t; /** Peer device handle */ typedef chip::DeviceProxy peer_device_t; @@ -856,28 +880,30 @@ typedef chip::DeviceProxy peer_device_t; /** CASE Session Manager */ typedef chip::CASESessionManager case_session_mgr_t; -/** Command send callback +/** Request send callback * * This callback will be called when `connect()` or `cluster_update()` is called and the connection completes. The - * send_command APIs can then be called from the callback. + * send_request APIs can then be called from the callback. * * @param[in] peer_device Peer device handle. This can be passed to the send_command APIs. - * @param[in] cmd_handle Command handle used by `connect()` or `cluster_update()`. + * @param[in] req_handle Request handle used by `connect()` or `cluster_update()`. * @param[in] priv_data (Optional) Private data associated with the callback. This will be passed to callback. It * should stay allocated throughout the lifetime of the device. */ -typedef void (*command_callback_t)(peer_device_t *peer_device, command_handle_t *cmd_handle, void *priv_data); +typedef void (*request_callback_t)(peer_device_t *peer_device, request_handle_t *req_handle, void *priv_data); -/** Group command send callback +/** Group request send callback * - * This callback will be called when `cluster_update()` is called and the group command is triggered for binding cluster. + * This callback will be called when `cluster_update()` is called and the group request is triggered for binding cluster. + * + * @note: The request type should be INVOKE_CMD and the command should not expect a response. * * @param[in] fabric_index The index of the fabric that the group command is sent to. - * @param[in] cmd_handle Command handle used by `cluster_update()`. + * @param[in] req_handle Request handle used by `cluster_update()`. * @param[in] priv_data (Optional) Private data associated with the callback. This will be passed to callback. It * should stay allocated throughout the lifetime of the device. */ -typedef void (*group_command_callback_t)(uint8_t fabric_index, command_handle_t *cmd_handle, void *priv_data); +typedef void (*group_request_callback_t)(uint8_t fabric_index, request_handle_t *req_handle, void *priv_data); /** Initialize binding * @@ -895,59 +921,59 @@ void binding_manager_init(); /** Connect * - * Connect to another device on the same fabric to send a command. + * Connect to another device on the same fabric to send a request. * * @param[in] case_session_mgr CASE Session Manager to find or establish the session * @param[in] fabric_index Fabric index. * @param[in] node_id Node ID of the other device. - * @param[in] cmd_handle Command to be sent to the remote device. + * @param[in] req_handle Request to be sent to the remote device. * * @return ESP_OK on success. * @return error in case of failure. */ esp_err_t connect(case_session_mgr_t *case_session_mgr, uint8_t fabric_index, uint64_t node_id, - command_handle_t *cmd_handle); + request_handle_t *req_handle); -/** group_command_send +/** group_request_send * - * on the same fabric to send a group command. + * on the same fabric to send a group request. * * @param[in] fabric_index Fabric index. - * @param[in] cmd_handle Command to be sent to the group. + * @param[in] req_handle Request to be sent to the group. * * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t group_command_send(uint8_t fabric_index, command_handle_t *cmd_handle); +esp_err_t group_request_send(uint8_t fabric_index, request_handle_t *req_handle); -/** Set command send callback +/** Set request send callback * - * Set the common command send callback and the group command send callback. The common callback will be called + * Set the common request send callback and the group request send callback. The common callback will be called * when `connect()` or `cluster_update()` is called and the connection completes. The group callback will be called - * when `cluster_update()` is called and the group command is triggered. + * when `cluster_update()` is called and the group request is triggered. * - * @param[in] callback command send callback. - * @param[in] g_callback group command send callback + * @param[in] callback request send callback. + * @param[in] g_callback group request send callback * @param[in] priv_data (Optional) Private data associated with the callback. This will be passed to callback. It * should stay allocated throughout the lifetime of the device. * * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t set_command_callback(command_callback_t callback, group_command_callback_t g_callback, void *priv_data); +esp_err_t set_request_callback(request_callback_t callback, group_request_callback_t g_callback, void *priv_data); /** Cluster update * - * For an already binded device, this API can be used to get the command send callback, and the send_command APIs can + * For an already binded device, this API can be used to get the request send callback, and the send_request APIs can * then be called from the callback. * * @param[in] local_endpoint_id The ID of the local endpoint with a binding cluster. - * @param[in] cmd_handle Command information to notify the bound cluster changed. + * @param[in] req_handle Request information to notify the bound cluster changed. * * @return ESP_OK on success. * @return error in case of failure. */ -esp_err_t cluster_update(uint16_t local_endpoint_id, command_handle_t *cmd_handle); +esp_err_t cluster_update(uint16_t local_endpoint_id, request_handle_t *req_handle); } /* client */ } /* esp_matter */ diff --git a/components/esp_matter/zap_common/zap-generated/CHIPClusters.h b/components/esp_matter/zap_common/zap-generated/CHIPClusters.h deleted file mode 100644 index afc21f0e1..000000000 --- a/components/esp_matter/zap_common/zap-generated/CHIPClusters.h +++ /dev/null @@ -1,733 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO: This header is removed from upstream zap generated files. We should also remove it. -// THIS FILE IS GENERATED BY ZAP -#pragma once - -#include -#include - -#include -#include -#include - -namespace chip { -namespace Controller { - -class DLL_EXPORT IdentifyCluster : public ClusterBase -{ -public: - IdentifyCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~IdentifyCluster() {} -}; - -class DLL_EXPORT GroupsCluster : public ClusterBase -{ -public: - GroupsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~GroupsCluster() {} -}; - -class DLL_EXPORT ScenesManagementCluster : public ClusterBase -{ -public: - ScenesManagementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ScenesManagementCluster() {} -}; - -class DLL_EXPORT OnOffCluster : public ClusterBase -{ -public: - OnOffCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OnOffCluster() {} -}; - -class DLL_EXPORT OnOffSwitchConfigurationCluster : public ClusterBase -{ -public: - OnOffSwitchConfigurationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OnOffSwitchConfigurationCluster() {} -}; - -class DLL_EXPORT LevelControlCluster : public ClusterBase -{ -public: - LevelControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LevelControlCluster() {} -}; - -class DLL_EXPORT BinaryInputBasicCluster : public ClusterBase -{ -public: - BinaryInputBasicCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BinaryInputBasicCluster() {} -}; - -class DLL_EXPORT DescriptorCluster : public ClusterBase -{ -public: - DescriptorCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DescriptorCluster() {} -}; - -class DLL_EXPORT BindingCluster : public ClusterBase -{ -public: - BindingCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BindingCluster() {} -}; - -class DLL_EXPORT AccessControlCluster : public ClusterBase -{ -public: - AccessControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~AccessControlCluster() {} -}; - -class DLL_EXPORT ActionsCluster : public ClusterBase -{ -public: - ActionsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ActionsCluster() {} -}; - -class DLL_EXPORT BasicInformationCluster : public ClusterBase -{ -public: - BasicInformationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BasicInformationCluster() {} -}; - -class DLL_EXPORT OtaSoftwareUpdateProviderCluster : public ClusterBase -{ -public: - OtaSoftwareUpdateProviderCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OtaSoftwareUpdateProviderCluster() {} -}; - -class DLL_EXPORT OtaSoftwareUpdateRequestorCluster : public ClusterBase -{ -public: - OtaSoftwareUpdateRequestorCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OtaSoftwareUpdateRequestorCluster() {} -}; - -class DLL_EXPORT LocalizationConfigurationCluster : public ClusterBase -{ -public: - LocalizationConfigurationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LocalizationConfigurationCluster() {} -}; - -class DLL_EXPORT TimeFormatLocalizationCluster : public ClusterBase -{ -public: - TimeFormatLocalizationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TimeFormatLocalizationCluster() {} -}; - -class DLL_EXPORT UnitLocalizationCluster : public ClusterBase -{ -public: - UnitLocalizationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~UnitLocalizationCluster() {} -}; - -class DLL_EXPORT PowerSourceConfigurationCluster : public ClusterBase -{ -public: - PowerSourceConfigurationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~PowerSourceConfigurationCluster() {} -}; - -class DLL_EXPORT PowerSourceCluster : public ClusterBase -{ -public: - PowerSourceCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~PowerSourceCluster() {} -}; - -class DLL_EXPORT GeneralCommissioningCluster : public ClusterBase -{ -public: - GeneralCommissioningCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~GeneralCommissioningCluster() {} -}; - -class DLL_EXPORT NetworkCommissioningCluster : public ClusterBase -{ -public: - NetworkCommissioningCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~NetworkCommissioningCluster() {} -}; - -class DLL_EXPORT DiagnosticLogsCluster : public ClusterBase -{ -public: - DiagnosticLogsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DiagnosticLogsCluster() {} -}; - -class DLL_EXPORT GeneralDiagnosticsCluster : public ClusterBase -{ -public: - GeneralDiagnosticsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~GeneralDiagnosticsCluster() {} -}; - -class DLL_EXPORT SoftwareDiagnosticsCluster : public ClusterBase -{ -public: - SoftwareDiagnosticsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~SoftwareDiagnosticsCluster() {} -}; - -class DLL_EXPORT ThreadNetworkDiagnosticsCluster : public ClusterBase -{ -public: - ThreadNetworkDiagnosticsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ThreadNetworkDiagnosticsCluster() {} -}; - -class DLL_EXPORT WiFiNetworkDiagnosticsCluster : public ClusterBase -{ -public: - WiFiNetworkDiagnosticsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~WiFiNetworkDiagnosticsCluster() {} -}; - -class DLL_EXPORT EthernetNetworkDiagnosticsCluster : public ClusterBase -{ -public: - EthernetNetworkDiagnosticsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~EthernetNetworkDiagnosticsCluster() {} -}; - -class DLL_EXPORT TimeSynchronizationCluster : public ClusterBase -{ -public: - TimeSynchronizationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TimeSynchronizationCluster() {} -}; - -class DLL_EXPORT BridgedDeviceBasicInformationCluster : public ClusterBase -{ -public: - BridgedDeviceBasicInformationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BridgedDeviceBasicInformationCluster() {} -}; - -class DLL_EXPORT SwitchCluster : public ClusterBase -{ -public: - SwitchCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~SwitchCluster() {} -}; - -class DLL_EXPORT AdministratorCommissioningCluster : public ClusterBase -{ -public: - AdministratorCommissioningCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~AdministratorCommissioningCluster() {} -}; - -class DLL_EXPORT OperationalCredentialsCluster : public ClusterBase -{ -public: - OperationalCredentialsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OperationalCredentialsCluster() {} -}; - -class DLL_EXPORT GroupKeyManagementCluster : public ClusterBase -{ -public: - GroupKeyManagementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~GroupKeyManagementCluster() {} -}; - -class DLL_EXPORT FixedLabelCluster : public ClusterBase -{ -public: - FixedLabelCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~FixedLabelCluster() {} -}; - -class DLL_EXPORT UserLabelCluster : public ClusterBase -{ -public: - UserLabelCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~UserLabelCluster() {} -}; - -class DLL_EXPORT BooleanStateCluster : public ClusterBase -{ -public: - BooleanStateCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BooleanStateCluster() {} -}; - -class DLL_EXPORT IcdManagementCluster : public ClusterBase -{ -public: - IcdManagementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~IcdManagementCluster() {} -}; - -class DLL_EXPORT TimerCluster : public ClusterBase -{ -public: - TimerCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TimerCluster() {} -}; - -class DLL_EXPORT OvenCavityOperationalStateCluster : public ClusterBase -{ -public: - OvenCavityOperationalStateCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OvenCavityOperationalStateCluster() {} -}; - -class DLL_EXPORT OvenModeCluster : public ClusterBase -{ -public: - OvenModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OvenModeCluster() {} -}; - -class DLL_EXPORT LaundryDryerControlsCluster : public ClusterBase -{ -public: - LaundryDryerControlsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LaundryDryerControlsCluster() {} -}; - -class DLL_EXPORT ModeSelectCluster : public ClusterBase -{ -public: - ModeSelectCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ModeSelectCluster() {} -}; - -class DLL_EXPORT LaundryWasherModeCluster : public ClusterBase -{ -public: - LaundryWasherModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LaundryWasherModeCluster() {} -}; - -class DLL_EXPORT RefrigeratorAndTemperatureControlledCabinetModeCluster : public ClusterBase -{ -public: - RefrigeratorAndTemperatureControlledCabinetModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RefrigeratorAndTemperatureControlledCabinetModeCluster() {} -}; - -class DLL_EXPORT LaundryWasherControlsCluster : public ClusterBase -{ -public: - LaundryWasherControlsCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LaundryWasherControlsCluster() {} -}; - -class DLL_EXPORT RvcRunModeCluster : public ClusterBase -{ -public: - RvcRunModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RvcRunModeCluster() {} -}; - -class DLL_EXPORT RvcCleanModeCluster : public ClusterBase -{ -public: - RvcCleanModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RvcCleanModeCluster() {} -}; - -class DLL_EXPORT TemperatureControlCluster : public ClusterBase -{ -public: - TemperatureControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TemperatureControlCluster() {} -}; - -class DLL_EXPORT RefrigeratorAlarmCluster : public ClusterBase -{ -public: - RefrigeratorAlarmCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RefrigeratorAlarmCluster() {} -}; - -class DLL_EXPORT DishwasherModeCluster : public ClusterBase -{ -public: - DishwasherModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DishwasherModeCluster() {} -}; - -class DLL_EXPORT AirQualityCluster : public ClusterBase -{ -public: - AirQualityCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~AirQualityCluster() {} -}; - -class DLL_EXPORT SmokeCoAlarmCluster : public ClusterBase -{ -public: - SmokeCoAlarmCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~SmokeCoAlarmCluster() {} -}; - -class DLL_EXPORT DishwasherAlarmCluster : public ClusterBase -{ -public: - DishwasherAlarmCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DishwasherAlarmCluster() {} -}; - -class DLL_EXPORT MicrowaveOvenModeCluster : public ClusterBase -{ -public: - MicrowaveOvenModeCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~MicrowaveOvenModeCluster() {} -}; - -class DLL_EXPORT OperationalStateCluster : public ClusterBase -{ -public: - OperationalStateCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OperationalStateCluster() {} -}; - -class DLL_EXPORT RvcOperationalStateCluster : public ClusterBase -{ -public: - RvcOperationalStateCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RvcOperationalStateCluster() {} -}; - -class DLL_EXPORT HepaFilterMonitoringCluster : public ClusterBase -{ -public: - HepaFilterMonitoringCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~HepaFilterMonitoringCluster() {} -}; - -class DLL_EXPORT ActivatedCarbonFilterMonitoringCluster : public ClusterBase -{ -public: - ActivatedCarbonFilterMonitoringCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ActivatedCarbonFilterMonitoringCluster() {} -}; - -class DLL_EXPORT DeviceEnergyManagementCluster : public ClusterBase -{ -public: - DeviceEnergyManagementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DeviceEnergyManagementCluster() {} -}; - -class DLL_EXPORT EnergyEvseCluster : public ClusterBase -{ -public: - EnergyEvseCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~EnergyEvseCluster() {} -}; - -class DLL_EXPORT DoorLockCluster : public ClusterBase -{ -public: - DoorLockCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~DoorLockCluster() {} -}; - -class DLL_EXPORT WindowCoveringCluster : public ClusterBase -{ -public: - WindowCoveringCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~WindowCoveringCluster() {} -}; - -class DLL_EXPORT BarrierControlCluster : public ClusterBase -{ -public: - BarrierControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BarrierControlCluster() {} -}; - -class DLL_EXPORT PumpConfigurationAndControlCluster : public ClusterBase -{ -public: - PumpConfigurationAndControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~PumpConfigurationAndControlCluster() {} -}; - -class DLL_EXPORT ThermostatCluster : public ClusterBase -{ -public: - ThermostatCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ThermostatCluster() {} -}; - -class DLL_EXPORT FanControlCluster : public ClusterBase -{ -public: - FanControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~FanControlCluster() {} -}; - -class DLL_EXPORT ThermostatUserInterfaceConfigurationCluster : public ClusterBase -{ -public: - ThermostatUserInterfaceConfigurationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ThermostatUserInterfaceConfigurationCluster() {} -}; - -class DLL_EXPORT ColorControlCluster : public ClusterBase -{ -public: - ColorControlCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ColorControlCluster() {} -}; - -class DLL_EXPORT BallastConfigurationCluster : public ClusterBase -{ -public: - BallastConfigurationCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~BallastConfigurationCluster() {} -}; - -class DLL_EXPORT IlluminanceMeasurementCluster : public ClusterBase -{ -public: - IlluminanceMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~IlluminanceMeasurementCluster() {} -}; - -class DLL_EXPORT TemperatureMeasurementCluster : public ClusterBase -{ -public: - TemperatureMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TemperatureMeasurementCluster() {} -}; - -class DLL_EXPORT PressureMeasurementCluster : public ClusterBase -{ -public: - PressureMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~PressureMeasurementCluster() {} -}; - -class DLL_EXPORT FlowMeasurementCluster : public ClusterBase -{ -public: - FlowMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~FlowMeasurementCluster() {} -}; - -class DLL_EXPORT RelativeHumidityMeasurementCluster : public ClusterBase -{ -public: - RelativeHumidityMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RelativeHumidityMeasurementCluster() {} -}; - -class DLL_EXPORT OccupancySensingCluster : public ClusterBase -{ -public: - OccupancySensingCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OccupancySensingCluster() {} -}; - -class DLL_EXPORT CarbonMonoxideConcentrationMeasurementCluster : public ClusterBase -{ -public: - CarbonMonoxideConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~CarbonMonoxideConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT CarbonDioxideConcentrationMeasurementCluster : public ClusterBase -{ -public: - CarbonDioxideConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~CarbonDioxideConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT NitrogenDioxideConcentrationMeasurementCluster : public ClusterBase -{ -public: - NitrogenDioxideConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~NitrogenDioxideConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT OzoneConcentrationMeasurementCluster : public ClusterBase -{ -public: - OzoneConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~OzoneConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT Pm25ConcentrationMeasurementCluster : public ClusterBase -{ -public: - Pm25ConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~Pm25ConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT FormaldehydeConcentrationMeasurementCluster : public ClusterBase -{ -public: - FormaldehydeConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~FormaldehydeConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT Pm1ConcentrationMeasurementCluster : public ClusterBase -{ -public: - Pm1ConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~Pm1ConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT Pm10ConcentrationMeasurementCluster : public ClusterBase -{ -public: - Pm10ConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~Pm10ConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT TotalVolatileOrganicCompoundsConcentrationMeasurementCluster : public ClusterBase -{ -public: - TotalVolatileOrganicCompoundsConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TotalVolatileOrganicCompoundsConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT RadonConcentrationMeasurementCluster : public ClusterBase -{ -public: - RadonConcentrationMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~RadonConcentrationMeasurementCluster() {} -}; - -class DLL_EXPORT WakeOnLanCluster : public ClusterBase -{ -public: - WakeOnLanCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~WakeOnLanCluster() {} -}; - -class DLL_EXPORT ChannelCluster : public ClusterBase -{ -public: - ChannelCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ChannelCluster() {} -}; - -class DLL_EXPORT TargetNavigatorCluster : public ClusterBase -{ -public: - TargetNavigatorCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~TargetNavigatorCluster() {} -}; - -class DLL_EXPORT MediaPlaybackCluster : public ClusterBase -{ -public: - MediaPlaybackCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~MediaPlaybackCluster() {} -}; - -class DLL_EXPORT MediaInputCluster : public ClusterBase -{ -public: - MediaInputCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~MediaInputCluster() {} -}; - -class DLL_EXPORT LowPowerCluster : public ClusterBase -{ -public: - LowPowerCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~LowPowerCluster() {} -}; - -class DLL_EXPORT KeypadInputCluster : public ClusterBase -{ -public: - KeypadInputCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~KeypadInputCluster() {} -}; - -class DLL_EXPORT ContentLauncherCluster : public ClusterBase -{ -public: - ContentLauncherCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ContentLauncherCluster() {} -}; - -class DLL_EXPORT AudioOutputCluster : public ClusterBase -{ -public: - AudioOutputCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~AudioOutputCluster() {} -}; - -class DLL_EXPORT ApplicationLauncherCluster : public ClusterBase -{ -public: - ApplicationLauncherCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ApplicationLauncherCluster() {} -}; - -class DLL_EXPORT ApplicationBasicCluster : public ClusterBase -{ -public: - ApplicationBasicCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ApplicationBasicCluster() {} -}; - -class DLL_EXPORT AccountLoginCluster : public ClusterBase -{ -public: - AccountLoginCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~AccountLoginCluster() {} -}; - -class DLL_EXPORT ElectricalMeasurementCluster : public ClusterBase -{ -public: - ElectricalMeasurementCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~ElectricalMeasurementCluster() {} -}; - -class DLL_EXPORT UnitTestingCluster : public ClusterBase -{ -public: - UnitTestingCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~UnitTestingCluster() {} -}; - -class DLL_EXPORT SampleMeiCluster : public ClusterBase -{ -public: - SampleMeiCluster(Messaging::ExchangeManager & exchangeManager, const SessionHandle & session, EndpointId endpoint) : ClusterBase(exchangeManager, session, endpoint) {} - ~SampleMeiCluster() {} -}; - -} // namespace Controller -} // namespace chip diff --git a/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.cpp b/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.cpp index 7e1936e05..d0ede9310 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.cpp +++ b/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.cpp @@ -29,6 +29,7 @@ using namespace chip::app::Clusters; using namespace esp_matter::cluster; +using namespace esp_matter::client; static const char *TAG = "cluster_command"; namespace esp_matter { @@ -153,7 +154,7 @@ void cluster_command::on_device_connected_fcn(void *context, ExchangeManager &ex chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle); chip::app::CommandPathParams command_path = {cmd->m_endpoint_id, 0, cmd->m_cluster_id, cmd->m_command_id, chip::app::CommandPathFlags::kEndpointIdValid}; - custom::command::send_command(context, &device_proxy, command_path, cmd->m_command_data_field, cmd->on_success_cb, + interaction::invoke::send_request(context, &device_proxy, command_path, cmd->m_command_data_field, cmd->on_success_cb, cmd->on_error_cb, chip::NullOptional); chip::Platform::Delete(cmd); return; @@ -218,7 +219,7 @@ esp_err_t cluster_command::dispatch_group_command(void *context) #endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER chip::app::CommandPathParams command_path = {cmd->m_endpoint_id, group_id, cmd->m_cluster_id, cmd->m_command_id, chip::app::CommandPathFlags::kGroupIdValid}; - err = custom::command::send_group_command(fabric_index, command_path, cmd->m_command_data_field); + err = interaction::invoke::send_group_request(fabric_index, command_path, cmd->m_command_data_field); chip::Platform::Delete(cmd); return err; } diff --git a/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.h b/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.h index ba75f626b..2004cc6cf 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.h +++ b/components/esp_matter_controller/commands/esp_matter_controller_cluster_command.h @@ -29,7 +29,7 @@ using chip::app::StatusIB; using chip::Messaging::ExchangeManager; using chip::TLV::TLVReader; using esp_matter::client::peer_device_t; -using esp_matter::cluster::custom::command::custom_command_callback; +using esp_matter::client::interaction::invoke::custom_command_callback; constexpr char k_empty_command_data_field[] = "{}"; constexpr size_t k_command_data_field_buffer_size = CONFIG_ESP_MATTER_CONTROLLER_JSON_STRING_BUFFER_LEN; diff --git a/components/esp_matter_controller/commands/esp_matter_controller_read_command.cpp b/components/esp_matter_controller/commands/esp_matter_controller_read_command.cpp index d6be69513..252081832 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_read_command.cpp +++ b/components/esp_matter_controller/commands/esp_matter_controller_read_command.cpp @@ -12,15 +12,18 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include #include +#include #include #include +#include + #include "DataModelLogger.h" using namespace chip::app::Clusters; +using namespace esp_matter::client; using chip::DeviceProxy; using chip::app::InteractionModelEngine; using chip::app::ReadClient; @@ -35,30 +38,11 @@ void read_command::on_device_connected_fcn(void *context, ExchangeManager &excha const SessionHandle &sessionHandle) { read_command *cmd = (read_command *)context; - ReadPrepareParams params(sessionHandle); - - if (cmd->m_attr_paths.AllocatedSize() == 0 && cmd->m_event_paths.AllocatedSize() == 0) { - ESP_LOGE(TAG, "Cannot send the read command with NULL attribute path and NULL event path"); - chip::Platform::Delete(cmd); - return; - } - params.mpAttributePathParamsList = cmd->m_attr_paths.Get(); - params.mAttributePathParamsListSize = cmd->m_attr_paths.AllocatedSize(); - params.mpEventPathParamsList = cmd->m_event_paths.Get(); - params.mEventPathParamsListSize = cmd->m_event_paths.AllocatedSize(); - params.mIsFabricFiltered = 0; - params.mpDataVersionFilterList = nullptr; - params.mDataVersionFilterListSize = 0; - - ReadClient *client = chip::Platform::New(InteractionModelEngine::GetInstance(), &exchangeMgr, - cmd->m_buffered_read_cb, ReadClient::InteractionType::Read); - if (!client) { - ESP_LOGE(TAG, "Failed to alloc memory for read client"); - chip::Platform::Delete(cmd); - } - if (CHIP_NO_ERROR != client->SendRequest(params)) { - ESP_LOGE(TAG, "Failed to send read request"); - chip::Platform::Delete(client); + chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle); + esp_err_t err = interaction::read::send_request(&device_proxy, cmd->m_attr_paths.Get(), + cmd->m_attr_paths.AllocatedSize(), cmd->m_event_paths.Get(), + cmd->m_event_paths.AllocatedSize(), cmd->m_buffered_read_cb); + if (err != ESP_OK) { chip::Platform::Delete(cmd); } return; @@ -168,7 +152,6 @@ void read_command::OnDone(ReadClient *apReadClient) if (read_done_cb) { read_done_cb(m_node_id, m_attr_paths, m_event_paths); } - chip::Platform::Delete(apReadClient); chip::Platform::Delete(this); } diff --git a/components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp b/components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp index 63eb9cd63..78ae6c0a4 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp +++ b/components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp @@ -15,12 +15,14 @@ #include #include #include +#include #include #include #include "DataModelLogger.h" using namespace chip::app::Clusters; +using namespace esp_matter::client; using chip::DeviceProxy; using chip::app::InteractionModelEngine; using chip::app::ReadClient; @@ -37,40 +39,12 @@ void subscribe_command::on_device_connected_fcn(void *context, ExchangeManager & const SessionHandle &sessionHandle) { subscribe_command *cmd = (subscribe_command *)context; - ReadPrepareParams params(sessionHandle); - CHIP_ERROR err = CHIP_NO_ERROR; - if (cmd->m_attr_paths.AllocatedSize() == 0 && cmd->m_event_paths.AllocatedSize() == 0) { - ESP_LOGE(TAG, "Cannot send Subscribe command with NULL attribute path and NULL event path"); - chip::Platform::Delete(cmd); - return; - } - - params.mpAttributePathParamsList = cmd->m_attr_paths.Get(); - params.mAttributePathParamsListSize = cmd->m_attr_paths.AllocatedSize(); - params.mpEventPathParamsList = cmd->m_event_paths.Get(); - params.mEventPathParamsListSize = cmd->m_event_paths.AllocatedSize(); - params.mIsFabricFiltered = 0; - params.mpDataVersionFilterList = nullptr; - params.mDataVersionFilterListSize = 0; - params.mMinIntervalFloorSeconds = cmd->m_min_interval; - params.mMaxIntervalCeilingSeconds = cmd->m_max_interval; - params.mKeepSubscriptions = true; - - ReadClient *client = - chip::Platform::New(InteractionModelEngine::GetInstance(), &exchangeMgr, cmd->m_buffered_read_cb, - ReadClient::InteractionType::Subscribe); - if (!client) { - ESP_LOGE(TAG, "Failed to alloc memory for read client"); - chip::Platform::Delete(cmd); - } - if (cmd->m_auto_resubscribe) { - err = client->SendAutoResubscribeRequest(std::move(params)); - } else { - err = client->SendRequest(params); - } - if (err != CHIP_NO_ERROR) { - ESP_LOGE(TAG, "Failed to send read request"); - chip::Platform::Delete(client); + chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle); + esp_err_t err = interaction::subscribe::send_request( + &device_proxy, cmd->m_attr_paths.Get(), cmd->m_attr_paths.AllocatedSize(), cmd->m_event_paths.Get(), + cmd->m_event_paths.AllocatedSize(), cmd->m_min_interval, cmd->m_max_interval, true, cmd->m_auto_resubscribe, + cmd->m_buffered_read_cb); + if (err != ESP_OK) { chip::Platform::Delete(cmd); } return; @@ -200,7 +174,6 @@ CHIP_ERROR subscribe_command::OnResubscriptionNeeded(ReadClient *apReadClient, C void subscribe_command::OnDone(ReadClient *apReadClient) { ESP_LOGI(TAG, "Subscription 0x%" PRIx32 " Done for remote node 0x%" PRIx64, m_subscription_id, m_node_id); - chip::Platform::Delete(apReadClient); if (subscribe_done_cb) { // This will be called when the subscription is terminated. subscribe_done_cb(m_node_id, m_subscription_id); diff --git a/components/esp_matter_controller/commands/esp_matter_controller_write_command.cpp b/components/esp_matter_controller/commands/esp_matter_controller_write_command.cpp index a44a230e6..cbbd97f64 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_write_command.cpp +++ b/components/esp_matter_controller/commands/esp_matter_controller_write_command.cpp @@ -13,14 +13,17 @@ // limitations under the License. #include +#include #include #include #include #include +#include #include using namespace chip::app::Clusters; +using namespace esp_matter::client; using chip::ByteSpan; using chip::DeviceProxy; using chip::app::DataModel::List; @@ -38,72 +41,16 @@ static constexpr size_t k_encoded_buf_size = chip::kMaxAppMessageLen; namespace esp_matter { namespace controller { -esp_err_t write_command::encode_attribute_value(uint8_t *encoded_buf, size_t encoded_buf_size, - const char *attr_val_json_str, TLVReader &out_reader) -{ - TLVWriter writer; - uint32_t encoded_len = 0; - TLVReader reader; - - writer.Init(encoded_buf, encoded_buf_size); - ESP_RETURN_ON_ERROR(json_to_tlv(attr_val_json_str, writer, chip::TLV::AnonymousTag()), TAG, - "Failed to parse attribute value"); - ESP_RETURN_ON_FALSE(writer.Finalize() == CHIP_NO_ERROR, ESP_FAIL, TAG, "Failed to finalize tlv writer"); - encoded_len = writer.GetLengthWritten(); - reader.Init(encoded_buf, encoded_len); - ESP_RETURN_ON_FALSE(reader.Next() == CHIP_NO_ERROR, ESP_FAIL, TAG, "Failed to read next"); - ESP_RETURN_ON_FALSE(reader.GetType() == TLVType::kTLVType_Structure, ESP_ERR_INVALID_ARG, TAG, - "The TLV type must be structure"); - ESP_RETURN_ON_FALSE(reader.OpenContainer(out_reader) == CHIP_NO_ERROR, ESP_FAIL, TAG, "Failed to open container"); - ESP_RETURN_ON_FALSE(out_reader.Next() == CHIP_NO_ERROR, ESP_FAIL, TAG, "Failed to read next"); - return ESP_OK; -} - void write_command::on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr, const SessionHandle &sessionHandle) { write_command *cmd = (write_command *)context; - if (cmd->m_attr_path.HasWildcardEndpointId()) { - ESP_LOGE(TAG, "Endpoint Id Invalid"); + chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle); + esp_err_t err = interaction::write::send_request(&device_proxy, cmd->m_attr_path, cmd->m_attr_val_str, + cmd->m_chunked_callback, chip::NullOptional); + if (err != ESP_OK) { chip::Platform::Delete(cmd); - return; } - ConcreteDataAttributePath path(cmd->m_attr_path.mEndpointId, cmd->m_attr_path.mClusterId, - cmd->m_attr_path.mAttributeId); - chip::Platform::ScopedMemoryBuffer encoded_buf; - - auto write_client = MakeUnique(&exchangeMgr, &(cmd->m_chunked_callback), chip::NullOptional, false); - if (write_client == nullptr) { - ESP_LOGE(TAG, "Failed to alloc memory for WriteClient"); - chip::Platform::Delete(cmd); - return; - } - encoded_buf.Alloc(k_encoded_buf_size); - if (!encoded_buf.Get()) { - ESP_LOGE(TAG, "Failed to alloc memory for encoded_buf"); - chip::Platform::Delete(cmd); - return; - } - TLVReader attr_val_reader; - if (encode_attribute_value(encoded_buf.Get(), k_encoded_buf_size, cmd->m_attr_val_str, attr_val_reader) != ESP_OK) { - ESP_LOGE(TAG, "Failed to encode attribute value to a TLV reader"); - chip::Platform::Delete(cmd); - return; - } - - if (write_client->PutPreencodedAttribute(path, attr_val_reader) != CHIP_NO_ERROR) { - ESP_LOGE(TAG, "Failed to put pre-encoded attribute value to WriteClient"); - chip::Platform::Delete(cmd); - return; - } - - if (write_client->SendWriteRequest(sessionHandle) != CHIP_NO_ERROR) { - ESP_LOGE(TAG, "Failed to Send Write Request"); - chip::Platform::Delete(cmd); - return; - } - // Release the write_client as it will be managed by the callbacks - write_client.release(); } void write_command::on_device_connection_failure_fcn(void *context, const ScopedNodeId &peerId, CHIP_ERROR error) diff --git a/components/esp_matter_controller/commands/esp_matter_controller_write_command.h b/components/esp_matter_controller/commands/esp_matter_controller_write_command.h index d54de5d9e..d07ffec32 100644 --- a/components/esp_matter_controller/commands/esp_matter_controller_write_command.h +++ b/components/esp_matter_controller/commands/esp_matter_controller_write_command.h @@ -79,7 +79,6 @@ public: void OnDone(WriteClient *client) override { ChipLogProgress(chipTool, "Write Done"); - chip::Platform::Delete(client); chip::Platform::Delete(this); } @@ -93,9 +92,6 @@ private: const SessionHandle &sessionHandle); static void on_device_connection_failure_fcn(void *context, const ScopedNodeId &peerId, CHIP_ERROR error); - static esp_err_t encode_attribute_value(uint8_t *encoded_buf, size_t encoded_buf_size, - const char *attr_val_json_str, TLVReader &out_reader); - chip::Callback::Callback on_device_connected_cb; chip::Callback::Callback on_device_connection_failure_cb; }; diff --git a/components/esp_matter_controller/core/esp_matter_controller_console.cpp b/components/esp_matter_controller/core/esp_matter_controller_console.cpp index 6800ca024..bf5fb9783 100644 --- a/components/esp_matter_controller/core/esp_matter_controller_console.cpp +++ b/components/esp_matter_controller/core/esp_matter_controller_console.cpp @@ -543,7 +543,7 @@ esp_err_t controller_register_commands() { .name = "subs-event", .description = "Subscribe events of the nodes.\n" - "\tUsage: controller subs-attr [node-id] [endpoint-id] [cluster-id] [event-id] " + "\tUsage: controller subs-event [node-id] [endpoint-id] [cluster-id] [event-id] " "[min-interval] [max-interval]", .handler = controller_subscribe_event_handler, }, diff --git a/examples/esp-now_bridge_light/main/app_driver.cpp b/examples/esp-now_bridge_light/main/app_driver.cpp index 256b5e488..f166807d8 100644 --- a/examples/esp-now_bridge_light/main/app_driver.cpp +++ b/examples/esp-now_bridge_light/main/app_driver.cpp @@ -18,6 +18,7 @@ #include #include +#include "app/CommandPathParams.h" using namespace chip::app::Clusters; using namespace esp_matter; @@ -36,10 +37,11 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv) "\tinvoke: parameters ... \n" "\t\tExample: matter esp bound invoke 0x0001 0x0008 0x0000 0x50 0x0 0x1 0x1.\n"); } else if (argc >= 4 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16); + req_handle.command_path.mClusterId = strtoul((const char *)&argv[2][2], NULL, 16); + req_handle.command_path.mCommandId = strtoul((const char *)&argv[3][2], NULL, 16); if (argc > 4) { console_buffer[0] = argc - 4; @@ -51,10 +53,10 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10*i), &argv[4+i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } - client::cluster_update(local_endpoint_id, &cmd_handle); + client::cluster_update(local_endpoint_id, &req_handle); } else { ESP_LOGE(TAG, "Incorrect arguments. Check help for more details."); @@ -76,12 +78,14 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) "\tinvoke-group: parameters ... \n" "\t\tExample: matter esp client invoke-group 0x0001 0x257 0x0008 0x0000 0x50 0x0 0x1 0x1.\n"); } else if (argc >= 6 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16); uint64_t node_id = strtoull((const char *)&argv[2][2], NULL, 16); - cmd_handle.endpoint_id = strtoul((const char *)&argv[3][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[4][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[5][2], NULL, 16); + req_handle.command_path = {(chip::EndpointId)strtoul((const char *)&argv[3][2], NULL, 16) /* EndpointId */, + 0 /* GroupId */, strtoul((const char *)&argv[4][2], NULL, 16) /* ClusterId */, + strtoul((const char *)&argv[5][2], NULL, 16) /* CommandId */, + chip::app::CommandPathFlags::kEndpointIdValid}; if (argc > 6) { console_buffer[0] = argc - 6; @@ -93,17 +97,19 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10*i), &argv[6+i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } auto &server = chip::Server::GetInstance(); - client::connect(server.GetCASESessionManager(), fabric_index, node_id, &cmd_handle); + client::connect(server.GetCASESessionManager(), fabric_index, node_id, &req_handle); } else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16); - cmd_handle.group_id = strtoul((const char *)&argv[2][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[3][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[4][2], NULL, 16); + req_handle.command_path = { + 0 /* EndpointId */, (chip::GroupId)strtoul((const char *)&argv[2][2], NULL, 16) /* GroupId */, + strtoul((const char *)&argv[3][2], NULL, 16) /* ClusterId */, + strtoul((const char *)&argv[4][2], NULL, 16) /* CommandId */, chip::app::CommandPathFlags::kGroupIdValid}; if (argc > 5) { console_buffer[0] = argc - 5; @@ -115,10 +121,10 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10*i), &argv[5+i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } - client::group_command_send(fabric_index, &cmd_handle); + client::group_request_send(fabric_index, &req_handle); }else { ESP_LOGE(TAG, "Incorrect arguments. Check help for more details."); return ESP_ERR_INVALID_ARG; @@ -153,81 +159,74 @@ static void app_driver_register_commands() } #endif // CONFIG_ENABLE_CHIP_SHELL -void app_driver_client_command_callback(client::peer_device_t *peer_device, client::command_handle_t *cmd_handle, - void *priv_data) +static void send_command_success_callback(void *context, const ConcreteCommandPath &command_path, + const chip::app::StatusIB &status, TLVReader *response_data) { - if (cmd_handle->cluster_id == OnOff::Id) { - switch(cmd_handle->command_id) { - case OnOff::Commands::Off::Id: - { - on_off::command::send_off(peer_device, cmd_handle->endpoint_id); - break; - }; - case OnOff::Commands::On::Id: - { - on_off::command::send_on(peer_device, cmd_handle->endpoint_id); - break; - }; - case OnOff::Commands::Toggle::Id: - { - on_off::command::send_toggle(peer_device, cmd_handle->endpoint_id); - break; - }; - default: - break; - } - } else if (cmd_handle->cluster_id == Identify::Id) { - if (cmd_handle->command_id == Identify::Commands::Identify::Id) { - if (((char *)cmd_handle->command_data)[0] != 1) { - ESP_LOGE(TAG, "Number of parameters error"); - return; - } - identify::command::send_identify(peer_device, cmd_handle->endpoint_id, - strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16)); - } else { - ESP_LOGE(TAG, "Unsupported command"); - } - } else { - ESP_LOGE(TAG, "Unsupported cluster"); - } + ESP_LOGI(TAG, "Send command success"); } -void app_driver_client_group_command_callback(uint8_t fabric_index, client::command_handle_t *cmd_handle, void *priv_data) +static void send_command_failure_callback(void *context, CHIP_ERROR error) { - if (cmd_handle->cluster_id == OnOff::Id) { - switch(cmd_handle->command_id) { - case OnOff::Commands::Off::Id: - { - on_off::command::group_send_off(fabric_index, cmd_handle->group_id); - break; - }; - case OnOff::Commands::On::Id: - { - on_off::command::group_send_on(fabric_index, cmd_handle->group_id); - break; - }; - case OnOff::Commands::Toggle::Id: - { - on_off::command::group_send_toggle(fabric_index, cmd_handle->group_id); - break; - }; - default: - break; - } - } else if (cmd_handle->cluster_id == Identify::Id) { - if (cmd_handle->command_id == Identify::Commands::Identify::Id) { - if (((char *)cmd_handle->command_data)[0] != 1) { + ESP_LOGI(TAG, "Send command failure: err :%" CHIP_ERROR_FORMAT, error.Format()); +} + +void app_driver_client_invoke_command_callback(client::peer_device_t *peer_device, client::request_handle_t *req_handle, + void *priv_data) +{ + if (req_handle->type != esp_matter::client::INVOKE_CMD || + !req_handle->command_path.mFlags.Has(chip::app::CommandPathFlags::kEndpointIdValid)) { + return; + } + char command_data_str[32]; + if (req_handle->command_path.mClusterId == OnOff::Id) { + strcpy(command_data_str, "{}"); + } else if (req_handle->command_path.mClusterId == Identify::Id) { + if (req_handle->command_path.mCommandId == Identify::Commands::Identify::Id) { + if (((char *)req_handle->request_data)[0] != 1) { ESP_LOGE(TAG, "Number of parameters error"); return; } - identify::command::group_send_identify(fabric_index, cmd_handle->group_id, - strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16)); + sprintf(command_data_str, "{\"0:U16\": %ld}", + strtoul((const char *)(req_handle->request_data) + 1, NULL, 16)); } else { ESP_LOGE(TAG, "Unsupported command"); + return; } } else { ESP_LOGE(TAG, "Unsupported cluster"); + return; } + client::interaction::invoke::send_request(NULL, peer_device, req_handle->command_path, command_data_str, + send_command_success_callback, send_command_failure_callback, + chip::NullOptional); +} + +void app_driver_client_group_invoke_command_callback(uint8_t fabric_index, client::request_handle_t *req_handle, void *priv_data) +{ + if (req_handle->type != esp_matter::client::INVOKE_CMD || + !req_handle->command_path.mFlags.Has(chip::app::CommandPathFlags::kGroupIdValid)) { + return; + } + char command_data_str[32]; + if (req_handle->command_path.mClusterId == OnOff::Id) { + strcpy(command_data_str, "{}"); + } else if (req_handle->command_path.mClusterId == Identify::Id) { + if (req_handle->command_path.mCommandId == Identify::Commands::Identify::Id) { + if (((char *)req_handle->request_data)[0] != 1) { + ESP_LOGE(TAG, "Number of parameters error"); + return; + } + sprintf(command_data_str, "{\"0:U16\": %ld}", + strtoul((const char *)(req_handle->request_data) + 1, NULL, 16)); + } else { + ESP_LOGE(TAG, "Unsupported command"); + return; + } + } else { + ESP_LOGE(TAG, "Unsupported cluster"); + return; + } + client::interaction::invoke::send_group_request(fabric_index, req_handle->command_path, command_data_str); } /* Do any conversions/remapping for the actual value here */ @@ -371,7 +370,7 @@ app_driver_handle_t app_driver_button_init() #if CONFIG_ENABLE_CHIP_SHELL app_driver_register_commands(); #endif // CONFIG_ENABLE_CHIP_SHELL - client::set_command_callback(app_driver_client_command_callback, app_driver_client_group_command_callback, NULL); + client::set_request_callback(app_driver_client_invoke_command_callback, app_driver_client_group_invoke_command_callback, NULL); return (app_driver_handle_t)handle; } diff --git a/examples/esp-now_bridge_light/main/app_espnow.cpp b/examples/esp-now_bridge_light/main/app_espnow.cpp index b0c0b85d3..a01ddaece 100644 --- a/examples/esp-now_bridge_light/main/app_espnow.cpp +++ b/examples/esp-now_bridge_light/main/app_espnow.cpp @@ -35,19 +35,20 @@ static void espnow_ctrl_onoff(espnow_addr_t src_addr, bool status) ESP_LOGI(TAG, "ESP-NOW button pressed"); // Update bound light - client::command_handle_t cmd_handle; - cmd_handle.cluster_id = OnOff::Id; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; + req_handle.command_path.mClusterId = OnOff::Id; if (status) { - cmd_handle.command_id = OnOff::Commands::On::Id; + req_handle.command_path.mCommandId = OnOff::Commands::On::Id; } else { - cmd_handle.command_id = OnOff::Commands::Off::Id; + req_handle.command_path.mCommandId = OnOff::Commands::Off::Id; } uint16_t bridged_switch_endpoint_id = app_bridge_get_matter_endpointid_by_espnow_macaddr(src_addr); ESP_LOGI(TAG, "Using bridge endpoint: %d", bridged_switch_endpoint_id); if (bridged_switch_endpoint_id != chip::kInvalidEndpointId) { lock::chip_stack_lock(portMAX_DELAY); - client::cluster_update(bridged_switch_endpoint_id, &cmd_handle); + client::cluster_update(bridged_switch_endpoint_id, &req_handle); lock::chip_stack_unlock(); } else { ESP_LOGE(TAG, "Can't find endpoint for bridged device: " MACSTR, MAC2STR(src_addr)); diff --git a/examples/light_switch/main/app_driver.cpp b/examples/light_switch/main/app_driver.cpp index 76963811c..8d77c29f8 100644 --- a/examples/light_switch/main/app_driver.cpp +++ b/examples/light_switch/main/app_driver.cpp @@ -6,6 +6,9 @@ CONDITIONS OF ANY KIND, either express or implied. */ +#include "esp_matter_client.h" +#include +#include #include #include #include @@ -18,6 +21,7 @@ #include #include +#include using chip::kInvalidClusterId; static constexpr chip::CommandId kInvalidCommandId = 0xFFFF'FFFF; @@ -39,10 +43,11 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv) "\tinvoke: parameters ... \n" "\t\tExample: matter esp bound invoke 0x0001 0x0003 0x0000 0x78.\n"); } else if (argc >= 4 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint16_t local_endpoint_id = strtoul((const char *)&argv[1][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[2][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[3][2], NULL, 16); + req_handle.command_path.mClusterId = strtoul((const char *)&argv[2][2], NULL, 16); + req_handle.command_path.mCommandId = strtoul((const char *)&argv[3][2], NULL, 16); if (argc > 4) { console_buffer[0] = argc - 4; @@ -55,10 +60,10 @@ static esp_err_t app_driver_bound_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10 * i), &argv[4 + i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } - client::cluster_update(local_endpoint_id, &cmd_handle); + client::cluster_update(local_endpoint_id, &req_handle); } else { ESP_LOGE(TAG, "Incorrect arguments. Check help for more details."); return ESP_ERR_INVALID_ARG; @@ -78,12 +83,14 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) "\tinvoke-group: parameters ... \n" "\t\tExample: matter esp client invoke-group 0x0001 0x257 0x0003 0x0000 0x78.\n"); } else if (argc >= 6 && strncmp(argv[0], "invoke", sizeof("invoke")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16); uint64_t node_id = strtoull((const char *)&argv[2][2], NULL, 16); - cmd_handle.endpoint_id = strtoul((const char *)&argv[3][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[4][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[5][2], NULL, 16); + req_handle.command_path = {(chip::EndpointId)strtoul((const char *)&argv[3][2], NULL, 16) /* EndpointId */, + 0 /* GroupId */, strtoul((const char *)&argv[4][2], NULL, 16) /* ClusterId */, + strtoul((const char *)&argv[5][2], NULL, 16) /* CommandId */, + chip::app::CommandPathFlags::kEndpointIdValid}; if (argc > 6) { console_buffer[0] = argc - 6; @@ -96,16 +103,21 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10 * i), &argv[6 + i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } auto &server = chip::Server::GetInstance(); - client::connect(server.GetCASESessionManager(), fabric_index, node_id, &cmd_handle); + client::connect(server.GetCASESessionManager(), fabric_index, node_id, &req_handle); } else if (argc >= 5 && strncmp(argv[0], "invoke-group", sizeof("invoke-group")) == 0) { - client::command_handle_t cmd_handle; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; uint8_t fabric_index = strtoul((const char *)&argv[1][2], NULL, 16); - cmd_handle.group_id = strtoul((const char *)&argv[2][2], NULL, 16); - cmd_handle.cluster_id = strtoul((const char *)&argv[3][2], NULL, 16); - cmd_handle.command_id = strtoul((const char *)&argv[4][2], NULL, 16); + req_handle.command_path.mGroupId = strtoul((const char *)&argv[2][2], NULL, 16); + req_handle.command_path.mClusterId = strtoul((const char *)&argv[3][2], NULL, 16); + req_handle.command_path.mCommandId = strtoul((const char *)&argv[4][2], NULL, 16); + req_handle.command_path = { + 0 /* EndpointId */, (chip::GroupId)strtoul((const char *)&argv[2][2], NULL, 16) /* GroupId */, + strtoul((const char *)&argv[3][2], NULL, 16) /* ClusterId */, + strtoul((const char *)&argv[4][2], NULL, 16) /* CommandId */, chip::app::CommandPathFlags::kGroupIdValid}; if (argc > 5) { console_buffer[0] = argc - 5; @@ -118,10 +130,10 @@ static esp_err_t app_driver_client_console_handler(int argc, char **argv) strcpy((console_buffer + 1 + 10 * i), &argv[5 + i][2]); } - cmd_handle.command_data = console_buffer; + req_handle.request_data = console_buffer; } - client::group_command_send(fabric_index, &cmd_handle); + client::group_request_send(fabric_index, &req_handle); } else { ESP_LOGE(TAG, "Incorrect arguments. Check help for more details."); return ESP_ERR_INVALID_ARG; @@ -154,89 +166,87 @@ static void app_driver_register_commands() } #endif // CONFIG_ENABLE_CHIP_SHELL -void app_driver_client_command_callback(client::peer_device_t *peer_device, client::command_handle_t *cmd_handle, - void *priv_data) +static void send_command_success_callback(void *context, const ConcreteCommandPath &command_path, + const chip::app::StatusIB &status, TLVReader *response_data) { - // on_off light switch should support on_off cluster and identify cluster commands sending. - if (cmd_handle->cluster_id == OnOff::Id) { - switch (cmd_handle->command_id) { - case OnOff::Commands::Off::Id: { - on_off::command::send_off(peer_device, cmd_handle->endpoint_id); - break; - }; - case OnOff::Commands::On::Id: { - on_off::command::send_on(peer_device, cmd_handle->endpoint_id); - break; - }; - case OnOff::Commands::Toggle::Id: { - on_off::command::send_toggle(peer_device, cmd_handle->endpoint_id); - break; - }; - default: - break; - } - } else if (cmd_handle->cluster_id == Identify::Id) { - if (cmd_handle->command_id == Identify::Commands::Identify::Id) { - if (((char *)cmd_handle->command_data)[0] != 1) { - ESP_LOGE(TAG, "Number of parameters error"); - return; - } - identify::command::send_identify(peer_device, cmd_handle->endpoint_id, - strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16)); - } else { - ESP_LOGE(TAG, "Unsupported command"); - } - } else { - ESP_LOGE(TAG, "Unsupported cluster"); - } + ESP_LOGI(TAG, "Send command success"); } -void app_driver_client_group_command_callback(uint8_t fabric_index, client::command_handle_t *cmd_handle, - void *priv_data) +static void send_command_failure_callback(void *context, CHIP_ERROR error) { + ESP_LOGI(TAG, "Send command failure: err :%" CHIP_ERROR_FORMAT, error.Format()); +} + +void app_driver_client_invoke_command_callback(client::peer_device_t *peer_device, client::request_handle_t *req_handle, + void *priv_data) +{ + if (req_handle->type != esp_matter::client::INVOKE_CMD) { + return; + } + char command_data_str[32]; // on_off light switch should support on_off cluster and identify cluster commands sending. - if (cmd_handle->cluster_id == OnOff::Id) { - switch (cmd_handle->command_id) { - case OnOff::Commands::Off::Id: { - on_off::command::group_send_off(fabric_index, cmd_handle->group_id); - break; - } - case OnOff::Commands::On::Id: { - on_off::command::group_send_on(fabric_index, cmd_handle->group_id); - break; - } - case OnOff::Commands::Toggle::Id: { - on_off::command::group_send_toggle(fabric_index, cmd_handle->group_id); - break; - } - default: - break; - } - } else if (cmd_handle->cluster_id == Identify::Id) { - if (cmd_handle->command_id == Identify::Commands::Identify::Id) { - if (((char *)cmd_handle->command_data)[0] != 1) { + if (req_handle->command_path.mClusterId == OnOff::Id) { + strcpy(command_data_str, "{}"); + } else if (req_handle->command_path.mClusterId == Identify::Id) { + if (req_handle->command_path.mCommandId == Identify::Commands::Identify::Id) { + if (((char *)req_handle->request_data)[0] != 1) { ESP_LOGE(TAG, "Number of parameters error"); return; } - identify::command::group_send_identify(fabric_index, cmd_handle->group_id, - strtoul((const char *)(cmd_handle->command_data) + 1, NULL, 16)); + sprintf(command_data_str, "{\"0:U16\": %ld}", + strtoul((const char *)(req_handle->request_data) + 1, NULL, 16)); } else { ESP_LOGE(TAG, "Unsupported command"); + return; } } else { ESP_LOGE(TAG, "Unsupported cluster"); + return; } + client::interaction::invoke::send_request(NULL, peer_device, req_handle->command_path, command_data_str, + send_command_success_callback, send_command_failure_callback, + chip::NullOptional); +} + +void app_driver_client_group_invoke_command_callback(uint8_t fabric_index, client::request_handle_t *req_handle, + void *priv_data) +{ + if (req_handle->type != esp_matter::client::INVOKE_CMD) { + return; + } + char command_data_str[32]; + // on_off light switch should support on_off cluster and identify cluster commands sending. + if (req_handle->command_path.mClusterId == OnOff::Id) { + strcpy(command_data_str, "{}"); + } else if (req_handle->command_path.mClusterId == Identify::Id) { + if (req_handle->command_path.mCommandId == Identify::Commands::Identify::Id) { + if (((char *)req_handle->request_data)[0] != 1) { + ESP_LOGE(TAG, "Number of parameters error"); + return; + } + sprintf(command_data_str, "{\"0:U16\": %ld}", + strtoul((const char *)(req_handle->request_data) + 1, NULL, 16)); + } else { + ESP_LOGE(TAG, "Unsupported command"); + return; + } + } else { + ESP_LOGE(TAG, "Unsupported cluster"); + return; + } + client::interaction::invoke::send_group_request(fabric_index, req_handle->command_path, command_data_str); } static void app_driver_button_toggle_cb(void *arg, void *data) { ESP_LOGI(TAG, "Toggle button pressed"); - client::command_handle_t cmd_handle; - cmd_handle.cluster_id = OnOff::Id; - cmd_handle.command_id = OnOff::Commands::Toggle::Id; + client::request_handle_t req_handle; + req_handle.type = esp_matter::client::INVOKE_CMD; + req_handle.command_path.mClusterId = OnOff::Id; + req_handle.command_path.mCommandId = OnOff::Commands::Toggle::Id; lock::chip_stack_lock(portMAX_DELAY); - client::cluster_update(switch_endpoint_id, &cmd_handle); + client::cluster_update(switch_endpoint_id, &req_handle); lock::chip_stack_unlock(); } @@ -252,7 +262,8 @@ app_driver_handle_t app_driver_switch_init() #if CONFIG_ENABLE_CHIP_SHELL app_driver_register_commands(); #endif // CONFIG_ENABLE_CHIP_SHELL - client::set_command_callback(app_driver_client_command_callback, app_driver_client_group_command_callback, NULL); + client::set_request_callback(app_driver_client_invoke_command_callback, + app_driver_client_group_invoke_command_callback, NULL); return (app_driver_handle_t)btns[0]; }