From 52449a3f818202c52844b79dc08132dbc59f647e Mon Sep 17 00:00:00 2001 From: Cecille Freeman Date: Wed, 25 Sep 2024 22:12:21 -0700 Subject: [PATCH] add feature map and cluster revision --- ...onfiguration-and-control-cluster-logic.cpp | 12 ++++++++ ...-configuration-and-control-cluster-logic.h | 9 +++++- ...configuration-and-control-server-disco.cpp | 8 +++++ .../TestValveConfigurationAndControl.cpp | 30 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp index 19db47e8162b69..94111d83d7cd18 100644 --- a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp +++ b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp @@ -276,6 +276,18 @@ CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t & levelStep) levelStep = mState.GetState().levelStep; return CHIP_NO_ERROR; } +CHIP_ERROR ClusterLogic::GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap) +{ + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); + featureMap = mConformance.featureMap; + return CHIP_NO_ERROR; +} +CHIP_ERROR ClusterLogic::GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision) +{ + VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE); + clusterRevision = kClusterRevision; + return CHIP_NO_ERROR; +} CHIP_ERROR ClusterLogic::SetDefaultOpenDuration(const DataModel::Nullable & defaultOpenDuration) { diff --git a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h index 2704af52732cab..dd1aacd1d7d38b 100644 --- a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h +++ b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h @@ -22,6 +22,7 @@ #include "valve-configuration-and-control-delegate.h" #include "valve-configuration-and-control-matter-context.h" +#include #include #include #include @@ -84,7 +85,7 @@ struct ClusterState class ClusterStateAttributes { public: - explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext){}; + explicit ClusterStateAttributes(MatterContext & matterContext) : mMatterContext(matterContext) {}; void Init(ClusterInitParameters initialState); const ClusterState & GetState() { return mState; } @@ -143,6 +144,8 @@ class ClusterLogic CHIP_ERROR GetDefaultOpenLevel(Percent & defaultOpenLevel); CHIP_ERROR GetValveFault(BitMask & valveFault); CHIP_ERROR GetLevelStep(uint8_t & levelStep); + CHIP_ERROR GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap); + CHIP_ERROR GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision); // All Set functions // Return CHIP_ERROR_INCORRECT_STATE if the class has not been initialized. @@ -181,6 +184,10 @@ class ClusterLogic CHIP_ERROR HandleCloseCommand(); private: + // This cluster implements version 1 of the valve cluster. Do not change this revision without updating + // the cluster to implement the newest features. + // TODO: consider implementing the server such that multiple revisions can be supported + static constexpr Attributes::ClusterRevision::TypeInfo::Type kClusterRevision = 1u; // Determines if the level value is allowed per the level step. bool ValueCompliesWithLevelStep(const uint8_t value); // Returns the target level to send to the delegate based on the targetLevel command field, the device conformance and the diff --git a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp index 6a7eec566633b2..7aebf0db153fe6 100644 --- a/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp +++ b/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server-disco.cpp @@ -115,6 +115,14 @@ CHIP_ERROR Interface::Read(const ConcreteReadAttributePath & aPath, AttributeVal typedef LevelStep::TypeInfo::Type T; return EncodeRead(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetLevelStep(ret); }); } + case FeatureMap::Id: { + typedef FeatureMap::TypeInfo::Type T; + return EncodeRead(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetFeatureMap(ret); }); + } + case ClusterRevision::Id: { + typedef ClusterRevision::TypeInfo::Type T; + return EncodeRead(aEncoder, [&logic = mClusterLogic](T & ret) -> CHIP_ERROR { return logic.GetClusterRevision(ret); }); + } default: return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute); } diff --git a/src/app/tests/TestValveConfigurationAndControl.cpp b/src/app/tests/TestValveConfigurationAndControl.cpp index 5d138ba82133f4..8108403918298d 100644 --- a/src/app/tests/TestValveConfigurationAndControl.cpp +++ b/src/app/tests/TestValveConfigurationAndControl.cpp @@ -105,6 +105,8 @@ namespace { // These are globals because SetUpTestSuite is static and I'm not shaving that yak today. System::TimerAndMockClock gSystemLayerAndClock = System::TimerAndMockClock(); System::Clock::ClockBase * gSavedClock = nullptr; + +constexpr uint16_t kExpectedClusterRevision = 1u; } // namespace class TestValveConfigurationAndControlClusterLogic : public ::testing::Test @@ -406,6 +408,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature Percent valPercent; uint8_t val8; BitMask valBitmap; + Attributes::FeatureMap::TypeInfo::Type featureMap; + Attributes::ClusterRevision::TypeInfo::Type clusterRevision; EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR); EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable); @@ -439,6 +443,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesAllFeature EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR); EXPECT_EQ(val8, 1); + + EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR); + EXPECT_EQ(featureMap, conformance.featureMap); + + EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR); + EXPECT_EQ(clusterRevision, kExpectedClusterRevision); } // This test ensures that attributes that are not supported by the conformance properly return errors @@ -463,6 +473,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesNoFeatures Percent valPercent; uint8_t val8; BitMask valBitmap; + Attributes::FeatureMap::TypeInfo::Type featureMap; + Attributes::ClusterRevision::TypeInfo::Type clusterRevision; EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR); EXPECT_EQ(valElapsedSNullable, DataModel::NullNullable); @@ -490,6 +502,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesNoFeatures EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE); + + EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR); + EXPECT_EQ(featureMap, conformance.featureMap); + + EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR); + EXPECT_EQ(clusterRevision, kExpectedClusterRevision); } // This test ensures that all attribute getters return the given starting state values before changes. @@ -526,6 +544,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesStartingSt Percent valPercent; uint8_t val8; BitMask valBitmap; + Attributes::FeatureMap::TypeInfo::Type featureMap; + Attributes::ClusterRevision::TypeInfo::Type clusterRevision; EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_NO_ERROR); EXPECT_EQ(valElapsedSNullable, state.openDuration); @@ -559,6 +579,12 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesStartingSt EXPECT_EQ(logic.GetLevelStep(val8), CHIP_NO_ERROR); EXPECT_EQ(val8, state.levelStep); + + EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_NO_ERROR); + EXPECT_EQ(featureMap, conformance.featureMap); + + EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_NO_ERROR); + EXPECT_EQ(clusterRevision, kExpectedClusterRevision); } // This test ensures that all attribute getter functions properly error on an uninitialized cluster. @@ -576,6 +602,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesUninitiali Percent valPercent; uint8_t val8; BitMask valBitmap; + Attributes::FeatureMap::TypeInfo::Type featureMap; + Attributes::ClusterRevision::TypeInfo::Type clusterRevision; EXPECT_EQ(logic.GetOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE); EXPECT_EQ(logic.GetDefaultOpenDuration(valElapsedSNullable), CHIP_ERROR_INCORRECT_STATE); @@ -588,6 +616,8 @@ TEST_F(TestValveConfigurationAndControlClusterLogic, TestGetAttributesUninitiali EXPECT_EQ(logic.GetDefaultOpenLevel(valPercent), CHIP_ERROR_INCORRECT_STATE); EXPECT_EQ(logic.GetValveFault(valBitmap), CHIP_ERROR_INCORRECT_STATE); EXPECT_EQ(logic.GetLevelStep(val8), CHIP_ERROR_INCORRECT_STATE); + EXPECT_EQ(logic.GetFeatureMap(featureMap), CHIP_ERROR_INCORRECT_STATE); + EXPECT_EQ(logic.GetClusterRevision(clusterRevision), CHIP_ERROR_INCORRECT_STATE); } //=========================================================================================