mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
Merge branch 'controller/unsupported_handler' into 'main'
controller: Provide APIs to send the unsupported commands and write the unsupported attributes See merge request app-frameworks/esp-matter!489
This commit is contained in:
@@ -432,33 +432,42 @@ static esp_err_t send_command(command_data_t *command_data, peer_device_t *remot
|
||||
|
||||
} // namespace clusters
|
||||
|
||||
cluster_command_handler_t cluster_command::unsupported_cluster_command_handler = NULL;
|
||||
cluster_group_command_handler_t cluster_command::unsupported_cluster_group_command_handler = NULL;
|
||||
|
||||
void cluster_command::on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
|
||||
const SessionHandle &sessionHandle)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
cluster_command *cmd = reinterpret_cast<cluster_command *>(context);
|
||||
chip::OperationalDeviceProxy device_proxy(&exchangeMgr, sessionHandle);
|
||||
switch (cmd->m_command_data->cluster_id) {
|
||||
case OnOff::Id:
|
||||
clusters::on_off::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
err = clusters::on_off::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
case LevelControl::Id:
|
||||
clusters::level_control::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
err = clusters::level_control::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
case ColorControl::Id:
|
||||
clusters::color_control::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
err = clusters::color_control::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
case GroupKeyManagement::Id:
|
||||
clusters::group_key_management::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
err = clusters::group_key_management::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
case Groups::Id:
|
||||
clusters::groups::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
err = clusters::groups::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
case WindowCovering::Id:
|
||||
clusters::window_covering::send_command(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
break;
|
||||
default:
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
|
||||
if (err == ESP_ERR_NOT_SUPPORTED && unsupported_cluster_command_handler) {
|
||||
unsupported_cluster_command_handler(cmd->m_command_data, &device_proxy, cmd->m_endpoint_id);
|
||||
}
|
||||
chip::Platform::Delete(cmd);
|
||||
return;
|
||||
}
|
||||
@@ -472,16 +481,22 @@ void cluster_command::on_device_connection_failure_fcn(void *context, const Scop
|
||||
|
||||
esp_err_t cluster_command::dispatch_group_command(void *context)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
cluster_command *cmd = reinterpret_cast<cluster_command *>(context);
|
||||
uint16_t group_id = cmd->m_destination_id & 0xFFFF;
|
||||
switch (cmd->m_command_data->cluster_id) {
|
||||
case OnOff::Id:
|
||||
return clusters::on_off::send_group_command(cmd->m_command_data, group_id);
|
||||
err = clusters::on_off::send_group_command(cmd->m_command_data, group_id);
|
||||
break;
|
||||
default:
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
if (err == ESP_ERR_NOT_SUPPORTED && unsupported_cluster_group_command_handler) {
|
||||
err = unsupported_cluster_group_command_handler(cmd->m_command_data, group_id);
|
||||
}
|
||||
chip::Platform::Delete(cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t cluster_command::send_command()
|
||||
|
||||
@@ -36,6 +36,11 @@ typedef struct command_data {
|
||||
char command_data_str[k_max_command_data_size][k_max_command_data_str_len];
|
||||
} command_data_t;
|
||||
|
||||
typedef esp_err_t (*cluster_command_handler_t)(command_data_t *command_data, chip::OperationalDeviceProxy *device_proxy,
|
||||
uint16_t endpoint_id);
|
||||
|
||||
typedef esp_err_t (*cluster_group_command_handler_t)(command_data_t *command_data, uint16_t group_id);
|
||||
|
||||
class cluster_command {
|
||||
public:
|
||||
cluster_command(uint64_t destination_id, uint16_t endpoint_id, command_data_t *command_data)
|
||||
@@ -56,16 +61,27 @@ public:
|
||||
|
||||
esp_err_t send_command();
|
||||
|
||||
bool is_group_command() {
|
||||
return chip::IsGroupId(m_destination_id);
|
||||
bool is_group_command() { return chip::IsGroupId(m_destination_id); }
|
||||
|
||||
static void set_unsupported_cluster_command_handler(cluster_command_handler_t handler)
|
||||
{
|
||||
unsupported_cluster_command_handler = handler;
|
||||
}
|
||||
|
||||
static void set_unsupported_cluster_group_command_handler(cluster_group_command_handler_t handler)
|
||||
{
|
||||
unsupported_cluster_group_command_handler = handler;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t m_destination_id;
|
||||
uint16_t m_endpoint_id;
|
||||
command_data_t *m_command_data;
|
||||
static cluster_command_handler_t unsupported_cluster_command_handler;
|
||||
static cluster_group_command_handler_t unsupported_cluster_group_command_handler;
|
||||
|
||||
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr, const SessionHandle &sessionHandle);
|
||||
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
|
||||
const SessionHandle &sessionHandle);
|
||||
static void on_device_connection_failure_fcn(void *context, const ScopedNodeId &peerId, CHIP_ERROR error);
|
||||
|
||||
static esp_err_t dispatch_group_command(void *context);
|
||||
|
||||
@@ -617,27 +617,35 @@ static esp_err_t write_attribute(uint64_t node_id, uint16_t endpoint_id, uint32_
|
||||
|
||||
} // namespace clusters
|
||||
|
||||
static attribute_write_handler_t s_unsupported_attribute_write_handler = NULL;
|
||||
|
||||
void set_unsupported_attribute_write_handler(attribute_write_handler_t handler)
|
||||
{
|
||||
s_unsupported_attribute_write_handler = handler;
|
||||
}
|
||||
|
||||
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
char *attribute_val_str)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
switch (cluster_id) {
|
||||
case OnOff::Id:
|
||||
return clusters::on_off::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::on_off::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case LevelControl::Id:
|
||||
return clusters::level_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::level_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case ColorControl::Id:
|
||||
return clusters::color_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::color_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case AccessControl::Id:
|
||||
return clusters::access_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::access_control::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case Binding::Id:
|
||||
return clusters::binding::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::binding::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case GroupKeyManagement::Id:
|
||||
return clusters::group_key_management::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
err = clusters::group_key_management::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
break;
|
||||
case OccupancySensing::Id:
|
||||
return clusters::occupancy_sensing::write_attribute(node_id, endpoint_id, attribute_id, attribute_val_str);
|
||||
@@ -650,9 +658,14 @@ esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32
|
||||
attribute_val_str);
|
||||
break;
|
||||
default:
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
err = ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
|
||||
if (err == ESP_ERR_NOT_SUPPORTED && s_unsupported_attribute_write_handler) {
|
||||
err = s_unsupported_attribute_write_handler(node_id, endpoint_id, cluster_id, attribute_id, attribute_val_str);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
} // namespace controller
|
||||
|
||||
@@ -31,6 +31,9 @@ using chip::app::WriteClient;
|
||||
using chip::Messaging::ExchangeManager;
|
||||
using esp_matter::client::peer_device_t;
|
||||
|
||||
typedef esp_err_t (*attribute_write_handler_t)(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id,
|
||||
uint32_t attribute_id, char *attribute_val_str);
|
||||
|
||||
template <class T>
|
||||
class write_command : public WriteClient::Callback {
|
||||
public:
|
||||
@@ -100,13 +103,16 @@ private:
|
||||
attribute_free_handler m_attr_free;
|
||||
void *m_attr_free_ctx;
|
||||
|
||||
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr, const SessionHandle &sessionHandle);
|
||||
static void on_device_connected_fcn(void *context, ExchangeManager &exchangeMgr,
|
||||
const SessionHandle &sessionHandle);
|
||||
static void on_device_connection_failure_fcn(void *context, const ScopedNodeId &peerId, CHIP_ERROR error);
|
||||
|
||||
chip::Callback::Callback<chip::OnDeviceConnected> on_device_connected_cb;
|
||||
chip::Callback::Callback<chip::OnDeviceConnectionFailure> on_device_connection_failure_cb;
|
||||
};
|
||||
|
||||
void set_unsupported_attribute_write_handler(attribute_write_handler_t handler);
|
||||
|
||||
esp_err_t send_write_attr_command(uint64_t node_id, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id,
|
||||
char *attribute_val_str);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user