From 4cfcf617c90c8b4d37b4d29f36671cc8a5d88765 Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Tue, 12 Jul 2022 19:44:58 +0800 Subject: [PATCH 1/5] Feature: Add NumberOfPrimaries, PrimarynX, PrimarynY and PrimarynIntensity attributes in ColorControl cluster --- .../esp_matter/esp_matter_attribute.cpp | 105 ++++++++++++++++++ components/esp_matter/esp_matter_attribute.h | 4 + components/esp_matter/esp_matter_cluster.cpp | 6 + components/esp_matter/esp_matter_cluster.h | 3 +- 4 files changed, 117 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 8e5b8cf8f..80f52143f 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -1005,6 +1005,111 @@ attribute_t *create_color_loop_stored_enhanced_hue(cluster_t *cluster, uint16_t ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value)); } +attribute_t *create_number_of_primaries(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, ColorControl::Attributes::NumberOfPrimaries::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); +} + +attribute_t *create_primary_n_x(cluster_t * cluster, uint16_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6X::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + default: + break; + } + return NULL; +} + +attribute_t *create_primary_n_y(cluster_t * cluster, uint16_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6Y::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint16(value)); + break; + default: + break; + } + return NULL; +} + +attribute_t *create_primary_n_intensity(cluster_t * cluster, uint8_t value, uint8_t index) +{ + switch (index) { + case 1: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary1Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 2: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary2Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 3: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary3Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 4: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary4Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 5: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary5Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + case 6: + return esp_matter::attribute::create(cluster, ColorControl::Attributes::Primary6Intensity::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_uint8(value)); + break; + default: + break; + } + return NULL; +} + } /* attribute */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 97afb00cc..4879032b8 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -265,6 +265,10 @@ attribute_t *create_color_loop_direction(cluster_t *cluster, uint8_t value); attribute_t *create_color_loop_time(cluster_t *cluster, uint16_t value); attribute_t *create_color_loop_start_enhanced_hue(cluster_t *cluster, uint16_t value); attribute_t *create_color_loop_stored_enhanced_hue(cluster_t *cluster, uint16_t value); +attribute_t *create_number_of_primaries(cluster_t *cluster, uint8_t value); +attribute_t *create_primary_n_x(cluster_t * cluster, uint16_t value, uint8_t index); +attribute_t *create_primary_n_y(cluster_t * cluster, uint16_t value, uint8_t index); +attribute_t *create_primary_n_intensity(cluster_t * cluster, uint8_t value, uint8_t index); } /* attribute */ } /* color_control */ diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index a6c72e7d2..b7046b92b 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1007,12 +1007,18 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_ attribute::create_color_control_options(cluster, config->color_control_options); attribute::create_enhanced_color_mode(cluster, config->enhanced_color_mode); attribute::create_color_capabilities(cluster, config->color_capabilities); + attribute::create_number_of_primaries(cluster, config->number_of_primaries); } else { ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); } /* Attributes managed internally */ attribute::create_remaining_time(cluster, 0); + for (uint8_t idx = 1; idx <= config->number_of_primaries; ++idx) { + attribute::create_primary_n_x(cluster, 0, idx); + attribute::create_primary_n_y(cluster, 0, idx); + attribute::create_primary_n_intensity(cluster, 0, idx); + } } /* Features */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 31301b4fa..15932c9b8 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -223,13 +223,14 @@ typedef struct config { uint8_t color_control_options; uint8_t enhanced_color_mode; uint16_t color_capabilities; + uint8_t number_of_primaries; feature::hue_saturation::config_t hue_saturation; feature::color_temperature::config_t color_temperature; feature::xy::config_t xy; feature::enhanced_hue::config_t enhanced_hue; feature::color_loop::config_t color_loop; config() : cluster_revision(5), color_mode(1), color_control_options(0), enhanced_color_mode(1), - color_capabilities(0) {} + color_capabilities(0), number_of_primaries(0) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features); From ed13200ebf16bbf6bbd07b701745d2b4da75456f Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Thu, 14 Jul 2022 16:57:47 +0800 Subject: [PATCH 2/5] Bugfix: Add check for attribute::set_val --- components/esp_matter/esp_matter_attribute_utils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/esp_matter/esp_matter_attribute_utils.cpp b/components/esp_matter/esp_matter_attribute_utils.cpp index 69d691f5d..cb2ad462b 100644 --- a/components/esp_matter/esp_matter_attribute_utils.cpp +++ b/components/esp_matter/esp_matter_attribute_utils.cpp @@ -1035,6 +1035,9 @@ EmberAfStatus emberAfExternalAttributeWriteCallback(EndpointId endpoint_id, Clus } /* Update val */ + if (val.type == ESP_MATTER_VAL_TYPE_INVALID) { + return EMBER_ZCL_STATUS_FAILURE; + } attribute::set_val(attribute, &val); return EMBER_ZCL_STATUS_SUCCESS; } From 68f7bd088bd870a62f473e4aebb343e40db625da Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Thu, 21 Jul 2022 22:35:17 +0800 Subject: [PATCH 3/5] Bugfix:Change the defaults_ota_provider type from octstr to array --- components/esp_matter/esp_matter_attribute.cpp | 4 ++-- components/esp_matter/esp_matter_attribute.h | 2 +- components/esp_matter/esp_matter_cluster.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 80f52143f..7912f7b63 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -247,10 +247,10 @@ attribute_t *create_binding(cluster_t *cluster, uint8_t *value, uint16_t length, namespace ota_requestor { namespace attribute { -attribute_t *create_default_ota_providers(cluster_t *cluster, uint8_t *value, uint16_t length) +attribute_t *create_default_ota_providers(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) { return esp_matter::attribute::create(cluster, OtaSoftwareUpdateRequestor::Attributes::DefaultOtaProviders::Id, - ATTRIBUTE_FLAG_WRITABLE, esp_matter_octet_str(value, length)); + ATTRIBUTE_FLAG_WRITABLE, esp_matter_array(value, length, count)); } attribute_t *create_update_possible(cluster_t *cluster, bool value) diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 4879032b8..ed0cbc50c 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -85,7 +85,7 @@ attribute_t *create_binding(cluster_t *cluster, uint8_t *value, uint16_t length, namespace ota_requestor { namespace attribute { -attribute_t *create_default_ota_providers(cluster_t *cluster, uint8_t *value, uint16_t length); +attribute_t *create_default_ota_providers(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); attribute_t *create_update_possible(cluster_t *cluster, bool value); attribute_t *create_update_state(cluster_t *cluster, uint8_t value); attribute_t *create_update_state_progress(cluster_t *cluster, uint8_t value); diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index b7046b92b..4546a0716 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -294,7 +294,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) if (flags & CLUSTER_FLAG_SERVER) { /* Attributes managed internally */ global::attribute::create_feature_map(cluster, 0); - attribute::create_default_ota_providers(cluster, NULL, 0); + attribute::create_default_ota_providers(cluster, NULL, 0, 0); /* Attributes not managed internally */ if (config) { From 0e26d72977e6ad9fbabc577767e57d866eb5ed98 Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Fri, 22 Jul 2022 13:17:11 +0800 Subject: [PATCH 4/5] Bugfix: Make ota_requestor update_progress nullable and set the update_possible default to true --- components/esp_matter/esp_matter_attribute.cpp | 2 +- components/esp_matter/esp_matter_cluster.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 7912f7b63..d74d15919 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -268,7 +268,7 @@ attribute_t *create_update_state(cluster_t *cluster, uint8_t value) attribute_t *create_update_state_progress(cluster_t *cluster, uint8_t value) { return esp_matter::attribute::create(cluster, OtaSoftwareUpdateRequestor::Attributes::UpdateStateProgress::Id, - ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value)); + ATTRIBUTE_FLAG_NULLABLE, esp_matter_uint8(value)); } } /* attribute */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 15932c9b8..c6f4c708f 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -82,7 +82,7 @@ typedef struct config { bool update_possible; uint8_t update_state; uint8_t update_state_progress; - config() : cluster_revision(1), update_possible(0), update_state(0), update_state_progress(0) {} + config() : cluster_revision(1), update_possible(1), update_state(0), update_state_progress(0) {} } config_t; cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); From f61e804313a3084dfff5e4755fa5df21eda1bb21 Mon Sep 17 00:00:00 2001 From: WangQixiang Date: Fri, 15 Jul 2022 13:48:22 +0800 Subject: [PATCH 5/5] Bugfix: Add record for boot reason event --- components/esp_matter/esp_matter_core.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index be60fe74b..0a23d233f 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -18,12 +18,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include #if CHIP_DEVICE_CONFIG_ENABLE_THREAD @@ -43,6 +45,8 @@ using chip::DeviceLayer::ConfigurationMgr; using chip::DeviceLayer::ConnectivityManager; using chip::DeviceLayer::ConnectivityMgr; using chip::DeviceLayer::PlatformMgr; +using chip::DeviceLayer::DiagnosticDataProvider; +using chip::DeviceLayer::GetDiagnosticDataProvider; #if CHIP_DEVICE_CONFIG_ENABLE_THREAD using chip::DeviceLayer::ThreadStackMgr; #endif @@ -665,8 +669,15 @@ static void esp_matter_chip_init_task(intptr_t context) if (endpoint::enable_all() != ESP_OK) { ESP_LOGE(TAG, "Enable all endpoints failure"); } - // Add this function to record start up event in basic information cluster. + // The following two events can't be recorded when we start the server because the endpoints are not enabled. + // TODO: Find a better way to record the events which should be recorded in matter server init + // Record start up event in basic information cluster. PlatformMgr().HandleServerStarted(); + // Record boot reason evnet in general diagnostics cluster. + chip::app::Clusters::GeneralDiagnostics::BootReasonType bootReason; + if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) { + chip::app::Clusters::GeneralDiagnosticsServer::Instance().OnDeviceReboot(bootReason); + } #if CHIP_DEVICE_CONFIG_ENABLE_WIFI { static chip::app::Clusters::NetworkCommissioning::Instance sWiFiNetworkCommissioningInstance(0,