From 825e9ad3c8231d25ea8905c40ca105a92d059eae Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 6 Jul 2022 16:52:13 +0800 Subject: [PATCH] Feature: Add optional features & attributes in basic cluster and wifinetworkdiag cluster --- .../esp_matter/esp_matter_attribute.cpp | 96 +++++++++++++++++++ components/esp_matter/esp_matter_attribute.h | 16 ++++ components/esp_matter/esp_matter_command.cpp | 30 +++++- components/esp_matter/esp_matter_command.h | 6 ++ components/esp_matter/esp_matter_feature.cpp | 64 +++++++++++++ components/esp_matter/esp_matter_feature.h | 20 ++++ 6 files changed, 229 insertions(+), 3 deletions(-) diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 5847c2f7c..8e5b8cf8f 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -181,6 +181,54 @@ attribute_t *create_capability_minima(cluster_t *cluster, uint8_t *value, uint16 esp_matter_array(value, length, count)); } +attribute_t *create_manufacturing_date(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::ManufacturingDate::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_part_number(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::PartNumber::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_product_url(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::ProductURL::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_product_label(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::ProductLabel::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_serial_number(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::SerialNumber::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + +attribute_t *create_local_config_diabled(cluster_t *cluster, bool value) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::LocalConfigDisabled::Id, + ATTRIBUTE_FLAG_WRITABLE, esp_matter_bool(value)); +} + +attribute_t *create_reachable(cluster_t *cluster, bool value) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::Reachable::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_bool(value)); +} + +attribute_t *create_unique_id(cluster_t *cluster, char *value, uint16_t length) +{ + return esp_matter::attribute::create(cluster, Basic::Attributes::UniqueID::Id, ATTRIBUTE_FLAG_NONE, + esp_matter_char_str(value, length)); +} + } /* attribute */ } /* basic */ @@ -469,6 +517,54 @@ attribute_t *create_rssi(cluster_t *cluster, int8_t value) esp_matter_int8(value)); } +attribute_t *create_beacon_lost_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::BeaconLostCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_beacon_rx_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::BeaconRxCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_packet_multicast_rx_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::PacketMulticastRxCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_packet_multicast_tx_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::PacketMulticastTxCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_packet_unicast_rx_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::PacketUnicastRxCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_packet_unicast_tx_count(cluster_t *cluster, uint32_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::PacketUnicastTxCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint32(value)); +} + +attribute_t *create_current_max_rate(cluster_t *cluster, uint64_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::CurrentMaxRate::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint64(value)); +} + +attribute_t *create_overrun_count(cluster_t *cluster, uint64_t value) +{ + return esp_matter::attribute::create(cluster, WiFiNetworkDiagnostics::Attributes::OverrunCount::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_uint64(value)); +} + } /* attribute */ } /* diagnostics_network_wifi */ diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index c4170c38f..97afb00cc 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -66,6 +66,14 @@ attribute_t *create_hardware_version_string(cluster_t *cluster, char *value, uin attribute_t *create_software_version(cluster_t *cluster, uint32_t value); attribute_t *create_software_version_string(cluster_t *cluster, char *value, uint16_t length); attribute_t *create_capability_minima(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +attribute_t *create_manufacturing_date(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_part_number(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_product_url(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_product_label(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_serial_number(cluster_t *cluster, char *value, uint16_t length); +attribute_t *create_local_config_diabled(cluster_t *cluster, bool value); +attribute_t *create_reachable(cluster_t *cluster, bool value); +attribute_t *create_unique_id(cluster_t *cluster, char *value, uint16_t length); } /* attribute */ } /* basic */ @@ -150,6 +158,14 @@ attribute_t *create_security_type(cluster_t *cluster, uint8_t value); attribute_t *create_wifi_version(cluster_t *cluster, uint8_t value); attribute_t *create_channel_number(cluster_t *cluster, uint16_t value); attribute_t *create_rssi(cluster_t *cluster, int8_t value); +attribute_t *create_beacon_lost_count(cluster_t *cluster, uint32_t value); +attribute_t *create_beacon_rx_count(cluster_t *cluster, uint32_t value); +attribute_t *create_packet_multicast_rx_count(cluster_t *cluster, uint32_t value); +attribute_t *create_packet_multicast_tx_count(cluster_t *cluster, uint32_t value); +attribute_t *create_packet_unicast_rx_count(cluster_t *cluster, uint32_t value); +attribute_t *create_packet_unicast_tx_count(cluster_t *cluster, uint32_t value); +attribute_t *create_current_max_rate(cluster_t *cluster, uint64_t value); +attribute_t *create_overrun_count(cluster_t *cluster, uint64_t value); } /* attribute */ } /* diagnostics_network_wifi */ diff --git a/components/esp_matter/esp_matter_command.cpp b/components/esp_matter/esp_matter_command.cpp index 35333e5cf..23ecd2503 100644 --- a/components/esp_matter/esp_matter_command.cpp +++ b/components/esp_matter/esp_matter_command.cpp @@ -992,8 +992,8 @@ static esp_err_t esp_matter_command_callback_setpoint_raise_lower(const Concrete return ESP_OK; } -static esp_err_t esp_matter_command_callback_reset_counts(const ConcreteCommandPath &command_path, - TLVReader &tlv_data, void *opaque_ptr) +static esp_err_t esp_matter_command_callback_thread_reset_counts(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) { chip::app::Clusters::ThreadNetworkDiagnostics::Commands::ResetCounts::DecodableType command_data; CHIP_ERROR error = Decode(tlv_data, command_data); @@ -1003,6 +1003,17 @@ static esp_err_t esp_matter_command_callback_reset_counts(const ConcreteCommandP return ESP_OK; } +static esp_err_t esp_matter_command_callback_wifi_reset_counts(const ConcreteCommandPath &command_path, + TLVReader &tlv_data, void *opaque_ptr) +{ + chip::app::Clusters::WiFiNetworkDiagnostics::Commands::ResetCounts::DecodableType command_data; + CHIP_ERROR error = Decode(tlv_data, command_data); + if (error == CHIP_NO_ERROR) { + emberAfWiFiNetworkDiagnosticsClusterResetCountsCallback((CommandHandler *)opaque_ptr, command_path, command_data); + } + return ESP_OK; +} + static esp_err_t esp_matter_command_callback_test_event_trigger(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr) { @@ -1023,12 +1034,25 @@ namespace command { command_t *create_reset_counts(cluster_t *cluster) { return esp_matter::command::create(cluster, ThreadNetworkDiagnostics::Commands::ResetCounts::Id, COMMAND_FLAG_ACCEPTED, - esp_matter_command_callback_reset_counts); + esp_matter_command_callback_thread_reset_counts); } } /* command */ } /* diagnostics_network_thread */ +namespace diagnostics_network_wifi { +namespace command { + +command_t *create_reset_counts(cluster_t *cluster) +{ + return esp_matter::command::create(cluster, WiFiNetworkDiagnostics::Commands::ResetCounts::Id, COMMAND_FLAG_ACCEPTED, + esp_matter_command_callback_wifi_reset_counts); +} + +} /* command */ +} /* diagnostics_network_wifi */ + + namespace general_diagnostics { namespace command { diff --git a/components/esp_matter/esp_matter_command.h b/components/esp_matter/esp_matter_command.h index aaf9e9366..04b2e18cc 100644 --- a/components/esp_matter/esp_matter_command.h +++ b/components/esp_matter/esp_matter_command.h @@ -31,6 +31,12 @@ command_t *create_reset_counts(cluster_t *cluster); } /* command */ } /* diagnostics_network_thread */ +namespace diagnostics_network_wifi { +namespace command { +command_t *create_reset_counts(cluster_t *cluster); +} /* command */ +} /* diagnostics_network_wifi */ + namespace general_diagnostics { namespace command { command_t *create_test_event_trigger(cluster_t *cluster); diff --git a/components/esp_matter/esp_matter_feature.cpp b/components/esp_matter/esp_matter_feature.cpp index 768f312e5..1952ed018 100644 --- a/components/esp_matter/esp_matter_feature.cpp +++ b/components/esp_matter/esp_matter_feature.cpp @@ -323,5 +323,69 @@ esp_err_t add(cluster_t *cluster, config_t *config) } /* feature */ } /* color_control */ +namespace diagnostics_network_wifi { +namespace feature { + +namespace packets_counts { + +uint32_t get_id() +{ + // The WiFiNetworkDiagnosticsFeature enum class is not added in the upstream code. + // Return the code according to the SPEC + return 0x01; +} + +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 managed internally */ + attribute::create_beacon_rx_count(cluster, 0); + attribute::create_packet_multicast_rx_count(cluster, 0); + attribute::create_packet_multicast_tx_count(cluster, 0); + attribute::create_packet_unicast_rx_count(cluster, 0); + attribute::create_packet_unicast_tx_count(cluster, 0); + + return ESP_OK; +} + +} /* packets_counts */ + +namespace error_counts { + +uint32_t get_id() +{ + // The WiFiNetworkDiagnosticsFeature enum class is not added in the upstream code. + // Return the code according to the SPEC + return 0x02; +} + +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 managed internally */ + attribute::create_beacon_lost_count(cluster, 0); + attribute::create_overrun_count(cluster, 0); + + /* Commands */ + command::create_reset_counts(cluster); + + return ESP_OK; +} + +} /* error_counts */ + +} /* feature */ +} /* diagnostics_network_wifi */ + } /* cluster */ } /* esp_matter */ diff --git a/components/esp_matter/esp_matter_feature.h b/components/esp_matter/esp_matter_feature.h index cf3659820..dbb5b339a 100644 --- a/components/esp_matter/esp_matter_feature.h +++ b/components/esp_matter/esp_matter_feature.h @@ -166,5 +166,25 @@ esp_err_t add(cluster_t *cluster, config_t *config); } /* feature */ } /* color_control */ +namespace diagnostics_network_wifi { +namespace feature { + +namespace packets_counts { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); + +} /* packets_counts */ + +namespace error_counts { + +uint32_t get_id(); +esp_err_t add(cluster_t *cluster); + +} /* error_counts */ + +} /* feature */ +} /* diagnostics_network_wifi */ + } /* cluster */ } /* esp_matter */