From 58f7a50fd93c21f8d14659953b73c4be073cf881 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Fri, 21 Jul 2023 15:18:13 -0700 Subject: [PATCH 01/33] Modifying ReplacementProductListManager to be generic Addressing feedback from PR #28095 and also addressing #28148 Tested to ensure functionality still works as expected using the all-clusters-app as well as the resource-monitoring-app --- .../include/resource-monitoring-instances.h | 8 ++--- .../src/resource-monitoring-instances.cpp | 19 +++++----- .../StaticReplacementProductListManager.h | 8 ++--- .../StaticReplacementProductListManager.cpp | 2 +- .../ActivatedCarbonFilterMonitoring.cpp | 18 ++++------ .../src/instances/HepafilterMonitoring.cpp | 18 ++++------ .../replacement-product-list-manager.h | 5 +-- .../resource-monitoring-cluster-objects.cpp | 6 ++-- .../resource-monitoring-cluster-objects.h | 36 ++++++++++--------- .../resource-monitoring-server.cpp | 16 ++++++--- 10 files changed, 64 insertions(+), 72 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index c12a686735abba..ff55441ea65de8 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -58,13 +58,11 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager { public: - uint8_t Size() override { return mReplacementProductListSize; }; - - CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type & item) override; + CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType & item) override; ~StaticReplacementProductListManager() {} StaticReplacementProductListManager( - chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * aReplacementProductsList, + chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; @@ -72,6 +70,6 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource } private: - chip::app::Clusters::ResourceMonitoring::Attributes::ReplacementProductStruct::Type * mReplacementProductsList; + chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index 891a7e85450b48..4249d11933b796 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -25,6 +25,7 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; +using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; using chip::Protocols::InteractionModel::Status; constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(Feature::kCondition) | @@ -37,16 +38,12 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; -static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sReplacementProductsList[] = { - { .productIdentifierType = ProductIdentifierTypeEnum::kUpc, - .productIdentifierValue = CharSpan::fromCharString("111112222233") }, - { .productIdentifierType = ProductIdentifierTypeEnum::kGtin8, .productIdentifierValue = CharSpan::fromCharString("gtin8xxx") }, - { .productIdentifierType = ProductIdentifierTypeEnum::kEan, - .productIdentifierValue = CharSpan::fromCharString("4444455555666") }, - { .productIdentifierType = ProductIdentifierTypeEnum::kGtin14, - .productIdentifierValue = CharSpan::fromCharString("gtin14xxxxxxxx") }, - { .productIdentifierType = ProductIdentifierTypeEnum::kOem, - .productIdentifierValue = CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") }, +static GenericType sReplacementProductsList[] = { + GenericType(ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), + GenericType(ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx")), + GenericType(ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), + GenericType(ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx")), + GenericType(ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")), }; StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0], ArraySize(sReplacementProductsList)); @@ -105,7 +102,7 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item) +CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericReplacementProductStruct::GenericType & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h index cb83148302f8b6..8192987bac5219 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h @@ -34,12 +34,10 @@ namespace ResourceMonitoring { class StaticReplacementProductListManager : public ReplacementProductListManager { public: - uint8_t Size() override { return mReplacementProductListSize; }; - - CHIP_ERROR Next(Attributes::ReplacementProductStruct::Type & item) override; + CHIP_ERROR Next(Attributes::GenericReplacementProductStruct::GenericType & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(Attributes::ReplacementProductStruct::Type * aReplacementProductsList, + StaticReplacementProductListManager(Attributes::GenericReplacementProductStruct::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; @@ -47,7 +45,7 @@ class StaticReplacementProductListManager : public ReplacementProductListManager } private: - Attributes::ReplacementProductStruct::Type * mReplacementProductsList; + Attributes::GenericReplacementProductStruct::GenericType * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp index 4c657ff05cc488..8da59c07720fe6 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp @@ -25,7 +25,7 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::ReplacementProductStruct::Type & item) +CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericReplacementProductStruct::GenericType & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp index 778bb9d6e22dd0..a83dbf6a538bfa 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp @@ -32,19 +32,15 @@ using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring; using namespace chip::app::Clusters::ResourceMonitoring; +using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; using chip::Protocols::InteractionModel::Status; -static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sActivatedCarbonFilterReplacementProductsList[] = { - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, - .productIdentifierValue = CharSpan::fromCharString("111112222233") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, - .productIdentifierValue = CharSpan::fromCharString("gtin8xca") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kEan, - .productIdentifierValue = CharSpan::fromCharString("4444455555666") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, - .productIdentifierValue = CharSpan::fromCharString("gtin14xcarbonx") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kOem, - .productIdentifierValue = CharSpan::fromCharString("oem20xcarbonxxxxxxxx") }, +static ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType sActivatedCarbonFilterReplacementProductsList[] = { + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx")), }; StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0], diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index c0ee95ed7c02ff..6dc5062ca990db 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -31,19 +31,15 @@ using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; +using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; using chip::Protocols::InteractionModel::Status; -static ResourceMonitoring::Attributes::ReplacementProductStruct::Type sHepaFilterReplacementProductsList[] = { - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, - .productIdentifierValue = CharSpan::fromCharString("111112222233") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, - .productIdentifierValue = CharSpan::fromCharString("gtin8xhe") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kEan, - .productIdentifierValue = CharSpan::fromCharString("4444455555666") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, - .productIdentifierValue = CharSpan::fromCharString("gtin14xhepaxxx") }, - { .productIdentifierType = ResourceMonitoring::ProductIdentifierTypeEnum::kOem, - .productIdentifierValue = CharSpan::fromCharString("oem20xhepaxxxxxxxxxx") }, +static GenericType sHepaFilterReplacementProductsList[] = { + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xhe")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xhepaxxx")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")), }; StaticReplacementProductListManager sHepaFilterReplacementProductListManager(&sHepaFilterReplacementProductsList[0], ArraySize(sHepaFilterReplacementProductsList)); diff --git a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h index b252597306c21a..98898caf0bb330 100644 --- a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h +++ b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h @@ -39,10 +39,7 @@ class ReplacementProductListManager void Reset() { mIndex = 0; } - // Returns total size of Replacement Products List. - virtual uint8_t Size() = 0; - - virtual CHIP_ERROR Next(Attributes::ReplacementProductStruct::Type & item) = 0; + virtual CHIP_ERROR Next(Attributes::GenericReplacementProductStruct::GenericType & item) = 0; protected: uint8_t mIndex; diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp index 932c95ce3a77ee..9241547e169e04 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp @@ -45,9 +45,9 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace Commands namespace Attributes { -namespace ReplacementProductStruct { +namespace GenericReplacementProductStruct { -CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const +CHIP_ERROR GenericType::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const { TLV::TLVType outer; ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); @@ -57,7 +57,7 @@ CHIP_ERROR Type::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const return CHIP_NO_ERROR; } -} // namespace ReplacementProductStruct +} // namespace GenericReplacementProductStruct } // namespace Attributes } // namespace ResourceMonitoring diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 995f42b6dc4d7c..7ff5b381728e28 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -141,37 +141,39 @@ struct TypeInfo }; } // namespace LastChangedTime -namespace ReplacementProductStruct { +namespace GenericReplacementProductStruct { enum class Fields : uint8_t { kProductIdentifierType = 0, kProductIdentifierValue = 1, }; -struct Type +class GenericType : protected app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { -public: - ProductIdentifierTypeEnum productIdentifierType = static_cast(0); - chip::CharSpan productIdentifierValue; - - CHIP_ERROR Decode(TLV::TLVReader & reader); + private: + ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; + chip::CharSpan productIdentifierValue; - static constexpr bool kIsFabricScoped = false; - - CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; + public: + GenericType() {} + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + productIdentifierType = aProductIdentifierType; + productIdentifierValue = aProductIdentifierValue; + } + virtual ~GenericType() = default; + static constexpr bool kIsFabricScoped = false; + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; }; - -using DecodableType = Type; - -} // namespace ReplacementProductStruct +} // namespace GenericReplacementProductStruct namespace ReplacementProductList { static constexpr AttributeId Id = 0x00000005; struct TypeInfo { - using Type = chip::app::DataModel::List; - using DecodableType = chip::app::DataModel::DecodableList; - using DecodableArgType = const chip::app::DataModel::DecodableList &; + using Type = chip::app::DataModel::List; + using DecodableType = chip::app::DataModel::DecodableList; + using DecodableArgType = const chip::app::DataModel::DecodableList &; static constexpr AttributeId GetAttributeId() { return Attributes::ReplacementProductList::Id; } static constexpr bool MustUseTimedWrite() { return false; } diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index 2cbcb433a23f42..f414ed276882e3 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -197,6 +197,12 @@ Status Instance::OnResetCondition() } } + ReplacementProductListManager * productListManagerInstance = Instance::GetReplacementProductListManagerInstance(); + if (nullptr != productListManagerInstance) + { + productListManagerInstance->Reset(); + } + // call application specific post reset logic status = PostResetCondition(); return status; @@ -245,7 +251,7 @@ CHIP_ERROR Instance::EnumerateAcceptedCommands(const ConcreteClusterPath & clust CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) { CHIP_ERROR err; - if (Instance::HasFeature(ResourceMonitoring::Feature::kReplacementProductList)) + if (HasFeature(ResourceMonitoring::Feature::kReplacementProductList)) { ReplacementProductListManager * productListManagerInstance = Instance::GetReplacementProductListManagerInstance(); if (nullptr == productListManagerInstance) @@ -257,12 +263,14 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) productListManagerInstance->Reset(); err = aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { - Attributes::ReplacementProductStruct::Type replacementProductStruct; - while (productListManagerInstance->Next(replacementProductStruct) == CHIP_NO_ERROR) + Attributes::GenericReplacementProductStruct::GenericType replacementProductStruct; + CHIP_ERROR iteratorError; + while (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED != iteratorError) { ReturnErrorOnFailure(encoder.Encode(replacementProductStruct)); + iteratorError = productListManagerInstance->Next(replacementProductStruct); } - return CHIP_NO_ERROR; + return (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED != iteratorError) ? iteratorError : CHIP_NO_ERROR; }); } return CHIP_NO_ERROR; From 53c50ebaecc2285a1ef468c08d567693e8549f02 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 21 Jul 2023 22:24:26 +0000 Subject: [PATCH 02/33] Restyled by whitespace --- .../resource-monitoring-cluster-objects.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 7ff5b381728e28..13c31b99581bbe 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -148,7 +148,7 @@ enum class Fields : uint8_t kProductIdentifierValue = 1, }; -class GenericType : protected app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::Type +class GenericType : protected app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { private: ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; From f9ed8b9598de588e93d5e4b355bf6128f20a7105 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 21 Jul 2023 22:24:27 +0000 Subject: [PATCH 03/33] Restyled by clang-format --- .../include/resource-monitoring-instances.h | 6 ++-- .../ActivatedCarbonFilterMonitoring.cpp | 15 +++++----- .../resource-monitoring-cluster-objects.h | 28 +++++++++---------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index ff55441ea65de8..01089b105b41e0 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -58,11 +58,13 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager { public: - CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType & item) override; + CHIP_ERROR + Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType & item) override; ~StaticReplacementProductListManager() {} StaticReplacementProductListManager( - chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * aReplacementProductsList, + chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * + aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp index a83dbf6a538bfa..b0ea401f938b13 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp @@ -35,13 +35,14 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; using chip::Protocols::InteractionModel::Status; -static ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType sActivatedCarbonFilterReplacementProductsList[] = { - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx")), -}; +static ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType + sActivatedCarbonFilterReplacementProductsList[] = { + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx")), + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx")), + }; StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0], ArraySize(sActivatedCarbonFilterReplacementProductsList)); diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 13c31b99581bbe..0ae47e9e6ef8a2 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -150,20 +150,20 @@ enum class Fields : uint8_t class GenericType : protected app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { - private: - ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; - chip::CharSpan productIdentifierValue; - - public: - GenericType() {} - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) - { - productIdentifierType = aProductIdentifierType; - productIdentifierValue = aProductIdentifierValue; - } - virtual ~GenericType() = default; - static constexpr bool kIsFabricScoped = false; - CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; +private: + ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; + chip::CharSpan productIdentifierValue; + +public: + GenericType() {} + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + productIdentifierType = aProductIdentifierType; + productIdentifierValue = aProductIdentifierValue; + } + virtual ~GenericType() = default; + static constexpr bool kIsFabricScoped = false; + CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; }; } // namespace GenericReplacementProductStruct From 3bbb7974f9da435b3ee49b5332136269d99a4831 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Fri, 21 Jul 2023 20:29:00 -0700 Subject: [PATCH 04/33] Passing error back up --- .../resource-monitoring-server.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index f414ed276882e3..f5f3fa3992c7d2 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -250,7 +250,7 @@ CHIP_ERROR Instance::EnumerateAcceptedCommands(const ConcreteClusterPath & clust CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) { - CHIP_ERROR err; + CHIP_ERROR err = CHIP_NO_ERROR; if (HasFeature(ResourceMonitoring::Feature::kReplacementProductList)) { ReplacementProductListManager * productListManagerInstance = Instance::GetReplacementProductListManagerInstance(); @@ -264,8 +264,8 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) err = aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { Attributes::GenericReplacementProductStruct::GenericType replacementProductStruct; - CHIP_ERROR iteratorError; - while (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED != iteratorError) + CHIP_ERROR iteratorError = CHIP_NO_ERROR; + while (CHIP_NO_ERROR == iteratorError) { ReturnErrorOnFailure(encoder.Encode(replacementProductStruct)); iteratorError = productListManagerInstance->Next(replacementProductStruct); @@ -273,7 +273,7 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) return (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED != iteratorError) ? iteratorError : CHIP_NO_ERROR; }); } - return CHIP_NO_ERROR; + return err; } // Implements the read functionality for non-standard attributes. From 3e0a65593555d911e491bf6abea8274e3995f319 Mon Sep 17 00:00:00 2001 From: Cliff Chung <116232729+cliffamzn@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:06:50 -0700 Subject: [PATCH 05/33] Apply @bzbarsky-apple's suggestions from code review Co-authored-by: Boris Zbarsky --- .../resource-monitoring-cluster-objects.h | 8 +++++++- .../resource-monitoring-server.cpp | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 0ae47e9e6ef8a2..c66125f5ba3543 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -148,7 +148,13 @@ enum class Fields : uint8_t kProductIdentifierValue = 1, }; -class GenericType : protected app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::Type +// A struct used during reads of the ReplacementProductList to store a single list instance we request +// from the application. +// +// Inherit from an auto-generated struct to pick up the implementation bits, but make +// it private inheritance so people can't accidentally use this struct where the other +// is expected. +class GenericType : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { private: ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index f5f3fa3992c7d2..2634f6e26af11f 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -253,7 +253,7 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) CHIP_ERROR err = CHIP_NO_ERROR; if (HasFeature(ResourceMonitoring::Feature::kReplacementProductList)) { - ReplacementProductListManager * productListManagerInstance = Instance::GetReplacementProductListManagerInstance(); + ReplacementProductListManager * productListManagerInstance = GetReplacementProductListManagerInstance(); if (nullptr == productListManagerInstance) { aEncoder.EncodeEmptyList(); @@ -262,7 +262,7 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) productListManagerInstance->Reset(); - err = aEncoder.EncodeList([&](const auto & encoder) -> CHIP_ERROR { + err = aEncoder.EncodeList([productListManagerInstance](const auto & encoder) -> CHIP_ERROR { Attributes::GenericReplacementProductStruct::GenericType replacementProductStruct; CHIP_ERROR iteratorError = CHIP_NO_ERROR; while (CHIP_NO_ERROR == iteratorError) From 60586e3bf79f62734ff8f065f7b689ed98b45e32 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 12:55:50 -0700 Subject: [PATCH 06/33] Integrating Borris' comments into ReplacementProductStruct Also added the DynamicReplacementProductListManager to demonstrate a non-static usage of the ReplacementProductListManager --- .../include/resource-monitoring-instances.h | 7 +- .../src/resource-monitoring-instances.cpp | 15 ++-- .../resource-monitoring-app/linux/BUILD.gn | 2 +- .../DynamicReplacementProductListManager.h | 62 ++++++++++++++ .../StaticReplacementProductListManager.h | 6 +- ....cpp => ReplacementProductListManager.cpp} | 15 +++- .../ActivatedCarbonFilterMonitoring.cpp | 14 +-- .../src/instances/HepafilterMonitoring.cpp | 22 +++-- .../replacement-product-list-manager.h | 11 ++- .../resource-monitoring-cluster-objects.cpp | 16 ---- .../resource-monitoring-cluster-objects.h | 85 +++++++++++++------ .../resource-monitoring-server.cpp | 11 +-- src/app/tests/suites/TestResourceMonitor.yaml | 52 ++++++++++++ 13 files changed, 229 insertions(+), 89 deletions(-) create mode 100644 examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h rename examples/resource-monitoring-app/resource-monitoring-common/src/{StaticReplacementProductListManager.cpp => ReplacementProductListManager.cpp} (78%) create mode 100644 src/app/tests/suites/TestResourceMonitor.yaml diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index 01089b105b41e0..b6da164d9d1b4c 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -59,11 +59,10 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource { public: CHIP_ERROR - Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType & item) override; + Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager( - chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * + StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) { @@ -72,6 +71,6 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource } private: - chip::app::Clusters::ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType * mReplacementProductsList; + chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index e0b7e059782503..e0e38681da1a09 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -25,7 +25,6 @@ using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; -using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; using chip::Protocols::InteractionModel::Status; constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(Feature::kCondition) | @@ -38,12 +37,12 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; -static GenericType sReplacementProductsList[] = { - GenericType(ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), - GenericType(ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx")), - GenericType(ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), - GenericType(ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx")), - GenericType(ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")), +static ResourceMonitoring::Attributes::GenericType sReplacementProductsList[] = { + { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, + { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, + { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, + { ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx") }, + { ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") }, }; StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0], ArraySize(sReplacementProductsList)); @@ -103,7 +102,7 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericReplacementProductStruct::GenericType & item) +CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/resource-monitoring-app/linux/BUILD.gn b/examples/resource-monitoring-app/linux/BUILD.gn index c5e769a39ce4f7..e9d5e391def96c 100644 --- a/examples/resource-monitoring-app/linux/BUILD.gn +++ b/examples/resource-monitoring-app/linux/BUILD.gn @@ -30,7 +30,7 @@ config("includes") { executable("chip-resource-monitoring-app") { sources = [ - "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp", + "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp", "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp", "${chip_root}/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepaFilterMonitoring.cpp", "include/CHIPProjectAppConfig.h", diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h new file mode 100644 index 00000000000000..37bd6a827fe6b0 --- /dev/null +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ResourceMonitoring { + +/** + * This implementation allows for items to be added dynamically. + */ + +class DynamicReplacementProductListManager : public ReplacementProductListManager +{ +public: + CHIP_ERROR Next(Attributes::GenericType & item) override; + + CHIP_ERROR addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + Attributes::GenericType * type = &mReplacementProductsList[mReplacementProductListSize]; + CHIP_ERROR err = type->setProductIdentifierValue(aProductIdentifierValue); + if (CHIP_NO_ERROR != err) + { + return err; + }; + + type->setProductIdentifierType(aProductIdentifierType); + mReplacementProductListSize++; + + return CHIP_NO_ERROR; + } + +private: + Attributes::GenericType mReplacementProductsList[ReplacementProductListManager::kReplacementProductListMaxSize]; + uint8_t mReplacementProductListSize; +}; + +} // namespace ResourceMonitoring +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h index 8192987bac5219..2fdaa60c685549 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h @@ -34,10 +34,10 @@ namespace ResourceMonitoring { class StaticReplacementProductListManager : public ReplacementProductListManager { public: - CHIP_ERROR Next(Attributes::GenericReplacementProductStruct::GenericType & item) override; + CHIP_ERROR Next(Attributes::GenericType & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(Attributes::GenericReplacementProductStruct::GenericType * aReplacementProductsList, + StaticReplacementProductListManager(Attributes::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; @@ -45,7 +45,7 @@ class StaticReplacementProductListManager : public ReplacementProductListManager } private: - Attributes::GenericReplacementProductStruct::GenericType * mReplacementProductsList; + Attributes::GenericType * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp similarity index 78% rename from examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp rename to examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index 8da59c07720fe6..c3651c924a13f1 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/StaticReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -25,7 +26,19 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericReplacementProductStruct::GenericType & item) +CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) +{ + if (mIndex < mReplacementProductListSize) + { + item = mReplacementProductsList[mIndex]; + mIndex++; + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; +} + +CHIP_ERROR DynamicReplacementProductListManager::Next(Attributes::GenericType & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp index b0ea401f938b13..bc58b9aff53b65 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp @@ -32,16 +32,16 @@ using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ActivatedCarbonFilterMonitoring; using namespace chip::app::Clusters::ResourceMonitoring; -using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; +using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -static ResourceMonitoring::Attributes::GenericReplacementProductStruct::GenericType +static GenericType sActivatedCarbonFilterReplacementProductsList[] = { - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx")), + { ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx") }, }; StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0], diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index 6dc5062ca990db..aefbe3a20f8913 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -31,25 +31,23 @@ using namespace chip; using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; -using namespace ResourceMonitoring::Attributes::GenericReplacementProductStruct; +using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -static GenericType sHepaFilterReplacementProductsList[] = { - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xhe")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xhepaxxx")), - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")), -}; -StaticReplacementProductListManager sHepaFilterReplacementProductListManager(&sHepaFilterReplacementProductsList[0], - ArraySize(sHepaFilterReplacementProductsList)); +DynamicReplacementProductListManager mHepaFilterReplacementProductListManager; //-- Hepa filter Monitoring instance methods CHIP_ERROR HepaFilterMonitoringInstance::AppInit() { ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - SetReplacementProductListManagerInstance(&sHepaFilterReplacementProductListManager); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xhe")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xhepaxxx")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); + + SetReplacementProductListManagerInstance(&mHepaFilterReplacementProductListManager); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h index 98898caf0bb330..3a0e1079db3c58 100644 --- a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h +++ b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h @@ -34,12 +34,21 @@ namespace ResourceMonitoring { class ReplacementProductListManager { public: + static constexpr size_t kReplacementProductListMaxSize = 5u; + ReplacementProductListManager() {} virtual ~ReplacementProductListManager() = default; void Reset() { mIndex = 0; } - virtual CHIP_ERROR Next(Attributes::GenericReplacementProductStruct::GenericType & item) = 0; + /** + * Iterates through the entries in the ReplacementProductListManager. Each call to this function move the list pointer to the next element. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function will return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the end of the list has been reached. + * + * @param[out] item An out parameter that is populated with the address of the item in the list. Will be empty if there are no remaining items in the list. In normal circumstances this parameter should never be modified. + * @return CHIP_NO_ERROR if the pointer to the list element has moved to the next element and there are still valid remaining entries in the list. + * Otherwise returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the list has hit the last element. + */ + virtual CHIP_ERROR Next(Attributes::GenericType & item) = 0; protected: uint8_t mIndex; diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp index 9241547e169e04..34388cba90c4d9 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.cpp @@ -44,22 +44,6 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader) } // namespace ResetCondition. } // namespace Commands -namespace Attributes { -namespace GenericReplacementProductStruct { - -CHIP_ERROR GenericType::Encode(TLV::TLVWriter & writer, TLV::Tag tag) const -{ - TLV::TLVType outer; - ReturnErrorOnFailure(writer.StartContainer(tag, TLV::kTLVType_Structure, outer)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(Fields::kProductIdentifierType), productIdentifierType)); - ReturnErrorOnFailure(DataModel::Encode(writer, TLV::ContextTag(Fields::kProductIdentifierValue), productIdentifierValue)); - ReturnErrorOnFailure(writer.EndContainer(outer)); - return CHIP_NO_ERROR; -} - -} // namespace GenericReplacementProductStruct -} // namespace Attributes - } // namespace ResourceMonitoring } // namespace Clusters } // namespace app diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index c66125f5ba3543..01ac3d8ff792b3 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -29,6 +29,8 @@ namespace app { namespace Clusters { namespace ResourceMonitoring { +// max of 20 characters + 1 for null terminator +static constexpr size_t kProductIdentifierValueMaxNameLength = 21u; static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; // Enum for ChangeIndicationEnum @@ -141,45 +143,72 @@ struct TypeInfo }; } // namespace LastChangedTime -namespace GenericReplacementProductStruct { -enum class Fields : uint8_t -{ - kProductIdentifierType = 0, - kProductIdentifierValue = 1, -}; - // A struct used during reads of the ReplacementProductList to store a single list instance we request // from the application. -// +// // Inherit from an auto-generated struct to pick up the implementation bits, but make // it private inheritance so people can't accidentally use this struct where the other // is expected. -class GenericType : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type +struct GenericType : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { -private: - ResourceMonitoring::ProductIdentifierTypeEnum productIdentifierType; - chip::CharSpan productIdentifierValue; - -public: - GenericType() {} - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) - { - productIdentifierType = aProductIdentifierType; - productIdentifierValue = aProductIdentifierValue; - } - virtual ~GenericType() = default; - static constexpr bool kIsFabricScoped = false; - CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag) const; -}; -} // namespace GenericReplacementProductStruct + private: + char productIdentifierValueBuffer[kProductIdentifierValueMaxNameLength]; + + public: + static constexpr bool kIsFabricScoped = false; + virtual ~GenericType() = default; + GenericType() {} + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + setProductIdentifierType(aProductIdentifierType); + setProductIdentifierValue(aProductIdentifierValue); + } + + using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; + + /** + * Sets the product identifier type. + * + * @param aProductIdentifierType The product identifier type. + */ + void setProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) + { + productIdentifierType = static_cast(aProductIdentifierType); + } + + /** + * Sets the product identifier value. + * This implementation will copy the argument to the local implementation. + * + * @param aProductIdentifierValue The value of the product identifier to set. + * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid, CHIP_NO_ERROR otherwise. + */ + CHIP_ERROR setProductIdentifierValue(chip::CharSpan aProductIdentifierValue) + { + VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT); + + if (aProductIdentifierValue.size() > sizeof(productIdentifierValueBuffer)) + { + memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), sizeof(productIdentifierValueBuffer)); + productIdentifierValue = CharSpan(productIdentifierValueBuffer, sizeof(productIdentifierValueBuffer)); + } + else + { + memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size()); + productIdentifierValue = CharSpan(productIdentifierValueBuffer, aProductIdentifierValue.size()); + } + + return CHIP_NO_ERROR; + } +}; namespace ReplacementProductList { static constexpr AttributeId Id = 0x00000005; struct TypeInfo { - using Type = chip::app::DataModel::List; - using DecodableType = chip::app::DataModel::DecodableList; - using DecodableArgType = const chip::app::DataModel::DecodableList &; + using Type = chip::app::DataModel::List; + using DecodableType = chip::app::DataModel::DecodableList; + using DecodableArgType = const chip::app::DataModel::DecodableList &; static constexpr AttributeId GetAttributeId() { return Attributes::ReplacementProductList::Id; } static constexpr bool MustUseTimedWrite() { return false; } diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index 2634f6e26af11f..6c36fbb8aace85 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -197,12 +197,6 @@ Status Instance::OnResetCondition() } } - ReplacementProductListManager * productListManagerInstance = Instance::GetReplacementProductListManagerInstance(); - if (nullptr != productListManagerInstance) - { - productListManagerInstance->Reset(); - } - // call application specific post reset logic status = PostResetCondition(); return status; @@ -263,8 +257,9 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) productListManagerInstance->Reset(); err = aEncoder.EncodeList([productListManagerInstance](const auto & encoder) -> CHIP_ERROR { - Attributes::GenericReplacementProductStruct::GenericType replacementProductStruct; - CHIP_ERROR iteratorError = CHIP_NO_ERROR; + Attributes::GenericType replacementProductStruct; + CHIP_ERROR iteratorError = productListManagerInstance->Next(replacementProductStruct); + while (CHIP_NO_ERROR == iteratorError) { ReturnErrorOnFailure(encoder.Encode(replacementProductStruct)); diff --git a/src/app/tests/suites/TestResourceMonitor.yaml b/src/app/tests/suites/TestResourceMonitor.yaml new file mode 100644 index 00000000000000..8a48e9a4b15268 --- /dev/null +++ b/src/app/tests/suites/TestResourceMonitor.yaml @@ -0,0 +1,52 @@ +# Copyright (c) 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Resource Monitor Cluster Tests + +config: + nodeId: 0x12344321 + cluster: "Resource Monitor" + endpoint: 1 + ReplacementProductList: + type: "ReplacementProductStruct" + defaultValue: + [ + { ProductIdentifierType: 0, ProductIdentifierValue: "111112222233" }, + { ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xxx" }, + { ProductIdentifierType: 2, ProductIdentifierValue: "4444455555666" }, + { ProductIdentifierType: 3, ProductIdentifierValue: "gtin14xxxxxxxx" }, + { ProductIdentifierType: 4, ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx" }, + ] + +tests: + - label: "Wait for the commissioned device to be retrieved" + cluster: "DelayCommands" + command: "WaitForCommissionee" + arguments: + values: + - name: "nodeId" + value: nodeId + + - label: "Read Replacement Product List" + command: "readAttribute" + attribute: "ReplacementProductList" + response: + value: + [ + { ProductIdentifierType: 0, ProductIdentifierValue: "111112222233" }, + { ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xxx" }, + { ProductIdentifierType: 2, ProductIdentifierValue: "4444455555666" }, + { ProductIdentifierType: 3, ProductIdentifierValue: "gtin14xxxxxxxx" }, + { ProductIdentifierType: 4, ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx" }, + ] From debbe5e75edac6d8e1a5a239b5cce1c20346ef9d Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jul 2023 21:09:04 +0000 Subject: [PATCH 07/33] Restyled by whitespace --- .../resource-monitoring-cluster-objects.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 01ac3d8ff792b3..b03044c1d188e0 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -168,7 +168,7 @@ struct GenericType : private HepaFilterMonitoring::Structs::ReplacementProductSt /** * Sets the product identifier type. - * + * * @param aProductIdentifierType The product identifier type. */ void setProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) @@ -179,7 +179,7 @@ struct GenericType : private HepaFilterMonitoring::Structs::ReplacementProductSt /** * Sets the product identifier value. * This implementation will copy the argument to the local implementation. - * + * * @param aProductIdentifierValue The value of the product identifier to set. * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid, CHIP_NO_ERROR otherwise. */ From 42d0d18d5ddb10d1a67b7d145b562f18e57e9fee Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jul 2023 21:09:16 +0000 Subject: [PATCH 08/33] Restyled by clang-format --- .../include/resource-monitoring-instances.h | 5 +- .../DynamicReplacementProductListManager.h | 5 +- .../StaticReplacementProductListManager.h | 3 +- .../src/ReplacementProductListManager.cpp | 2 +- .../ActivatedCarbonFilterMonitoring.cpp | 15 ++-- .../src/instances/HepafilterMonitoring.cpp | 15 ++-- .../replacement-product-list-manager.h | 13 +-- .../resource-monitoring-cluster-objects.h | 90 +++++++++---------- 8 files changed, 77 insertions(+), 71 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index b6da164d9d1b4c..9cd859d22fe027 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -62,9 +62,8 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * - aReplacementProductsList, - uint8_t aReplacementProductListSize) + StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * aReplacementProductsList, + uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; mReplacementProductListSize = aReplacementProductListSize; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h index 37bd6a827fe6b0..af9c81ef658cb9 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h @@ -36,10 +36,11 @@ class DynamicReplacementProductListManager : public ReplacementProductListManage public: CHIP_ERROR Next(Attributes::GenericType & item) override; - CHIP_ERROR addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + CHIP_ERROR addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, + chip::CharSpan aProductIdentifierValue) { Attributes::GenericType * type = &mReplacementProductsList[mReplacementProductListSize]; - CHIP_ERROR err = type->setProductIdentifierValue(aProductIdentifierValue); + CHIP_ERROR err = type->setProductIdentifierValue(aProductIdentifierValue); if (CHIP_NO_ERROR != err) { return err; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h index 2fdaa60c685549..51566b627289fe 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h @@ -37,8 +37,7 @@ class StaticReplacementProductListManager : public ReplacementProductListManager CHIP_ERROR Next(Attributes::GenericType & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(Attributes::GenericType * aReplacementProductsList, - uint8_t aReplacementProductListSize) + StaticReplacementProductListManager(Attributes::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; mReplacementProductListSize = aReplacementProductListSize; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index c3651c924a13f1..b5f9a5fb698542 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -16,8 +16,8 @@ * limitations under the License. */ -#include #include +#include #include #include #include diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp index bc58b9aff53b65..a45cfe525619ba 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp @@ -35,14 +35,13 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -static GenericType - sActivatedCarbonFilterReplacementProductsList[] = { - { ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, - { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca") }, - { ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, - { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx") }, - { ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx") }, - }; +static GenericType sActivatedCarbonFilterReplacementProductsList[] = { + { ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xcarbonx") }, + { ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xcarbonxxxxxxxx") }, +}; StaticReplacementProductListManager sActivatedCarbonFilterReplacementProductListManager(&sActivatedCarbonFilterReplacementProductsList[0], ArraySize(sActivatedCarbonFilterReplacementProductsList)); diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index aefbe3a20f8913..b31a31c7caf121 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -41,11 +41,16 @@ CHIP_ERROR HepaFilterMonitoringInstance::AppInit() { ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xhe")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xhepaxxx")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, + CharSpan::fromCharString("111112222233")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, + CharSpan::fromCharString("gtin8xhe")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, + CharSpan::fromCharString("4444455555666")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, + CharSpan::fromCharString("gtin14xhepaxxx")); + mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, + CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); SetReplacementProductListManagerInstance(&mHepaFilterReplacementProductListManager); diff --git a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h index 3a0e1079db3c58..f23736b5fe5878 100644 --- a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h +++ b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h @@ -42,12 +42,15 @@ class ReplacementProductListManager void Reset() { mIndex = 0; } /** - * Iterates through the entries in the ReplacementProductListManager. Each call to this function move the list pointer to the next element. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function will return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the end of the list has been reached. + * Iterates through the entries in the ReplacementProductListManager. Each call to this function move the list pointer to the + * next element. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function + * will return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the end of the list has been reached. * - * @param[out] item An out parameter that is populated with the address of the item in the list. Will be empty if there are no remaining items in the list. In normal circumstances this parameter should never be modified. - * @return CHIP_NO_ERROR if the pointer to the list element has moved to the next element and there are still valid remaining entries in the list. - * Otherwise returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the list has hit the last element. - */ + * @param[out] item An out parameter that is populated with the address of the item in the list. Will be empty if there are no + * remaining items in the list. In normal circumstances this parameter should never be modified. + * @return CHIP_NO_ERROR if the pointer to the list element has moved to the next element and there are still valid remaining + * entries in the list. Otherwise returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the list has hit the last element. + */ virtual CHIP_ERROR Next(Attributes::GenericType & item) = 0; protected: diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index b03044c1d188e0..fc12cdb9e3979b 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -31,7 +31,7 @@ namespace ResourceMonitoring { // max of 20 characters + 1 for null terminator static constexpr size_t kProductIdentifierValueMaxNameLength = 21u; -static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; +static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; // Enum for ChangeIndicationEnum enum class ChangeIndicationEnum : uint8_t @@ -151,55 +151,55 @@ struct TypeInfo // is expected. struct GenericType : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type { - private: - char productIdentifierValueBuffer[kProductIdentifierValueMaxNameLength]; - - public: - static constexpr bool kIsFabricScoped = false; - virtual ~GenericType() = default; - GenericType() {} - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) - { - setProductIdentifierType(aProductIdentifierType); - setProductIdentifierValue(aProductIdentifierValue); - } - - using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; +private: + char productIdentifierValueBuffer[kProductIdentifierValueMaxNameLength]; - /** - * Sets the product identifier type. - * - * @param aProductIdentifierType The product identifier type. - */ - void setProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) +public: + static constexpr bool kIsFabricScoped = false; + virtual ~GenericType() = default; + GenericType() {} + GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + setProductIdentifierType(aProductIdentifierType); + setProductIdentifierValue(aProductIdentifierValue); + } + + using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; + + /** + * Sets the product identifier type. + * + * @param aProductIdentifierType The product identifier type. + */ + void setProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) + { + productIdentifierType = static_cast(aProductIdentifierType); + } + + /** + * Sets the product identifier value. + * This implementation will copy the argument to the local implementation. + * + * @param aProductIdentifierValue The value of the product identifier to set. + * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid, CHIP_NO_ERROR otherwise. + */ + CHIP_ERROR setProductIdentifierValue(chip::CharSpan aProductIdentifierValue) + { + VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT); + + if (aProductIdentifierValue.size() > sizeof(productIdentifierValueBuffer)) { - productIdentifierType = static_cast(aProductIdentifierType); + memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), sizeof(productIdentifierValueBuffer)); + productIdentifierValue = CharSpan(productIdentifierValueBuffer, sizeof(productIdentifierValueBuffer)); } - - /** - * Sets the product identifier value. - * This implementation will copy the argument to the local implementation. - * - * @param aProductIdentifierValue The value of the product identifier to set. - * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid, CHIP_NO_ERROR otherwise. - */ - CHIP_ERROR setProductIdentifierValue(chip::CharSpan aProductIdentifierValue) + else { - VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT); - - if (aProductIdentifierValue.size() > sizeof(productIdentifierValueBuffer)) - { - memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), sizeof(productIdentifierValueBuffer)); - productIdentifierValue = CharSpan(productIdentifierValueBuffer, sizeof(productIdentifierValueBuffer)); - } - else - { - memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size()); - productIdentifierValue = CharSpan(productIdentifierValueBuffer, aProductIdentifierValue.size()); - } - - return CHIP_NO_ERROR; + memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size()); + productIdentifierValue = CharSpan(productIdentifierValueBuffer, aProductIdentifierValue.size()); } + + return CHIP_NO_ERROR; + } }; namespace ReplacementProductList { From 72a588aaf44b0be845ad353028c2623de7558c53 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jul 2023 21:09:23 +0000 Subject: [PATCH 09/33] Restyled by prettier-yaml --- src/app/tests/suites/TestResourceMonitor.yaml | 64 ++++++++++++++----- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/src/app/tests/suites/TestResourceMonitor.yaml b/src/app/tests/suites/TestResourceMonitor.yaml index 8a48e9a4b15268..901b1235478740 100644 --- a/src/app/tests/suites/TestResourceMonitor.yaml +++ b/src/app/tests/suites/TestResourceMonitor.yaml @@ -19,15 +19,30 @@ config: cluster: "Resource Monitor" endpoint: 1 ReplacementProductList: - type: "ReplacementProductStruct" - defaultValue: - [ - { ProductIdentifierType: 0, ProductIdentifierValue: "111112222233" }, - { ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xxx" }, - { ProductIdentifierType: 2, ProductIdentifierValue: "4444455555666" }, - { ProductIdentifierType: 3, ProductIdentifierValue: "gtin14xxxxxxxx" }, - { ProductIdentifierType: 4, ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx" }, - ] + type: "ReplacementProductStruct" + defaultValue: + [ + { + ProductIdentifierType: 0, + ProductIdentifierValue: "111112222233", + }, + { + ProductIdentifierType: 1, + ProductIdentifierValue: "gtin8xxx", + }, + { + ProductIdentifierType: 2, + ProductIdentifierValue: "4444455555666", + }, + { + ProductIdentifierType: 3, + ProductIdentifierValue: "gtin14xxxxxxxx", + }, + { + ProductIdentifierType: 4, + ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx", + }, + ] tests: - label: "Wait for the commissioned device to be retrieved" @@ -42,11 +57,26 @@ tests: command: "readAttribute" attribute: "ReplacementProductList" response: - value: - [ - { ProductIdentifierType: 0, ProductIdentifierValue: "111112222233" }, - { ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xxx" }, - { ProductIdentifierType: 2, ProductIdentifierValue: "4444455555666" }, - { ProductIdentifierType: 3, ProductIdentifierValue: "gtin14xxxxxxxx" }, - { ProductIdentifierType: 4, ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx" }, - ] + value: + [ + { + ProductIdentifierType: 0, + ProductIdentifierValue: "111112222233", + }, + { + ProductIdentifierType: 1, + ProductIdentifierValue: "gtin8xxx", + }, + { + ProductIdentifierType: 2, + ProductIdentifierValue: "4444455555666", + }, + { + ProductIdentifierType: 3, + ProductIdentifierValue: "gtin14xxxxxxxx", + }, + { + ProductIdentifierType: 4, + ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx", + }, + ] From 9de85181af1ea5ac4a5ecba960d02a1fa4e80a81 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 14:31:36 -0700 Subject: [PATCH 10/33] Adding Tests for ResourceMonitor to ci tests list --- .../TestActivatedCarbonFilterMonitoring.yaml | 50 +++++++++++++++++++ ...tor.yaml => TestHepaFilterMonitoring.yaml} | 2 +- src/app/tests/suites/ciTests.json | 2 + 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml rename src/app/tests/suites/{TestResourceMonitor.yaml => TestHepaFilterMonitoring.yaml} (98%) diff --git a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml new file mode 100644 index 00000000000000..5eca255f7539de --- /dev/null +++ b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml @@ -0,0 +1,50 @@ +# Copyright (c) 2021 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Resource Monitor Cluster Tests + +config: + nodeId: 0x12344321 + cluster: "Activated Carbon Filter Monitoring" + endpoint: 1 + ReplacementProductList: + type: "ReplacementProductStruct" + defaultValue: + [ + { + ProductIdentifierType: 1, + ProductIdentifierValue: "gtin8xac", + }, + ] + +tests: + - label: "Wait for the commissioned device to be retrieved" + cluster: "DelayCommands" + command: "WaitForCommissionee" + arguments: + values: + - name: "nodeId" + value: nodeId + + - label: "Read Replacement Product List" + command: "readAttribute" + attribute: "ReplacementProductList" + response: + value: + [ + { + ProductIdentifierType: 1, + ProductIdentifierValue: "gtin8xac", + }, + ] diff --git a/src/app/tests/suites/TestResourceMonitor.yaml b/src/app/tests/suites/TestHepaFilterMonitoring.yaml similarity index 98% rename from src/app/tests/suites/TestResourceMonitor.yaml rename to src/app/tests/suites/TestHepaFilterMonitoring.yaml index 901b1235478740..f6af00f533a3d7 100644 --- a/src/app/tests/suites/TestResourceMonitor.yaml +++ b/src/app/tests/suites/TestHepaFilterMonitoring.yaml @@ -16,7 +16,7 @@ name: Resource Monitor Cluster Tests config: nodeId: 0x12344321 - cluster: "Resource Monitor" + cluster: "HEPA Filter Monitoring" endpoint: 1 ReplacementProductList: type: "ReplacementProductStruct" diff --git a/src/app/tests/suites/ciTests.json b/src/app/tests/suites/ciTests.json index 377dd568b2aea0..a22aea164ddc76 100644 --- a/src/app/tests/suites/ciTests.json +++ b/src/app/tests/suites/ciTests.json @@ -303,6 +303,8 @@ ], "Scenes": ["Test_TC_S_1_1"], "ResourceMonitoring": [ + "TestActivatedCarbonFilterMonitoring", + "TestHepaFilterMonitoring", "Test_TC_ACFREMON_1_1", "Test_TC_ACFREMON_2_1", "Test_TC_HEPAFREMON_1_1", From 623b42cc1b82e47a7d339cfefa626db0e74843ac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 25 Jul 2023 21:52:00 +0000 Subject: [PATCH 11/33] Restyled by prettier-yaml --- .../TestActivatedCarbonFilterMonitoring.yaml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml index 5eca255f7539de..b7d3856dbcea45 100644 --- a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml +++ b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml @@ -21,12 +21,7 @@ config: ReplacementProductList: type: "ReplacementProductStruct" defaultValue: - [ - { - ProductIdentifierType: 1, - ProductIdentifierValue: "gtin8xac", - }, - ] + [{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }] tests: - label: "Wait for the commissioned device to be retrieved" @@ -42,9 +37,4 @@ tests: attribute: "ReplacementProductList" response: value: - [ - { - ProductIdentifierType: 1, - ProductIdentifierValue: "gtin8xac", - }, - ] + [{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }] From 399ff30b77819ef207dfda34475083cc938018ee Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 15:16:38 -0700 Subject: [PATCH 12/33] Adding newly generated zap files --- .../chip-tool/zap-generated/test/Commands.h | 214 ++++++++++++++ .../zap-generated/test/Commands.h | 273 ++++++++++++++++++ 2 files changed, 487 insertions(+) diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index ce0c3be66f3523..26be6ad6f1a24a 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -322,6 +322,8 @@ class TestList : public Command printf("TestGroupKeyManagementCluster\n"); printf("Test_TC_G_1_1\n"); printf("Test_TC_G_2_1\n"); + printf("TestActivatedCarbonFilterMonitoring\n"); + printf("TestHepaFilterMonitoring\n"); printf("Test_TC_ACFREMON_1_1\n"); printf("Test_TC_ACFREMON_2_1\n"); printf("Test_TC_HEPAFREMON_1_1\n"); @@ -113638,6 +113640,216 @@ class Test_TC_G_2_1Suite : public TestCommand } }; +class TestActivatedCarbonFilterMonitoringSuite : public TestCommand +{ +public: + TestActivatedCarbonFilterMonitoringSuite(CredentialIssuerCommands * credsIssuerConfig) : + TestCommand("TestActivatedCarbonFilterMonitoring", 2, credsIssuerConfig) + { + AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); + AddArgument("cluster", &mCluster); + AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); + AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); + AddArgument("timeout", 0, UINT16_MAX, &mTimeout); + } + + ~TestActivatedCarbonFilterMonitoringSuite() {} + + chip::System::Clock::Timeout GetWaitDuration() const override + { + return chip::System::Clock::Seconds16(mTimeout.ValueOr(kTimeoutInSeconds)); + } + +private: + chip::Optional mNodeId; + chip::Optional mCluster; + chip::Optional mEndpoint; + chip::Optional mReplacementProductList; + chip::Optional mTimeout; + + chip::EndpointId GetEndpoint(chip::EndpointId endpoint) { return mEndpoint.HasValue() ? mEndpoint.Value() : endpoint; } + + // + // Tests methods + // + + void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override + { + bool shouldContinue = false; + + switch (mTestIndex - 1) + { + case 0: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + shouldContinue = true; + break; + case 1: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + { + chip::app::DataModel::DecodableList< + chip::app::Clusters::ActivatedCarbonFilterMonitoring::Structs::ReplacementProductStruct::DecodableType> + value; + VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); + { + auto iter_0 = value.begin(); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 0)); + VerifyOrReturn( + CheckValue("replacementProductList[0].productIdentifierType", iter_0.GetValue().productIdentifierType, 1U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[0].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, chip::CharSpan("gtin8xac", 8))); + VerifyOrReturn(CheckNoMoreListItems("replacementProductList", iter_0, 1)); + } + } + break; + default: + LogErrorOnFailure(ContinueOnChipMainThread(CHIP_ERROR_INVALID_ARGUMENT)); + } + + if (shouldContinue) + { + ContinueOnChipMainThread(CHIP_NO_ERROR); + } + } + + CHIP_ERROR DoTestStep(uint16_t testIndex) override + { + using namespace chip::app::Clusters; + switch (testIndex) + { + case 0: { + LogStep(0, "Wait for the commissioned device to be retrieved"); + ListFreer listFreer; + chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type value; + value.nodeId = mNodeId.HasValue() ? mNodeId.Value() : 305414945ULL; + return WaitForCommissionee(kIdentityAlpha, value); + } + case 1: { + LogStep(1, "Read Replacement Product List"); + return ReadAttribute(kIdentityAlpha, GetEndpoint(1), ActivatedCarbonFilterMonitoring::Id, + ActivatedCarbonFilterMonitoring::Attributes::ReplacementProductList::Id, true, chip::NullOptional); + } + } + return CHIP_NO_ERROR; + } +}; + +class TestHepaFilterMonitoringSuite : public TestCommand +{ +public: + TestHepaFilterMonitoringSuite(CredentialIssuerCommands * credsIssuerConfig) : + TestCommand("TestHepaFilterMonitoring", 2, credsIssuerConfig) + { + AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); + AddArgument("cluster", &mCluster); + AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); + AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); + AddArgument("timeout", 0, UINT16_MAX, &mTimeout); + } + + ~TestHepaFilterMonitoringSuite() {} + + chip::System::Clock::Timeout GetWaitDuration() const override + { + return chip::System::Clock::Seconds16(mTimeout.ValueOr(kTimeoutInSeconds)); + } + +private: + chip::Optional mNodeId; + chip::Optional mCluster; + chip::Optional mEndpoint; + chip::Optional mReplacementProductList; + chip::Optional mTimeout; + + chip::EndpointId GetEndpoint(chip::EndpointId endpoint) { return mEndpoint.HasValue() ? mEndpoint.Value() : endpoint; } + + // + // Tests methods + // + + void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override + { + bool shouldContinue = false; + + switch (mTestIndex - 1) + { + case 0: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + shouldContinue = true; + break; + case 1: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + { + chip::app::DataModel::DecodableList< + chip::app::Clusters::HepaFilterMonitoring::Structs::ReplacementProductStruct::DecodableType> + value; + VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); + { + auto iter_0 = value.begin(); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 0)); + VerifyOrReturn( + CheckValue("replacementProductList[0].productIdentifierType", iter_0.GetValue().productIdentifierType, 0U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[0].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("111112222233", 12))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 1)); + VerifyOrReturn( + CheckValue("replacementProductList[1].productIdentifierType", iter_0.GetValue().productIdentifierType, 1U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[1].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, chip::CharSpan("gtin8xxx", 8))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 2)); + VerifyOrReturn( + CheckValue("replacementProductList[2].productIdentifierType", iter_0.GetValue().productIdentifierType, 2U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[2].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("4444455555666", 13))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 3)); + VerifyOrReturn( + CheckValue("replacementProductList[3].productIdentifierType", iter_0.GetValue().productIdentifierType, 3U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[3].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("gtin14xxxxxxxx", 14))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 4)); + VerifyOrReturn( + CheckValue("replacementProductList[4].productIdentifierType", iter_0.GetValue().productIdentifierType, 4U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[4].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("oem20xxxxxxxxxxxxxxx", 20))); + VerifyOrReturn(CheckNoMoreListItems("replacementProductList", iter_0, 5)); + } + } + break; + default: + LogErrorOnFailure(ContinueOnChipMainThread(CHIP_ERROR_INVALID_ARGUMENT)); + } + + if (shouldContinue) + { + ContinueOnChipMainThread(CHIP_NO_ERROR); + } + } + + CHIP_ERROR DoTestStep(uint16_t testIndex) override + { + using namespace chip::app::Clusters; + switch (testIndex) + { + case 0: { + LogStep(0, "Wait for the commissioned device to be retrieved"); + ListFreer listFreer; + chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type value; + value.nodeId = mNodeId.HasValue() ? mNodeId.Value() : 305414945ULL; + return WaitForCommissionee(kIdentityAlpha, value); + } + case 1: { + LogStep(1, "Read Replacement Product List"); + return ReadAttribute(kIdentityAlpha, GetEndpoint(1), HepaFilterMonitoring::Id, + HepaFilterMonitoring::Attributes::ReplacementProductList::Id, true, chip::NullOptional); + } + } + return CHIP_NO_ERROR; + } +}; + class Test_TC_ACFREMON_1_1Suite : public TestCommand { public: @@ -144946,6 +145158,8 @@ void registerCommandsTests(Commands & commands, CredentialIssuerCommands * creds make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), + make_unique(credsIssuerConfig), + make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), make_unique(credsIssuerConfig), diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 3d69b11871f7b8..2f9a3369643e46 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -286,6 +286,8 @@ class TestList : public Command { printf("TestGroupsCluster\n"); printf("TestGroupKeyManagementCluster\n"); printf("Test_TC_G_1_1\n"); + printf("TestActivatedCarbonFilterMonitoring\n"); + printf("TestHepaFilterMonitoring\n"); printf("Test_TC_ACFREMON_1_1\n"); printf("Test_TC_ACFREMON_2_1\n"); printf("Test_TC_HEPAFREMON_1_1\n"); @@ -172696,6 +172698,275 @@ class Test_TC_G_1_1 : public TestCommandBridge { } }; +class TestActivatedCarbonFilterMonitoring : public TestCommandBridge { +public: + // NOLINTBEGIN(clang-analyzer-nullability.NullPassedToNonnull): Test constructor nullability not enforced + TestActivatedCarbonFilterMonitoring() + : TestCommandBridge("TestActivatedCarbonFilterMonitoring") + , mTestIndex(0) + { + AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); + AddArgument("cluster", &mCluster); + AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); + AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); + AddArgument("timeout", 0, UINT16_MAX, &mTimeout); + } + // NOLINTEND(clang-analyzer-nullability.NullPassedToNonnull) + + ~TestActivatedCarbonFilterMonitoring() {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) { + ChipLogProgress(chipTool, " **** Test Start: TestActivatedCarbonFilterMonitoring\n"); + } + + if (mTestCount == mTestIndex) { + ChipLogProgress(chipTool, " **** Test Complete: TestActivatedCarbonFilterMonitoring\n"); + SetCommandExitStatus(CHIP_NO_ERROR); + return; + } + + Wait(); + + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) { + case 0: + ChipLogProgress(chipTool, " ***** Test Step 0 : Wait for the commissioned device to be retrieved\n"); + err = TestWaitForTheCommissionedDeviceToBeRetrieved_0(); + break; + case 1: + ChipLogProgress(chipTool, " ***** Test Step 1 : Read Replacement Product List\n"); + err = TestReadReplacementProductList_1(); + break; + } + + if (CHIP_NO_ERROR != err) { + ChipLogError(chipTool, " ***** Test Failure: %s\n", chip::ErrorStr(err)); + SetCommandExitStatus(err); + } + } + + void OnStatusUpdate(const chip::app::StatusIB & status) override + { + switch (mTestIndex - 1) { + case 0: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 1: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + } + + // Go on to the next test. + ContinueOnChipMainThread(CHIP_NO_ERROR); + } + + chip::System::Clock::Timeout GetWaitDuration() const override + { + return chip::System::Clock::Seconds16(mTimeout.ValueOr(kTimeoutInSeconds)); + } + +private: + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = 2; + + chip::Optional mNodeId; + chip::Optional mCluster; + chip::Optional mEndpoint; + chip::Optional mReplacementProductList; + chip::Optional mTimeout; + + CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrieved_0() + { + + chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type value; + value.nodeId = mNodeId.HasValue() ? mNodeId.Value() : 305414945ULL; + return WaitForCommissionee("alpha", value); + } + + CHIP_ERROR TestReadReplacementProductList_1() + { + + MTRBaseDevice * device = GetDevice("alpha"); + __auto_type * cluster = [[MTRBaseClusterActivatedCarbonFilterMonitoring alloc] initWithDevice:device + endpointID:@(1) + queue:mCallbackQueue]; + VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE); + + [cluster readAttributeReplacementProductListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable err) { + NSLog(@"Read Replacement Product List Error: %@", err); + + VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); + + { + id actualValue = value; + VerifyOrReturn(CheckValue("ReplacementProductList", [actualValue count], static_cast(1))); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierType, + 1U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierValue, + @"gtin8xac")); + } + + NextTest(); + }]; + + return CHIP_NO_ERROR; + } +}; + +class TestHepaFilterMonitoring : public TestCommandBridge { +public: + // NOLINTBEGIN(clang-analyzer-nullability.NullPassedToNonnull): Test constructor nullability not enforced + TestHepaFilterMonitoring() + : TestCommandBridge("TestHepaFilterMonitoring") + , mTestIndex(0) + { + AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); + AddArgument("cluster", &mCluster); + AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); + AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); + AddArgument("timeout", 0, UINT16_MAX, &mTimeout); + } + // NOLINTEND(clang-analyzer-nullability.NullPassedToNonnull) + + ~TestHepaFilterMonitoring() {} + + /////////// TestCommand Interface ///////// + void NextTest() override + { + CHIP_ERROR err = CHIP_NO_ERROR; + + if (0 == mTestIndex) { + ChipLogProgress(chipTool, " **** Test Start: TestHepaFilterMonitoring\n"); + } + + if (mTestCount == mTestIndex) { + ChipLogProgress(chipTool, " **** Test Complete: TestHepaFilterMonitoring\n"); + SetCommandExitStatus(CHIP_NO_ERROR); + return; + } + + Wait(); + + // Ensure we increment mTestIndex before we start running the relevant + // command. That way if we lose the timeslice after we send the message + // but before our function call returns, we won't end up with an + // incorrect mTestIndex value observed when we get the response. + switch (mTestIndex++) { + case 0: + ChipLogProgress(chipTool, " ***** Test Step 0 : Wait for the commissioned device to be retrieved\n"); + err = TestWaitForTheCommissionedDeviceToBeRetrieved_0(); + break; + case 1: + ChipLogProgress(chipTool, " ***** Test Step 1 : Read Replacement Product List\n"); + err = TestReadReplacementProductList_1(); + break; + } + + if (CHIP_NO_ERROR != err) { + ChipLogError(chipTool, " ***** Test Failure: %s\n", chip::ErrorStr(err)); + SetCommandExitStatus(err); + } + } + + void OnStatusUpdate(const chip::app::StatusIB & status) override + { + switch (mTestIndex - 1) { + case 0: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + case 1: + VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); + break; + } + + // Go on to the next test. + ContinueOnChipMainThread(CHIP_NO_ERROR); + } + + chip::System::Clock::Timeout GetWaitDuration() const override + { + return chip::System::Clock::Seconds16(mTimeout.ValueOr(kTimeoutInSeconds)); + } + +private: + std::atomic_uint16_t mTestIndex; + const uint16_t mTestCount = 2; + + chip::Optional mNodeId; + chip::Optional mCluster; + chip::Optional mEndpoint; + chip::Optional mReplacementProductList; + chip::Optional mTimeout; + + CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrieved_0() + { + + chip::app::Clusters::DelayCommands::Commands::WaitForCommissionee::Type value; + value.nodeId = mNodeId.HasValue() ? mNodeId.Value() : 305414945ULL; + return WaitForCommissionee("alpha", value); + } + + CHIP_ERROR TestReadReplacementProductList_1() + { + + MTRBaseDevice * device = GetDevice("alpha"); + __auto_type * cluster = [[MTRBaseClusterHEPAFilterMonitoring alloc] initWithDevice:device + endpointID:@(1) + queue:mCallbackQueue]; + VerifyOrReturnError(cluster != nil, CHIP_ERROR_INCORRECT_STATE); + + [cluster readAttributeReplacementProductListWithCompletion:^(NSArray * _Nullable value, NSError * _Nullable err) { + NSLog(@"Read Replacement Product List Error: %@", err); + + VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); + + { + id actualValue = value; + VerifyOrReturn(CheckValue("ReplacementProductList", [actualValue count], static_cast(5))); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierType, 0U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierValue, + @"111112222233")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[1]).productIdentifierType, 1U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[1]).productIdentifierValue, + @"gtin8xxx")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[2]).productIdentifierType, 2U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[2]).productIdentifierValue, + @"4444455555666")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[3]).productIdentifierType, 3U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[3]).productIdentifierValue, + @"gtin14xxxxxxxx")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[4]).productIdentifierType, 4U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRHEPAFilterMonitoringClusterReplacementProductStruct *) actualValue[4]).productIdentifierValue, + @"oem20xxxxxxxxxxxxxxx")); + } + + NextTest(); + }]; + + return CHIP_NO_ERROR; + } +}; + class Test_TC_ACFREMON_1_1 : public TestCommandBridge { public: // NOLINTBEGIN(clang-analyzer-nullability.NullPassedToNonnull): Test constructor nullability not enforced @@ -174471,6 +174742,8 @@ void registerCommandsTests(Commands & commands) make_unique(), make_unique(), make_unique(), + make_unique(), + make_unique(), make_unique(), make_unique(), make_unique(), From 73e8a9542f5161634c97c28602b9272ebb95e2c4 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 25 Jul 2023 11:07:22 +0100 Subject: [PATCH 13/33] Replaced the use of std::set with IntrusiveList in ModeBase. (#28163) * Replaced the use of std::set with IntrusiveList in ModeBase. * Removed the std::set exeption for ModeBase. * Restyled by clang-format * Refoctor from review. * Added a way to gracefully shutdown the ModeBase dreived clusters and used it in the linux all-clusters-app. * Restyled by whitespace * Restyled by clang-format * Implemented required ApplicationExit(). * Restyled by clang-format * Modified the ModeBase example shutdowns to be safe if Shutdown is called twice and properly free the memory. * Renamed ApplicationExit() to ApplicationShutdown() * Apply documentation suggestions from code review Co-authored-by: Boris Zbarsky --------- Co-authored-by: Restyled.io Co-authored-by: Boris Zbarsky --- .../include/dishwasher-mode.h | 2 ++ .../include/laundry-washer-mode.h | 2 ++ .../all-clusters-common/include/rvc-modes.h | 4 +++ .../all-clusters-common/include/tcc-mode.h | 2 ++ .../src/dishwasher-mode.cpp | 14 +++++++++- .../src/laundry-washer-mode.cpp | 13 ++++++++++ .../all-clusters-common/src/rvc-modes.cpp | 26 +++++++++++++++++++ .../all-clusters-common/src/tcc-mode.cpp | 13 ++++++++++ .../all-clusters-app/linux/main-common.cpp | 10 +++++-- examples/all-clusters-app/linux/main-common.h | 21 --------------- examples/all-clusters-app/linux/main.cpp | 2 -- examples/all-clusters-app/tizen/src/main.cpp | 2 ++ .../linux/main-common.cpp | 2 ++ .../tizen/src/main.cpp | 2 ++ examples/bridge-app/linux/main.cpp | 2 ++ examples/chef/linux/main.cpp | 2 ++ examples/contact-sensor-app/linux/main.cpp | 2 ++ examples/dishwasher-app/linux/main.cpp | 2 ++ examples/lighting-app/linux/main.cpp | 2 +- examples/lighting-app/tizen/src/main.cpp | 2 ++ examples/lock-app/linux/main.cpp | 2 ++ examples/ota-provider-app/linux/main.cpp | 2 ++ examples/ota-requestor-app/linux/main.cpp | 2 ++ examples/placeholder/linux/main.cpp | 2 ++ examples/platform/linux/AppMain.cpp | 2 ++ examples/platform/linux/AppMain.h | 3 +++ .../linux/src/main.cpp | 2 ++ examples/thermostat/linux/main.cpp | 2 ++ examples/tv-app/linux/main.cpp | 2 ++ scripts/tools/check_includes_config.py | 3 --- .../mode-base-server/mode-base-server.cpp | 22 ++++++++++++---- .../mode-base-server/mode-base-server.h | 21 ++++++++++++--- .../clusters/on-off-server/on-off-server.cpp | 10 +++---- 33 files changed, 158 insertions(+), 44 deletions(-) delete mode 100644 examples/all-clusters-app/linux/main-common.h diff --git a/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h b/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h index 51a5ab5d0d80d8..54d78c56b23132 100644 --- a/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h +++ b/examples/all-clusters-app/all-clusters-common/include/dishwasher-mode.h @@ -69,6 +69,8 @@ class DishwasherModeDelegate : public ModeBase::Delegate ~DishwasherModeDelegate() override = default; }; +void Shutdown(); + } // namespace DishwasherMode } // namespace Clusters diff --git a/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h index 06fffda82d99b1..f8acce69295f46 100644 --- a/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h +++ b/examples/all-clusters-app/all-clusters-common/include/laundry-washer-mode.h @@ -74,6 +74,8 @@ class LaundryWasherModeDelegate : public ModeBase::Delegate ~LaundryWasherModeDelegate() override = default; }; +void Shutdown(); + } // namespace LaundryWasherMode } // namespace Clusters diff --git a/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h b/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h index 3e2841654fb5e5..b8e7e13cf2c6ee 100644 --- a/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h +++ b/examples/all-clusters-app/all-clusters-common/include/rvc-modes.h @@ -66,6 +66,8 @@ class RvcRunModeDelegate : public ModeBase::Delegate ~RvcRunModeDelegate() override = default; }; +void Shutdown(); + } // namespace RvcRunMode namespace RvcCleanMode { @@ -107,6 +109,8 @@ class RvcCleanModeDelegate : public ModeBase::Delegate ~RvcCleanModeDelegate() override = default; }; +void Shutdown(); + } // namespace RvcCleanMode } // namespace Clusters diff --git a/examples/all-clusters-app/all-clusters-common/include/tcc-mode.h b/examples/all-clusters-app/all-clusters-common/include/tcc-mode.h index 7294fac8cbccd8..dcd9024e8d0385 100644 --- a/examples/all-clusters-app/all-clusters-common/include/tcc-mode.h +++ b/examples/all-clusters-app/all-clusters-common/include/tcc-mode.h @@ -67,6 +67,8 @@ class TccModeDelegate : public ModeBase::Delegate ~TccModeDelegate() override = default; }; +void Shutdown(); + } // namespace RefrigeratorAndTemperatureControlledCabinetMode } // namespace Clusters diff --git a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp index 845ecb6d32a8a9..c96ec297a2e2d2 100644 --- a/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp @@ -76,12 +76,24 @@ CHIP_ERROR DishwasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List~DishwasherModeDelegate(); + } +} + void emberAfDishwasherModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gDishwasherModeDelegate == nullptr && gDishwasherModeInstance == nullptr); gDishwasherModeDelegate = new DishwasherMode::DishwasherModeDelegate; - // todo use Clusters::XxxMode::Feature::kXxxx to set features. gDishwasherModeInstance = new ModeBase::Instance(gDishwasherModeDelegate, 0x1, DishwasherMode::Id, chip::to_underlying(Feature::kOnOff)); gDishwasherModeInstance->Init(); diff --git a/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp index 3cc44deee84878..9d05b4b58850e0 100644 --- a/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/laundry-washer-mode.cpp @@ -75,6 +75,19 @@ CHIP_ERROR LaundryWasherModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List return CHIP_NO_ERROR; } +void LaundryWasherMode::Shutdown() +{ + if (gLaundryWasherModeInstance != nullptr) + { + delete gLaundryWasherModeInstance; + gLaundryWasherModeInstance = nullptr; + } + if (gLaundryWasherModeDelegate != nullptr) + { + gLaundryWasherModeDelegate->~LaundryWasherModeDelegate(); + } +} + void emberAfLaundryWasherModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. diff --git a/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp b/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp index 36a2fd7204a77c..9a95054c26f8ab 100644 --- a/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/rvc-modes.cpp @@ -88,6 +88,19 @@ CHIP_ERROR RvcRunModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List~RvcRunModeDelegate(); + } +} + void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. @@ -158,6 +171,19 @@ CHIP_ERROR RvcCleanModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List~RvcCleanModeDelegate(); + } +} + void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. diff --git a/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp b/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp index 704e5b17be22cb..30b8c03075e2ea 100644 --- a/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp @@ -75,6 +75,19 @@ CHIP_ERROR TccModeDelegate::GetModeTagsByIndex(uint8_t modeIndex, List~TccModeDelegate(); + } +} + void emberAfRefrigeratorAndTemperatureControlledCabinetModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. diff --git a/examples/all-clusters-app/linux/main-common.cpp b/examples/all-clusters-app/linux/main-common.cpp index 0ebeff439e9dc2..727bddb955056b 100644 --- a/examples/all-clusters-app/linux/main-common.cpp +++ b/examples/all-clusters-app/linux/main-common.cpp @@ -16,7 +16,6 @@ * limitations under the License. */ -#include "main-common.h" #include "AllClustersCommandDelegate.h" #include "WindowCoveringManager.h" #include "dishwasher-mode.h" @@ -191,8 +190,15 @@ void ApplicationInit() app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate); } -void ApplicationExit() +void ApplicationShutdown() { + // These may have been initialised via the emberAfXxxClusterInitCallback methods. We need to destroy them before shutdown. + Clusters::DishwasherMode::Shutdown(); + Clusters::LaundryWasherMode::Shutdown(); + Clusters::RvcCleanMode::Shutdown(); + Clusters::RvcRunMode::Shutdown(); + Clusters::RefrigeratorAndTemperatureControlledCabinetMode::Shutdown(); + if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR) { ChipLogError(NotSpecified, "Failed to stop CHIP NamedPipeCommands"); diff --git a/examples/all-clusters-app/linux/main-common.h b/examples/all-clusters-app/linux/main-common.h deleted file mode 100644 index d6e076b4416798..00000000000000 --- a/examples/all-clusters-app/linux/main-common.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -void ApplicationExit(); diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp index c9d829ba423e44..cd1e88c87e3108 100644 --- a/examples/all-clusters-app/linux/main.cpp +++ b/examples/all-clusters-app/linux/main.cpp @@ -19,7 +19,6 @@ #include "AppMain.h" #include "AppOptions.h" #include "binding-handler.h" -#include "main-common.h" // Network commissioning namespace { @@ -35,7 +34,6 @@ int main(int argc, char * argv[]) LinuxDeviceOptions::GetInstance().dacProvider = AppOptions::GetDACProvider(); ChipLinuxAppMainLoop(); - ApplicationExit(); return 0; } diff --git a/examples/all-clusters-app/tizen/src/main.cpp b/examples/all-clusters-app/tizen/src/main.cpp index b7e3a501df17b3..e3e8aa736846fc 100644 --- a/examples/all-clusters-app/tizen/src/main.cpp +++ b/examples/all-clusters-app/tizen/src/main.cpp @@ -51,6 +51,8 @@ void ApplicationInit() app::Clusters::TemperatureControl::SetInstance(&sAppSupportedTemperatureLevelsDelegate); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { TizenServiceAppMain app; diff --git a/examples/all-clusters-minimal-app/linux/main-common.cpp b/examples/all-clusters-minimal-app/linux/main-common.cpp index 698e1400b8e2b7..a6fd0a9866220e 100644 --- a/examples/all-clusters-minimal-app/linux/main-common.cpp +++ b/examples/all-clusters-minimal-app/linux/main-common.cpp @@ -84,6 +84,8 @@ static Identify gIdentify1 = { void ApplicationInit() {} +void ApplicationShutdown() {} + void emberAfLowPowerClusterInitCallback(EndpointId endpoint) { ChipLogProgress(Zcl, "TV Linux App: LowPower::SetDefaultDelegate"); diff --git a/examples/all-clusters-minimal-app/tizen/src/main.cpp b/examples/all-clusters-minimal-app/tizen/src/main.cpp index adeb8735752332..327623911831bb 100644 --- a/examples/all-clusters-minimal-app/tizen/src/main.cpp +++ b/examples/all-clusters-minimal-app/tizen/src/main.cpp @@ -47,6 +47,8 @@ void ApplicationInit() sEthernetNetworkCommissioningInstance.Init(); } +void ApplicationShutdown(){}; + int main(int argc, char * argv[]) { TizenServiceAppMain app; diff --git a/examples/bridge-app/linux/main.cpp b/examples/bridge-app/linux/main.cpp index 382ff7fe456de0..32930d7133db77 100644 --- a/examples/bridge-app/linux/main.cpp +++ b/examples/bridge-app/linux/main.cpp @@ -741,6 +741,8 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj void ApplicationInit() {} +void ApplicationShutdown() {} + const EmberAfDeviceType gBridgedOnOffDeviceTypes[] = { { DEVICE_TYPE_LO_ON_OFF_LIGHT, DEVICE_VERSION_DEFAULT }, { DEVICE_TYPE_BRIDGED_NODE, DEVICE_VERSION_DEFAULT } }; diff --git a/examples/chef/linux/main.cpp b/examples/chef/linux/main.cpp index 57e5273d5a58d2..9b15ae9cba6582 100644 --- a/examples/chef/linux/main.cpp +++ b/examples/chef/linux/main.cpp @@ -32,6 +32,8 @@ using namespace chip::app; void ApplicationInit() {} +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { if (ChipLinuxAppInit(argc, argv) != 0) diff --git a/examples/contact-sensor-app/linux/main.cpp b/examples/contact-sensor-app/linux/main.cpp index b72cd7f755ab46..fcc56d7c3d02a4 100644 --- a/examples/contact-sensor-app/linux/main.cpp +++ b/examples/contact-sensor-app/linux/main.cpp @@ -33,6 +33,8 @@ using namespace chip::app::Clusters; void ApplicationInit() {} +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); diff --git a/examples/dishwasher-app/linux/main.cpp b/examples/dishwasher-app/linux/main.cpp index 080df313425cba..54e320ffc9e14c 100644 --- a/examples/dishwasher-app/linux/main.cpp +++ b/examples/dishwasher-app/linux/main.cpp @@ -32,6 +32,8 @@ void ApplicationInit() MatterOperationalStateServerInit(); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { if (ChipLinuxAppInit(argc, argv) != 0) diff --git a/examples/lighting-app/linux/main.cpp b/examples/lighting-app/linux/main.cpp index 5689a0cd68979c..3bd27fddc0f95a 100644 --- a/examples/lighting-app/linux/main.cpp +++ b/examples/lighting-app/linux/main.cpp @@ -85,7 +85,7 @@ void ApplicationInit() } } -void ApplicationExit() +void ApplicationShutdown() { if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR) { diff --git a/examples/lighting-app/tizen/src/main.cpp b/examples/lighting-app/tizen/src/main.cpp index e69bc25fdc1c7a..8f0bafaec72e31 100644 --- a/examples/lighting-app/tizen/src/main.cpp +++ b/examples/lighting-app/tizen/src/main.cpp @@ -52,6 +52,8 @@ void ApplicationInit() #endif } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { TizenServiceAppMain app; diff --git a/examples/lock-app/linux/main.cpp b/examples/lock-app/linux/main.cpp index 5031fda7db3755..bf4f485758485a 100644 --- a/examples/lock-app/linux/main.cpp +++ b/examples/lock-app/linux/main.cpp @@ -43,6 +43,8 @@ void ApplicationInit() } } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); diff --git a/examples/ota-provider-app/linux/main.cpp b/examples/ota-provider-app/linux/main.cpp index 71b8630cdb2e48..15d8ecdf55feea 100644 --- a/examples/ota-provider-app/linux/main.cpp +++ b/examples/ota-provider-app/linux/main.cpp @@ -380,6 +380,8 @@ void ApplicationInit() chip::app::Clusters::OTAProvider::SetDelegate(kOtaProviderEndpoint, &gOtaProvider); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv, &cmdLineOptions) == 0); diff --git a/examples/ota-requestor-app/linux/main.cpp b/examples/ota-requestor-app/linux/main.cpp index 355f5c2c133e87..50cf24191a5a98 100644 --- a/examples/ota-requestor-app/linux/main.cpp +++ b/examples/ota-requestor-app/linux/main.cpp @@ -255,6 +255,8 @@ void ApplicationInit() InitOTARequestor(); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv, &cmdLineOptions, MakeOptional(kNetworkCommissioningEndpointSecondary)) == 0); diff --git a/examples/placeholder/linux/main.cpp b/examples/placeholder/linux/main.cpp index 610e7b65dc1ae3..11f7529e07aa03 100644 --- a/examples/placeholder/linux/main.cpp +++ b/examples/placeholder/linux/main.cpp @@ -22,6 +22,8 @@ void ApplicationInit() {} +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv, AppOptions::GetOptions()) == 0); diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index ac97e6104417b3..22ff4d2db71cb6 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -578,6 +578,8 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl) } gMainLoopImplementation = nullptr; + ApplicationShutdown(); + #if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE ShutdownCommissioner(); #endif // CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE diff --git a/examples/platform/linux/AppMain.h b/examples/platform/linux/AppMain.h index 759b5da6eb4b3f..94bf4d3e609da1 100644 --- a/examples/platform/linux/AppMain.h +++ b/examples/platform/linux/AppMain.h @@ -103,3 +103,6 @@ CommissionerDiscoveryController * GetCommissionerDiscoveryController(); // For extra init calls, the function will be called right before running Matter main loop. void ApplicationInit(); + +// For extra shutdown calls, the function will be called before any of the core Matter objects are shut down. +void ApplicationShutdown(); diff --git a/examples/resource-monitoring-app/linux/src/main.cpp b/examples/resource-monitoring-app/linux/src/main.cpp index 6e515b7ea5845c..dd6e1231d6a9e2 100644 --- a/examples/resource-monitoring-app/linux/src/main.cpp +++ b/examples/resource-monitoring-app/linux/src/main.cpp @@ -48,6 +48,8 @@ void ApplicationInit() gActivatedCarbonFilterInstance.Init(); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { if (ChipLinuxAppInit(argc, argv) != 0) diff --git a/examples/thermostat/linux/main.cpp b/examples/thermostat/linux/main.cpp index c039b4cd1902d5..77de93055e3aa0 100644 --- a/examples/thermostat/linux/main.cpp +++ b/examples/thermostat/linux/main.cpp @@ -71,6 +71,8 @@ static Identify gIdentify1 = { void ApplicationInit() {} +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); diff --git a/examples/tv-app/linux/main.cpp b/examples/tv-app/linux/main.cpp index ffdd5e00bc5513..859b3f47284929 100644 --- a/examples/tv-app/linux/main.cpp +++ b/examples/tv-app/linux/main.cpp @@ -47,6 +47,8 @@ void ApplicationInit() // emberAfEndpointEnableDisable(3, false); } +void ApplicationShutdown() {} + int main(int argc, char * argv[]) { diff --git a/scripts/tools/check_includes_config.py b/scripts/tools/check_includes_config.py index fba3a095e74a6d..cb1f4e1062fb26 100644 --- a/scripts/tools/check_includes_config.py +++ b/scripts/tools/check_includes_config.py @@ -158,7 +158,4 @@ # Library meant for non-embedded 'src/tracing/json/json_tracing.cpp': {'string', 'sstream'}, 'src/tracing/json/json_tracing.h': {'fstream'}, - - # Temporary solution util the OnOff server can provide a callback API for state change. - 'src/app/clusters/mode-base-server/mode-base-server.h': {'set'} } diff --git a/src/app/clusters/mode-base-server/mode-base-server.cpp b/src/app/clusters/mode-base-server/mode-base-server.cpp index ac85ccb9941ec9..f4ec6a46ec7581 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.cpp +++ b/src/app/clusters/mode-base-server/mode-base-server.cpp @@ -38,6 +38,19 @@ namespace app { namespace Clusters { namespace ModeBase { +void Instance::RegisterInstance() +{ + if (!gModeBaseAliasesInstances.Contains(this)) + { + gModeBaseAliasesInstances.PushBack(this); + } +} + +void Instance::UnregisterInstance() +{ + gModeBaseAliasesInstances.Remove(this); +} + bool Instance::HasFeature(Feature feature) const { return (mFeature & to_underlying(feature)) != 0; @@ -137,10 +150,9 @@ CHIP_ERROR Instance::Init() ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(this)); VerifyOrReturnError(registerAttributeAccessOverride(this), CHIP_ERROR_INCORRECT_STATE); + RegisterInstance(); ReturnErrorOnFailure(mDelegate->Init()); - ModeBaseAliasesInstances.insert(this); - // If the StartUpMode is set, the CurrentMode attribute SHALL be set to the StartUpMode value, when the server is powered up. if (!mStartUpMode.IsNull()) { @@ -476,14 +488,14 @@ Instance::Instance(Delegate * aDelegate, EndpointId aEndpointId, ClusterId aClus Instance::~Instance() { - ModeBaseAliasesInstances.erase(this); + UnregisterInstance(); chip::app::InteractionModelEngine::GetInstance()->UnregisterCommandHandler(this); unregisterAttributeAccessOverride(this); } -std::set * GetModeBaseInstances() +IntrusiveList & GetModeBaseInstanceList() { - return &ModeBaseAliasesInstances; + return gModeBaseAliasesInstances; } } // namespace ModeBase diff --git a/src/app/clusters/mode-base-server/mode-base-server.h b/src/app/clusters/mode-base-server/mode-base-server.h index 617fd262ba8515..3e1b77bcbf7e2a 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.h +++ b/src/app/clusters/mode-base-server/mode-base-server.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace chip { namespace app { @@ -32,7 +32,7 @@ namespace ModeBase { class Delegate; -class Instance : public CommandHandlerInterface, public AttributeAccessInterface +class Instance : public CommandHandlerInterface, public AttributeAccessInterface, public IntrusiveListNodeBase<> { private: Delegate * mDelegate; @@ -55,6 +55,16 @@ class Instance : public CommandHandlerInterface, public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; CHIP_ERROR Write(const ConcreteDataAttributePath & aPath, AttributeValueDecoder & aDecoder) override; + /** + * Register this ModeBase instance. + */ + void RegisterInstance(); + + /** + * Unregister this ModeBase instance. + */ + void UnregisterInstance(); + /** * Internal change-to-mode command handler function. */ @@ -229,9 +239,12 @@ class Delegate // A set of pointers to all initialised ModeBase instances. It provides a way to access all ModeBase derived clusters. // todo change once there is a clear public interface for the OnOff cluster data dependencies (#27508) -static std::set ModeBaseAliasesInstances; +static IntrusiveList gModeBaseAliasesInstances; -std::set * GetModeBaseInstances(); +// This does not return a refernce to const IntrusiveList, because the caller might need +// to change the state of the instances in the list and const IntrusiveList only allows +// access to const Instance. +IntrusiveList & GetModeBaseInstanceList(); } // namespace ModeBase } // namespace Clusters diff --git a/src/app/clusters/on-off-server/on-off-server.cpp b/src/app/clusters/on-off-server/on-off-server.cpp index eb1c320b800da6..440ea0a471fa30 100644 --- a/src/app/clusters/on-off-server/on-off-server.cpp +++ b/src/app/clusters/on-off-server/on-off-server.cpp @@ -60,16 +60,16 @@ namespace { */ void UpdateModeBaseCurrentModeToOnMode(EndpointId endpoint) { - for (const auto & modeBaseInstance : *ModeBase::GetModeBaseInstances()) + for (auto & modeBaseInstance : ModeBase::GetModeBaseInstanceList()) { - if (modeBaseInstance->GetEndpointId() == endpoint) + if (modeBaseInstance.GetEndpointId() == endpoint) { - if (modeBaseInstance->HasFeature(ModeBase::Feature::kOnOff)) + if (modeBaseInstance.HasFeature(ModeBase::Feature::kOnOff)) { - ModeBase::Attributes::OnMode::TypeInfo::Type onMode = modeBaseInstance->GetOnMode(); + ModeBase::Attributes::OnMode::TypeInfo::Type onMode = modeBaseInstance.GetOnMode(); if (!onMode.IsNull()) { - Status status = modeBaseInstance->UpdateCurrentMode(onMode.Value()); + Status status = modeBaseInstance.UpdateCurrentMode(onMode.Value()); if (status == Status::Success) { ChipLogProgress(Zcl, "Changed the Current Mode to %x", onMode.Value()); From 1c2f26ddc694ec0d0053a2740a88637d6d0ae633 Mon Sep 17 00:00:00 2001 From: manjunath-grl <102359958+manjunath-grl@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:02:27 +0530 Subject: [PATCH 14/33] Remove unwanted "\" at line 156 from DA-1.4 test (#28252) --- src/app/tests/suites/certification/Test_TC_DA_1_4.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/tests/suites/certification/Test_TC_DA_1_4.yaml b/src/app/tests/suites/certification/Test_TC_DA_1_4.yaml index 7795144645bc41..db416d3c119f35 100644 --- a/src/app/tests/suites/certification/Test_TC_DA_1_4.yaml +++ b/src/app/tests/suites/certification/Test_TC_DA_1_4.yaml @@ -153,7 +153,7 @@ tests: verification: | "The all-cluster-app in the sample application is not a certified commissionee (Certification Declaration has certification_type 0). Launch all-cluster-app on TH raspi and provision the app using the DUT " - disabled: true\ + disabled: true - label: "Verify that DUT notifies a warning stating that Commissionee is not a From baa4eb0c58e99f2249269ace13b1d55fb80814ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20M=C3=B8ller?= Date: Tue, 25 Jul 2023 07:09:33 -0700 Subject: [PATCH 15/33] Remove zap development install. (#28223) `zap` is now available as arm64 binaries, and bootstrap will take care of installing it. --- .../docker/images/chip-cert-bins/Dockerfile | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/integrations/docker/images/chip-cert-bins/Dockerfile b/integrations/docker/images/chip-cert-bins/Dockerfile index 18ebd7263fc701..47d7cc0b606742 100644 --- a/integrations/docker/images/chip-cert-bins/Dockerfile +++ b/integrations/docker/images/chip-cert-bins/Dockerfile @@ -5,11 +5,6 @@ ARG TARGETPLATFORM # COMMITHASH defines the target commit to build from. May be passed in using --build-arg. ARG COMMITHASH=7b99e6399c6069037c613782d78132c69b9dcabb -# ZAP Development install, so that it runs on both x64 and arm64 -# Generally this should match with the ZAP version that is used for codegen within the -# specified SHA -ARG ZAP_VERSION=v2023.07.21-nightly - # Ensure TARGETPLATFORM is set RUN case ${TARGETPLATFORM} in \ "linux/amd64") \ @@ -157,45 +152,6 @@ RUN set -x \ && rm -rf bloaty \ && : # last line -# NodeJS: install a newer version than what apt-get would read -# This installs the latest LTS version of nodejs -RUN case ${TARGETPLATFORM} in \ - "linux/amd64") \ - set -x \ - && mkdir node_js \ - && cd node_js \ - && wget https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz \ - && tar xfvJ node-v12.22.12-linux-x64.tar.xz \ - && mv node-v12.22.12-linux-x64 /opt/ \ - && ln -s /opt/node-v12.22.12-linux-x64 /opt/node \ - && ln -s /opt/node/bin/* /usr/bin \ - && cd .. \ - && rm -rf node_js \ - ;; \ - "linux/arm64")\ - set -x \ - && mkdir node_js \ - && cd node_js \ - && wget https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-arm64.tar.xz \ - && tar xfvJ node-v12.22.12-linux-arm64.tar.xz \ - && mv node-v12.22.12-linux-arm64 /opt/ \ - && ln -s /opt/node-v12.22.12-linux-arm64 /opt/node \ - && ln -s /opt/node/bin/* /usr/bin \ - && cd .. \ - && rm -rf node_js \ - ;; \ - *) ;; \ - esac - -RUN set -x \ - && mkdir -p /opt/zap-${ZAP_VERSION} \ - && git clone https://github.com/project-chip/zap.git /opt/zap-${ZAP_VERSION} \ - && cd /opt/zap-${ZAP_VERSION} \ - && git checkout ${ZAP_VERSION} \ - && npm config set user 0 \ - && npm ci -ENV ZAP_DEVELOPMENT_PATH=/opt/zap-${ZAP_VERSION} - # Stage 1.5: Bootstrap Matter. RUN mkdir /root/connectedhomeip RUN git clone https://github.com/project-chip/connectedhomeip.git /root/connectedhomeip From b598ad6ae437f06c436654dd9e95a83ea62aaf0a Mon Sep 17 00:00:00 2001 From: mideayanghui <106149377+mideayanghui@users.noreply.github.com> Date: Tue, 25 Jul 2023 22:12:46 +0800 Subject: [PATCH 16/33] [feature]Add dishwasher-app example for ASR platform (#28207) * Add dishwasher-app example for ASR platform * Restyled by clang-format * Restyled by gn * remove unuseful macro * update document * fix CI build error * delete unuseful code * remove chip:: prefixed * Restyled by whitespace * Restyled by clang-format --------- Co-authored-by: Restyled.io --- examples/dishwasher-app/asr/.gn | 29 ++++ examples/dishwasher-app/asr/BUILD.gn | 131 ++++++++++++++++++ examples/dishwasher-app/asr/args.gni | 27 ++++ examples/dishwasher-app/asr/build_overrides | 1 + examples/dishwasher-app/asr/cfg.gni | 23 +++ .../dishwasher-app/asr/include/AppConfig.h | 45 ++++++ examples/dishwasher-app/asr/include/AppTask.h | 43 ++++++ .../asr/include/CHIPProjectConfig.h | 111 +++++++++++++++ .../asr/include/DeviceCallbacks.h | 40 ++++++ examples/dishwasher-app/asr/src/AppTask.cpp | 112 +++++++++++++++ .../asr/src/DeviceCallbacks.cpp | 122 ++++++++++++++++ examples/dishwasher-app/asr/src/main.cpp | 92 ++++++++++++ .../asr/third_party/connectedhomeip | 1 + scripts/build/build/targets.py | 1 + scripts/build/builders/asr.py | 5 + .../build/testdata/all_targets_linux_x64.txt | 2 +- 16 files changed, 784 insertions(+), 1 deletion(-) create mode 100755 examples/dishwasher-app/asr/.gn create mode 100755 examples/dishwasher-app/asr/BUILD.gn create mode 100755 examples/dishwasher-app/asr/args.gni create mode 120000 examples/dishwasher-app/asr/build_overrides create mode 100755 examples/dishwasher-app/asr/cfg.gni create mode 100644 examples/dishwasher-app/asr/include/AppConfig.h create mode 100644 examples/dishwasher-app/asr/include/AppTask.h create mode 100755 examples/dishwasher-app/asr/include/CHIPProjectConfig.h create mode 100644 examples/dishwasher-app/asr/include/DeviceCallbacks.h create mode 100644 examples/dishwasher-app/asr/src/AppTask.cpp create mode 100644 examples/dishwasher-app/asr/src/DeviceCallbacks.cpp create mode 100644 examples/dishwasher-app/asr/src/main.cpp create mode 120000 examples/dishwasher-app/asr/third_party/connectedhomeip diff --git a/examples/dishwasher-app/asr/.gn b/examples/dishwasher-app/asr/.gn new file mode 100755 index 00000000000000..8d75f1eafcdb89 --- /dev/null +++ b/examples/dishwasher-app/asr/.gn @@ -0,0 +1,29 @@ +# Copyright (c) 2023 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/build.gni") + +# The location of the build configuration file. +buildconfig = "${build_root}/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +default_args = { + target_cpu = "arm" + + target_os = "freertos" + + import("//args.gni") +} diff --git a/examples/dishwasher-app/asr/BUILD.gn b/examples/dishwasher-app/asr/BUILD.gn new file mode 100755 index 00000000000000..2b0cc1ef7507df --- /dev/null +++ b/examples/dishwasher-app/asr/BUILD.gn @@ -0,0 +1,131 @@ +# Copyright (c) 2023 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/asr.gni") +import("//build_overrides/build.gni") +import("//build_overrides/chip.gni") +import("${asr_sdk_build_root}/asr_sdk.gni") +import("${build_root}/config/defaults.gni") +import("${chip_root}/src/lib/lib.gni") +import("${chip_root}/src/platform/device.gni") +import("${chip_root}/third_party/asr/asr_executable.gni") + +import("cfg.gni") + +assert(current_os == "freertos") + +asr_project_dir = "${chip_root}/examples/dishwasher-app/asr" +examples_plat_dir = "${chip_root}/examples/platform/asr" + +declare_args() { + # Dump memory usage at link time. + chip_print_memory_usage = false +} + +asr_sdk_sources("dishwasher_app_sdk_sources") { + include_dirs = [ + "${chip_root}/src/platform/ASR", + "${asr_project_dir}/include", + "${examples_plat_dir}", + ] + + defines = [ + "ASR_LOG_ENABLED=1", + "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE=${setupPinCode}", + "CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR=${setupDiscriminator}", + ] + + if (chip_enable_factory_data) { + defines += [ + "CONFIG_ENABLE_ASR_FACTORY_DATA_PROVIDER=1", + "CONFIG_ENABLE_ASR_FACTORY_DEVICE_INFO_PROVIDER=1", + ] + } + + if (chip_lwip_ip6_hook) { + defines += [ + "CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT", + "CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT", + ] + } + + sources = [ "${asr_project_dir}/include/CHIPProjectConfig.h" ] + + public_configs = [ "${asr_sdk_build_root}:asr_sdk_config" ] +} + +asr_executable("dishwasher_app") { + include_dirs = [] + defines = [] + output_name = "chip-asr-dishwasher-example.out" + + sources = [ + "${chip_root}/examples/dishwasher-app/dishwasher-common/src/operational-state-delegate-impl.cpp", + "${chip_root}/examples/dishwasher-app/dishwasher-common/src/operational-state-delegates.cpp", + "${examples_plat_dir}/CHIPDeviceManager.cpp", + "${examples_plat_dir}/LEDWidget.cpp", + "${examples_plat_dir}/init_Matter.cpp", + "${examples_plat_dir}/init_asrPlatform.cpp", + "${examples_plat_dir}/shell/matter_shell.cpp", + "src/AppTask.cpp", + "src/DeviceCallbacks.cpp", + "src/main.cpp", + ] + + if (chip_enable_ota_requestor) { + sources += [ "${examples_plat_dir}/init_OTARequestor.cpp" ] + } + + deps = [ + ":dishwasher_app_sdk_sources", + "${chip_root}/examples/common/QRCode", + "${chip_root}/examples/dishwasher-app/dishwasher-common", + "${chip_root}/examples/providers:device_info_provider", + "${chip_root}/src/lib", + "${chip_root}/src/setup_payload", + ] + + include_dirs += [ + "include", + "${examples_plat_dir}", + "${asr_project_dir}/include", + "${chip_root}/src/lib", + "${chip_root}/examples/dishwasher-app/dishwasher-common/include", + ] + + defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ] + + if (chip_build_libshell) { + defines += [ "CONFIG_ENABLE_CHIP_SHELL=1" ] + sources += [ "${examples_plat_dir}/shell/launch_shell.cpp" ] + include_dirs += [ "${examples_plat_dir}/shell" ] + } + + if (chip_print_memory_usage) { + ldflags += [ + "-Wl,--print-memory-usage", + "-fstack-usage", + ] + } + + output_dir = root_out_dir +} + +group("asr") { + deps = [ ":dishwasher_app" ] +} + +group("default") { + deps = [ ":asr" ] +} diff --git a/examples/dishwasher-app/asr/args.gni b/examples/dishwasher-app/asr/args.gni new file mode 100755 index 00000000000000..b7599ea01b20dd --- /dev/null +++ b/examples/dishwasher-app/asr/args.gni @@ -0,0 +1,27 @@ +# Copyright (c) 2023 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") +import("//cfg.gni") +import("${chip_root}/src/platform/ASR/args.gni") + +asr_target_project = + get_label_info(":dishwasher_app_sdk_sources", "label_no_toolchain") + +declare_args() { + # Disable lock tracking, since our FreeRTOS configuration does not set + # INCLUDE_xSemaphoreGetMutexHolder + chip_stack_lock_tracking = "none" +} diff --git a/examples/dishwasher-app/asr/build_overrides b/examples/dishwasher-app/asr/build_overrides new file mode 120000 index 00000000000000..194ee0b812dc3d --- /dev/null +++ b/examples/dishwasher-app/asr/build_overrides @@ -0,0 +1 @@ +../../build_overrides/ \ No newline at end of file diff --git a/examples/dishwasher-app/asr/cfg.gni b/examples/dishwasher-app/asr/cfg.gni new file mode 100755 index 00000000000000..15fe50e79efb6d --- /dev/null +++ b/examples/dishwasher-app/asr/cfg.gni @@ -0,0 +1,23 @@ +# Copyright (c) 2023 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + chip_enable_factory_data = false + + chip_lwip_ip6_hook = false + + setupPinCode = 20202021 + + setupDiscriminator = 3840 +} diff --git a/examples/dishwasher-app/asr/include/AppConfig.h b/examples/dishwasher-app/asr/include/AppConfig.h new file mode 100644 index 00000000000000..d475e4c41e3f2f --- /dev/null +++ b/examples/dishwasher-app/asr/include/AppConfig.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +// ---- Dishwasher Example App Config ---- + +#if (CFG_EASY_LOG_ENABLE == 1) +#include "elog.h" +#endif + +#define APP_TASK_NAME "APP" + +#define APP_TASK_STACK_SIZE (1024 * 4) + +#define MATTER_DEVICE_NAME "Dishwasher" + +#ifdef __cplusplus +extern "C" { +#endif + +void appError(int err); +void ASR_LOG(const char * aFormat, ...); + +#ifdef __cplusplus +} + +#include +void appError(CHIP_ERROR error); +#endif diff --git a/examples/dishwasher-app/asr/include/AppTask.h b/examples/dishwasher-app/asr/include/AppTask.h new file mode 100644 index 00000000000000..138c1b7260c63f --- /dev/null +++ b/examples/dishwasher-app/asr/include/AppTask.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include +#include + +class AppTask +{ + +public: + CHIP_ERROR StartAppTask(); + static void AppTaskMain(void * pvParameter); + +private: + friend AppTask & GetAppTask(void); + + static AppTask sAppTask; +}; + +inline AppTask & GetAppTask(void) +{ + return AppTask::sAppTask; +} diff --git a/examples/dishwasher-app/asr/include/CHIPProjectConfig.h b/examples/dishwasher-app/asr/include/CHIPProjectConfig.h new file mode 100755 index 00000000000000..38ba84fe10f85a --- /dev/null +++ b/examples/dishwasher-app/asr/include/CHIPProjectConfig.h @@ -0,0 +1,111 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Example project configuration file for CHIP. + * + * This is a place to put application or project-specific overrides + * to the default configuration values for general CHIP features. + * + */ + +#pragma once + +/** + * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY + * + * Enables the use of a hard-coded default Chip device id and credentials if no device id + * is found in Chip NV storage. + * + * This option is for testing only and should be disabled in production releases. + */ +#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 34 + +// Use a default pairing code if one hasn't been provisioned in flash. +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 +#endif + +#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR +#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 +#endif + +// define Device type based on the application +#define CHIP_DEVICE_CONFIG_DEVICE_TYPE 117 // 0x0075 Dishwasher + +// For convenience, Chip Security Test Mode can be enabled and the +// requirement for authentication in various protocols can be disabled. +// +// WARNING: These options make it possible to circumvent basic Chip security functionality, +// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. +// +#define CHIP_CONFIG_SECURITY_TEST_MODE 0 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION + * + * The hardware version number assigned to device or product by the device vendor. This + * number is scoped to the device product id, and typically corresponds to a revision of the + * physical device, a change to its packaging, and/or a change to its marketing presentation. + * This value is generally *not* incremented for device software versions. + */ +#define CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION 1 + +/** + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING + * + * A string identifying the software version running on the device. + * CHIP service currently expects the software version to be in the format + * {MAJOR_VERSION}.0d{MINOR_VERSION} + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING "1.0" +#endif + +/** + * CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION + * + * A uint32_t identifying the software version running on the device. + */ +/* The SoftwareVersion attribute of the Basic cluster. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION +#define CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER + * + * Enables the use of a hard-coded default serial number if none + * is found in Chip NV storage. + */ +#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" + +/** + * CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS + * + * Enable recording UTC timestamps. + */ +#define CHIP_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 + +/** + * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE + * + * A size, in bytes, of the individual debug event logging buffer. + */ +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) diff --git a/examples/dishwasher-app/asr/include/DeviceCallbacks.h b/examples/dishwasher-app/asr/include/DeviceCallbacks.h new file mode 100644 index 00000000000000..dcd71806f6f2d3 --- /dev/null +++ b/examples/dishwasher-app/asr/include/DeviceCallbacks.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DeviceCallbacks.h + * + * Implementations for the DeviceManager callbacks for this application + * + **/ + +#pragma once + +#include "CHIPDeviceManager.h" +#include +#include +#include + +class DeviceCallbacks : public chip::DeviceManager::CHIPDeviceManagerCallbacks +{ +public: + virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) override; + +private: + void OnInternetConnectivityChange(const chip::DeviceLayer::ChipDeviceEvent * event); +}; diff --git a/examples/dishwasher-app/asr/src/AppTask.cpp b/examples/dishwasher-app/asr/src/AppTask.cpp new file mode 100644 index 00000000000000..d2d8d0cb34fa64 --- /dev/null +++ b/examples/dishwasher-app/asr/src/AppTask.cpp @@ -0,0 +1,112 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "AppTask.h" +#include "AppConfig.h" +#include "CHIPDeviceManager.h" +#include "DeviceCallbacks.h" +#include "operational-state-delegates.h" +#include "qrcodegen.h" +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "init_Matter.h" +#if CONFIG_ENABLE_CHIP_SHELL +#include "matter_shell.h" +#endif +#include + +namespace { +lega_thread_t sAppTaskHandle; +} // namespace + +using namespace ::chip; +using namespace ::chip::Credentials; +using namespace ::chip::DeviceManager; +using namespace ::chip::DeviceLayer; +using namespace ::chip::System; + +AppTask AppTask::sAppTask; + +namespace { +constexpr EndpointId kNetworkCommissioningEndpointMain = 0; +constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; + +app::Clusters::NetworkCommissioning::Instance + sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */, + &(NetworkCommissioning::ASRWiFiDriver::GetInstance())); +} // namespace + +void NetWorkCommissioningInstInit() +{ + sWiFiNetworkCommissioningInstance.Init(); + + // We only have network commissioning on endpoint 0. + emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false); +} + +static DeviceCallbacks EchoCallbacks; + +CHIP_ERROR AppTask::StartAppTask() +{ + // Start App task. + OSStatus result = lega_rtos_create_thread(&sAppTaskHandle, 2, APP_TASK_NAME, (lega_thread_function_t) AppTaskMain, + APP_TASK_STACK_SIZE, (lega_thread_arg_t) this); + return (result == kNoErr) ? CHIP_NO_ERROR : CHIP_APPLICATION_ERROR(0x02); +} + +void AppTask::AppTaskMain(void * pvParameter) +{ + ASR_LOG("App Task started"); + + if (MatterInitializer::Init_Matter_Stack(MATTER_DEVICE_NAME) != CHIP_NO_ERROR) + appError(CHIP_ERROR_INTERNAL); + + CHIPDeviceManager & deviceMgr = CHIPDeviceManager::GetInstance(); + + if (deviceMgr.Init(&EchoCallbacks) != CHIP_NO_ERROR) + appError(CHIP_ERROR_INTERNAL); + + if (MatterInitializer::Init_Matter_Server() != CHIP_NO_ERROR) + appError(CHIP_ERROR_INTERNAL); + + NetWorkCommissioningInstInit(); + + ASR_LOG("Current Firmware Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); + + ConfigurationMgr().LogDeviceConfig(); + + // Print setup info +#if CONFIG_NETWORK_LAYER_BLE + PrintOnboardingCodes(RendezvousInformationFlag(RendezvousInformationFlag::kBLE)); +#else + PrintOnboardingCodes(RendezvousInformationFlag(RendezvousInformationFlag::kOnNetwork)); +#endif /* CONFIG_NETWORK_LAYER_BLE */ + + /*Operational State Server Init*/ + MatterOperationalStateServerInit(); + /* Delete task */ + lega_rtos_delete_thread(NULL); +} diff --git a/examples/dishwasher-app/asr/src/DeviceCallbacks.cpp b/examples/dishwasher-app/asr/src/DeviceCallbacks.cpp new file mode 100644 index 00000000000000..23e6de9a118b03 --- /dev/null +++ b/examples/dishwasher-app/asr/src/DeviceCallbacks.cpp @@ -0,0 +1,122 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file DeviceCallbacks.cpp + * + * Implements all the callbacks to the application from the CHIP Stack + * + **/ +#include "DeviceCallbacks.h" +#include "AppConfig.h" +#include "CHIPDeviceManager.h" +#include "init_OTARequestor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT || defined CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT +#include "route_hook/asr_route_hook.h" +#endif + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::System; +using namespace ::chip::DeviceLayer; +using namespace ::chip::DeviceManager; +using namespace ::chip::Logging; + +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR +constexpr uint32_t kInitOTARequestorDelaySec = 3; + +void InitOTARequestorHandler(System::Layer * systemLayer, void * appState) +{ + OTAInitializer::Instance().InitOTARequestor(); +} +#endif +void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) +{ + switch (event->Type) + { + case DeviceEventType::kInternetConnectivityChange: + OnInternetConnectivityChange(event); + break; + + case DeviceEventType::kInterfaceIpAddressChanged: + if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) || + (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned)) + { + // MDNS server restart on any ip assignment: if link local ipv6 is configured, that + // will not trigger a 'internet connectivity change' as there is no internet + // connectivity. MDNS still wants to refresh its listening interfaces to include the + // newly selected address. + app::DnssdServer::Instance().StartServer(); + + if (event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned) + { +#if defined CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT || defined CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT + ChipLogProgress(NotSpecified, "Initializing route hook..."); + asr_route_hook_init(); +#endif + } + } + break; + } +} + +void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) +{ +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + static bool isOTAInitialized = false; +#endif + if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) + { + ASR_LOG("IPv4 Server ready..."); + app::DnssdServer::Instance().StartServer(); + } + else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost) + { + ASR_LOG("Lost IPv4 connectivity..."); + } + if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established) + { + ASR_LOG("IPv6 Server ready..."); + app::DnssdServer::Instance().StartServer(); +#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR + // Init OTA requestor only when we have gotten IPv6 address + if (!isOTAInitialized) + { + DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(kInitOTARequestorDelaySec), InitOTARequestorHandler, + nullptr); + isOTAInitialized = true; + } +#endif + } + else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost) + { + ASR_LOG("Lost IPv6 connectivity..."); + } +} diff --git a/examples/dishwasher-app/asr/src/main.cpp b/examples/dishwasher-app/asr/src/main.cpp new file mode 100644 index 00000000000000..31c3543bd27b69 --- /dev/null +++ b/examples/dishwasher-app/asr/src/main.cpp @@ -0,0 +1,92 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "AppConfig.h" +#include "init_asrPlatform.h" +#include + +using namespace ::chip; +using namespace ::chip::Inet; +using namespace ::chip::DeviceLayer; + +volatile int apperror_cnt; +// ================================================================================ +// App Error +//================================================================================= +void appError(int err) +{ + ASR_LOG("!!!!!!!!!!!! App Critical Error: %d !!!!!!!!!!!", err); + lega_rtos_declare_critical(); + lega_rtos_enter_critical(); + while (1) + ; +} + +void appError(CHIP_ERROR error) +{ + appError(static_cast(error.AsInteger())); +} + +// ================================================================================ +// FreeRTOS Callbacks +// ================================================================================ +extern "C" void vApplicationIdleHook(void) +{ + // FreeRTOS Idle callback +} + +// ================================================================================ +// Main Code +// ================================================================================ +int main(void) +{ + init_asrPlatform(); + + CHIP_ERROR ret = GetAppTask().StartAppTask(); + if (ret != CHIP_NO_ERROR) + { + ASR_LOG("GetAppTask().Init() failed"); + appError(ret); + } + /* Start the FreeRTOS scheduler */ + vTaskStartScheduler(); + + chip::Platform::MemoryShutdown(); + PlatformMgr().StopEventLoopTask(); + PlatformMgr().Shutdown(); + + // Should never get here. + ASR_LOG("vTaskStartScheduler() failed"); + appError(ret); +} diff --git a/examples/dishwasher-app/asr/third_party/connectedhomeip b/examples/dishwasher-app/asr/third_party/connectedhomeip new file mode 120000 index 00000000000000..11a54ed360106c --- /dev/null +++ b/examples/dishwasher-app/asr/third_party/connectedhomeip @@ -0,0 +1 @@ +../../../../ \ No newline at end of file diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 6be42b1525c125..b6bb80b2ebe5c7 100755 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -433,6 +433,7 @@ def BuildASRTarget(): TargetPart('temperature-measurement', app=ASRApp.TEMPERATURE_MEASUREMENT), TargetPart('thermostat', app=ASRApp.THERMOSTAT), TargetPart('ota-requestor', app=ASRApp.OTA_REQUESTOR), + TargetPart('dishwasher', app=ASRApp.DISHWASHER), ]) # modifiers diff --git a/scripts/build/builders/asr.py b/scripts/build/builders/asr.py index bf856862e583e9..98062b3bbc7c8b 100644 --- a/scripts/build/builders/asr.py +++ b/scripts/build/builders/asr.py @@ -28,6 +28,7 @@ class ASRApp(Enum): TEMPERATURE_MEASUREMENT = auto() THERMOSTAT = auto() OTA_REQUESTOR = auto() + DISHWASHER = auto() def ExampleName(self): if self == ASRApp.ALL_CLUSTERS: @@ -48,6 +49,8 @@ def ExampleName(self): return 'thermostat' elif self == ASRApp.OTA_REQUESTOR: return 'ota-requestor-app' + elif self == ASRApp.DISHWASHER: + return 'dishwasher-app' else: raise Exception('Unknown app type: %r' % self) @@ -70,6 +73,8 @@ def AppNamePrefix(self): return 'chip-asr-thermostat-example' elif self == ASRApp.OTA_REQUESTOR: return 'chip-asr-ota-requestor-example' + elif self == ASRApp.DISHWASHER: + return 'chip-asr-dishwasher-example' else: raise Exception('Unknown app type: %r' % self) diff --git a/scripts/build/testdata/all_targets_linux_x64.txt b/scripts/build/testdata/all_targets_linux_x64.txt index 61daa468a6967d..db0d31ea145989 100644 --- a/scripts/build/testdata/all_targets_linux_x64.txt +++ b/scripts/build/testdata/all_targets_linux_x64.txt @@ -1,5 +1,5 @@ ameba-amebad-{all-clusters,all-clusters-minimal,light,light-switch,pigweed} -asr-{asr582x,asr595x,asr550x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor}[-ota][-shell][-no_logging][-factory][-rotating_id][-rio] +asr-{asr582x,asr595x,asr550x}-{all-clusters,all-clusters-minimal,lighting,light-switch,lock,bridge,temperature-measurement,thermostat,ota-requestor,dishwasher}[-ota][-shell][-no_logging][-factory][-rotating_id][-rio] android-{arm,arm64,x86,x64,androidstudio-arm,androidstudio-arm64,androidstudio-x86,androidstudio-x64}-{chip-tool,chip-test,tv-server,tv-casting-app,java-matter-controller,virtual-device-app}[-no-debug] bouffalolab-{bl602-iot-matter-v1,bl602-night-light,xt-zb6-devkit,bl706-night-light,bl706-eth,bl704l-dvk}-light[-shell][-115200][-rpc][-cdc][-resetcnt][-rotating_device_id] cc32xx-lock From 0c25d18c358830187553325d390bd739e65474c5 Mon Sep 17 00:00:00 2001 From: joonhaengHeo <85541460+joonhaengHeo@users.noreply.github.com> Date: Wed, 26 Jul 2023 01:43:52 +0900 Subject: [PATCH 17/33] [ Java] Decouple generated API in build option (#27624) * Decouple Java generated API * Add comment * restyle * remove tlvdecoder in controller library * Restyled by whitespace * Restyled by google-java-format * Restyled by clang-format * Restyled by gn --------- Co-authored-by: Restyled.io --- build/chip/java/config.gni | 4 + src/controller/java/AndroidCallbacks.cpp | 31 ++++--- .../java/AndroidDeviceControllerWrapper.cpp | 20 ++--- src/controller/java/BUILD.gn | 61 +++++++++----- .../ChipDeviceController.java | 12 +-- .../devicecontroller/ThreadScanResult.java | 82 +++++++++++++++++++ .../chip/devicecontroller/WiFiScanResult.java | 70 ++++++++++++++++ 7 files changed, 228 insertions(+), 52 deletions(-) create mode 100644 src/controller/java/src/chip/devicecontroller/ThreadScanResult.java create mode 100644 src/controller/java/src/chip/devicecontroller/WiFiScanResult.java diff --git a/build/chip/java/config.gni b/build/chip/java/config.gni index ca18c9231fef1d..fbc1d95755863f 100644 --- a/build/chip/java/config.gni +++ b/build/chip/java/config.gni @@ -15,6 +15,9 @@ java_path = getenv("JAVA_PATH") declare_args() { java_matter_controller_dependent_paths = [] + + # The class of each cluster created by ZAP is added to the library. (e.g., ChipClusters) + matter_enable_java_generated_api = true matter_enable_java_compilation = false if (java_path != "" && current_os == "linux") { java_matter_controller_dependent_paths += [ "${java_path}/include/" ] @@ -27,6 +30,7 @@ declare_args() { [ "${java_path}/include/linux/" ] } + matter_enable_java_generated_api = false matter_enable_java_compilation = true } } diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index e236aef95fc41a..d55dfdf953c91c 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -17,8 +17,10 @@ #include "AndroidCallbacks.h" #include #include +#if USE_JAVA_TLV_ENCODE_DECODE #include #include +#endif #include #include #include @@ -243,14 +245,17 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat return; } - TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; - readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); - jobject value = DecodeAttributeValue(aPath, readerForJavaObject, &err); + jobject value = nullptr; +#if USE_JAVA_TLV_ENCODE_DECODE + TLV::TLVReader readerForJavaObject; + readerForJavaObject.Init(*apData); + + value = DecodeAttributeValue(aPath, readerForJavaObject, &err); // If we don't know this attribute, suppress it. if (err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB) { @@ -260,7 +265,7 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(attributePathObj, nullptr, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(attributePathObj, nullptr, CHIP_JNI_ERROR_EXCEPTION_THROWN)); - +#endif // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); std::unique_ptr buffer = std::unique_ptr(new uint8_t[bufferLen]); @@ -354,10 +359,8 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV return; } - TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; - readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); @@ -365,7 +368,11 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(aEventHeader.mTimestamp.mValue); - jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); + jobject value = nullptr; +#if USE_JAVA_TLV_ENCODE_DECODE + TLV::TLVReader readerForJavaObject; + readerForJavaObject.Init(*apData); + value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); // If we don't know this event, just skip it. if (err == CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB) { @@ -374,6 +381,7 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(nullptr, eventPathObj, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(nullptr, eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN)); +#endif // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); @@ -699,10 +707,8 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV return; } - TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; - readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); @@ -710,11 +716,16 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(aEventHeader.mTimestamp.mValue); - jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); + jobject value = nullptr; +#if USE_JAVA_TLV_ENCODE_DECODE + TLV::TLVReader readerForJavaObject; + readerForJavaObject.Init(*apData); + value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); // If we don't know this event, just skip it. VerifyOrReturn(err != CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB); VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(eventPathObj, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN)); +#endif // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 974cb882cd2a9e..110121d6e2e41c 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -653,12 +653,11 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("java/lang/Integer", "(I)V", entry.rssi, newElement_rssi); jclass wiFiInterfaceScanResultStructClass; - err = chip::JniReferences::GetInstance().GetClassRef( - env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct", - wiFiInterfaceScanResultStructClass); + err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/WiFiScanResult", + wiFiInterfaceScanResultStructClass); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct"); + ChipLogError(Zcl, "Could not find class WiFiScanResult"); return; } jmethodID wiFiInterfaceScanResultStructCtor = @@ -666,8 +665,7 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( "(Ljava/lang/Integer;[B[BLjava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V"); if (wiFiInterfaceScanResultStructCtor == nullptr) { - ChipLogError(Zcl, - "Could not find ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct constructor"); + ChipLogError(Zcl, "Could not find WiFiScanResult constructor"); return; } @@ -717,12 +715,11 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("java/lang/Integer", "(I)V", entry.lqi, newElement_lqi); jclass threadInterfaceScanResultStructClass; - err = chip::JniReferences::GetInstance().GetClassRef( - env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct", - threadInterfaceScanResultStructClass); + err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ThreadScanResult", + threadInterfaceScanResultStructClass); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct"); + ChipLogError(Zcl, "Could not find class ThreadScanResult"); return; } jmethodID threadInterfaceScanResultStructCtor = @@ -731,8 +728,7 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( "Integer;[BLjava/lang/Integer;Ljava/lang/Integer;)V"); if (threadInterfaceScanResultStructCtor == nullptr) { - ChipLogError(Zcl, - "Could not find ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct constructor"); + ChipLogError(Zcl, "Could not find ThreadScanResult constructor"); return; } diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index d6c78191e37fe0..7a3f2b5b41dac8 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -29,6 +29,8 @@ shared_library("jni") { output_extension = "dylib" } + defines = [] + # Temporary while we have circular dependencies between codegen.py and zap # generated files check_includes = false @@ -53,23 +55,14 @@ shared_library("jni") { "AttestationTrustStoreBridge.h", "BaseCHIPCluster-JNI.cpp", "CHIPAttributeTLVValueDecoder.h", - "CHIPDefaultCallbacks.cpp", - "CHIPDefaultCallbacks.h", "CHIPDeviceController-JNI.cpp", "CHIPTLVValueDecoder-JNI.cpp", "DeviceAttestationDelegateBridge.cpp", "DeviceAttestationDelegateBridge.h", - "zap-generated/CHIPAttributeTLVValueDecoder.cpp", - "zap-generated/CHIPClustersWrite-JNI.cpp", - "zap-generated/CHIPEventTLVValueDecoder.cpp", - "zap-generated/CHIPInvokeCallbacks.cpp", - "zap-generated/CHIPInvokeCallbacks.h", - "zap-generated/CHIPReadCallbacks.cpp", ] deps = [ "${chip_root}/src/controller/data_model", - "${chip_root}/src/controller/data_model:java-jni-sources", "${chip_root}/src/credentials:default_attestation_verifier", "${chip_root}/src/inet", "${chip_root}/src/lib", @@ -77,8 +70,25 @@ shared_library("jni") { "${chip_root}/src/platform", ] + if (matter_enable_java_generated_api) { + defines += [ "USE_JAVA_TLV_ENCODE_DECODE" ] + + sources += [ + "CHIPDefaultCallbacks.cpp", + "CHIPDefaultCallbacks.h", + "zap-generated/CHIPAttributeTLVValueDecoder.cpp", + "zap-generated/CHIPClustersWrite-JNI.cpp", + "zap-generated/CHIPEventTLVValueDecoder.cpp", + "zap-generated/CHIPInvokeCallbacks.cpp", + "zap-generated/CHIPInvokeCallbacks.h", + "zap-generated/CHIPReadCallbacks.cpp", + ] + + deps += [ "${chip_root}/src/controller/data_model:java-jni-sources" ] + } + if (matter_enable_java_compilation) { - defines = [ "JAVA_MATTER_CONTROLLER_TEST" ] + defines += [ "JAVA_MATTER_CONTROLLER_TEST" ] sources += [ "${chip_root}/src/controller/ExamplePersistentStorage.cpp", @@ -313,14 +323,6 @@ android_library("java") { sources = [ "generated/java/chip/devicecontroller/ClusterIDMapping.java", - "generated/java/chip/devicecontroller/ClusterReadMapping.java", - "generated/java/chip/devicecontroller/ClusterWriteMapping.java", - "src/chip/clusterinfo/ClusterCommandCallback.java", - "src/chip/clusterinfo/ClusterInfo.java", - "src/chip/clusterinfo/CommandParameterInfo.java", - "src/chip/clusterinfo/CommandResponseInfo.java", - "src/chip/clusterinfo/DelegatedClusterCallback.java", - "src/chip/clusterinfo/InteractionInfo.java", "src/chip/devicecontroller/AttestationInfo.java", "src/chip/devicecontroller/AttestationTrustStoreDelegate.java", "src/chip/devicecontroller/CSRInfo.java", @@ -348,7 +350,9 @@ android_library("java") { "src/chip/devicecontroller/ReportEventCallbackJni.java", "src/chip/devicecontroller/ResubscriptionAttemptCallback.java", "src/chip/devicecontroller/SubscriptionEstablishedCallback.java", + "src/chip/devicecontroller/ThreadScanResult.java", "src/chip/devicecontroller/UnpairDeviceCallback.java", + "src/chip/devicecontroller/WiFiScanResult.java", "src/chip/devicecontroller/WriteAttributesCallback.java", "src/chip/devicecontroller/WriteAttributesCallbackJni.java", "src/chip/devicecontroller/model/AttributeState.java", @@ -361,12 +365,25 @@ android_library("java") { "src/chip/devicecontroller/model/EventState.java", "src/chip/devicecontroller/model/InvokeElement.java", "src/chip/devicecontroller/model/NodeState.java", - "zap-generated/chip/devicecontroller/ChipClusters.java", - "zap-generated/chip/devicecontroller/ChipEventStructs.java", - "zap-generated/chip/devicecontroller/ChipStructs.java", - "zap-generated/chip/devicecontroller/ClusterInfoMapping.java", ] + if (matter_enable_java_generated_api) { + sources += [ + "generated/java/chip/devicecontroller/ClusterReadMapping.java", + "generated/java/chip/devicecontroller/ClusterWriteMapping.java", + "src/chip/clusterinfo/ClusterCommandCallback.java", + "src/chip/clusterinfo/ClusterInfo.java", + "src/chip/clusterinfo/CommandParameterInfo.java", + "src/chip/clusterinfo/CommandResponseInfo.java", + "src/chip/clusterinfo/DelegatedClusterCallback.java", + "src/chip/clusterinfo/InteractionInfo.java", + "zap-generated/chip/devicecontroller/ChipClusters.java", + "zap-generated/chip/devicecontroller/ChipEventStructs.java", + "zap-generated/chip/devicecontroller/ChipStructs.java", + "zap-generated/chip/devicecontroller/ClusterInfoMapping.java", + ] + } + if (matter_enable_java_compilation) { deps += [ "${chip_root}/third_party/java_deps:json", diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 916f65fb270819..33cb7a9ff3ae6e 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -389,10 +389,8 @@ public void onScanNetworksFailure(int errorCode) { public void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> - wiFiScanResults, - Optional> - threadScanResults) { + Optional> wiFiScanResults, + Optional> threadScanResults) { if (scanNetworksListener != null) { scanNetworksListener.onScanNetworksSuccess( networkingStatus, debugText, wiFiScanResults, threadScanResults); @@ -1268,10 +1266,8 @@ public interface ScanNetworksListener { void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> - wiFiScanResults, - Optional> - threadScanResults); + Optional> wiFiScanResults, + Optional> threadScanResults); } /** Interface to listen for callbacks from CHIPDeviceController. */ diff --git a/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java b/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java new file mode 100644 index 00000000000000..64c837bdca411d --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2020-2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller; + +import java.util.Arrays; + +public class ThreadScanResult { + public Integer panId; + public Long extendedPanId; + public String networkName; + public Integer channel; + public Integer version; + public byte[] extendedAddress; + public Integer rssi; + public Integer lqi; + + public ThreadScanResult( + Integer panId, + Long extendedPanId, + String networkName, + Integer channel, + Integer version, + byte[] extendedAddress, + Integer rssi, + Integer lqi) { + this.panId = panId; + this.extendedPanId = extendedPanId; + this.networkName = networkName; + this.channel = channel; + this.version = version; + this.extendedAddress = extendedAddress; + this.rssi = rssi; + this.lqi = lqi; + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("ThreadScanResult {\n"); + output.append("\tpanId: "); + output.append(panId); + output.append("\n"); + output.append("\textendedPanId: "); + output.append(extendedPanId); + output.append("\n"); + output.append("\tnetworkName: "); + output.append(networkName); + output.append("\n"); + output.append("\tchannel: "); + output.append(channel); + output.append("\n"); + output.append("\tversion: "); + output.append(version); + output.append("\n"); + output.append("\textendedAddress: "); + output.append(Arrays.toString(extendedAddress)); + output.append("\n"); + output.append("\trssi: "); + output.append(rssi); + output.append("\n"); + output.append("\tlqi: "); + output.append(lqi); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} diff --git a/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java b/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java new file mode 100644 index 00000000000000..bcc01e0af26874 --- /dev/null +++ b/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020-2022 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package chip.devicecontroller; + +import java.util.Arrays; + +public class WiFiScanResult { + public Integer security; + public byte[] ssid; + public byte[] bssid; + public Integer channel; + public Integer wiFiBand; + public Integer rssi; + + public WiFiScanResult( + Integer security, + byte[] ssid, + byte[] bssid, + Integer channel, + Integer wiFiBand, + Integer rssi) { + this.security = security; + this.ssid = ssid; + this.bssid = bssid; + this.channel = channel; + this.wiFiBand = wiFiBand; + this.rssi = rssi; + } + + @Override + public String toString() { + StringBuilder output = new StringBuilder(); + output.append("WiFiScanResult {\n"); + output.append("\tsecurity: "); + output.append(security); + output.append("\n"); + output.append("\tssid: "); + output.append(Arrays.toString(ssid)); + output.append("\n"); + output.append("\tbssid: "); + output.append(Arrays.toString(bssid)); + output.append("\n"); + output.append("\tchannel: "); + output.append(channel); + output.append("\n"); + output.append("\twiFiBand: "); + output.append(wiFiBand); + output.append("\n"); + output.append("\trssi: "); + output.append(rssi); + output.append("\n"); + output.append("}\n"); + return output.toString(); + } +} From 37f7188671060083ef5db6959e9e62edcc2d1d78 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 25 Jul 2023 13:12:32 -0400 Subject: [PATCH 18/33] Revert "[ Java] Decouple generated API in build option (#27624)" (#28272) This reverts commit 1ed2425961ad81ac03a2d12e2dd0c1cbb5a5c068. Co-authored-by: Andrei Litvin --- build/chip/java/config.gni | 4 - src/controller/java/AndroidCallbacks.cpp | 31 +++---- .../java/AndroidDeviceControllerWrapper.cpp | 20 +++-- src/controller/java/BUILD.gn | 61 +++++--------- .../ChipDeviceController.java | 12 ++- .../devicecontroller/ThreadScanResult.java | 82 ------------------- .../chip/devicecontroller/WiFiScanResult.java | 70 ---------------- 7 files changed, 52 insertions(+), 228 deletions(-) delete mode 100644 src/controller/java/src/chip/devicecontroller/ThreadScanResult.java delete mode 100644 src/controller/java/src/chip/devicecontroller/WiFiScanResult.java diff --git a/build/chip/java/config.gni b/build/chip/java/config.gni index fbc1d95755863f..ca18c9231fef1d 100644 --- a/build/chip/java/config.gni +++ b/build/chip/java/config.gni @@ -15,9 +15,6 @@ java_path = getenv("JAVA_PATH") declare_args() { java_matter_controller_dependent_paths = [] - - # The class of each cluster created by ZAP is added to the library. (e.g., ChipClusters) - matter_enable_java_generated_api = true matter_enable_java_compilation = false if (java_path != "" && current_os == "linux") { java_matter_controller_dependent_paths += [ "${java_path}/include/" ] @@ -30,7 +27,6 @@ declare_args() { [ "${java_path}/include/linux/" ] } - matter_enable_java_generated_api = false matter_enable_java_compilation = true } } diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp index d55dfdf953c91c..e236aef95fc41a 100644 --- a/src/controller/java/AndroidCallbacks.cpp +++ b/src/controller/java/AndroidCallbacks.cpp @@ -17,10 +17,8 @@ #include "AndroidCallbacks.h" #include #include -#if USE_JAVA_TLV_ENCODE_DECODE #include #include -#endif #include #include #include @@ -245,17 +243,14 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat return; } + TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; + readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); - jobject value = nullptr; -#if USE_JAVA_TLV_ENCODE_DECODE - TLV::TLVReader readerForJavaObject; - readerForJavaObject.Init(*apData); - - value = DecodeAttributeValue(aPath, readerForJavaObject, &err); + jobject value = DecodeAttributeValue(aPath, readerForJavaObject, &err); // If we don't know this attribute, suppress it. if (err == CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB) { @@ -265,7 +260,7 @@ void ReportCallback::OnAttributeData(const app::ConcreteDataAttributePath & aPat VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(attributePathObj, nullptr, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(attributePathObj, nullptr, CHIP_JNI_ERROR_EXCEPTION_THROWN)); -#endif + // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); std::unique_ptr buffer = std::unique_ptr(new uint8_t[bufferLen]); @@ -359,8 +354,10 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV return; } + TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; + readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); @@ -368,11 +365,7 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(aEventHeader.mTimestamp.mValue); - jobject value = nullptr; -#if USE_JAVA_TLV_ENCODE_DECODE - TLV::TLVReader readerForJavaObject; - readerForJavaObject.Init(*apData); - value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); + jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); // If we don't know this event, just skip it. if (err == CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB) { @@ -381,7 +374,6 @@ void ReportCallback::OnEventData(const app::EventHeader & aEventHeader, TLV::TLV VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(nullptr, eventPathObj, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(nullptr, eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN)); -#endif // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); @@ -707,8 +699,10 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV return; } + TLV::TLVReader readerForJavaObject; TLV::TLVReader readerForJavaTLV; TLV::TLVReader readerForJson; + readerForJavaObject.Init(*apData); readerForJavaTLV.Init(*apData); readerForJson.Init(*apData); @@ -716,16 +710,11 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV jlong priorityLevel = static_cast(aEventHeader.mPriorityLevel); jlong timestamp = static_cast(aEventHeader.mTimestamp.mValue); - jobject value = nullptr; -#if USE_JAVA_TLV_ENCODE_DECODE - TLV::TLVReader readerForJavaObject; - readerForJavaObject.Init(*apData); - value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); + jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err); // If we don't know this event, just skip it. VerifyOrReturn(err != CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB); VerifyOrReturn(err == CHIP_NO_ERROR, ReportError(eventPathObj, err)); VerifyOrReturn(!env->ExceptionCheck(), env->ExceptionDescribe(), ReportError(eventPathObj, CHIP_JNI_ERROR_EXCEPTION_THROWN)); -#endif // Create TLV byte array to pass to Java layer size_t bufferLen = readerForJavaTLV.GetRemainingLength() + readerForJavaTLV.GetLengthRead(); diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index 110121d6e2e41c..974cb882cd2a9e 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -653,11 +653,12 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("java/lang/Integer", "(I)V", entry.rssi, newElement_rssi); jclass wiFiInterfaceScanResultStructClass; - err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/WiFiScanResult", - wiFiInterfaceScanResultStructClass); + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct", + wiFiInterfaceScanResultStructClass); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Could not find class WiFiScanResult"); + ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct"); return; } jmethodID wiFiInterfaceScanResultStructCtor = @@ -665,7 +666,8 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( "(Ljava/lang/Integer;[B[BLjava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V"); if (wiFiInterfaceScanResultStructCtor == nullptr) { - ChipLogError(Zcl, "Could not find WiFiScanResult constructor"); + ChipLogError(Zcl, + "Could not find ChipStructs$NetworkCommissioningClusterWiFiInterfaceScanResultStruct constructor"); return; } @@ -715,11 +717,12 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( chip::JniReferences::GetInstance().CreateBoxedObject("java/lang/Integer", "(I)V", entry.lqi, newElement_lqi); jclass threadInterfaceScanResultStructClass; - err = chip::JniReferences::GetInstance().GetClassRef(env, "chip/devicecontroller/ThreadScanResult", - threadInterfaceScanResultStructClass); + err = chip::JniReferences::GetInstance().GetClassRef( + env, "chip/devicecontroller/ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct", + threadInterfaceScanResultStructClass); if (err != CHIP_NO_ERROR) { - ChipLogError(Zcl, "Could not find class ThreadScanResult"); + ChipLogError(Zcl, "Could not find class ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct"); return; } jmethodID threadInterfaceScanResultStructCtor = @@ -728,7 +731,8 @@ void AndroidDeviceControllerWrapper::OnScanNetworksSuccess( "Integer;[BLjava/lang/Integer;Ljava/lang/Integer;)V"); if (threadInterfaceScanResultStructCtor == nullptr) { - ChipLogError(Zcl, "Could not find ThreadScanResult constructor"); + ChipLogError(Zcl, + "Could not find ChipStructs$NetworkCommissioningClusterThreadInterfaceScanResultStruct constructor"); return; } diff --git a/src/controller/java/BUILD.gn b/src/controller/java/BUILD.gn index 7a3f2b5b41dac8..d6c78191e37fe0 100644 --- a/src/controller/java/BUILD.gn +++ b/src/controller/java/BUILD.gn @@ -29,8 +29,6 @@ shared_library("jni") { output_extension = "dylib" } - defines = [] - # Temporary while we have circular dependencies between codegen.py and zap # generated files check_includes = false @@ -55,14 +53,23 @@ shared_library("jni") { "AttestationTrustStoreBridge.h", "BaseCHIPCluster-JNI.cpp", "CHIPAttributeTLVValueDecoder.h", + "CHIPDefaultCallbacks.cpp", + "CHIPDefaultCallbacks.h", "CHIPDeviceController-JNI.cpp", "CHIPTLVValueDecoder-JNI.cpp", "DeviceAttestationDelegateBridge.cpp", "DeviceAttestationDelegateBridge.h", + "zap-generated/CHIPAttributeTLVValueDecoder.cpp", + "zap-generated/CHIPClustersWrite-JNI.cpp", + "zap-generated/CHIPEventTLVValueDecoder.cpp", + "zap-generated/CHIPInvokeCallbacks.cpp", + "zap-generated/CHIPInvokeCallbacks.h", + "zap-generated/CHIPReadCallbacks.cpp", ] deps = [ "${chip_root}/src/controller/data_model", + "${chip_root}/src/controller/data_model:java-jni-sources", "${chip_root}/src/credentials:default_attestation_verifier", "${chip_root}/src/inet", "${chip_root}/src/lib", @@ -70,25 +77,8 @@ shared_library("jni") { "${chip_root}/src/platform", ] - if (matter_enable_java_generated_api) { - defines += [ "USE_JAVA_TLV_ENCODE_DECODE" ] - - sources += [ - "CHIPDefaultCallbacks.cpp", - "CHIPDefaultCallbacks.h", - "zap-generated/CHIPAttributeTLVValueDecoder.cpp", - "zap-generated/CHIPClustersWrite-JNI.cpp", - "zap-generated/CHIPEventTLVValueDecoder.cpp", - "zap-generated/CHIPInvokeCallbacks.cpp", - "zap-generated/CHIPInvokeCallbacks.h", - "zap-generated/CHIPReadCallbacks.cpp", - ] - - deps += [ "${chip_root}/src/controller/data_model:java-jni-sources" ] - } - if (matter_enable_java_compilation) { - defines += [ "JAVA_MATTER_CONTROLLER_TEST" ] + defines = [ "JAVA_MATTER_CONTROLLER_TEST" ] sources += [ "${chip_root}/src/controller/ExamplePersistentStorage.cpp", @@ -323,6 +313,14 @@ android_library("java") { sources = [ "generated/java/chip/devicecontroller/ClusterIDMapping.java", + "generated/java/chip/devicecontroller/ClusterReadMapping.java", + "generated/java/chip/devicecontroller/ClusterWriteMapping.java", + "src/chip/clusterinfo/ClusterCommandCallback.java", + "src/chip/clusterinfo/ClusterInfo.java", + "src/chip/clusterinfo/CommandParameterInfo.java", + "src/chip/clusterinfo/CommandResponseInfo.java", + "src/chip/clusterinfo/DelegatedClusterCallback.java", + "src/chip/clusterinfo/InteractionInfo.java", "src/chip/devicecontroller/AttestationInfo.java", "src/chip/devicecontroller/AttestationTrustStoreDelegate.java", "src/chip/devicecontroller/CSRInfo.java", @@ -350,9 +348,7 @@ android_library("java") { "src/chip/devicecontroller/ReportEventCallbackJni.java", "src/chip/devicecontroller/ResubscriptionAttemptCallback.java", "src/chip/devicecontroller/SubscriptionEstablishedCallback.java", - "src/chip/devicecontroller/ThreadScanResult.java", "src/chip/devicecontroller/UnpairDeviceCallback.java", - "src/chip/devicecontroller/WiFiScanResult.java", "src/chip/devicecontroller/WriteAttributesCallback.java", "src/chip/devicecontroller/WriteAttributesCallbackJni.java", "src/chip/devicecontroller/model/AttributeState.java", @@ -365,25 +361,12 @@ android_library("java") { "src/chip/devicecontroller/model/EventState.java", "src/chip/devicecontroller/model/InvokeElement.java", "src/chip/devicecontroller/model/NodeState.java", + "zap-generated/chip/devicecontroller/ChipClusters.java", + "zap-generated/chip/devicecontroller/ChipEventStructs.java", + "zap-generated/chip/devicecontroller/ChipStructs.java", + "zap-generated/chip/devicecontroller/ClusterInfoMapping.java", ] - if (matter_enable_java_generated_api) { - sources += [ - "generated/java/chip/devicecontroller/ClusterReadMapping.java", - "generated/java/chip/devicecontroller/ClusterWriteMapping.java", - "src/chip/clusterinfo/ClusterCommandCallback.java", - "src/chip/clusterinfo/ClusterInfo.java", - "src/chip/clusterinfo/CommandParameterInfo.java", - "src/chip/clusterinfo/CommandResponseInfo.java", - "src/chip/clusterinfo/DelegatedClusterCallback.java", - "src/chip/clusterinfo/InteractionInfo.java", - "zap-generated/chip/devicecontroller/ChipClusters.java", - "zap-generated/chip/devicecontroller/ChipEventStructs.java", - "zap-generated/chip/devicecontroller/ChipStructs.java", - "zap-generated/chip/devicecontroller/ClusterInfoMapping.java", - ] - } - if (matter_enable_java_compilation) { deps += [ "${chip_root}/third_party/java_deps:json", diff --git a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java index 33cb7a9ff3ae6e..916f65fb270819 100644 --- a/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java +++ b/src/controller/java/src/chip/devicecontroller/ChipDeviceController.java @@ -389,8 +389,10 @@ public void onScanNetworksFailure(int errorCode) { public void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> wiFiScanResults, - Optional> threadScanResults) { + Optional> + wiFiScanResults, + Optional> + threadScanResults) { if (scanNetworksListener != null) { scanNetworksListener.onScanNetworksSuccess( networkingStatus, debugText, wiFiScanResults, threadScanResults); @@ -1266,8 +1268,10 @@ public interface ScanNetworksListener { void onScanNetworksSuccess( Integer networkingStatus, Optional debugText, - Optional> wiFiScanResults, - Optional> threadScanResults); + Optional> + wiFiScanResults, + Optional> + threadScanResults); } /** Interface to listen for callbacks from CHIPDeviceController. */ diff --git a/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java b/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java deleted file mode 100644 index 64c837bdca411d..00000000000000 --- a/src/controller/java/src/chip/devicecontroller/ThreadScanResult.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2020-2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package chip.devicecontroller; - -import java.util.Arrays; - -public class ThreadScanResult { - public Integer panId; - public Long extendedPanId; - public String networkName; - public Integer channel; - public Integer version; - public byte[] extendedAddress; - public Integer rssi; - public Integer lqi; - - public ThreadScanResult( - Integer panId, - Long extendedPanId, - String networkName, - Integer channel, - Integer version, - byte[] extendedAddress, - Integer rssi, - Integer lqi) { - this.panId = panId; - this.extendedPanId = extendedPanId; - this.networkName = networkName; - this.channel = channel; - this.version = version; - this.extendedAddress = extendedAddress; - this.rssi = rssi; - this.lqi = lqi; - } - - @Override - public String toString() { - StringBuilder output = new StringBuilder(); - output.append("ThreadScanResult {\n"); - output.append("\tpanId: "); - output.append(panId); - output.append("\n"); - output.append("\textendedPanId: "); - output.append(extendedPanId); - output.append("\n"); - output.append("\tnetworkName: "); - output.append(networkName); - output.append("\n"); - output.append("\tchannel: "); - output.append(channel); - output.append("\n"); - output.append("\tversion: "); - output.append(version); - output.append("\n"); - output.append("\textendedAddress: "); - output.append(Arrays.toString(extendedAddress)); - output.append("\n"); - output.append("\trssi: "); - output.append(rssi); - output.append("\n"); - output.append("\tlqi: "); - output.append(lqi); - output.append("\n"); - output.append("}\n"); - return output.toString(); - } -} diff --git a/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java b/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java deleted file mode 100644 index bcc01e0af26874..00000000000000 --- a/src/controller/java/src/chip/devicecontroller/WiFiScanResult.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020-2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -package chip.devicecontroller; - -import java.util.Arrays; - -public class WiFiScanResult { - public Integer security; - public byte[] ssid; - public byte[] bssid; - public Integer channel; - public Integer wiFiBand; - public Integer rssi; - - public WiFiScanResult( - Integer security, - byte[] ssid, - byte[] bssid, - Integer channel, - Integer wiFiBand, - Integer rssi) { - this.security = security; - this.ssid = ssid; - this.bssid = bssid; - this.channel = channel; - this.wiFiBand = wiFiBand; - this.rssi = rssi; - } - - @Override - public String toString() { - StringBuilder output = new StringBuilder(); - output.append("WiFiScanResult {\n"); - output.append("\tsecurity: "); - output.append(security); - output.append("\n"); - output.append("\tssid: "); - output.append(Arrays.toString(ssid)); - output.append("\n"); - output.append("\tbssid: "); - output.append(Arrays.toString(bssid)); - output.append("\n"); - output.append("\tchannel: "); - output.append(channel); - output.append("\n"); - output.append("\twiFiBand: "); - output.append(wiFiBand); - output.append("\n"); - output.append("\trssi: "); - output.append(rssi); - output.append("\n"); - output.append("}\n"); - return output.toString(); - } -} From 9a6feb42726076db6336403d85f9983459ad30b7 Mon Sep 17 00:00:00 2001 From: weicheng Date: Wed, 26 Jul 2023 01:16:38 +0800 Subject: [PATCH 19/33] [ASR] update device manager (#28251) Co-authored-by: weicheng --- examples/platform/asr/CHIPDeviceManager.cpp | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 examples/platform/asr/CHIPDeviceManager.cpp diff --git a/examples/platform/asr/CHIPDeviceManager.cpp b/examples/platform/asr/CHIPDeviceManager.cpp old mode 100644 new mode 100755 index c546175e2f393a..98ebda9a85134d --- a/examples/platform/asr/CHIPDeviceManager.cpp +++ b/examples/platform/asr/CHIPDeviceManager.cpp @@ -27,6 +27,7 @@ #include "CHIPDeviceManager.h" #include #include +#include #include #include #include From aef213ae93ed89614314c4258f462c0b58197541 Mon Sep 17 00:00:00 2001 From: Petru Lauric <81822411+plauric@users.noreply.github.com> Date: Tue, 25 Jul 2023 13:21:30 -0400 Subject: [PATCH 20/33] Add RVC device type to XML + fix RVC Clean/Run XML issue (#28239) * add rvc device type * Apply suggestions from code review Co-authored-by: Boris Zbarsky --------- Co-authored-by: Boris Zbarsky --- .../zcl/data-model/chip/matter-devices.xml | 15 +++++++++++++++ .../data-model/chip/rvc-clean-mode-cluster.xml | 2 +- .../zcl/data-model/chip/rvc-run-mode-cluster.xml | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/app/zap-templates/zcl/data-model/chip/matter-devices.xml b/src/app/zap-templates/zcl/data-model/chip/matter-devices.xml index 3c923129fb9f12..be7b55cb5ed43e 100644 --- a/src/app/zap-templates/zcl/data-model/chip/matter-devices.xml +++ b/src/app/zap-templates/zcl/data-model/chip/matter-devices.xml @@ -1989,6 +1989,21 @@ limitations under the License. + + MA-robotic-vacuum-cleaner + CHIP + Matter Robotic Vacuum Cleaner + 0x0103 + 0x0074 + + + + + + + + + MA-temperature-controlled-cabinet CHIP diff --git a/src/app/zap-templates/zcl/data-model/chip/rvc-clean-mode-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/rvc-clean-mode-cluster.xml index 1baf10841b9672..8921822d4f89c5 100644 --- a/src/app/zap-templates/zcl/data-model/chip/rvc-clean-mode-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/rvc-clean-mode-cluster.xml @@ -30,7 +30,7 @@ limitations under the License. - General + Robots RVC Clean Mode 0x0055 RVC_CLEAN_MODE_CLUSTER diff --git a/src/app/zap-templates/zcl/data-model/chip/rvc-run-mode-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/rvc-run-mode-cluster.xml index dd7905ce9891d7..d6a3a241c32bd1 100644 --- a/src/app/zap-templates/zcl/data-model/chip/rvc-run-mode-cluster.xml +++ b/src/app/zap-templates/zcl/data-model/chip/rvc-run-mode-cluster.xml @@ -36,7 +36,7 @@ limitations under the License. - General + Robots RVC Run Mode 0x0054 RVC_RUN_MODE_CLUSTER From a55fbb4d9603887c63304d8484d3f7a7c17a217d Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 25 Jul 2023 14:44:22 -0400 Subject: [PATCH 21/33] Make C++17 the default everywhere (#28269) * Make cpp17 the default * Restyle * Add a clean for build on linux, since I had a run out of space --------- Co-authored-by: Andrei Litvin --- .github/workflows/build.yaml | 2 ++ build/config/compiler/compiler.gni | 7 +------ config/ameba/args.gni | 1 - config/mbed/CMakeLists.txt | 4 +--- examples/chef/silabs/with_pw_rpc.gni | 2 -- examples/chip-tool/args.gni | 3 --- examples/common/tracing/BUILD.gn | 5 +---- examples/light-switch-app/genio/with_pw_rpc.gni | 2 -- examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni | 2 -- examples/lighting-app/bouffalolab/bl702/with_pw_rpc.gni | 2 -- examples/lighting-app/bouffalolab/bl702l/with_pw_rpc.gni | 2 -- examples/lighting-app/genio/with_pw_rpc.gni | 2 -- examples/lighting-app/qpg/with_pw_rpc.gni | 2 -- examples/lighting-app/silabs/with_pw_rpc.gni | 2 -- examples/lock-app/genio/with_pw_rpc.gni | 2 -- examples/lock-app/qpg/with_pw_rpc.gni | 2 -- examples/lock-app/silabs/with_pw_rpc.gni | 2 -- examples/ota-requestor-app/genio/with_pw_rpc.gni | 2 -- examples/pump-app/silabs/with_pw_rpc.gni | 2 -- examples/smoke-co-alarm-app/silabs/with_pw_rpc.gni | 2 -- examples/thermostat/genio/with_pw_rpc.gni | 2 -- src/test_driver/efr32/args.gni | 1 - 22 files changed, 5 insertions(+), 48 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 14ced0ab7474a8..c3914b86230305 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -174,6 +174,8 @@ jobs: BUILD_TYPE=gcc_release scripts/build/gn_gen.sh --args="is_debug=false" scripts/run_in_build_env.sh "ninja -C ./out/gcc_release" BUILD_TYPE=gcc_release scripts/tests/gn_tests.sh + - name: Clean output + run: rm -rf ./out - name: Run Tests with sanitizers env: LSAN_OPTIONS: detect_leaks=1 diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni index 12a93863be8ce0..74dc224f3ecec7 100644 --- a/build/config/compiler/compiler.gni +++ b/build/config/compiler/compiler.gni @@ -43,12 +43,7 @@ declare_args() { c_standard = "gnu11" # C++ standard level (value for -std flag). - if (current_os == "linux" || current_os == "mac" || current_os == "ios" || - current_os == "android") { - cpp_standard = "gnu++17" - } else { - cpp_standard = "gnu++14" - } + cpp_standard = "gnu++17" # enable libfuzzer is_libfuzzer = false diff --git a/config/ameba/args.gni b/config/ameba/args.gni index 51634a9d738da6..a60eee6db2887c 100755 --- a/config/ameba/args.gni +++ b/config/ameba/args.gni @@ -37,4 +37,3 @@ custom_toolchain = "//third_party/connectedhomeip/config/ameba/toolchain:ameba" pw_build_PIP_CONSTRAINTS = [ "//third_party/connectedhomeip/scripts/setup/constraints.txt" ] -cpp_standard = "c++17" diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index a7006062f12ace..88567b604e3254 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -106,9 +106,7 @@ matter_get_compiler_flags_from_targets("${CONFIG_CHIP_EXTERNAL_TARGETS}") matter_add_flags(-D__LINUX_ERRNO_EXTENSIONS__=1) matter_add_flags(-DCHIP_ADDRESS_RESOLVE_IMPL_INCLUDE_HEADER=) -if (CONFIG_CHIP_PW_RPC) - matter_add_gnu_cpp_standard("17") -endif() +matter_add_gnu_cpp_standard("17") if (CONFIG_MBED_BSD_SOCKET_TRACE) matter_add_flags(-DMBED_BSD_SOCKET_TRACE=1) diff --git a/examples/chef/silabs/with_pw_rpc.gni b/examples/chef/silabs/with_pw_rpc.gni index f07744d855c6f9..ec2d4cff28e7ad 100644 --- a/examples/chef/silabs/with_pw_rpc.gni +++ b/examples/chef/silabs/with_pw_rpc.gni @@ -24,7 +24,5 @@ silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true -cpp_standard = "gnu++17" - # Light app on EFR enables tracing server pw_trace_BACKEND = "$dir_pw_trace_tokenized" diff --git a/examples/chip-tool/args.gni b/examples/chip-tool/args.gni index 96dd37f02f03a1..a0b30a430f23f3 100644 --- a/examples/chip-tool/args.gni +++ b/examples/chip-tool/args.gni @@ -25,8 +25,5 @@ chip_project_config_include_dirs += [ "${chip_root}/config/standalone" ] matter_enable_tracing_support = true -# Perfetto requires C++17 -cpp_standard = "gnu++17" - matter_log_json_payload_hex = true matter_log_json_payload_decode_full = true diff --git a/examples/common/tracing/BUILD.gn b/examples/common/tracing/BUILD.gn index 57eaaca3952245..266c3fc0f31581 100644 --- a/examples/common/tracing/BUILD.gn +++ b/examples/common/tracing/BUILD.gn @@ -19,10 +19,7 @@ import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/lib/lib.gni") declare_args() { - # TODO: cpp_standard check is not ideal, it should be >= 17, - # however for now this is what we use in compilations - matter_commandline_enable_perfetto_tracing = - current_os == "linux" && cpp_standard == "gnu++17" + matter_commandline_enable_perfetto_tracing = current_os == "linux" } config("default_config") { diff --git a/examples/light-switch-app/genio/with_pw_rpc.gni b/examples/light-switch-app/genio/with_pw_rpc.gni index 581b4f415d5654..b8fc451b7c4a3a 100644 --- a/examples/light-switch-app/genio/with_pw_rpc.gni +++ b/examples/light-switch-app/genio/with_pw_rpc.gni @@ -23,5 +23,3 @@ mt793x_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni b/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni index f398cda41f8c7d..4b76ad23d426ac 100644 --- a/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni +++ b/examples/lighting-app/bouffalolab/bl602/with_pw_rpc.gni @@ -22,8 +22,6 @@ import("${chip_root}/examples/platform/bouffalolab/bl602/args.gni") chip_enable_pw_rpc = true -cpp_standard = "gnu++17" - # pigweed updated to a1bd248 makes compile conversion errors; # it seems riscv gcc (version > 10) can fixes this issue. # let's disable strict warnings for RPC enabled for now. diff --git a/examples/lighting-app/bouffalolab/bl702/with_pw_rpc.gni b/examples/lighting-app/bouffalolab/bl702/with_pw_rpc.gni index 0a075b0e27228c..130936065cd57c 100644 --- a/examples/lighting-app/bouffalolab/bl702/with_pw_rpc.gni +++ b/examples/lighting-app/bouffalolab/bl702/with_pw_rpc.gni @@ -22,8 +22,6 @@ import("${chip_root}/examples/platform/bouffalolab/bl702/args.gni") chip_enable_pw_rpc = true -cpp_standard = "gnu++17" - # pigweed updated to a1bd248 makes compile conversion errors; # it seems riscv gcc (version > 10) can fixes this issue. # let's disable strict warnings for RPC enabled for now. diff --git a/examples/lighting-app/bouffalolab/bl702l/with_pw_rpc.gni b/examples/lighting-app/bouffalolab/bl702l/with_pw_rpc.gni index 81aacad443b43c..5d7ce27c99df3d 100644 --- a/examples/lighting-app/bouffalolab/bl702l/with_pw_rpc.gni +++ b/examples/lighting-app/bouffalolab/bl702l/with_pw_rpc.gni @@ -22,6 +22,4 @@ import("${chip_root}/examples/platform/bouffalolab/bl702l/args.gni") chip_enable_pw_rpc = true chip_build_pw_trace_lib = false - -cpp_standard = "gnu++17" #pw_trace_BACKEND = "$dir_pw_trace_tokenized" diff --git a/examples/lighting-app/genio/with_pw_rpc.gni b/examples/lighting-app/genio/with_pw_rpc.gni index 581b4f415d5654..b8fc451b7c4a3a 100644 --- a/examples/lighting-app/genio/with_pw_rpc.gni +++ b/examples/lighting-app/genio/with_pw_rpc.gni @@ -23,5 +23,3 @@ mt793x_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/lighting-app/qpg/with_pw_rpc.gni b/examples/lighting-app/qpg/with_pw_rpc.gni index 2c388aa153388e..a2d2b536b17682 100644 --- a/examples/lighting-app/qpg/with_pw_rpc.gni +++ b/examples/lighting-app/qpg/with_pw_rpc.gni @@ -22,5 +22,3 @@ qpg_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/lighting-app/silabs/with_pw_rpc.gni b/examples/lighting-app/silabs/with_pw_rpc.gni index f8af7659ce1ed8..b53832f4b3d468 100644 --- a/examples/lighting-app/silabs/with_pw_rpc.gni +++ b/examples/lighting-app/silabs/with_pw_rpc.gni @@ -25,7 +25,5 @@ app_data_model = "${chip_root}/examples/lighting-app/lighting-common" chip_enable_pw_rpc = true chip_enable_openthread = true -cpp_standard = "gnu++17" - # Light app on EFR enables tracing server pw_trace_BACKEND = "$dir_pw_trace_tokenized" diff --git a/examples/lock-app/genio/with_pw_rpc.gni b/examples/lock-app/genio/with_pw_rpc.gni index 581b4f415d5654..b8fc451b7c4a3a 100644 --- a/examples/lock-app/genio/with_pw_rpc.gni +++ b/examples/lock-app/genio/with_pw_rpc.gni @@ -23,5 +23,3 @@ mt793x_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/lock-app/qpg/with_pw_rpc.gni b/examples/lock-app/qpg/with_pw_rpc.gni index 60eff2c6f10c42..6f195eee957169 100644 --- a/examples/lock-app/qpg/with_pw_rpc.gni +++ b/examples/lock-app/qpg/with_pw_rpc.gni @@ -22,5 +22,3 @@ import("${chip_root}/examples/platform/qpg/args.gni") qpg_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true - -cpp_standard = "gnu++17" diff --git a/examples/lock-app/silabs/with_pw_rpc.gni b/examples/lock-app/silabs/with_pw_rpc.gni index 2592790c03e2ce..c919d90189eb7c 100644 --- a/examples/lock-app/silabs/with_pw_rpc.gni +++ b/examples/lock-app/silabs/with_pw_rpc.gni @@ -26,8 +26,6 @@ chip_enable_pw_rpc = true chip_enable_openthread = true chip_openthread_ftd = true -cpp_standard = "gnu++17" - # To fit in flash chip_detail_logging = false show_qr_code = false diff --git a/examples/ota-requestor-app/genio/with_pw_rpc.gni b/examples/ota-requestor-app/genio/with_pw_rpc.gni index 581b4f415d5654..b8fc451b7c4a3a 100644 --- a/examples/ota-requestor-app/genio/with_pw_rpc.gni +++ b/examples/ota-requestor-app/genio/with_pw_rpc.gni @@ -23,5 +23,3 @@ mt793x_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/pump-app/silabs/with_pw_rpc.gni b/examples/pump-app/silabs/with_pw_rpc.gni index bade7c7ea1f376..fb05fde8b4ccc3 100644 --- a/examples/pump-app/silabs/with_pw_rpc.gni +++ b/examples/pump-app/silabs/with_pw_rpc.gni @@ -26,7 +26,5 @@ chip_enable_pw_rpc = true chip_enable_openthread = true chip_build_pw_trace_lib = true -cpp_standard = "gnu++17" - # Light app on EFR enables tracing server pw_trace_BACKEND = "$dir_pw_trace_tokenized" diff --git a/examples/smoke-co-alarm-app/silabs/with_pw_rpc.gni b/examples/smoke-co-alarm-app/silabs/with_pw_rpc.gni index d06a784404a350..9b757515aceca9 100644 --- a/examples/smoke-co-alarm-app/silabs/with_pw_rpc.gni +++ b/examples/smoke-co-alarm-app/silabs/with_pw_rpc.gni @@ -25,5 +25,3 @@ app_data_model = "${chip_root}/examples/smoke-co-alarm-app/smoke-co-alarm-common" chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/examples/thermostat/genio/with_pw_rpc.gni b/examples/thermostat/genio/with_pw_rpc.gni index 581b4f415d5654..b8fc451b7c4a3a 100644 --- a/examples/thermostat/genio/with_pw_rpc.gni +++ b/examples/thermostat/genio/with_pw_rpc.gni @@ -23,5 +23,3 @@ mt793x_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true chip_enable_openthread = true - -cpp_standard = "gnu++17" diff --git a/src/test_driver/efr32/args.gni b/src/test_driver/efr32/args.gni index 2ef6653a0181e2..a8d442d5c2140e 100644 --- a/src/test_driver/efr32/args.gni +++ b/src/test_driver/efr32/args.gni @@ -21,7 +21,6 @@ import("${chip_root}/src/platform/silabs/efr32/args.gni") silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") chip_enable_pw_rpc = true -cpp_standard = "gnu++17" chip_build_tests = true chip_enable_openthread = true chip_openthread_ftd = true From 4963c26ebc077001921b54be07cc61eaf603c685 Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Tue, 25 Jul 2023 16:59:22 -0400 Subject: [PATCH 22/33] Add ipv6only build for rpc target, to not run out of ram when linking after #28104 (#28276) Co-authored-by: Andrei Litvin --- integrations/cloudbuild/smoke-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/cloudbuild/smoke-test.yaml b/integrations/cloudbuild/smoke-test.yaml index 05511e2b184670..a745ee172004cc 100644 --- a/integrations/cloudbuild/smoke-test.yaml +++ b/integrations/cloudbuild/smoke-test.yaml @@ -32,7 +32,7 @@ steps: ./scripts/build/build_examples.py --enable-flashbundle --target esp32-devkitc-light-rpc --target esp32-m5stack-all-clusters-ipv6only --target - esp32-m5stack-all-clusters-rpc --target + esp32-m5stack-all-clusters-rpc-ipv6only --target esp32-m5stack-light --target esp32-m5stack-light-ipv6only --target esp32-m5stack-ota-requestor build --create-archives From ae10124a47ea17da09b7c2ecf146ec86d103c02e Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 15:45:24 -0700 Subject: [PATCH 23/33] Attempting to fix error ` error: 'ReplacementProductStruct' was not declared in this scope` https://github.com/project-chip/connectedhomeip/actions/runs/5662424327/job/15342317066?pr=28185 --- src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml | 2 +- src/app/tests/suites/TestHepaFilterMonitoring.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml index b7d3856dbcea45..ea82685b266f74 100644 --- a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml +++ b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Resource Monitor Cluster Tests +name: Activated Carbon Filter Monitoring Cluster Tests config: nodeId: 0x12344321 diff --git a/src/app/tests/suites/TestHepaFilterMonitoring.yaml b/src/app/tests/suites/TestHepaFilterMonitoring.yaml index f6af00f533a3d7..ad1011142a0111 100644 --- a/src/app/tests/suites/TestHepaFilterMonitoring.yaml +++ b/src/app/tests/suites/TestHepaFilterMonitoring.yaml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: Resource Monitor Cluster Tests +name: HEPA Filter Monitoring Cluster Tests config: nodeId: 0x12344321 From f6d1305b22d7f1542da02d6e363abb8dfdba462b Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 17:09:13 -0700 Subject: [PATCH 24/33] Modifying the placeholder app to have example output --- examples/placeholder/linux/apps/app1/BUILD.gn | 1 + examples/placeholder/linux/apps/app2/BUILD.gn | 1 + .../include/resource-monitoring-instances.h | 75 ++++++++++++ .../linux/resource-monitoring-instances.cpp | 115 ++++++++++++++++++ .../TestActivatedCarbonFilterMonitoring.yaml | 27 +++- .../suites/TestHepaFilterMonitoring.yaml | 25 ---- .../chip-tool/zap-generated/test/Commands.h | 34 ++++-- .../zap-generated/test/Commands.h | 34 ++++-- 8 files changed, 268 insertions(+), 44 deletions(-) create mode 100644 examples/placeholder/linux/include/resource-monitoring-instances.h create mode 100644 examples/placeholder/linux/resource-monitoring-instances.cpp diff --git a/examples/placeholder/linux/apps/app1/BUILD.gn b/examples/placeholder/linux/apps/app1/BUILD.gn index 595a0b7563132c..99b3547b81e7c8 100644 --- a/examples/placeholder/linux/apps/app1/BUILD.gn +++ b/examples/placeholder/linux/apps/app1/BUILD.gn @@ -30,6 +30,7 @@ source_set("app1") { ] sources = [ + "../../resource-monitoring-instances.cpp", "../../src/bridged-actions-stub.cpp", "../../static-supported-modes-manager.cpp", ] diff --git a/examples/placeholder/linux/apps/app2/BUILD.gn b/examples/placeholder/linux/apps/app2/BUILD.gn index 7d8f30a8ea83ec..91777971875d15 100644 --- a/examples/placeholder/linux/apps/app2/BUILD.gn +++ b/examples/placeholder/linux/apps/app2/BUILD.gn @@ -30,6 +30,7 @@ source_set("app2") { ] sources = [ + "../../resource-monitoring-instances.cpp", "../../src/bridged-actions-stub.cpp", "../../static-supported-modes-manager.cpp", ] diff --git a/examples/placeholder/linux/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-instances.h new file mode 100644 index 00000000000000..9cd859d22fe027 --- /dev/null +++ b/examples/placeholder/linux/include/resource-monitoring-instances.h @@ -0,0 +1,75 @@ +/* + * + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +/// This is an application level Instance to handle ActivatedCarbonfilterMonitoringInstance commands according to the specific +/// business logic. +class ActivatedCarbonFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance +{ +private: + CHIP_ERROR AppInit() override; + chip::Protocols::InteractionModel::Status PreResetCondition() override; + chip::Protocols::InteractionModel::Status PostResetCondition() override; + +public: + ActivatedCarbonFilterMonitoringInstance( + chip::EndpointId aEndpointId, uint32_t aFeature, + chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported) : + Instance(aEndpointId, chip::app::Clusters::ActivatedCarbonFilterMonitoring::Id, aFeature, aDegradationDirection, + aResetConditionCommandSupported){}; +}; + +/// This is an application level instance to handle HepaFilterMonitoringInstance commands according to the specific business logic. +class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitoring::Instance +{ +private: + CHIP_ERROR AppInit() override; + chip::Protocols::InteractionModel::Status PreResetCondition() override; + chip::Protocols::InteractionModel::Status PostResetCondition() override; + +public: + HepaFilterMonitoringInstance( + chip::EndpointId aEndpointId, uint32_t aFeature, + chip::app::Clusters::ResourceMonitoring::Attributes::DegradationDirection::TypeInfo::Type aDegradationDirection, + bool aResetConditionCommandSupported) : + Instance(aEndpointId, chip::app::Clusters::HepaFilterMonitoring::Id, aFeature, aDegradationDirection, + aResetConditionCommandSupported){}; +}; + +class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager +{ +public: + CHIP_ERROR + Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType & item) override; + + ~StaticReplacementProductListManager() {} + StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * aReplacementProductsList, + uint8_t aReplacementProductListSize) + { + mReplacementProductsList = aReplacementProductsList; + mReplacementProductListSize = aReplacementProductListSize; + } + +private: + chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * mReplacementProductsList; + uint8_t mReplacementProductListSize; +}; diff --git a/examples/placeholder/linux/resource-monitoring-instances.cpp b/examples/placeholder/linux/resource-monitoring-instances.cpp new file mode 100644 index 00000000000000..e0e38681da1a09 --- /dev/null +++ b/examples/placeholder/linux/resource-monitoring-instances.cpp @@ -0,0 +1,115 @@ +/* + * + * Copyright (c) 2023 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; +using namespace chip::app::Clusters::ResourceMonitoring; +using chip::Protocols::InteractionModel::Status; + +constexpr std::bitset<4> gHepaFilterFeatureMap{ static_cast(Feature::kCondition) | + static_cast(Feature::kWarning) | + static_cast(Feature::kReplacementProductList) }; +constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Feature::kCondition) | + static_cast(Feature::kWarning) | + static_cast(Feature::kReplacementProductList) }; + +static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; +static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; + +static ResourceMonitoring::Attributes::GenericType sReplacementProductsList[] = { + { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, + { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, + { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, + { ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx") }, + { ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") }, +}; +StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0], + ArraySize(sReplacementProductsList)); + +//-- Activated Carbon Filter Monitoring Instance methods +CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() +{ + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringDelegate::Init()"); + SetReplacementProductListManagerInstance(&sReplacementProductListManager); + return CHIP_NO_ERROR; +} + +Status ActivatedCarbonFilterMonitoringInstance::PreResetCondition() +{ + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PreResetCondition()"); + return Status::Success; +} + +Status ActivatedCarbonFilterMonitoringInstance::PostResetCondition() +{ + ChipLogDetail(Zcl, "ActivatedCarbonFilterMonitoringInstance::PostResetCondition()"); + return Status::Success; +} + +//-- Hepa Filter Monitoring instance methods +CHIP_ERROR HepaFilterMonitoringInstance::AppInit() +{ + ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); + SetReplacementProductListManagerInstance(&sReplacementProductListManager); + return CHIP_NO_ERROR; +} + +Status HepaFilterMonitoringInstance::PreResetCondition() +{ + ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PreResetCondition()"); + return Status::Success; +} + +Status HepaFilterMonitoringInstance::PostResetCondition() +{ + ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::PostResetCondition()"); + return Status::Success; +} + +void emberAfActivatedCarbonFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) +{ + VerifyOrDie(gActivatedCarbonFilterInstance == nullptr); + gActivatedCarbonFilterInstance = new ActivatedCarbonFilterMonitoringInstance( + endpoint, static_cast(gActivatedCarbonFeatureMap.to_ulong()), DegradationDirectionEnum::kDown, true); + gActivatedCarbonFilterInstance->Init(); +} +void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) +{ + VerifyOrDie(gHepaFilterInstance == nullptr); + gHepaFilterInstance = new HepaFilterMonitoringInstance(endpoint, static_cast(gHepaFilterFeatureMap.to_ulong()), + DegradationDirectionEnum::kDown, true); + gHepaFilterInstance->Init(); +} + +CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) +{ + if (mIndex < mReplacementProductListSize) + { + item = mReplacementProductsList[mIndex]; + mIndex++; + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; +} diff --git a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml index ea82685b266f74..c47e01fc473bf4 100644 --- a/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml +++ b/src/app/tests/suites/TestActivatedCarbonFilterMonitoring.yaml @@ -18,10 +18,6 @@ config: nodeId: 0x12344321 cluster: "Activated Carbon Filter Monitoring" endpoint: 1 - ReplacementProductList: - type: "ReplacementProductStruct" - defaultValue: - [{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }] tests: - label: "Wait for the commissioned device to be retrieved" @@ -37,4 +33,25 @@ tests: attribute: "ReplacementProductList" response: value: - [{ ProductIdentifierType: 1, ProductIdentifierValue: "gtin8xac" }] + [ + { + ProductIdentifierType: 0, + ProductIdentifierValue: "111112222233", + }, + { + ProductIdentifierType: 1, + ProductIdentifierValue: "gtin8xxx", + }, + { + ProductIdentifierType: 2, + ProductIdentifierValue: "4444455555666", + }, + { + ProductIdentifierType: 3, + ProductIdentifierValue: "gtin14xxxxxxxx", + }, + { + ProductIdentifierType: 4, + ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx", + }, + ] diff --git a/src/app/tests/suites/TestHepaFilterMonitoring.yaml b/src/app/tests/suites/TestHepaFilterMonitoring.yaml index ad1011142a0111..44b79eec8afc5c 100644 --- a/src/app/tests/suites/TestHepaFilterMonitoring.yaml +++ b/src/app/tests/suites/TestHepaFilterMonitoring.yaml @@ -18,31 +18,6 @@ config: nodeId: 0x12344321 cluster: "HEPA Filter Monitoring" endpoint: 1 - ReplacementProductList: - type: "ReplacementProductStruct" - defaultValue: - [ - { - ProductIdentifierType: 0, - ProductIdentifierValue: "111112222233", - }, - { - ProductIdentifierType: 1, - ProductIdentifierValue: "gtin8xxx", - }, - { - ProductIdentifierType: 2, - ProductIdentifierValue: "4444455555666", - }, - { - ProductIdentifierType: 3, - ProductIdentifierValue: "gtin14xxxxxxxx", - }, - { - ProductIdentifierType: 4, - ProductIdentifierValue: "oem20xxxxxxxxxxxxxxx", - }, - ] tests: - label: "Wait for the commissioned device to be retrieved" diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 26be6ad6f1a24a..e16d6adacf431e 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -113649,7 +113649,6 @@ class TestActivatedCarbonFilterMonitoringSuite : public TestCommand AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); AddArgument("cluster", &mCluster); AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); - AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); AddArgument("timeout", 0, UINT16_MAX, &mTimeout); } @@ -113664,7 +113663,6 @@ class TestActivatedCarbonFilterMonitoringSuite : public TestCommand chip::Optional mNodeId; chip::Optional mCluster; chip::Optional mEndpoint; - chip::Optional mReplacementProductList; chip::Optional mTimeout; chip::EndpointId GetEndpoint(chip::EndpointId endpoint) { return mEndpoint.HasValue() ? mEndpoint.Value() : endpoint; } @@ -113694,10 +113692,34 @@ class TestActivatedCarbonFilterMonitoringSuite : public TestCommand auto iter_0 = value.begin(); VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 0)); VerifyOrReturn( - CheckValue("replacementProductList[0].productIdentifierType", iter_0.GetValue().productIdentifierType, 1U)); + CheckValue("replacementProductList[0].productIdentifierType", iter_0.GetValue().productIdentifierType, 0U)); VerifyOrReturn(CheckValueAsString("replacementProductList[0].productIdentifierValue", - iter_0.GetValue().productIdentifierValue, chip::CharSpan("gtin8xac", 8))); - VerifyOrReturn(CheckNoMoreListItems("replacementProductList", iter_0, 1)); + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("111112222233", 12))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 1)); + VerifyOrReturn( + CheckValue("replacementProductList[1].productIdentifierType", iter_0.GetValue().productIdentifierType, 1U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[1].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, chip::CharSpan("gtin8xxx", 8))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 2)); + VerifyOrReturn( + CheckValue("replacementProductList[2].productIdentifierType", iter_0.GetValue().productIdentifierType, 2U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[2].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("4444455555666", 13))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 3)); + VerifyOrReturn( + CheckValue("replacementProductList[3].productIdentifierType", iter_0.GetValue().productIdentifierType, 3U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[3].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("gtin14xxxxxxxx", 14))); + VerifyOrReturn(CheckNextListItemDecodes("replacementProductList", iter_0, 4)); + VerifyOrReturn( + CheckValue("replacementProductList[4].productIdentifierType", iter_0.GetValue().productIdentifierType, 4U)); + VerifyOrReturn(CheckValueAsString("replacementProductList[4].productIdentifierValue", + iter_0.GetValue().productIdentifierValue, + chip::CharSpan("oem20xxxxxxxxxxxxxxx", 20))); + VerifyOrReturn(CheckNoMoreListItems("replacementProductList", iter_0, 5)); } } break; @@ -113742,7 +113764,6 @@ class TestHepaFilterMonitoringSuite : public TestCommand AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); AddArgument("cluster", &mCluster); AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); - AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); AddArgument("timeout", 0, UINT16_MAX, &mTimeout); } @@ -113757,7 +113778,6 @@ class TestHepaFilterMonitoringSuite : public TestCommand chip::Optional mNodeId; chip::Optional mCluster; chip::Optional mEndpoint; - chip::Optional mReplacementProductList; chip::Optional mTimeout; chip::EndpointId GetEndpoint(chip::EndpointId endpoint) { return mEndpoint.HasValue() ? mEndpoint.Value() : endpoint; } diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 2f9a3369643e46..125b3516ffbc3d 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -172708,7 +172708,6 @@ class TestActivatedCarbonFilterMonitoring : public TestCommandBridge { AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); AddArgument("cluster", &mCluster); AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); - AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); AddArgument("timeout", 0, UINT16_MAX, &mTimeout); } // NOLINTEND(clang-analyzer-nullability.NullPassedToNonnull) @@ -172780,7 +172779,6 @@ class TestActivatedCarbonFilterMonitoring : public TestCommandBridge { chip::Optional mNodeId; chip::Optional mCluster; chip::Optional mEndpoint; - chip::Optional mReplacementProductList; chip::Optional mTimeout; CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrieved_0() @@ -172807,13 +172805,37 @@ class TestActivatedCarbonFilterMonitoring : public TestCommandBridge { { id actualValue = value; - VerifyOrReturn(CheckValue("ReplacementProductList", [actualValue count], static_cast(1))); + VerifyOrReturn(CheckValue("ReplacementProductList", [actualValue count], static_cast(5))); VerifyOrReturn(CheckValue("ProductIdentifierType", ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierType, - 1U)); + 0U)); VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[0]).productIdentifierValue, - @"gtin8xac")); + @"111112222233")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[1]).productIdentifierType, + 1U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[1]).productIdentifierValue, + @"gtin8xxx")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[2]).productIdentifierType, + 2U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[2]).productIdentifierValue, + @"4444455555666")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[3]).productIdentifierType, + 3U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[3]).productIdentifierValue, + @"gtin14xxxxxxxx")); + VerifyOrReturn(CheckValue("ProductIdentifierType", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[4]).productIdentifierType, + 4U)); + VerifyOrReturn(CheckValueAsString("ProductIdentifierValue", + ((MTRActivatedCarbonFilterMonitoringClusterReplacementProductStruct *) actualValue[4]).productIdentifierValue, + @"oem20xxxxxxxxxxxxxxx")); } NextTest(); @@ -172833,7 +172855,6 @@ class TestHepaFilterMonitoring : public TestCommandBridge { AddArgument("nodeId", 0, UINT64_MAX, &mNodeId); AddArgument("cluster", &mCluster); AddArgument("endpoint", 0, UINT16_MAX, &mEndpoint); - AddArgument("ReplacementProductList", 0, UINT0_MAX, &mReplacementProductList); AddArgument("timeout", 0, UINT16_MAX, &mTimeout); } // NOLINTEND(clang-analyzer-nullability.NullPassedToNonnull) @@ -172905,7 +172926,6 @@ class TestHepaFilterMonitoring : public TestCommandBridge { chip::Optional mNodeId; chip::Optional mCluster; chip::Optional mEndpoint; - chip::Optional mReplacementProductList; chip::Optional mTimeout; CHIP_ERROR TestWaitForTheCommissionedDeviceToBeRetrieved_0() From 11802f75ee199f8bbb5c3cb2fd19e540a93839fe Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 22:16:04 -0700 Subject: [PATCH 25/33] Moved around the ReplacementProductStruct to the ResourceMonitoring namespace (rather than Attributes) Also removed the ReplacementProductList namespace and changed the implementation of the DynamicReplacementProductListManager --- .../include/resource-monitoring-instances.h | 6 +- .../src/resource-monitoring-instances.cpp | 4 +- .../include/resource-monitoring-instances.h | 6 +- .../linux/resource-monitoring-instances.cpp | 4 +- .../DynamicReplacementProductListManager.h | 25 +++- .../StaticReplacementProductListManager.h | 6 +- .../src/ReplacementProductListManager.cpp | 21 ++- .../ActivatedCarbonFilterMonitoring.cpp | 2 +- .../src/instances/HepafilterMonitoring.cpp | 14 +- .../replacement-product-list-manager.h | 10 +- .../resource-monitoring-cluster-objects.h | 133 ++++++++---------- .../resource-monitoring-server.cpp | 6 +- 12 files changed, 124 insertions(+), 113 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index 9cd859d22fe027..9571c28381a179 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -59,10 +59,10 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource { public: CHIP_ERROR - Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType & item) override; + Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * aReplacementProductsList, + StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; @@ -70,6 +70,6 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource } private: - chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * mReplacementProductsList; + chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index e0e38681da1a09..693dad09860ddd 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -37,7 +37,7 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; -static ResourceMonitoring::Attributes::GenericType sReplacementProductsList[] = { +static ReplacementProductStruct sReplacementProductsList[] = { { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, @@ -102,7 +102,7 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) +CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/placeholder/linux/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-instances.h index 9cd859d22fe027..9571c28381a179 100644 --- a/examples/placeholder/linux/include/resource-monitoring-instances.h +++ b/examples/placeholder/linux/include/resource-monitoring-instances.h @@ -59,10 +59,10 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource { public: CHIP_ERROR - Next(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType & item) override; + Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * aReplacementProductsList, + StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; @@ -70,6 +70,6 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource } private: - chip::app::Clusters::ResourceMonitoring::Attributes::GenericType * mReplacementProductsList; + chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/placeholder/linux/resource-monitoring-instances.cpp b/examples/placeholder/linux/resource-monitoring-instances.cpp index e0e38681da1a09..141a34fb70ab5c 100644 --- a/examples/placeholder/linux/resource-monitoring-instances.cpp +++ b/examples/placeholder/linux/resource-monitoring-instances.cpp @@ -37,7 +37,7 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; -static ResourceMonitoring::Attributes::GenericType sReplacementProductsList[] = { +static ResourceMonitoring::ReplacementProductStruct sReplacementProductsList[] = { { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, @@ -102,7 +102,7 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) +CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & item) { if (mIndex < mReplacementProductListSize) { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h index af9c81ef658cb9..4f6d398c313c6a 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h @@ -34,26 +34,39 @@ namespace ResourceMonitoring { class DynamicReplacementProductListManager : public ReplacementProductListManager { public: - CHIP_ERROR Next(Attributes::GenericType & item) override; + CHIP_ERROR Next(ReplacementProductStruct & item) override; - CHIP_ERROR addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, + /** + * Creates a ReplacementProductStruct and adds it to the list. Can only add up to kReplacementProductListMaxSize + * entries to a list (as defined by the spec). + * + * @param aProductIdentifierType The identifier type of the product. + * @param aProductIdentifierValue The value of the product. + * @return CHIP_ERROR_NO_MEMORY if the list is full, a CHIP_ERROR if there was a problem creating the + * ReplacementProductStruct and a CHIP_NO_ERROR otherwise. + */ + CHIP_ERROR AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) { - Attributes::GenericType * type = &mReplacementProductsList[mReplacementProductListSize]; - CHIP_ERROR err = type->setProductIdentifierValue(aProductIdentifierValue); + if (mReplacementProductListSize == kReplacementProductListMaxSize) + { + return CHIP_ERROR_NO_MEMORY; + } + ReplacementProductStruct * type = &mReplacementProductsList[mReplacementProductListSize]; + CHIP_ERROR err = type->SetProductIdentifierValue(aProductIdentifierValue); if (CHIP_NO_ERROR != err) { return err; }; - type->setProductIdentifierType(aProductIdentifierType); + type->SetProductIdentifierType(aProductIdentifierType); mReplacementProductListSize++; return CHIP_NO_ERROR; } private: - Attributes::GenericType mReplacementProductsList[ReplacementProductListManager::kReplacementProductListMaxSize]; + ReplacementProductStruct mReplacementProductsList[ReplacementProductListManager::kReplacementProductListMaxSize]; uint8_t mReplacementProductListSize; }; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h index 51566b627289fe..26601a235fcb1d 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/StaticReplacementProductListManager.h @@ -34,17 +34,17 @@ namespace ResourceMonitoring { class StaticReplacementProductListManager : public ReplacementProductListManager { public: - CHIP_ERROR Next(Attributes::GenericType & item) override; + CHIP_ERROR Next(ReplacementProductStruct & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(Attributes::GenericType * aReplacementProductsList, uint8_t aReplacementProductListSize) + StaticReplacementProductListManager(ReplacementProductStruct * aReplacementProductsList, uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; mReplacementProductListSize = aReplacementProductListSize; } private: - Attributes::GenericType * mReplacementProductsList; + ReplacementProductStruct * mReplacementProductsList; uint8_t mReplacementProductListSize; }; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index b5f9a5fb698542..bb0f453aff9421 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -26,7 +26,7 @@ using namespace chip::app::Clusters; using namespace chip::app::Clusters::ResourceMonitoring; -CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & item) +CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & item) { if (mIndex < mReplacementProductListSize) { @@ -38,14 +38,27 @@ CHIP_ERROR StaticReplacementProductListManager::Next(Attributes::GenericType & i return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } -CHIP_ERROR DynamicReplacementProductListManager::Next(Attributes::GenericType & item) +CHIP_ERROR DynamicReplacementProductListManager::Next(ReplacementProductStruct & item) { +// if (mIndex < mReplacementProductListSize) +// { +// item = mReplacementProductsList[mIndex]; +// mIndex++; +// return CHIP_NO_ERROR; +// } +// +// return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; +//} + +//CHIP_ERROR ReplacementProductListManager::Next(ReplacementProductStruct & item) +//{ if (mIndex < mReplacementProductListSize) { - item = mReplacementProductsList[mIndex]; + item.SetProductIdentifierType(mReplacementProductsList[mIndex].GetProductIdentifierType()); + item.SetProductIdentifierValue(mReplacementProductsList[mIndex].GetProductIdentifierValue()); mIndex++; return CHIP_NO_ERROR; } return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; -} +} \ No newline at end of file diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp index a45cfe525619ba..3ab33e675e02a9 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/ActivatedCarbonFilterMonitoring.cpp @@ -35,7 +35,7 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -static GenericType sActivatedCarbonFilterReplacementProductsList[] = { +static ReplacementProductStruct sActivatedCarbonFilterReplacementProductsList[] = { { ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, { ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xca") }, { ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index b31a31c7caf121..ba795681af4e31 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -34,25 +34,25 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -DynamicReplacementProductListManager mHepaFilterReplacementProductListManager; +DynamicReplacementProductListManager hepaFilterReplacementProductListManager; //-- Hepa filter Monitoring instance methods CHIP_ERROR HepaFilterMonitoringInstance::AppInit() { ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, + hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, + hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xhe")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, + hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, + hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xhepaxxx")); - mHepaFilterReplacementProductListManager.addItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, + hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); - SetReplacementProductListManagerInstance(&mHepaFilterReplacementProductListManager); + SetReplacementProductListManagerInstance(&hepaFilterReplacementProductListManager); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h index f23736b5fe5878..52305bf68d2483 100644 --- a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h +++ b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h @@ -34,6 +34,7 @@ namespace ResourceMonitoring { class ReplacementProductListManager { public: + // The max replacement product list size as defined in the specification static constexpr size_t kReplacementProductListMaxSize = 5u; ReplacementProductListManager() {} @@ -42,16 +43,15 @@ class ReplacementProductListManager void Reset() { mIndex = 0; } /** - * Iterates through the entries in the ReplacementProductListManager. Each call to this function move the list pointer to the - * next element. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function + * Iterates through the entries in the ReplacementProductListManager. Each call to this function copies the next item into + * the out param. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function * will return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the end of the list has been reached. * - * @param[out] item An out parameter that is populated with the address of the item in the list. Will be empty if there are no - * remaining items in the list. In normal circumstances this parameter should never be modified. + * @param[out] item An out parameter that has a copy of the item retrieved in the list. * @return CHIP_NO_ERROR if the pointer to the list element has moved to the next element and there are still valid remaining * entries in the list. Otherwise returns CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the list has hit the last element. */ - virtual CHIP_ERROR Next(Attributes::GenericType & item) = 0; + virtual CHIP_ERROR Next(ReplacementProductStruct & item) = 0; protected: uint8_t mIndex; diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index fc12cdb9e3979b..ab1e85cbd2ed54 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -29,8 +29,8 @@ namespace app { namespace Clusters { namespace ResourceMonitoring { -// max of 20 characters + 1 for null terminator -static constexpr size_t kProductIdentifierValueMaxNameLength = 21u; +// max of 20 characters as defined by the constraint on the ProductIdentifierValue in the specification +static constexpr size_t kProductIdentifierValueMaxNameLength = 20u; static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; // Enum for ChangeIndicationEnum @@ -76,6 +76,63 @@ enum class ProductIdentifierTypeEnum : uint8_t kOem = 0x04 }; +// A struct used during reads of the ReplacementProductList to store a single list instance we request +// from the application. +// +// Inherit from an auto-generated struct to pick up the implementation bits, but make +// it private inheritance so people can't accidentally use this struct where the other +// is expected. +struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type +{ +private: + char productIdentifierValueBuffer[kProductIdentifierValueMaxNameLength]; + +public: + static constexpr bool kIsFabricScoped = false; + virtual ~ReplacementProductStruct() = default; + ReplacementProductStruct() {} + ReplacementProductStruct(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + { + SetProductIdentifierType(aProductIdentifierType); + SetProductIdentifierValue(aProductIdentifierValue); + } + + using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; + + /** + * Sets the product identifier type. + * + * @param aProductIdentifierType The product identifier type. + */ + void SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) + { + productIdentifierType = static_cast(aProductIdentifierType); + } + + /** + * Sets the product identifier value. + * This implementation will copy the argument into this struct's buffer. + * + * @param aProductIdentifierValue The value of the product identifier to set. + * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid + * or the size exceeds kProductIdentifierValueMaxNameLength, returns CHIP_NO_ERROR + * otherwise. + */ + CHIP_ERROR SetProductIdentifierValue(chip::CharSpan aProductIdentifierValue) + { + VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(aProductIdentifierValue.size() <= sizeof(productIdentifierValueBuffer), CHIP_ERROR_INVALID_ARGUMENT); + + memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size()); + productIdentifierValue = CharSpan(productIdentifierValueBuffer, aProductIdentifierValue.size()); + + return CHIP_NO_ERROR; + } + + ProductIdentifierTypeEnum GetProductIdentifierType() { return static_cast(productIdentifierType); }; + chip::CharSpan GetProductIdentifierValue() { return productIdentifierValue; }; +}; + namespace Attributes { namespace Condition { @@ -143,78 +200,6 @@ struct TypeInfo }; } // namespace LastChangedTime -// A struct used during reads of the ReplacementProductList to store a single list instance we request -// from the application. -// -// Inherit from an auto-generated struct to pick up the implementation bits, but make -// it private inheritance so people can't accidentally use this struct where the other -// is expected. -struct GenericType : private HepaFilterMonitoring::Structs::ReplacementProductStruct::Type -{ -private: - char productIdentifierValueBuffer[kProductIdentifierValueMaxNameLength]; - -public: - static constexpr bool kIsFabricScoped = false; - virtual ~GenericType() = default; - GenericType() {} - GenericType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) - { - setProductIdentifierType(aProductIdentifierType); - setProductIdentifierValue(aProductIdentifierValue); - } - - using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; - - /** - * Sets the product identifier type. - * - * @param aProductIdentifierType The product identifier type. - */ - void setProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType) - { - productIdentifierType = static_cast(aProductIdentifierType); - } - - /** - * Sets the product identifier value. - * This implementation will copy the argument to the local implementation. - * - * @param aProductIdentifierValue The value of the product identifier to set. - * @return CHIP_ERROR_INVALID_ARGUMENT when aProductIdentifierValue is invalid, CHIP_NO_ERROR otherwise. - */ - CHIP_ERROR setProductIdentifierValue(chip::CharSpan aProductIdentifierValue) - { - VerifyOrReturnError(IsSpanUsable(aProductIdentifierValue), CHIP_ERROR_INVALID_ARGUMENT); - - if (aProductIdentifierValue.size() > sizeof(productIdentifierValueBuffer)) - { - memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), sizeof(productIdentifierValueBuffer)); - productIdentifierValue = CharSpan(productIdentifierValueBuffer, sizeof(productIdentifierValueBuffer)); - } - else - { - memcpy(productIdentifierValueBuffer, aProductIdentifierValue.data(), aProductIdentifierValue.size()); - productIdentifierValue = CharSpan(productIdentifierValueBuffer, aProductIdentifierValue.size()); - } - - return CHIP_NO_ERROR; - } -}; - -namespace ReplacementProductList { -static constexpr AttributeId Id = 0x00000005; -struct TypeInfo -{ - using Type = chip::app::DataModel::List; - using DecodableType = chip::app::DataModel::DecodableList; - using DecodableArgType = const chip::app::DataModel::DecodableList &; - - static constexpr AttributeId GetAttributeId() { return Attributes::ReplacementProductList::Id; } - static constexpr bool MustUseTimedWrite() { return false; } -}; -} // namespace ReplacementProductList - namespace GeneratedCommandList { static constexpr AttributeId Id = Globals::Attributes::GeneratedCommandList::Id; struct TypeInfo : public Clusters::Globals::Attributes::GeneratedCommandList::TypeInfo diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index 6c36fbb8aace85..a95203d06a22a8 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -257,7 +257,7 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) productListManagerInstance->Reset(); err = aEncoder.EncodeList([productListManagerInstance](const auto & encoder) -> CHIP_ERROR { - Attributes::GenericType replacementProductStruct; + ReplacementProductStruct replacementProductStruct; CHIP_ERROR iteratorError = productListManagerInstance->Next(replacementProductStruct); while (CHIP_NO_ERROR == iteratorError) @@ -265,7 +265,7 @@ CHIP_ERROR Instance::ReadReplacableProductList(AttributeValueEncoder & aEncoder) ReturnErrorOnFailure(encoder.Encode(replacementProductStruct)); iteratorError = productListManagerInstance->Next(replacementProductStruct); } - return (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED != iteratorError) ? iteratorError : CHIP_NO_ERROR; + return (CHIP_ERROR_PROVIDER_LIST_EXHAUSTED == iteratorError) ? CHIP_NO_ERROR : iteratorError; }); } return err; @@ -300,7 +300,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu ReturnErrorOnFailure(aEncoder.Encode(mLastChangedTime)); break; } - case Attributes::ReplacementProductList::Id: { + case HepaFilterMonitoring::Attributes::ReplacementProductList::TypeInfo::GetAttributeId(): { return ReadReplacableProductList(aEncoder); break; } From aa6e303d8f28ef7f9aad74c9ea26b64ef06b91e9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 26 Jul 2023 05:17:31 +0000 Subject: [PATCH 26/33] Restyled by whitespace --- .../include/DynamicReplacementProductListManager.h | 2 +- .../src/ReplacementProductListManager.cpp | 2 +- .../replacement-product-list-manager.h | 2 +- .../resource-monitoring-cluster-objects.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h index 4f6d398c313c6a..6491549eaff9d9 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h @@ -39,7 +39,7 @@ class DynamicReplacementProductListManager : public ReplacementProductListManage /** * Creates a ReplacementProductStruct and adds it to the list. Can only add up to kReplacementProductListMaxSize * entries to a list (as defined by the spec). - * + * * @param aProductIdentifierType The identifier type of the product. * @param aProductIdentifierValue The value of the product. * @return CHIP_ERROR_NO_MEMORY if the list is full, a CHIP_ERROR if there was a problem creating the diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index bb0f453aff9421..f9c0f61e18f27b 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -61,4 +61,4 @@ CHIP_ERROR DynamicReplacementProductListManager::Next(ReplacementProductStruct & } return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; -} \ No newline at end of file +} diff --git a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h index 52305bf68d2483..bd63dabca180c9 100644 --- a/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h +++ b/src/app/clusters/resource-monitoring-server/replacement-product-list-manager.h @@ -43,7 +43,7 @@ class ReplacementProductListManager void Reset() { mIndex = 0; } /** - * Iterates through the entries in the ReplacementProductListManager. Each call to this function copies the next item into + * Iterates through the entries in the ReplacementProductListManager. Each call to this function copies the next item into * the out param. Calls to this function will return CHIP_NO_ERROR if there are still valid elements in the list. The function * will return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED if the end of the list has been reached. * diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index ab1e85cbd2ed54..7c47eacd40a9c2 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -29,7 +29,7 @@ namespace app { namespace Clusters { namespace ResourceMonitoring { -// max of 20 characters as defined by the constraint on the ProductIdentifierValue in the specification +// max of 20 characters as defined by the constraint on the ProductIdentifierValue in the specification static constexpr size_t kProductIdentifierValueMaxNameLength = 20u; static constexpr std::array AliasedClusters = { HepaFilterMonitoring::Id, ActivatedCarbonFilterMonitoring::Id }; From 8e91c3564dfa3b3421317f2c4b174ba95eeb28c8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 26 Jul 2023 05:17:32 +0000 Subject: [PATCH 27/33] Restyled by clang-format --- .../include/resource-monitoring-instances.h | 5 +++-- .../include/resource-monitoring-instances.h | 5 +++-- .../DynamicReplacementProductListManager.h | 2 +- .../src/ReplacementProductListManager.cpp | 22 +++++++++---------- .../src/instances/HepafilterMonitoring.cpp | 10 ++++----- .../resource-monitoring-cluster-objects.h | 5 +++-- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index 9571c28381a179..e4fb00fdcfcbf7 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -62,8 +62,9 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, - uint8_t aReplacementProductListSize) + StaticReplacementProductListManager( + chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, + uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; mReplacementProductListSize = aReplacementProductListSize; diff --git a/examples/placeholder/linux/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-instances.h index 9571c28381a179..e4fb00fdcfcbf7 100644 --- a/examples/placeholder/linux/include/resource-monitoring-instances.h +++ b/examples/placeholder/linux/include/resource-monitoring-instances.h @@ -62,8 +62,9 @@ class StaticReplacementProductListManager : public chip::app::Clusters::Resource Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, - uint8_t aReplacementProductListSize) + StaticReplacementProductListManager( + chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, + uint8_t aReplacementProductListSize) { mReplacementProductsList = aReplacementProductsList; mReplacementProductListSize = aReplacementProductListSize; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h index 6491549eaff9d9..56086b6a966d29 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h @@ -44,7 +44,7 @@ class DynamicReplacementProductListManager : public ReplacementProductListManage * @param aProductIdentifierValue The value of the product. * @return CHIP_ERROR_NO_MEMORY if the list is full, a CHIP_ERROR if there was a problem creating the * ReplacementProductStruct and a CHIP_NO_ERROR otherwise. - */ + */ CHIP_ERROR AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) { diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index f9c0f61e18f27b..e7364870cdac65 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -40,18 +40,18 @@ CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & CHIP_ERROR DynamicReplacementProductListManager::Next(ReplacementProductStruct & item) { -// if (mIndex < mReplacementProductListSize) -// { -// item = mReplacementProductsList[mIndex]; -// mIndex++; -// return CHIP_NO_ERROR; -// } -// -// return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; -//} + // if (mIndex < mReplacementProductListSize) + // { + // item = mReplacementProductsList[mIndex]; + // mIndex++; + // return CHIP_NO_ERROR; + // } + // + // return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + //} -//CHIP_ERROR ReplacementProductListManager::Next(ReplacementProductStruct & item) -//{ + // CHIP_ERROR ReplacementProductListManager::Next(ReplacementProductStruct & item) + //{ if (mIndex < mReplacementProductListSize) { item.SetProductIdentifierType(mReplacementProductsList[mIndex].GetProductIdentifierType()); diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index ba795681af4e31..e330d060e4f2f0 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -42,15 +42,15 @@ CHIP_ERROR HepaFilterMonitoringInstance::AppInit() ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, - CharSpan::fromCharString("111112222233")); + CharSpan::fromCharString("111112222233")); hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, - CharSpan::fromCharString("gtin8xhe")); + CharSpan::fromCharString("gtin8xhe")); hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, - CharSpan::fromCharString("4444455555666")); + CharSpan::fromCharString("4444455555666")); hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, - CharSpan::fromCharString("gtin14xhepaxxx")); + CharSpan::fromCharString("gtin14xhepaxxx")); hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, - CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); + CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); SetReplacementProductListManagerInstance(&hepaFilterReplacementProductListManager); diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 7c47eacd40a9c2..895c0a481b0a2f 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -89,9 +89,10 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace public: static constexpr bool kIsFabricScoped = false; - virtual ~ReplacementProductStruct() = default; + virtual ~ReplacementProductStruct() = default; ReplacementProductStruct() {} - ReplacementProductStruct(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, chip::CharSpan aProductIdentifierValue) + ReplacementProductStruct(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, + chip::CharSpan aProductIdentifierValue) { SetProductIdentifierType(aProductIdentifierType); SetProductIdentifierValue(aProductIdentifierValue); From 84ccb8ef4327ddabd1ae5b612187f379aac12b9f Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Tue, 25 Jul 2023 22:22:04 -0700 Subject: [PATCH 28/33] Removing commented out code --- .../src/ReplacementProductListManager.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index e7364870cdac65..80e4104e8c617a 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -40,18 +40,6 @@ CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & CHIP_ERROR DynamicReplacementProductListManager::Next(ReplacementProductStruct & item) { - // if (mIndex < mReplacementProductListSize) - // { - // item = mReplacementProductsList[mIndex]; - // mIndex++; - // return CHIP_NO_ERROR; - // } - // - // return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; - //} - - // CHIP_ERROR ReplacementProductListManager::Next(ReplacementProductStruct & item) - //{ if (mIndex < mReplacementProductListSize) { item.SetProductIdentifierType(mReplacementProductsList[mIndex].GetProductIdentifierType()); From 64b531691eb369e575c5b3e791e8c1935466b0c5 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Wed, 26 Jul 2023 08:29:50 -0700 Subject: [PATCH 29/33] Changing DynamicReplacementProductListManager to an ImmutableReplacementProductListManager This better represents devices that might read each replacement product from flash --- .../include/resource-monitoring-instances.h | 15 +--- .../src/resource-monitoring-instances.cpp | 52 ++++++++----- .../include/resource-monitoring-instances.h | 15 +--- .../linux/resource-monitoring-instances.cpp | 49 ++++++++---- .../DynamicReplacementProductListManager.h | 76 ------------------- .../ImmutableReplacementProductListManager.h | 44 +++++++++++ .../src/ReplacementProductListManager.cpp | 42 ++++++++-- .../src/instances/HepafilterMonitoring.cpp | 15 +--- 8 files changed, 151 insertions(+), 157 deletions(-) delete mode 100644 examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h create mode 100644 examples/resource-monitoring-app/resource-monitoring-common/include/ImmutableReplacementProductListManager.h diff --git a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h index e4fb00fdcfcbf7..276e423626c1d7 100644 --- a/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h +++ b/examples/all-clusters-app/all-clusters-common/include/resource-monitoring-instances.h @@ -55,22 +55,9 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor aResetConditionCommandSupported){}; }; -class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager +class ImmutableReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager { public: CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; - - ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager( - chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, - uint8_t aReplacementProductListSize) - { - mReplacementProductsList = aReplacementProductsList; - mReplacementProductListSize = aReplacementProductListSize; - } - -private: - chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * mReplacementProductsList; - uint8_t mReplacementProductListSize; }; diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index 693dad09860ddd..e20d7e262aa7ad 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -36,16 +36,7 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; - -static ReplacementProductStruct sReplacementProductsList[] = { - { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, - { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, - { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, - { ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx") }, - { ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") }, -}; -StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0], - ArraySize(sReplacementProductsList)); +static ImmutableReplacementProductListManager sReplacementProductListManager; //-- Activated Carbon Filter Monitoring Instance methods CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() @@ -102,14 +93,41 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & item) +CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct & item) { - if (mIndex < mReplacementProductListSize) + if (mIndex >= kReplacementProductListMaxSize) { - item = mReplacementProductsList[mIndex]; - mIndex++; - return CHIP_NO_ERROR; + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; -} + switch(mIndex) + { + case 0: + { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } + } + mIndex++; + return CHIP_NO_ERROR; +} \ No newline at end of file diff --git a/examples/placeholder/linux/include/resource-monitoring-instances.h b/examples/placeholder/linux/include/resource-monitoring-instances.h index e4fb00fdcfcbf7..276e423626c1d7 100644 --- a/examples/placeholder/linux/include/resource-monitoring-instances.h +++ b/examples/placeholder/linux/include/resource-monitoring-instances.h @@ -55,22 +55,9 @@ class HepaFilterMonitoringInstance : public chip::app::Clusters::ResourceMonitor aResetConditionCommandSupported){}; }; -class StaticReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager +class ImmutableReplacementProductListManager : public chip::app::Clusters::ResourceMonitoring::ReplacementProductListManager { public: CHIP_ERROR Next(chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct & item) override; - - ~StaticReplacementProductListManager() {} - StaticReplacementProductListManager( - chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * aReplacementProductsList, - uint8_t aReplacementProductListSize) - { - mReplacementProductsList = aReplacementProductsList; - mReplacementProductListSize = aReplacementProductListSize; - } - -private: - chip::app::Clusters::ResourceMonitoring::ReplacementProductStruct * mReplacementProductsList; - uint8_t mReplacementProductListSize; }; diff --git a/examples/placeholder/linux/resource-monitoring-instances.cpp b/examples/placeholder/linux/resource-monitoring-instances.cpp index 141a34fb70ab5c..a11c5c6eb56fbc 100644 --- a/examples/placeholder/linux/resource-monitoring-instances.cpp +++ b/examples/placeholder/linux/resource-monitoring-instances.cpp @@ -37,15 +37,7 @@ constexpr std::bitset<4> gActivatedCarbonFeatureMap{ static_cast(Featu static HepaFilterMonitoringInstance * gHepaFilterInstance = nullptr; static ActivatedCarbonFilterMonitoringInstance * gActivatedCarbonFilterInstance = nullptr; -static ResourceMonitoring::ReplacementProductStruct sReplacementProductsList[] = { - { ProductIdentifierTypeEnum::kUpc, CharSpan::fromCharString("111112222233") }, - { ProductIdentifierTypeEnum::kGtin8, CharSpan::fromCharString("gtin8xxx") }, - { ProductIdentifierTypeEnum::kEan, CharSpan::fromCharString("4444455555666") }, - { ProductIdentifierTypeEnum::kGtin14, CharSpan::fromCharString("gtin14xxxxxxxx") }, - { ProductIdentifierTypeEnum::kOem, CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx") }, -}; -StaticReplacementProductListManager sReplacementProductListManager(&sReplacementProductsList[0], - ArraySize(sReplacementProductsList)); +static ImmutableReplacementProductListManager sReplacementProductListManager; //-- Activated Carbon Filter Monitoring Instance methods CHIP_ERROR ActivatedCarbonFilterMonitoringInstance::AppInit() @@ -102,14 +94,41 @@ void emberAfHepaFilterMonitoringClusterInitCallback(chip::EndpointId endpoint) gHepaFilterInstance->Init(); } -CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & item) +CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct & item) { - if (mIndex < mReplacementProductListSize) + if (mIndex >= kReplacementProductListMaxSize) { - item = mReplacementProductsList[mIndex]; - mIndex++; - return CHIP_NO_ERROR; + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + switch(mIndex) + { + case 0: + { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } + } + mIndex++; + return CHIP_NO_ERROR; } diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h deleted file mode 100644 index 56086b6a966d29..00000000000000 --- a/examples/resource-monitoring-app/resource-monitoring-common/include/DynamicReplacementProductListManager.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -namespace chip { -namespace app { -namespace Clusters { -namespace ResourceMonitoring { - -/** - * This implementation allows for items to be added dynamically. - */ - -class DynamicReplacementProductListManager : public ReplacementProductListManager -{ -public: - CHIP_ERROR Next(ReplacementProductStruct & item) override; - - /** - * Creates a ReplacementProductStruct and adds it to the list. Can only add up to kReplacementProductListMaxSize - * entries to a list (as defined by the spec). - * - * @param aProductIdentifierType The identifier type of the product. - * @param aProductIdentifierValue The value of the product. - * @return CHIP_ERROR_NO_MEMORY if the list is full, a CHIP_ERROR if there was a problem creating the - * ReplacementProductStruct and a CHIP_NO_ERROR otherwise. - */ - CHIP_ERROR AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum aProductIdentifierType, - chip::CharSpan aProductIdentifierValue) - { - if (mReplacementProductListSize == kReplacementProductListMaxSize) - { - return CHIP_ERROR_NO_MEMORY; - } - ReplacementProductStruct * type = &mReplacementProductsList[mReplacementProductListSize]; - CHIP_ERROR err = type->SetProductIdentifierValue(aProductIdentifierValue); - if (CHIP_NO_ERROR != err) - { - return err; - }; - - type->SetProductIdentifierType(aProductIdentifierType); - mReplacementProductListSize++; - - return CHIP_NO_ERROR; - } - -private: - ReplacementProductStruct mReplacementProductsList[ReplacementProductListManager::kReplacementProductListMaxSize]; - uint8_t mReplacementProductListSize; -}; - -} // namespace ResourceMonitoring -} // namespace Clusters -} // namespace app -} // namespace chip diff --git a/examples/resource-monitoring-app/resource-monitoring-common/include/ImmutableReplacementProductListManager.h b/examples/resource-monitoring-app/resource-monitoring-common/include/ImmutableReplacementProductListManager.h new file mode 100644 index 00000000000000..2dcbff41372866 --- /dev/null +++ b/examples/resource-monitoring-app/resource-monitoring-common/include/ImmutableReplacementProductListManager.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace chip { +namespace app { +namespace Clusters { +namespace ResourceMonitoring { + +/** + * This implementation returns an immutable list of replacement products. + * It holds ReplacementProductListManager::kReplacementProductListMaxSize products in the list. + */ + +class ImmutableReplacementProductListManager : public ReplacementProductListManager +{ +public: + CHIP_ERROR Next(ReplacementProductStruct & item) override; +}; + +} // namespace ResourceMonitoring +} // namespace Clusters +} // namespace app +} // namespace chip diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index 80e4104e8c617a..5de4701cdb10e8 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -38,15 +38,41 @@ CHIP_ERROR StaticReplacementProductListManager::Next(ReplacementProductStruct & return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } -CHIP_ERROR DynamicReplacementProductListManager::Next(ReplacementProductStruct & item) +CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct & item) { - if (mIndex < mReplacementProductListSize) + if (mIndex >= kReplacementProductListMaxSize) { - item.SetProductIdentifierType(mReplacementProductsList[mIndex].GetProductIdentifierType()); - item.SetProductIdentifierValue(mReplacementProductsList[mIndex].GetProductIdentifierValue()); - mIndex++; - return CHIP_NO_ERROR; + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + switch(mIndex) + { + case 0: + { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } + } + mIndex++; + return CHIP_NO_ERROR; } diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index e330d060e4f2f0..5894d4e856dac3 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -16,7 +16,7 @@ * limitations under the License. */ -#include +#include #include #include #include @@ -34,24 +34,13 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -DynamicReplacementProductListManager hepaFilterReplacementProductListManager; +ImmutableReplacementProductListManager hepaFilterReplacementProductListManager; //-- Hepa filter Monitoring instance methods CHIP_ERROR HepaFilterMonitoringInstance::AppInit() { ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc, - CharSpan::fromCharString("111112222233")); - hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8, - CharSpan::fromCharString("gtin8xhe")); - hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kEan, - CharSpan::fromCharString("4444455555666")); - hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14, - CharSpan::fromCharString("gtin14xhepaxxx")); - hepaFilterReplacementProductListManager.AddItemToList(ResourceMonitoring::ProductIdentifierTypeEnum::kOem, - CharSpan::fromCharString("oem20xhepaxxxxxxxxxx")); - SetReplacementProductListManagerInstance(&hepaFilterReplacementProductListManager); return CHIP_NO_ERROR; From cc9622a17cdb4f806cbfc1946bdca4491910bb37 Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Wed, 26 Jul 2023 08:42:22 -0700 Subject: [PATCH 30/33] Overriding the = operation to always do a copy --- .../src/instances/HepafilterMonitoring.cpp | 4 ++-- .../resource-monitoring-cluster-objects.h | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp index 5894d4e856dac3..6404f973a95097 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/instances/HepafilterMonitoring.cpp @@ -34,14 +34,14 @@ using namespace chip::app::Clusters::ResourceMonitoring; using namespace chip::app::Clusters::ResourceMonitoring::Attributes; using chip::Protocols::InteractionModel::Status; -ImmutableReplacementProductListManager hepaFilterReplacementProductListManager; +static ImmutableReplacementProductListManager sHepaFilterReplacementProductListManager; //-- Hepa filter Monitoring instance methods CHIP_ERROR HepaFilterMonitoringInstance::AppInit() { ChipLogDetail(Zcl, "HepaFilterMonitoringInstance::Init()"); - SetReplacementProductListManagerInstance(&hepaFilterReplacementProductListManager); + SetReplacementProductListManagerInstance(&sHepaFilterReplacementProductListManager); return CHIP_NO_ERROR; } diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 895c0a481b0a2f..efcac5cb710466 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -98,6 +98,13 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace SetProductIdentifierValue(aProductIdentifierValue); } + ReplacementProductStruct & operator=(const ReplacementProductStruct & aReplacementProductStruct) + { + SetProductIdentifierType(aReplacementProductStruct.GetProductIdentifierType()); + SetProductIdentifierValue(aReplacementProductStruct.GetProductIdentifierValue()); + return *this; + } + using HepaFilterMonitoring::Structs::ReplacementProductStruct::Type::Encode; /** @@ -130,8 +137,8 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace return CHIP_NO_ERROR; } - ProductIdentifierTypeEnum GetProductIdentifierType() { return static_cast(productIdentifierType); }; - chip::CharSpan GetProductIdentifierValue() { return productIdentifierValue; }; + ProductIdentifierTypeEnum GetProductIdentifierType() const { return static_cast(productIdentifierType); }; + chip::CharSpan GetProductIdentifierValue() const { return productIdentifierValue; }; }; namespace Attributes { From 021040a6b61b69a7bd310bd0c80737c313cb7347 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 26 Jul 2023 15:43:26 +0000 Subject: [PATCH 31/33] Restyled by whitespace --- .../all-clusters-common/src/resource-monitoring-instances.cpp | 2 +- .../resource-monitoring-cluster-objects.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index e20d7e262aa7ad..2d049810dc9bfa 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -130,4 +130,4 @@ CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct } mIndex++; return CHIP_NO_ERROR; -} \ No newline at end of file +} diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index efcac5cb710466..00caf68b5d240b 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -98,7 +98,7 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace SetProductIdentifierValue(aProductIdentifierValue); } - ReplacementProductStruct & operator=(const ReplacementProductStruct & aReplacementProductStruct) + ReplacementProductStruct & operator=(const ReplacementProductStruct & aReplacementProductStruct) { SetProductIdentifierType(aReplacementProductStruct.GetProductIdentifierType()); SetProductIdentifierValue(aReplacementProductStruct.GetProductIdentifierValue()); From 4c34b664d893d98c88eddca57b101efdc5a0eefd Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 26 Jul 2023 15:43:29 +0000 Subject: [PATCH 32/33] Restyled by clang-format --- .../src/resource-monitoring-instances.cpp | 51 +++++++++---------- .../linux/resource-monitoring-instances.cpp | 51 +++++++++---------- .../src/ReplacementProductListManager.cpp | 51 +++++++++---------- .../resource-monitoring-cluster-objects.h | 5 +- 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp index 2d049810dc9bfa..dc4283539b437b 100644 --- a/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp +++ b/examples/all-clusters-app/all-clusters-common/src/resource-monitoring-instances.cpp @@ -100,33 +100,32 @@ CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - switch(mIndex) + switch (mIndex) { - case 0: - { - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); - item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); - break; - case 1: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); - break; - case 2: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); - item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); - break; - case 3: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); - break; - case 4: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); - item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); - break; - default: - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; - break; - } + case 0: { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } } mIndex++; return CHIP_NO_ERROR; diff --git a/examples/placeholder/linux/resource-monitoring-instances.cpp b/examples/placeholder/linux/resource-monitoring-instances.cpp index a11c5c6eb56fbc..a030beed78c7e6 100644 --- a/examples/placeholder/linux/resource-monitoring-instances.cpp +++ b/examples/placeholder/linux/resource-monitoring-instances.cpp @@ -101,33 +101,32 @@ CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - switch(mIndex) + switch (mIndex) { - case 0: - { - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); - item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); - break; - case 1: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); - break; - case 2: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); - item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); - break; - case 3: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); - break; - case 4: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); - item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); - break; - default: - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; - break; - } + case 0: { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } } mIndex++; return CHIP_NO_ERROR; diff --git a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp index 5de4701cdb10e8..f450df6f380ef3 100644 --- a/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp +++ b/examples/resource-monitoring-app/resource-monitoring-common/src/ReplacementProductListManager.cpp @@ -45,33 +45,32 @@ CHIP_ERROR ImmutableReplacementProductListManager::Next(ReplacementProductStruct return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; } - switch(mIndex) + switch (mIndex) { - case 0: - { - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); - item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); - break; - case 1: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); - break; - case 2: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); - item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); - break; - case 3: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); - item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); - break; - case 4: - item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); - item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); - break; - default: - return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; - break; - } + case 0: { + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kUpc); + item.SetProductIdentifierValue(CharSpan::fromCharString("111112222233")); + break; + case 1: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin8); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin8xxx")); + break; + case 2: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kEan); + item.SetProductIdentifierValue(CharSpan::fromCharString("4444455555666")); + break; + case 3: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kGtin14); + item.SetProductIdentifierValue(CharSpan::fromCharString("gtin14xxxxxxxx")); + break; + case 4: + item.SetProductIdentifierType(ResourceMonitoring::ProductIdentifierTypeEnum::kOem); + item.SetProductIdentifierValue(CharSpan::fromCharString("oem20xxxxxxxxxxxxxxx")); + break; + default: + return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED; + break; + } } mIndex++; return CHIP_NO_ERROR; diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 00caf68b5d240b..0381f8821d4982 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -137,7 +137,10 @@ struct ReplacementProductStruct : private HepaFilterMonitoring::Structs::Replace return CHIP_NO_ERROR; } - ProductIdentifierTypeEnum GetProductIdentifierType() const { return static_cast(productIdentifierType); }; + ProductIdentifierTypeEnum GetProductIdentifierType() const + { + return static_cast(productIdentifierType); + }; chip::CharSpan GetProductIdentifierValue() const { return productIdentifierValue; }; }; From 26ef1aa99de4a692367bf46451e1210b5106fd2d Mon Sep 17 00:00:00 2001 From: Cliff Chung Date: Wed, 26 Jul 2023 21:12:27 -0700 Subject: [PATCH 33/33] Adding back the instance of the ReplacementProductList so that it can be used in the Read function --- .../resource-monitoring-cluster-objects.h | 4 ++++ .../resource-monitoring-server/resource-monitoring-server.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h index 0381f8821d4982..970a85c957bdf3 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-cluster-objects.h @@ -211,6 +211,10 @@ struct TypeInfo }; } // namespace LastChangedTime +namespace ReplacementProductList { +static constexpr AttributeId Id = 0x00000005; +} + namespace GeneratedCommandList { static constexpr AttributeId Id = Globals::Attributes::GeneratedCommandList::Id; struct TypeInfo : public Clusters::Globals::Attributes::GeneratedCommandList::TypeInfo diff --git a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp index a95203d06a22a8..c5687467d00ca0 100644 --- a/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp +++ b/src/app/clusters/resource-monitoring-server/resource-monitoring-server.cpp @@ -300,7 +300,7 @@ CHIP_ERROR Instance::Read(const ConcreteReadAttributePath & aPath, AttributeValu ReturnErrorOnFailure(aEncoder.Encode(mLastChangedTime)); break; } - case HepaFilterMonitoring::Attributes::ReplacementProductList::TypeInfo::GetAttributeId(): { + case Attributes::ReplacementProductList::Id: { return ReadReplacableProductList(aEncoder); break; }