From 3e9b04fd05b2ff1449fd160953ba51ca295e3651 Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Wed, 12 Jun 2024 01:06:34 +0800 Subject: [PATCH 1/7] Fix TLV Reader in LastChangedTime --- .../chef-resource-monitoring-delegates.cpp | 148 +++++++++++++++- .../chef-resource-monitoring-delegates.h | 45 +++-- examples/chef/common/stubs.cpp | 17 ++ .../rootnode_airpurifier_73a6fe2651.matter | 88 ++++++++++ .../rootnode_airpurifier_73a6fe2651.zap | 163 +++++++++++++++++- examples/chef/esp32/main/CMakeLists.txt | 1 + examples/chef/linux/BUILD.gn | 2 +- examples/chef/nrfconnect/CMakeLists.txt | 2 +- 8 files changed, 443 insertions(+), 23 deletions(-) rename examples/chef/common/{ => clusters/resource-monitoring}/chef-resource-monitoring-delegates.cpp (52%) rename examples/chef/common/{ => clusters/resource-monitoring}/chef-resource-monitoring-delegates.h (59%) diff --git a/examples/chef/common/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp similarity index 52% rename from examples/chef/common/chef-resource-monitoring-delegates.cpp rename to examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index ca2b713385669d..f8a5174953cadc 100644 --- a/examples/chef/common/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,13 @@ * limitations under the License. */ +#include #include #include #include #include -#include +#include +#include using namespace chip; using namespace chip::app; @@ -37,10 +39,10 @@ const chip::BitMask gActivatedCarbonFeatureMap(Reso ResourceMonitoring::Feature::kReplacementProductList); static std::unique_ptr gActivatedCarbonFilterDelegate; -static std::unique_ptr gActivatedCarbonFilterInstance; +static std::unique_ptr gActivatedCarbonFilterInstance; static std::unique_ptr gHepaFilterDelegate; -static std::unique_ptr gHepaFilterInstance; +static std::unique_ptr gHepaFilterInstance; static ImmutableReplacementProductListManager sReplacementProductListManager; @@ -96,25 +98,155 @@ void HepaFilterMonitoring::Shutdown() gHepaFilterDelegate.reset(); } +chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +{ + Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + AttributeId attributeId = attributeMetadata->attributeId; + + switch (attributeId) { + case HepaFilterMonitoring::Attributes::Condition::Id: + { + uint8_t newCondition = *(uint8_t *)buffer; + ret = UpdateCondition(newCondition); + } + break; + case HepaFilterMonitoring::Attributes::ChangeIndication::Id: + { + ResourceMonitoring::ChangeIndicationEnum newIndication = static_cast(*(uint8_t *)buffer); + ret = UpdateChangeIndication(newIndication); + } + break; + case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: + { + bool newInPlaceIndicator = *(bool *)buffer; + ret = UpdateInPlaceIndicator(newInPlaceIndicator); + } + break; + case HepaFilterMonitoring::Attributes::LastChangedTime::Id: + { + uint32_t newValue = 0; + uint16_t tlvLen = *(uint16_t *) buffer; + chip::TLV::TLVReader reader; + reader.Init(buffer + sizeof(uint16_t), tlvLen); + reader.Next(); + reader.Get(newValue); + DataModel::Nullable newLastChangedTime = DataModel::MakeNullable(newValue); + ret = UpdateLastChangedTime(newLastChangedTime); + } + break; + case HepaFilterMonitoring::Attributes::DegradationDirection::Id: + default: + { + ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); + ret = Protocols::InteractionModel::Status::UnsupportedWrite; + } + break; + } + + return ret; +} + void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { VerifyOrDie(!gActivatedCarbonFilterInstance && !gActivatedCarbonFilterDelegate); - gActivatedCarbonFilterDelegate = std::make_unique(); + bool bResetConditionCommandSupported = true; // The ResetCondition command is supported by the ResourceMonitor cluster - gActivatedCarbonFilterInstance = std::make_unique( + gActivatedCarbonFilterDelegate = std::make_unique(); + gActivatedCarbonFilterInstance = std::make_unique( gActivatedCarbonFilterDelegate.get(), endpoint, ActivatedCarbonFilterMonitoring::Id, static_cast(gActivatedCarbonFeatureMap.Raw()), ResourceMonitoring::DegradationDirectionEnum::kDown, bResetConditionCommandSupported); gActivatedCarbonFilterInstance->Init(); } +chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +{ + Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + AttributeId attributeId = attributeMetadata->attributeId; + ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + + switch (clusterId) { + case HepaFilterMonitoring::Id: + ret = gHepaFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); + break; + case ActivatedCarbonFilterMonitoring::Id: + ret = gActivatedCarbonFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); + break; + default: + ret = Protocols::InteractionModel::Status::UnsupportedWrite; + break; + } + + return ret; +} + +chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) +{ + Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + AttributeId attributeId = attributeMetadata->attributeId; + ChipLogProgress(Zcl, "chefResourceMonitoringExternalReadCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + + switch (clusterId) { + case HepaFilterMonitoring::Id: + ret = gHepaFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); + break; + case ActivatedCarbonFilterMonitoring::Id: + ret = gActivatedCarbonFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); + break; + default: + ret = Protocols::InteractionModel::Status::UnsupportedRead; + break; + } + + return ret; +} + +chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) +{ + Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + AttributeId attributeId = attributeMetadata->attributeId; + + switch (attributeId) { + case HepaFilterMonitoring::Attributes::Condition::Id: + { + *buffer = GetCondition(); + } + break; + case HepaFilterMonitoring::Attributes::ChangeIndication::Id: + { + ResourceMonitoring::ChangeIndicationEnum changeIndication = GetChangeIndication(); + // The underlying type of ResourceMonitoring::ChangeIndicationEnum is uint8_t + *buffer = to_underlying(changeIndication); + } + break; + case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: + { + *(bool *)buffer = GetInPlaceIndicator(); + } + break; + case HepaFilterMonitoring::Attributes::LastChangedTime::Id: + { + DataModel::Nullable lastChangedTime = GetLastChangedTime(); + *(uint32_t *)buffer = lastChangedTime.IsNull() ? 0 : lastChangedTime.Value(); + } + break; + case HepaFilterMonitoring::Attributes::DegradationDirection::Id: + default: + ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); + ret = Protocols::InteractionModel::Status::UnsupportedRead; + break; + } + + return ret; +} + void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) { VerifyOrDie(!gHepaFilterInstance && !gHepaFilterDelegate); - gHepaFilterDelegate = std::make_unique(); bool bResetConditionCommandSupported = true; // The ResetCondition command is supported by the ResourceMonitor cluster - gHepaFilterInstance = std::make_unique( + gHepaFilterDelegate = std::make_unique(); + gHepaFilterInstance = std::make_unique( gHepaFilterDelegate.get(), endpoint, HepaFilterMonitoring::Id, static_cast(gHepaFilterFeatureMap.Raw()), ResourceMonitoring::DegradationDirectionEnum::kDown, bResetConditionCommandSupported); gHepaFilterInstance->Init(); diff --git a/examples/chef/common/chef-resource-monitoring-delegates.h b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h similarity index 59% rename from examples/chef/common/chef-resource-monitoring-delegates.h rename to examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h index f161be0006a238..9c3e13efcf391a 100644 --- a/examples/chef/common/chef-resource-monitoring-delegates.h +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2023 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,21 +24,24 @@ namespace chip { namespace app { namespace Clusters { -namespace ActivatedCarbonFilterMonitoring { -class ActivatedCarbonFilterMonitoringDelegate : public ResourceMonitoring::Delegate -{ -private: - CHIP_ERROR Init() override; - chip::Protocols::InteractionModel::Status PreResetCondition() override; - chip::Protocols::InteractionModel::Status PostResetCondition() override; +namespace ResourceMonitoring { +// Inherit ResourceMonitoring class to able to write external attributes +class ChefResourceMonitorInstance : public ResourceMonitoring::Instance +{ public: - ~ActivatedCarbonFilterMonitoringDelegate() override = default; + ChefResourceMonitorInstance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, uint32_t aFeatureMap, + ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported) : ResourceMonitoring::Instance(aDelegate, aEndpointId, aClusterId, aFeatureMap, + aDegradationDirection, aResetConditionCommandSupported) { }; + + chip::Protocols::InteractionModel::Status ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); + chip::Protocols::InteractionModel::Status ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); + }; -void Shutdown(); +} // namespace ResourceMonitor -} // namespace ActivatedCarbonFilterMonitoring namespace HepaFilterMonitoring { class HepaFilterMonitoringDelegate : public ResourceMonitoring::Delegate @@ -63,6 +66,26 @@ void Shutdown(); } // namespace HepaFilterMonitoring +namespace ActivatedCarbonFilterMonitoring { +class ActivatedCarbonFilterMonitoringDelegate : public ResourceMonitoring::Delegate +{ +private: + CHIP_ERROR Init() override; + chip::Protocols::InteractionModel::Status PreResetCondition() override; + chip::Protocols::InteractionModel::Status PostResetCondition() override; + +public: + ~ActivatedCarbonFilterMonitoringDelegate() override = default; +}; + +void Shutdown(); + +} // namespace ActivatedCarbonFilterMonitoring + } // namespace Clusters } // namespace app } // namespace chip + +chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); + +chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index 5756aaa35b7e26..46f679ff999a9c 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -18,6 +18,11 @@ defined(MATTER_DM_PLUGIN_RADON_CONCENTRATION_MEASUREMENT_SERVER) #include "chef-concentration-measurement.h" #endif +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ + defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) +#include "resource-monitoring/chef-resource-monitoring-delegates.h" +#endif + using chip::app::DataModel::Nullable; @@ -56,6 +61,12 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin case chip::app::Clusters::RadonConcentrationMeasurement::Id: case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); +#endif +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ + defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) + case chip::app::Clusters::HepaFilterMonitoring::Id: + case chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id: + return chefResourceMonitoringExternalReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); #endif default: break; @@ -104,6 +115,12 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi case chip::app::Clusters::RadonConcentrationMeasurement::Id: case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementWriteCallback(endpoint, clusterId, attributeMetadata, buffer); +#endif +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ + defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) + case chip::app::Clusters::HepaFilterMonitoring::Id: + case chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id: + return chefResourceMonitoringExternalWriteCallback(endpoint, clusterId, attributeMetadata, buffer); #endif default: break; diff --git a/examples/chef/devices/rootnode_airpurifier_73a6fe2651.matter b/examples/chef/devices/rootnode_airpurifier_73a6fe2651.matter index bcc9bd054ff722..3251a054454d0f 100644 --- a/examples/chef/devices/rootnode_airpurifier_73a6fe2651.matter +++ b/examples/chef/devices/rootnode_airpurifier_73a6fe2651.matter @@ -51,6 +51,78 @@ cluster Identify = 3 { command access(invoke: manage) TriggerEffect(TriggerEffectRequest): DefaultSuccess = 64; } +/** Attributes and commands for switching devices between 'On' and 'Off' states. */ +cluster OnOff = 6 { + revision 6; + + enum DelayedAllOffEffectVariantEnum : enum8 { + kDelayedOffFastFade = 0; + kNoFade = 1; + kDelayedOffSlowFade = 2; + } + + enum DyingLightEffectVariantEnum : enum8 { + kDyingLightFadeOff = 0; + } + + enum EffectIdentifierEnum : enum8 { + kDelayedAllOff = 0; + kDyingLight = 1; + } + + enum StartUpOnOffEnum : enum8 { + kOff = 0; + kOn = 1; + kToggle = 2; + } + + bitmap Feature : bitmap32 { + kLighting = 0x1; + kDeadFrontBehavior = 0x2; + kOffOnly = 0x4; + } + + bitmap OnOffControlBitmap : bitmap8 { + kAcceptOnlyWhenOn = 0x1; + } + + readonly attribute boolean onOff = 0; + readonly attribute optional boolean globalSceneControl = 16384; + attribute optional int16u onTime = 16385; + attribute optional int16u offWaitTime = 16386; + attribute access(write: manage) optional nullable StartUpOnOffEnum startUpOnOff = 16387; + readonly attribute command_id generatedCommandList[] = 65528; + readonly attribute command_id acceptedCommandList[] = 65529; + readonly attribute event_id eventList[] = 65530; + readonly attribute attrib_id attributeList[] = 65531; + readonly attribute bitmap32 featureMap = 65532; + readonly attribute int16u clusterRevision = 65533; + + request struct OffWithEffectRequest { + EffectIdentifierEnum effectIdentifier = 0; + enum8 effectVariant = 1; + } + + request struct OnWithTimedOffRequest { + OnOffControlBitmap onOffControl = 0; + int16u onTime = 1; + int16u offWaitTime = 2; + } + + /** On receipt of this command, a device SHALL enter its ‘Off’ state. This state is device dependent, but it is recommended that it is used for power off or similar functions. On receipt of the Off command, the OnTime attribute SHALL be set to 0. */ + command Off(): DefaultSuccess = 0; + /** On receipt of this command, a device SHALL enter its ‘On’ state. This state is device dependent, but it is recommended that it is used for power on or similar functions. On receipt of the On command, if the value of the OnTime attribute is equal to 0, the device SHALL set the OffWaitTime attribute to 0. */ + command On(): DefaultSuccess = 1; + /** On receipt of this command, if a device is in its ‘Off’ state it SHALL enter its ‘On’ state. Otherwise, if it is in its ‘On’ state it SHALL enter its ‘Off’ state. On receipt of the Toggle command, if the value of the OnOff attribute is equal to FALSE and if the value of the OnTime attribute is equal to 0, the device SHALL set the OffWaitTime attribute to 0. If the value of the OnOff attribute is equal to TRUE, the OnTime attribute SHALL be set to 0. */ + command Toggle(): DefaultSuccess = 2; + /** The OffWithEffect command allows devices to be turned off using enhanced ways of fading. */ + command OffWithEffect(OffWithEffectRequest): DefaultSuccess = 64; + /** The OnWithRecallGlobalScene command allows the recall of the settings when the device was turned off. */ + command OnWithRecallGlobalScene(): DefaultSuccess = 65; + /** The OnWithTimedOff command allows devices to be turned on for a specific duration with a guarded off duration so that SHOULD the device be subsequently switched off, further OnWithTimedOff commands, received during this time, are prevented from turning the devices back on. */ + command OnWithTimedOff(OnWithTimedOffRequest): DefaultSuccess = 66; +} + /** The Descriptor Cluster is meant to replace the support from the Zigbee Device Object (ZDO) for describing a node, its endpoints and clusters. */ cluster Descriptor = 29 { revision 2; @@ -1552,6 +1624,20 @@ endpoint 1 { handle command Identify; } + server cluster OnOff { + ram attribute onOff default = 0; + callback attribute generatedCommandList; + callback attribute acceptedCommandList; + callback attribute eventList; + callback attribute attributeList; + ram attribute featureMap default = 0; + ram attribute clusterRevision default = 6; + + handle command Off; + handle command On; + handle command Toggle; + } + server cluster Descriptor { callback attribute deviceTypeList; callback attribute serverList; @@ -1578,6 +1664,8 @@ endpoint 1 { callback attribute attributeList; callback attribute featureMap; ram attribute clusterRevision default = 1; + + handle command ResetCondition; } server cluster ActivatedCarbonFilterMonitoring { diff --git a/examples/chef/devices/rootnode_airpurifier_73a6fe2651.zap b/examples/chef/devices/rootnode_airpurifier_73a6fe2651.zap index 4e5b3241032f45..fc392ea914fffe 100644 --- a/examples/chef/devices/rootnode_airpurifier_73a6fe2651.zap +++ b/examples/chef/devices/rootnode_airpurifier_73a6fe2651.zap @@ -1,6 +1,6 @@ { "fileFormat": 2, - "featureLevel": 100, + "featureLevel": 102, "creator": "zap", "keyValuePairs": [ { @@ -29,6 +29,7 @@ "pathRelativity": "relativeToZap", "path": "../../../src/app/zap-templates/app-templates.json", "type": "gen-templates-json", + "category": "matter", "version": "chip-v1" } ], @@ -2468,6 +2469,154 @@ } ] }, + { + "name": "On/Off", + "code": 6, + "mfgCode": null, + "define": "ON_OFF_CLUSTER", + "side": "server", + "enabled": 1, + "commands": [ + { + "name": "Off", + "code": 0, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + }, + { + "name": "On", + "code": 1, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + }, + { + "name": "Toggle", + "code": 2, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + } + ], + "attributes": [ + { + "name": "OnOff", + "code": 0, + "mfgCode": null, + "side": "server", + "type": "boolean", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "GeneratedCommandList", + "code": 65528, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AcceptedCommandList", + "code": 65529, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EventList", + "code": 65530, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AttributeList", + "code": 65531, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "6", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ] + }, { "name": "Descriptor", "code": 29, @@ -2645,6 +2794,16 @@ "define": "HEPA_FILTER_MONITORING_CLUSTER", "side": "server", "enabled": 1, + "commands": [ + { + "name": "ResetCondition", + "code": 0, + "mfgCode": null, + "source": "client", + "isIncoming": 1, + "isEnabled": 1 + } + ], "attributes": [ { "name": "Condition", @@ -2836,7 +2995,7 @@ "reportable": 1, "minInterval": 1, "maxInterval": 65534, - "reportableChange": 0 + "reportableChange": 1 } ] }, diff --git a/examples/chef/esp32/main/CMakeLists.txt b/examples/chef/esp32/main/CMakeLists.txt index ac436a7919637b..8848e93b77d3b2 100644 --- a/examples/chef/esp32/main/CMakeLists.txt +++ b/examples/chef/esp32/main/CMakeLists.txt @@ -70,6 +70,7 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/../common/clusters/low-power/" "${CMAKE_SOURCE_DIR}/../common/clusters/media-input/" "${CMAKE_SOURCE_DIR}/../common/clusters/media-playback/" + "${CMAKE_SOURCE_DIR}/../common/clusters/resource-monitoring/" "${CMAKE_SOURCE_DIR}/../common/clusters/target-navigator/" "${CMAKE_SOURCE_DIR}/../common/clusters/wake-on-lan/" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" diff --git a/examples/chef/linux/BUILD.gn b/examples/chef/linux/BUILD.gn index 264ced698b62e8..2fafd227933b32 100644 --- a/examples/chef/linux/BUILD.gn +++ b/examples/chef/linux/BUILD.gn @@ -46,7 +46,6 @@ executable("${sample_name}") { "${project_dir}/common/chef-laundry-washer-controls-delegate-impl.cpp", "${project_dir}/common/chef-laundry-washer-mode.cpp", "${project_dir}/common/chef-operational-state-delegate-impl.cpp", - "${project_dir}/common/chef-resource-monitoring-delegates.cpp", "${project_dir}/common/chef-rvc-mode-delegate.cpp", "${project_dir}/common/chef-rvc-operational-state-delegate.cpp", "${project_dir}/common/clusters/audio-output/AudioOutputManager.cpp", @@ -58,6 +57,7 @@ executable("${sample_name}") { "${project_dir}/common/clusters/low-power/LowPowerManager.cpp", "${project_dir}/common/clusters/media-input/MediaInputManager.cpp", "${project_dir}/common/clusters/media-playback/MediaPlaybackManager.cpp", + "${project_dir}/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp", "${project_dir}/common/clusters/target-navigator/TargetNavigatorManager.cpp", "${project_dir}/common/clusters/wake-on-lan/WakeOnLanManager.cpp", "${project_dir}/common/stubs.cpp", diff --git a/examples/chef/nrfconnect/CMakeLists.txt b/examples/chef/nrfconnect/CMakeLists.txt index 0e943cd90719f3..0dc9b81a4c6bcf 100644 --- a/examples/chef/nrfconnect/CMakeLists.txt +++ b/examples/chef/nrfconnect/CMakeLists.txt @@ -87,7 +87,6 @@ target_sources(app PRIVATE ${CHEF}/common/chef-laundry-washer-controls-delegate-impl.cpp ${CHEF}/common/chef-laundry-washer-mode.cpp ${CHEF}/common/chef-operational-state-delegate-impl.cpp - ${CHEF}/common/chef-resource-monitoring-delegates.cpp ${CHEF}/common/chef-rvc-mode-delegate.cpp ${CHEF}/common/chef-rvc-operational-state-delegate.cpp ${CHEF}/common/clusters/audio-output/AudioOutputManager.cpp @@ -99,6 +98,7 @@ target_sources(app PRIVATE ${CHEF}/common/clusters/low-power/LowPowerManager.cpp ${CHEF}/common/clusters/media-input/MediaInputManager.cpp ${CHEF}/common/clusters/media-playback/MediaPlaybackManager.cpp + ${CHEF}/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp ${CHEF}/common/clusters/target-navigator/TargetNavigatorManager.cpp ${CHEF}/common/clusters/wake-on-lan/WakeOnLanManager.cpp ${CHEF}/common/stubs.cpp From 47e9eb7e0a1e80e7053e237b1548f0e7e1e46713 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 11 Jun 2024 17:16:11 +0000 Subject: [PATCH 2/7] Restyled by whitespace --- .../chef-resource-monitoring-delegates.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index f8a5174953cadc..b48ee42a70fb19 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -137,7 +137,7 @@ chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalA case HepaFilterMonitoring::Attributes::DegradationDirection::Id: default: { - ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); + ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); ret = Protocols::InteractionModel::Status::UnsupportedWrite; } break; @@ -163,7 +163,7 @@ chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalWriteCal { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; AttributeId attributeId = attributeMetadata->attributeId; - ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); switch (clusterId) { case HepaFilterMonitoring::Id: @@ -184,7 +184,7 @@ chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalReadCall { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; AttributeId attributeId = attributeMetadata->attributeId; - ChipLogProgress(Zcl, "chefResourceMonitoringExternalReadCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + ChipLogProgress(Zcl, "chefResourceMonitoringExternalReadCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); switch (clusterId) { case HepaFilterMonitoring::Id: @@ -232,7 +232,7 @@ chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalA break; case HepaFilterMonitoring::Attributes::DegradationDirection::Id: default: - ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); + ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); ret = Protocols::InteractionModel::Status::UnsupportedRead; break; } From cc895039b5f53541661128fff45d7b988d95e139 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 11 Jun 2024 17:16:23 +0000 Subject: [PATCH 3/7] Restyled by clang-format --- .../chef-resource-monitoring-delegates.cpp | 126 +++++++++--------- .../chef-resource-monitoring-delegates.h | 28 ++-- examples/chef/common/stubs.cpp | 10 +- 3 files changed, 86 insertions(+), 78 deletions(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index b48ee42a70fb19..9a4731427f7fad 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -15,13 +15,13 @@ * limitations under the License. */ -#include #include #include #include #include -#include #include +#include +#include using namespace chip; using namespace chip::app; @@ -98,49 +98,47 @@ void HepaFilterMonitoring::Shutdown() gHepaFilterDelegate.reset(); } -chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +chip::Protocols::InteractionModel::Status +ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; - AttributeId attributeId = attributeMetadata->attributeId; + AttributeId attributeId = attributeMetadata->attributeId; - switch (attributeId) { - case HepaFilterMonitoring::Attributes::Condition::Id: + switch (attributeId) { - uint8_t newCondition = *(uint8_t *)buffer; - ret = UpdateCondition(newCondition); + case HepaFilterMonitoring::Attributes::Condition::Id: { + uint8_t newCondition = *(uint8_t *) buffer; + ret = UpdateCondition(newCondition); } - break; - case HepaFilterMonitoring::Attributes::ChangeIndication::Id: - { - ResourceMonitoring::ChangeIndicationEnum newIndication = static_cast(*(uint8_t *)buffer); - ret = UpdateChangeIndication(newIndication); + break; + case HepaFilterMonitoring::Attributes::ChangeIndication::Id: { + ResourceMonitoring::ChangeIndicationEnum newIndication = + static_cast(*(uint8_t *) buffer); + ret = UpdateChangeIndication(newIndication); } - break; - case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: - { - bool newInPlaceIndicator = *(bool *)buffer; - ret = UpdateInPlaceIndicator(newInPlaceIndicator); + break; + case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: { + bool newInPlaceIndicator = *(bool *) buffer; + ret = UpdateInPlaceIndicator(newInPlaceIndicator); } - break; - case HepaFilterMonitoring::Attributes::LastChangedTime::Id: - { - uint32_t newValue = 0; - uint16_t tlvLen = *(uint16_t *) buffer; + break; + case HepaFilterMonitoring::Attributes::LastChangedTime::Id: { + uint32_t newValue = 0; + uint16_t tlvLen = *(uint16_t *) buffer; chip::TLV::TLVReader reader; reader.Init(buffer + sizeof(uint16_t), tlvLen); reader.Next(); reader.Get(newValue); DataModel::Nullable newLastChangedTime = DataModel::MakeNullable(newValue); - ret = UpdateLastChangedTime(newLastChangedTime); + ret = UpdateLastChangedTime(newLastChangedTime); } - break; + break; case HepaFilterMonitoring::Attributes::DegradationDirection::Id: - default: - { + default: { ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); - ret = Protocols::InteractionModel::Status::UnsupportedWrite; + ret = Protocols::InteractionModel::Status::UnsupportedWrite; } - break; + break; } return ret; @@ -159,81 +157,89 @@ void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId gActivatedCarbonFilterInstance->Init(); } -chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +chip::Protocols::InteractionModel::Status +chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; - AttributeId attributeId = attributeMetadata->attributeId; - ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + AttributeId attributeId = attributeMetadata->attributeId; + ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), + static_cast(clusterId), static_cast(attributeId)); - switch (clusterId) { + switch (clusterId) + { case HepaFilterMonitoring::Id: - ret = gHepaFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); + ret = gHepaFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); break; case ActivatedCarbonFilterMonitoring::Id: - ret = gActivatedCarbonFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); + ret = gActivatedCarbonFilterInstance->ExternalAttributeWrite(attributeMetadata, buffer); break; default: - ret = Protocols::InteractionModel::Status::UnsupportedWrite; + ret = Protocols::InteractionModel::Status::UnsupportedWrite; break; } return ret; } -chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) +chip::Protocols::InteractionModel::Status +chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength) { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; - AttributeId attributeId = attributeMetadata->attributeId; - ChipLogProgress(Zcl, "chefResourceMonitoringExternalReadCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); + AttributeId attributeId = attributeMetadata->attributeId; + ChipLogProgress(Zcl, "chefResourceMonitoringExternalReadCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), + static_cast(clusterId), static_cast(attributeId)); - switch (clusterId) { + switch (clusterId) + { case HepaFilterMonitoring::Id: - ret = gHepaFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); + ret = gHepaFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); break; case ActivatedCarbonFilterMonitoring::Id: - ret = gActivatedCarbonFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); + ret = gActivatedCarbonFilterInstance->ExternalAttributeRead(attributeMetadata, buffer, maxReadLength); break; default: - ret = Protocols::InteractionModel::Status::UnsupportedRead; + ret = Protocols::InteractionModel::Status::UnsupportedRead; break; } return ret; } -chip::Protocols::InteractionModel::Status ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) +chip::Protocols::InteractionModel::Status +ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength) { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; - AttributeId attributeId = attributeMetadata->attributeId; + AttributeId attributeId = attributeMetadata->attributeId; - switch (attributeId) { - case HepaFilterMonitoring::Attributes::Condition::Id: + switch (attributeId) { + case HepaFilterMonitoring::Attributes::Condition::Id: { *buffer = GetCondition(); } - break; - case HepaFilterMonitoring::Attributes::ChangeIndication::Id: - { + break; + case HepaFilterMonitoring::Attributes::ChangeIndication::Id: { ResourceMonitoring::ChangeIndicationEnum changeIndication = GetChangeIndication(); // The underlying type of ResourceMonitoring::ChangeIndicationEnum is uint8_t *buffer = to_underlying(changeIndication); } - break; - case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: - { - *(bool *)buffer = GetInPlaceIndicator(); + break; + case HepaFilterMonitoring::Attributes::InPlaceIndicator::Id: { + *(bool *) buffer = GetInPlaceIndicator(); } - break; - case HepaFilterMonitoring::Attributes::LastChangedTime::Id: - { + break; + case HepaFilterMonitoring::Attributes::LastChangedTime::Id: { DataModel::Nullable lastChangedTime = GetLastChangedTime(); - *(uint32_t *)buffer = lastChangedTime.IsNull() ? 0 : lastChangedTime.Value(); + *(uint32_t *) buffer = lastChangedTime.IsNull() ? 0 : lastChangedTime.Value(); } - break; + break; case HepaFilterMonitoring::Attributes::DegradationDirection::Id: default: ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); - ret = Protocols::InteractionModel::Status::UnsupportedRead; + ret = Protocols::InteractionModel::Status::UnsupportedRead; break; } diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h index 9c3e13efcf391a..2334be90b4ab3a 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.h @@ -31,17 +31,18 @@ class ChefResourceMonitorInstance : public ResourceMonitoring::Instance { public: ChefResourceMonitorInstance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClusterId, uint32_t aFeatureMap, - ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, - bool aResetConditionCommandSupported) : ResourceMonitoring::Instance(aDelegate, aEndpointId, aClusterId, aFeatureMap, - aDegradationDirection, aResetConditionCommandSupported) { }; - - chip::Protocols::InteractionModel::Status ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); - chip::Protocols::InteractionModel::Status ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); - + ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported) : + ResourceMonitoring::Instance(aDelegate, aEndpointId, aClusterId, aFeatureMap, aDegradationDirection, + aResetConditionCommandSupported){}; + + chip::Protocols::InteractionModel::Status ExternalAttributeWrite(const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer); + chip::Protocols::InteractionModel::Status ExternalAttributeRead(const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength); }; -} // namespace ResourceMonitor - +} // namespace ResourceMonitoring namespace HepaFilterMonitoring { class HepaFilterMonitoringDelegate : public ResourceMonitoring::Delegate @@ -86,6 +87,11 @@ void Shutdown(); } // namespace app } // namespace chip -chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); +chip::Protocols::InteractionModel::Status +chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); -chip::Protocols::InteractionModel::Status chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); +chip::Protocols::InteractionModel::Status +chefResourceMonitoringExternalReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength); diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index 9887a0b412cb13..8771bf78dccaf5 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -18,12 +18,10 @@ defined(MATTER_DM_PLUGIN_RADON_CONCENTRATION_MEASUREMENT_SERVER) #include "chef-concentration-measurement.h" #endif -#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ - defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) #include "resource-monitoring/chef-resource-monitoring-delegates.h" #endif - #if defined(MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER) || defined(MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER) #include "chef-rvc-mode-delegate.h" #endif @@ -70,8 +68,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); #endif -#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ - defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) case chip::app::Clusters::HepaFilterMonitoring::Id: case chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id: return chefResourceMonitoringExternalReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); @@ -136,8 +133,7 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementWriteCallback(endpoint, clusterId, attributeMetadata, buffer); #endif -#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || \ - defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) +#if defined(MATTER_DM_PLUGIN_HEPA_FILTER_MONITORING_SERVER) || defined(MATTER_DM_PLUGIN_ACTIVATED_CARBON_FILTER_MONITORING_SERVER) case chip::app::Clusters::HepaFilterMonitoring::Id: case chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id: return chefResourceMonitoringExternalWriteCallback(endpoint, clusterId, attributeMetadata, buffer); From b1b1f8247d2ed3c38f3c9dc50583ccb22b3bc09f Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Wed, 12 Jun 2024 22:19:32 +0800 Subject: [PATCH 4/7] Fix debug messages --- .../resource-monitoring/chef-resource-monitoring-delegates.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index 9a4731427f7fad..fd6f3aa47150a0 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -135,7 +135,7 @@ ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetada break; case HepaFilterMonitoring::Attributes::DegradationDirection::Id: default: { - ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); + ChipLogError(Zcl, "Unsupported External Attribute Write: %d", static_cast(attributeId)); ret = Protocols::InteractionModel::Status::UnsupportedWrite; } break; From 24bfb2b11c5703b4fb7ccfc2fbf990a8b7842f49 Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Fri, 14 Jun 2024 10:18:25 +0800 Subject: [PATCH 5/7] Using BufferReader / BufferWriter to avoid Endianness Using BufferReader / BufferWriter to avoid Endianness issue --- .../chef-resource-monitoring-delegates.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index fd6f3aa47150a0..fa9b5fe33bb280 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -123,12 +125,17 @@ ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetada } break; case HepaFilterMonitoring::Attributes::LastChangedTime::Id: { + // We already know the input is a buffer started with a uint16_t as the length + chip::Encoding::LittleEndian::Reader bufReader(buffer, sizeof(uint16_t)); + uint16_t tlvLen; + VerifyOrReturnError( CHIP_NO_ERROR == bufReader.Read16(&tlvLen).StatusCode(), Protocols::InteractionModel::Status::UnsupportedWrite); + + // Read from TLV uint32_t newValue = 0; - uint16_t tlvLen = *(uint16_t *) buffer; - chip::TLV::TLVReader reader; - reader.Init(buffer + sizeof(uint16_t), tlvLen); - reader.Next(); - reader.Get(newValue); + chip::TLV::TLVReader tlvReader; + tlvReader.Init(buffer + sizeof(uint16_t), tlvLen); + tlvReader.Next(); + tlvReader.Get(newValue); DataModel::Nullable newLastChangedTime = DataModel::MakeNullable(newValue); ret = UpdateLastChangedTime(newLastChangedTime); } @@ -163,7 +170,7 @@ chefResourceMonitoringExternalWriteCallback(chip::EndpointId endpoint, chip::Clu { Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; AttributeId attributeId = attributeMetadata->attributeId; - ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %d, Att: %d", static_cast(endpoint), + ChipLogProgress(Zcl, "chefResourceMonitoringExternalWriteCallback EP: %d, Cluster: %04x, Att: %04x", static_cast(endpoint), static_cast(clusterId), static_cast(attributeId)); switch (clusterId) @@ -232,8 +239,11 @@ ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadat } break; case HepaFilterMonitoring::Attributes::LastChangedTime::Id: { + // Only LastChangedTime needs to handle Endianness DataModel::Nullable lastChangedTime = GetLastChangedTime(); - *(uint32_t *) buffer = lastChangedTime.IsNull() ? 0 : lastChangedTime.Value(); + chip::Encoding::LittleEndian::BufferWriter bufWriter(buffer, sizeof(uint16_t)); + + bufWriter.Put32(lastChangedTime.IsNull() ? 0 : lastChangedTime.Value()); } break; case HepaFilterMonitoring::Attributes::DegradationDirection::Id: From 31c7aa16a16d59d1c884ef53d016ac151cfd8d37 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 14 Jun 2024 02:20:07 +0000 Subject: [PATCH 6/7] Restyled by clang-format --- .../resource-monitoring/chef-resource-monitoring-delegates.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index fa9b5fe33bb280..9e6db1fd2f3145 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -128,7 +128,8 @@ ChefResourceMonitorInstance::ExternalAttributeWrite(const EmberAfAttributeMetada // We already know the input is a buffer started with a uint16_t as the length chip::Encoding::LittleEndian::Reader bufReader(buffer, sizeof(uint16_t)); uint16_t tlvLen; - VerifyOrReturnError( CHIP_NO_ERROR == bufReader.Read16(&tlvLen).StatusCode(), Protocols::InteractionModel::Status::UnsupportedWrite); + VerifyOrReturnError(CHIP_NO_ERROR == bufReader.Read16(&tlvLen).StatusCode(), + Protocols::InteractionModel::Status::UnsupportedWrite); // Read from TLV uint32_t newValue = 0; From bfb6d9b8e6efbcfce20dfcbf31fe77ea290b64cb Mon Sep 17 00:00:00 2001 From: erwinpan1 Date: Mon, 17 Jun 2024 18:10:57 +0800 Subject: [PATCH 7/7] Fix DegradationDirection Get --- .../chef-resource-monitoring-delegates.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp index 9e6db1fd2f3145..9b0f6d8df13404 100644 --- a/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp +++ b/examples/chef/common/clusters/resource-monitoring/chef-resource-monitoring-delegates.cpp @@ -247,7 +247,12 @@ ChefResourceMonitorInstance::ExternalAttributeRead(const EmberAfAttributeMetadat bufWriter.Put32(lastChangedTime.IsNull() ? 0 : lastChangedTime.Value()); } break; - case HepaFilterMonitoring::Attributes::DegradationDirection::Id: + case HepaFilterMonitoring::Attributes::DegradationDirection::Id: { + ResourceMonitoring::DegradationDirectionEnum degradationDirection = GetDegradationDirection(); + // The underlying type of ResourceMonitoring::DegradationDirectionEnum is uint8_t + *buffer = to_underlying(degradationDirection); + } + break; default: ChipLogError(Zcl, "Unsupported External Attribute Read: %d", static_cast(attributeId)); ret = Protocols::InteractionModel::Status::UnsupportedRead;