From 170bdc74005f514342edb4de83fe0daaf6e4c9f8 Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 28 Nov 2025 17:55:19 +0530 Subject: [PATCH] components/esp_matter: add meter_identification cluster in esp_matter --- .../data_model/esp_matter_attribute.cpp | 36 +++++++++++++++++++ .../data_model/esp_matter_attribute.h | 11 ++++++ .../data_model/esp_matter_cluster.cpp | 32 +++++++++++++++++ .../data_model/esp_matter_cluster.h | 6 ++++ .../data_model/esp_matter_feature.cpp | 23 ++++++++++++ .../data_model/esp_matter_feature.h | 12 +++++++ .../private/esp_matter_cluster_revisions.h | 4 +++ 7 files changed, 124 insertions(+) diff --git a/components/esp_matter/data_model/esp_matter_attribute.cpp b/components/esp_matter/data_model/esp_matter_attribute.cpp index 98cc4c010..7803255b8 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.cpp +++ b/components/esp_matter/data_model/esp_matter_attribute.cpp @@ -5351,5 +5351,41 @@ attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t *value, uint } /* electrical_grid_conditions */ +namespace meter_identification { +namespace attribute { +attribute_t *create_meter_type(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::MeterType::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value)); +} + +attribute_t *create_point_of_delivery(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::PointOfDelivery::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_meter_serial_number(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::MeterSerialNumber::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_protocol_version(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::ProtocolVersion::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_char_str(value, length)); +} + +attribute_t *create_power_threshold(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, MeterIdentification::Attributes::PowerThreshold::Id, + ATTRIBUTE_FLAG_MANAGED_INTERNALLY | ATTRIBUTE_FLAG_NULLABLE, esp_matter_array(value, length, count)); +} + +} /* attribute */ + +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_attribute.h b/components/esp_matter/data_model/esp_matter_attribute.h index 337308c9c..ab3b9cbe2 100644 --- a/components/esp_matter/data_model/esp_matter_attribute.h +++ b/components/esp_matter/data_model/esp_matter_attribute.h @@ -1385,5 +1385,16 @@ attribute_t *create_forecast_conditions(cluster_t *cluster, uint8_t * value, uin } /* attribute */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace attribute { + +attribute_t *create_meter_type(cluster_t *cluster, nullable value); +attribute_t *create_point_of_delivery(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_meter_serial_number(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_protocol_version(cluster_t *cluster, char * value, uint16_t length); +attribute_t *create_power_threshold(cluster_t *cluster, uint8_t * value, uint16_t length, uint16_t count); +} /* attribute */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.cpp b/components/esp_matter/data_model/esp_matter_cluster.cpp index 0408a756f..d61261da1 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.cpp +++ b/components/esp_matter/data_model/esp_matter_cluster.cpp @@ -4525,5 +4525,37 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } /* electrical_grid_conditions */ +namespace meter_identification { +const function_generic_t *function_list = NULL; + +const int function_flags = CLUSTER_FLAG_NONE; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) +{ + cluster_t *cluster = esp_matter::cluster::create(endpoint, MeterIdentification::Id, flags); + VerifyOrReturnValue(cluster, NULL, ESP_LOGE(TAG, "Could not create cluster. cluster_id: 0x%08" PRIX32, MeterIdentification::Id)); + if (flags & CLUSTER_FLAG_SERVER) { + static const auto plugin_server_init_cb = CALL_ONCE(MatterMeterIdentificationPluginServerInitCallback); + set_plugin_server_init_callback(cluster, plugin_server_init_cb); + add_function_list(cluster, function_list, function_flags); + + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + attribute::create_meter_type(cluster, 0); + attribute::create_point_of_delivery(cluster, NULL, 0); + attribute::create_meter_serial_number(cluster, NULL, 0); + + /* Attributes not managed internally */ + global::attribute::create_cluster_revision(cluster, cluster_revision); + } + + if (flags & CLUSTER_FLAG_CLIENT) { + create_default_binding_cluster(endpoint); + } + return cluster; +} + +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_cluster.h b/components/esp_matter/data_model/esp_matter_cluster.h index fc00d3abf..4ea41b346 100644 --- a/components/esp_matter/data_model/esp_matter_cluster.h +++ b/components/esp_matter/data_model/esp_matter_cluster.h @@ -1071,5 +1071,11 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* electrical_grid_conditions */ +namespace meter_identification { +using config_t = common::config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.cpp b/components/esp_matter/data_model/esp_matter_feature.cpp index 4dd250b42..6b398f06b 100644 --- a/components/esp_matter/data_model/esp_matter_feature.cpp +++ b/components/esp_matter/data_model/esp_matter_feature.cpp @@ -4824,5 +4824,28 @@ esp_err_t add(cluster_t *cluster) } /* feature */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace feature { +namespace power_threshold { + +uint32_t get_id() +{ + return static_cast(MeterIdentification::Feature::kPowerThreshold); +} + +esp_err_t add(cluster_t *cluster) +{ + VerifyOrReturnError(cluster, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Cluster cannot be NULL")); + update_feature_map(cluster, get_id()); + // Attributes + attribute::create_power_threshold(cluster, NULL, 0, 0); + return ESP_OK; +} + +} /* power_threshold */ + +} /* feature */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/esp_matter_feature.h b/components/esp_matter/data_model/esp_matter_feature.h index cc6772593..668ba51f9 100644 --- a/components/esp_matter/data_model/esp_matter_feature.h +++ b/components/esp_matter/data_model/esp_matter_feature.h @@ -2127,5 +2127,17 @@ esp_err_t add(cluster_t *cluster); } /* feature */ } /* electrical_grid_conditions */ +namespace meter_identification { +namespace feature { + +namespace power_threshold { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* power_threshold */ + +} /* feature */ +} /* meter_identification */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h index ae376d582..75185915d 100644 --- a/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h +++ b/components/esp_matter/data_model/private/esp_matter_cluster_revisions.h @@ -414,6 +414,10 @@ constexpr uint16_t cluster_revision = 1; namespace electrical_grid_conditions { constexpr uint16_t cluster_revision = 1; } // namespace electrical_grid_conditions + +namespace meter_identification { +constexpr uint16_t cluster_revision = 1; +} // namespace meter_identification } // namespace cluster } // namespace esp_matter