diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 5b9541dd5..e24d4ce33 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -706,6 +706,35 @@ attribute_t *create_active_network_faults(cluster_t *cluster, uint8_t *value, ui } /* attribute */ } /* diagnostics_network_thread */ +namespace software_diagnostics { +namespace attribute { +attribute_t *create_thread_metrics(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, SoftwareDiagnostics::Attributes::ThreadMetrics::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_array(value, length, count)); +} + +attribute_t *create_current_heap_free(cluster_t *cluster, uint64_t value) +{ + return esp_matter::attribute::create(cluster, SoftwareDiagnostics::Attributes::CurrentHeapFree::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint64(value)); +} + +attribute_t *create_current_heap_used(cluster_t *cluster, uint64_t value) +{ + return esp_matter::attribute::create(cluster, SoftwareDiagnostics::Attributes::CurrentHeapUsed::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint64(value)); +} + +attribute_t *create_current_heap_high_watermark(cluster_t *cluster, uint64_t value) +{ + return esp_matter::attribute::create(cluster, SoftwareDiagnostics::Attributes::CurrentHeapHighWatermark::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint64(value)); +} + +} /* attribute */ +} /* software_diagnostics */ + namespace bridged_device_basic_information { namespace attribute { diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index f9e286c75..460e9c603 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -207,6 +207,15 @@ attribute_t *create_active_network_faults(cluster_t *cluster, uint8_t *value, ui } /* attribute */ } /* diagnostics_network_thread */ +namespace software_diagnostics { +namespace attribute { +attribute_t *create_thread_metrics(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +attribute_t *create_current_heap_free(cluster_t *cluster, uint64_t value); +attribute_t *create_current_heap_used(cluster_t *cluster, uint64_t value); +attribute_t *create_current_heap_high_watermark(cluster_t *cluster, uint64_t value); +} /* attribute */ +} /* software_diagnostics */ + namespace bridged_device_basic_information { namespace attribute { attribute_t *create_node_label(cluster_t *cluster, char *value, uint16_t length); diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 47a559ebc..46f914eb4 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -747,6 +747,42 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* diagnostics_network_thread */ +namespace software_diagnostics { +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 = cluster::create(endpoint, SoftwareDiagnostics::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + set_plugin_server_init_callback(cluster, MatterSoftwareDiagnosticsPluginServerInitCallback); + add_function_list(cluster, function_list, function_flags); + } + if (flags & CLUSTER_FLAG_CLIENT) { + set_plugin_client_init_callback(cluster, MatterSoftwareDiagnosticsPluginClientInitCallback); + } + if (flags & CLUSTER_FLAG_SERVER) { + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + return cluster; +} + +} /* software_diagnostics */ + namespace time_synchronization { const function_generic_t *function_list = NULL; const int function_flags = CLUSTER_FLAG_NONE; diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 627a12083..0c2cbf8cb 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -160,6 +160,15 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* diagnostics_network_thread */ +namespace software_diagnostics { +typedef struct config { + uint16_t cluster_revision; + config() : cluster_revision(1) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* software_diagnostics */ + namespace time_synchronization { typedef struct config { uint16_t cluster_revision; @@ -226,7 +235,7 @@ typedef struct config { uint16_t current_group; bool scene_valid; uint8_t scene_name_support; - config() : cluster_revision(4), scene_count(0), current_scene(0), current_group(0), scene_valid(false), + config() : cluster_revision(5), scene_count(0), current_scene(0), current_group(0), scene_valid(false), scene_name_support(0) {} } config_t; diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 83f7dc493..d678bf734 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -986,6 +986,17 @@ static esp_err_t esp_matter_command_callback_test_event_trigger(const ConcreteCo return ESP_OK; } +static esp_err_t esp_matter_command_callback_reset_watermarks(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::SoftwareDiagnostics::Commands::ResetWatermarks::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfSoftwareDiagnosticsClusterResetWatermarksCallback((CommandHandler *)opaque_ptr, command_path, command_data); + } + return ESP_OK; +} + static esp_err_t esp_matter_command_callback_up_or_open(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr) { @@ -1312,6 +1323,18 @@ command_t *create_test_event_trigger(cluster_t *cluster) } /* command */ } /* general_diagnostics */ +namespace software_diagnostics { +namespace command { + +command_t *create_reset_watermarks(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, SoftwareDiagnostics::Commands::ResetWatermarks::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_reset_watermarks); +} + +} /* command */ +} /* software_diagnostics */ + namespace group_key_management { namespace command { diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index 1e41d35b0..c5bb8796d 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -60,6 +60,12 @@ command_t *create_test_event_trigger(cluster_t *cluster); } /* command */ } /* general_diagnostics */ +namespace software_diagnostics { +namespace command { +command_t *create_reset_watermarks(cluster_t *cluster); +} /* command */ +} /* software_diagnostics */ + namespace group_key_management { namespace command { command_t *create_key_set_write(cluster_t *cluster); diff --git a/components/esp_matter/esp_matter_event.cpp b/components/esp_matter/esp_matter_event.cpp index f170344ca..580f045bd 100644 --- a/components/esp_matter/esp_matter_event.cpp +++ b/components/esp_matter/esp_matter_event.cpp @@ -192,6 +192,16 @@ esp_err_t create_network_fault_change(cluster_t *cluster) } // namespace event } // namespace diagnostics_network_thread +namespace software_diagnostics { +namespace event { +esp_err_t create_software_fault(cluster_t *cluster) +{ + event_t *event = esp_matter::event::create(cluster, SoftwareDiagnostics::Events::SoftwareFault::Id); + return event ? ESP_OK : ESP_FAIL; +} +} // namespace event +} // namespace diagnostics_network_thread + namespace time_synchronization { namespace event { esp_err_t create_dst_table_empty(cluster_t *cluster) diff --git a/components/esp_matter/esp_matter_event.h b/components/esp_matter/esp_matter_event.h index 1f6a773fb..b0853130f 100644 --- a/components/esp_matter/esp_matter_event.h +++ b/components/esp_matter/esp_matter_event.h @@ -81,6 +81,12 @@ esp_err_t create_network_fault_change(cluster_t *cluster); } // namespace event } // namespace diagnostics_network_thread +namespace software_diagnostics { +namespace event { +esp_err_t create_software_fault(cluster_t *cluster); +} // namespace event +} // namespace diagnostics_network_thread + namespace time_synchronization { namespace event { esp_err_t create_dst_table_empty(cluster_t *cluster); diff --git a/components/esp_matter/esp_matter_feature.cpp b/components/esp_matter/esp_matter_feature.cpp index 7b489d464..fc0f82cac 100644 --- a/components/esp_matter/esp_matter_feature.cpp +++ b/components/esp_matter/esp_matter_feature.cpp @@ -63,6 +63,36 @@ static uint32_t get_feature_map_value(cluster_t *cluster) return val.val.u32; } +namespace software_diagnostics { +namespace feature { +namespace watermarks { + +uint32_t get_id() +{ + return (uint32_t)SoftwareDiagnostics::Feature::kWaterMarks; +} + +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_current_heap_high_watermark(cluster, 0); + + /* Commands */ + command::create_reset_watermarks(cluster); + + return ESP_OK; + +} +} /* watermarks */ +} /* feature */ +} /* software_diagnostics */ + namespace on_off { namespace feature { namespace lighting { diff --git a/components/esp_matter/esp_matter_feature.h b/components/esp_matter/esp_matter_feature.h index 7e1d32367..33b806f43 100644 --- a/components/esp_matter/esp_matter_feature.h +++ b/components/esp_matter/esp_matter_feature.h @@ -31,6 +31,15 @@ namespace esp_matter { namespace cluster { +namespace software_diagnostics { +namespace feature { +namespace watermarks { +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); +} /* watermarks */ +} /* feature */ +} /* software_diagnostics */ + namespace on_off { namespace feature { namespace lighting {