From eadcdc68038ea6b442444d424d854354236f0da6 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Fri, 8 Mar 2024 18:44:08 +0800 Subject: [PATCH] esp-matter: Update features for ICD Management cluster --- .../esp_matter/esp_matter_attribute.cpp | 75 +++++++++---------- components/esp_matter/esp_matter_attribute.h | 13 ++-- components/esp_matter/esp_matter_cluster.cpp | 17 +++-- components/esp_matter/esp_matter_cluster.h | 6 +- components/esp_matter/esp_matter_endpoint.cpp | 11 ++- components/esp_matter/esp_matter_feature.cpp | 69 ++++++++++++++++- components/esp_matter/esp_matter_feature.h | 24 +++++- 7 files changed, 150 insertions(+), 65 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index f511f785c..8f1b06443 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -588,65 +588,58 @@ attribute_t *create_max_group_keys_per_fabric(cluster_t *cluster, uint16_t value namespace icd_management { namespace attribute { -attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min, uint32_t max) +attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value) { - attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::IdleModeDuration::Id, - ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); - if (!attribute) { - ESP_LOGE(TAG, "Could not create attribute"); - return NULL; - } - esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(max)); - return attribute; + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::IdleModeDuration::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); } -attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min) +attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value) { - attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeDuration::Id, - ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); - if (!attribute) { - ESP_LOGE(TAG, "Could not create attribute"); - return NULL; - } - esp_matter::attribute::add_bounds(attribute, esp_matter_uint32(min), esp_matter_uint32(UINT32_MAX)); - return attribute; + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeDuration::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); } -attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value, uint16_t min) +attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value) { - attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeThreshold::Id, - ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); - if (!attribute) { - ESP_LOGE(TAG, "Could not create attribute"); - return NULL; - } - esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(UINT16_MAX)); - return attribute; + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ActiveModeThreshold::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); } attribute_t *create_registered_clients(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) { - return esp_matter::attribute::create(cluster, IcdManagement::Attributes::RegisteredClients::Id, ATTRIBUTE_FLAG_NONVOLATILE, - esp_matter_array(value,length, count)); + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::RegisteredClients::Id, + ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_array(value,length, count)); } -attribute_t *create_icd_counter(cluster_t *cluster,uint32_t value) +attribute_t *create_icd_counter(cluster_t *cluster, uint32_t value) { - return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ICDCounter::Id, ATTRIBUTE_FLAG_NONVOLATILE, - esp_matter_uint32(value)); + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ICDCounter::Id, + ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint32(value)); } -attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value, uint16_t min) +attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value) { - attribute_t *attribute = esp_matter::attribute::create(cluster, IcdManagement::Attributes::ClientsSupportedPerFabric::Id, - ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); - if (!attribute) { - ESP_LOGE(TAG, "Could not create attribute"); - return NULL; - } - esp_matter::attribute::add_bounds(attribute, esp_matter_uint16(min), esp_matter_uint16(UINT16_MAX)); - return attribute; + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::ClientsSupportedPerFabric::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); +} +attribute_t *create_user_active_mode_trigger_hint(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::UserActiveModeTriggerHint::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_bitmap32(value)); +} + +attribute_t *create_user_active_mode_trigger_instruction(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::UserActiveModeTriggerInstruction::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length)); +} + +attribute_t *create_operating_mode(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, IcdManagement::Attributes::OperatingMode::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value)); } } /* attribute */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index b885d2b5d..1aff69e61 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -181,12 +181,15 @@ attribute_t *create_max_group_keys_per_fabric(cluster_t *cluster, uint16_t value namespace icd_management { namespace attribute { -attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min, uint32_t max); -attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value, uint32_t min); -attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value, uint16_t min); +attribute_t *create_idle_mode_duration(cluster_t *cluster, uint32_t value); +attribute_t *create_active_mode_duration(cluster_t *cluster, uint32_t value); +attribute_t *create_active_mode_threshold(cluster_t *cluster, uint16_t value); attribute_t *create_registered_clients(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); -attribute_t *create_icd_counter(cluster_t *cluster,uint32_t value); -attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value, uint16_t min); +attribute_t *create_icd_counter(cluster_t *cluster, uint32_t value); +attribute_t *create_clients_supported_per_fabric(cluster_t *cluster, uint16_t value); +attribute_t *create_user_active_mode_trigger_hint(cluster_t *cluster, uint32_t value); +attribute_t *create_user_active_mode_trigger_instruction(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_operating_mode(cluster_t *cluster, uint8_t value); } /* attribute */ } /* icd_management */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index b73830028..07b39bb42 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -985,22 +985,27 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ if (flags & CLUSTER_FLAG_SERVER) { /* Attributes managed internally */ global::attribute::create_feature_map(cluster, 0); + attribute::create_idle_mode_duration(cluster, CONFIG_ICD_ACTIVE_MODE_INTERVAL_MS); + attribute::create_active_mode_duration(cluster, CONFIG_ICD_IDLE_MODE_INTERVAL_SEC); + attribute::create_active_mode_threshold(cluster, CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS); /* Attributes not managed internally */ if (config) { global::attribute::create_cluster_revision(cluster, config->cluster_revision); - attribute::create_idle_mode_duration(cluster, config->idle_mode_interval, 500, 64800000); - attribute::create_active_mode_duration(cluster, config->active_mode_interval, 300); - attribute::create_active_mode_threshold(cluster, config->active_mode_threshold, 300); } else { ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); } } #if defined(CHIP_CONFIG_ENABLE_ICD_CIP) && CHIP_CONFIG_ENABLE_ICD_CIP - if (features & feature::check_in_protocol_support::get_id()) { - feature::check_in_protocol_support::config_t cip_config; - feature::check_in_protocol_support::add(cluster, &cip_config); + if (features & feature::long_idle_time_support::get_id()) { + feature::long_idle_time_support::add(cluster); + if (features & feature::user_active_mode_trigger::get_id()) { + feature::user_active_mode_trigger::add(cluster, &config->user_active_mode_trigger); + } + if (features & feature::check_in_protocol_support::get_id()) { + feature::check_in_protocol_support::add(cluster); + } } #endif // defined(CHIP_CONFIG_ENABLE_ICD_CIP) && CHIP_CONFIG_ENABLE_ICD_CIP #endif // CONFIG_ENABLE_ICD_SERVER diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 5393b9a7f..7cab92fb6 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -246,10 +246,8 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ namespace icd_management { typedef struct config { uint16_t cluster_revision; - uint32_t idle_mode_interval; - uint32_t active_mode_interval; - uint16_t active_mode_threshold; - config() : cluster_revision(2), idle_mode_interval(5000), active_mode_interval(300), active_mode_threshold(300) {} + feature::user_active_mode_trigger::config_t user_active_mode_trigger; + config() : cluster_revision(2) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features); diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 954d5906f..88ad611dc 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -71,8 +71,15 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) #endif #if CHIP_CONFIG_ENABLE_ICD_SERVER icd_management::create(endpoint, &(config->icd_management), CLUSTER_FLAG_SERVER, - icd_management::feature::check_in_protocol_support::get_id()); -#endif +#if CHIP_CONFIG_ENABLE_ICD_LIT + icd_management::feature::long_idle_time_support::get_id() +#if CHIP_CONFIG_ENABLE_ICD_CIP + | icd_management::feature::check_in_protocol_support::get_id()); +#endif // CHIP_CONFIG_ENABLE_ICD_CIP +#else + 0); +#endif // CHIP_CONFIG_ENABLE_ICD_LIT +#endif // CHIP_CONFIG_ENABLE_ICD_SERVER return ESP_OK; } diff --git a/components/esp_matter/esp_matter_feature.cpp b/components/esp_matter/esp_matter_feature.cpp index fec1b4e15..097aa6bb8 100644 --- a/components/esp_matter/esp_matter_feature.cpp +++ b/components/esp_matter/esp_matter_feature.cpp @@ -269,20 +269,24 @@ uint32_t get_id() return (uint32_t)IcdManagement::Feature::kCheckInProtocolSupport; } -esp_err_t add(cluster_t *cluster, config_t *config) +esp_err_t add(cluster_t *cluster) { if (!cluster) { ESP_LOGE(TAG, "Cluster cannot be NULL"); return ESP_ERR_INVALID_ARG; } + uint32_t lits_feature_map = feature::long_idle_time_support::get_id(); + if ((get_feature_map_value(cluster) & lits_feature_map) != lits_feature_map) { + ESP_LOGE(TAG, "Long Idle Time Support feature should be added to this cluster"); + return ESP_ERR_INVALID_STATE; + } + update_feature_map(cluster, get_id()); /* Attributes managed internally */ attribute::create_registered_clients(cluster, NULL, 0, 0); attribute::create_icd_counter(cluster, 0); - - /* Attribute not managed internally*/ - attribute::create_clients_supported_per_fabric(cluster, config->clients_supported_per_fabric, 1); + attribute::create_clients_supported_per_fabric(cluster, 0); /* Commands */ command::create_register_client(cluster); @@ -293,6 +297,63 @@ esp_err_t add(cluster_t *cluster, config_t *config) } } /* check_in_protocol_support */ + +namespace user_active_mode_trigger { + +uint32_t get_id() +{ + return (uint32_t)IcdManagement::Feature::kUserActiveModeTrigger; +} + +esp_err_t add(cluster_t *cluster, config_t *config) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + if (!config) { + ESP_LOGE(TAG, "config cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + uint32_t lits_feature_map = feature::long_idle_time_support::get_id(); + if ((get_feature_map_value(cluster) & lits_feature_map) != lits_feature_map) { + ESP_LOGE(TAG, "Long Idle Time Support feature should be added to this cluster"); + return ESP_ERR_INVALID_STATE; + } + + update_feature_map(cluster, get_id()); + + /* Attributes not managed internally */ + attribute::create_user_active_mode_trigger_hint(cluster, config->user_active_mode_trigger_hint); + attribute::create_user_active_mode_trigger_instruction(cluster, config->user_active_mode_trigger_instruction, + strlen(config->user_active_mode_trigger_instruction)); + + return ESP_OK; +} + +} /* user_active_mode_trigger */ + +namespace long_idle_time_support { + +uint32_t get_id() +{ + return (uint32_t)IcdManagement::Feature::kLongIdleTimeSupport; +} + +esp_err_t add(cluster_t *cluster) +{ + if (!cluster) { + ESP_LOGE(TAG, "Cluster cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + update_feature_map(cluster, get_id()); + + /* Attributes not managed internally */ + attribute::create_operating_mode(cluster, 0); + return ESP_OK; +} + +} /* long_idle_time_support */ } /* feature */ } /* icd_management */ diff --git a/components/esp_matter/esp_matter_feature.h b/components/esp_matter/esp_matter_feature.h index 68fa638df..617a60b96 100644 --- a/components/esp_matter/esp_matter_feature.h +++ b/components/esp_matter/esp_matter_feature.h @@ -149,14 +149,32 @@ esp_err_t add(cluster_t *cluster); namespace icd_management { namespace feature { namespace check_in_protocol_support { -typedef struct config { - uint16_t clients_supported_per_fabric; + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); + +} /* check_in_protocol_support */ + +constexpr size_t k_max_user_active_mode_trigger_instruction_length = 128; + +namespace user_active_mode_trigger { +typedef struct { + uint32_t user_active_mode_trigger_hint; + char user_active_mode_trigger_instruction[k_max_user_active_mode_trigger_instruction_length + 1]; } config_t; uint32_t get_id(); esp_err_t add(cluster_t *cluster, config_t *config); -} /* check_in_protocol_support */ +} /* user_active_mode_trigger */ + +namespace long_idle_time_support { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); + +} /* long_idle_time_support */ + } /* feature */ } /* icd_management */