Skip to content

Commit de69ea7

Browse files
committed
check
1 parent e96ddd9 commit de69ea7

6 files changed

+318
-0
lines changed

src/app/chip_data_model.gni

+9
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,15 @@ template("chip_data_model") {
443443
"${_app_root}/clusters/${cluster}/ArlEncoder.cpp",
444444
"${_app_root}/clusters/${cluster}/ArlEncoder.h",
445445
]
446+
} else if (cluster == "valve-configuration-and-control-server") {
447+
sources += [
448+
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
449+
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-cluster-logic.cpp",
450+
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-cluster-logic.h",
451+
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-delegate.h",
452+
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-matter-context.h",
453+
]
454+
cflags += [ "-Wno-unused-private-field" ]
446455
} else {
447456
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
448457
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/**
18+
* @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint.
19+
*/
20+
21+
#include "valve-configuration-and-control-cluster-logic.h"
22+
#include <lib/core/CHIPError.h>
23+
24+
namespace chip {
25+
namespace app {
26+
namespace Clusters {
27+
namespace ValveConfigurationAndControl {
28+
29+
CHIP_ERROR ClusterLogic::Init(const ClusterConformance & conformance, const ClusterState & initialState)
30+
{
31+
if (!conformance.Valid())
32+
{
33+
return CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR;
34+
}
35+
mConformance = conformance;
36+
mState = initialState;
37+
mInitialized = true;
38+
return CHIP_NO_ERROR;
39+
}
40+
41+
// All Get functions:
42+
// Return CHIP_ERROR_INVALID_STATE if the class has not been initialized.
43+
// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance.
44+
// Return CHIP_NO_ERROR and set the parameter value otherwise
45+
CHIP_ERROR ClusterLogic::GetOpenDuration(DataModel::Nullable<uint32_t> * openDuration)
46+
{
47+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
48+
*openDuration = mState.openDuration;
49+
return CHIP_NO_ERROR;
50+
}
51+
CHIP_ERROR ClusterLogic::GetDefaultOpenDuration(DataModel::Nullable<uint32_t> * defaultOpenDuration)
52+
{
53+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
54+
*defaultOpenDuration = mState.openDuration;
55+
return CHIP_NO_ERROR;
56+
}
57+
CHIP_ERROR ClusterLogic::GetAutoCloseTime(DataModel::Nullable<uint64_t> * autoCloseTime)
58+
{
59+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
60+
VerifyOrReturnError(mConformance.HasFeature(Feature::kTimeSync), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
61+
*autoCloseTime = mState.autoCloseTime;
62+
return CHIP_NO_ERROR;
63+
}
64+
CHIP_ERROR ClusterLogic::GetRemainingDuration(DataModel::Nullable<uint32_t> * remainingDuration)
65+
{
66+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
67+
*remainingDuration = mState.remainingDuration;
68+
return CHIP_NO_ERROR;
69+
}
70+
CHIP_ERROR ClusterLogic::GetCurrentState(DataModel::Nullable<ValveStateEnum> * currentState)
71+
{
72+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
73+
*currentState = mState.currentState;
74+
return CHIP_NO_ERROR;
75+
}
76+
CHIP_ERROR ClusterLogic::GetTargetState(DataModel::Nullable<ValveStateEnum> * targetState)
77+
{
78+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
79+
*targetState = mState.targetState;
80+
return CHIP_NO_ERROR;
81+
}
82+
CHIP_ERROR ClusterLogic::GetCurrentLevel(DataModel::Nullable<uint8_t> * currentLevel)
83+
{
84+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
85+
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
86+
*currentLevel = mState.currentLevel;
87+
return CHIP_NO_ERROR;
88+
}
89+
CHIP_ERROR ClusterLogic::GetTargetLevel(DataModel::Nullable<uint8_t> * targetLevel)
90+
{
91+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
92+
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
93+
*targetLevel = mState.targetLevel;
94+
return CHIP_NO_ERROR;
95+
}
96+
CHIP_ERROR ClusterLogic::GetDefaultOpenLevel(uint8_t * defaultOpenLevel)
97+
{
98+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
99+
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
100+
VerifyOrReturnError(mConformance.supportsDefaultOpenLevel, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
101+
*defaultOpenLevel = mState.defaultOpenLevel;
102+
return CHIP_NO_ERROR;
103+
}
104+
CHIP_ERROR ClusterLogic::GetValveFault(BitMask<ValveFaultBitmap> * valveFault)
105+
{
106+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
107+
VerifyOrReturnError(mConformance.supportsValveFault, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
108+
*valveFault = mState.valveFault;
109+
return CHIP_NO_ERROR;
110+
}
111+
CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t * levelStep)
112+
{
113+
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
114+
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
115+
VerifyOrReturnError(mConformance.supportsLevelStep, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
116+
*levelStep = mState.levelStep;
117+
return CHIP_NO_ERROR;
118+
}
119+
120+
} // namespace ValveConfigurationAndControl
121+
} // namespace Clusters
122+
} // namespace app
123+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
/**
18+
* @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint.
19+
*/
20+
21+
#pragma once
22+
23+
#include "valve-configuration-and-control-delegate.h"
24+
#include "valve-configuration-and-control-matter-context.h"
25+
#include <lib/core/CHIPError.h>
26+
27+
namespace chip {
28+
namespace app {
29+
namespace Clusters {
30+
namespace ValveConfigurationAndControl {
31+
32+
struct ClusterConformance
33+
{
34+
inline bool HasFeature(Feature feature) const { return featureMap & to_underlying(feature); }
35+
uint32_t featureMap;
36+
bool supportsDefaultOpenLevel;
37+
bool supportsValveFault;
38+
bool supportsLevelStep;
39+
bool Valid() const
40+
{
41+
bool supportsLvl = HasFeature(Feature::kLevel);
42+
if (supportsDefaultOpenLevel & !supportsLvl)
43+
{
44+
ChipLogError(Zcl,
45+
"Invalid Valve configuration and control conformance - DefaultOpenLevel is not supported without LVL");
46+
return false;
47+
}
48+
if (supportsLevelStep & !supportsLvl)
49+
{
50+
ChipLogError(Zcl, "Invalid Valve configuration and control conformance - LevelStep is not supported without LVL");
51+
return false;
52+
}
53+
return true;
54+
}
55+
};
56+
57+
struct ClusterState
58+
{
59+
DataModel::Nullable<uint32_t> openDuration = DataModel::NullNullable;
60+
DataModel::Nullable<uint32_t> defaultOpenDuration = DataModel::NullNullable;
61+
DataModel::Nullable<uint64_t> autoCloseTime = DataModel::NullNullable;
62+
DataModel::Nullable<uint32_t> remainingDuration = DataModel::NullNullable;
63+
DataModel::Nullable<ValveStateEnum> currentState = DataModel::NullNullable;
64+
DataModel::Nullable<ValveStateEnum> targetState = DataModel::NullNullable;
65+
DataModel::Nullable<uint8_t> currentLevel = DataModel::NullNullable;
66+
DataModel::Nullable<uint8_t> targetLevel = DataModel::NullNullable;
67+
uint8_t defaultOpenLevel = 100u;
68+
BitMask<ValveFaultBitmap> valveFault = 0u;
69+
uint8_t levelStep = 1u;
70+
};
71+
72+
class ClusterLogic
73+
{
74+
public:
75+
// Instantiates a ClusterLogic class. The caller maintains ownership of the driver and the context, but provides them for use by
76+
// the ClusterLogic class.
77+
ClusterLogic(Delegate & clusterDriver, MatterContext & matterContext) :
78+
mClusterDriver(clusterDriver), mMatterContext(matterContext)
79+
{
80+
// TODO: remove these once the fields are used properly
81+
(void) mClusterDriver;
82+
(void) mMatterContext;
83+
}
84+
85+
// Validates the conformance and performs initialization.
86+
// Returns CHIP_ERROR_INVALID_STATE if the cluster has already been initialized.
87+
// Returns CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR if the conformance is incorrect.
88+
CHIP_ERROR Init(const ClusterConformance & conformance, const ClusterState & initialState = ClusterState());
89+
// CHIP_ERROR HandleOpen();
90+
// CHIP_ERROR HandleClose();
91+
92+
// All Get functions:
93+
// Return CHIP_ERROR_INVALID_STATE if the class has not been initialized.
94+
// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance.
95+
// Return CHIP_NO_ERROR and set the parameter value otherwise
96+
CHIP_ERROR GetOpenDuration(DataModel::Nullable<uint32_t> * openDuration);
97+
CHIP_ERROR GetDefaultOpenDuration(DataModel::Nullable<uint32_t> * defaultOpenDuration);
98+
CHIP_ERROR GetAutoCloseTime(DataModel::Nullable<uint64_t> * autoCloseTime);
99+
CHIP_ERROR GetRemainingDuration(DataModel::Nullable<uint32_t> * remainingDuration);
100+
CHIP_ERROR GetCurrentState(DataModel::Nullable<ValveStateEnum> * currentState);
101+
CHIP_ERROR GetTargetState(DataModel::Nullable<ValveStateEnum> * targetState);
102+
CHIP_ERROR GetCurrentLevel(DataModel::Nullable<uint8_t> * currentLevel);
103+
CHIP_ERROR GetTargetLevel(DataModel::Nullable<uint8_t> * targetLevel);
104+
CHIP_ERROR GetDefaultOpenLevel(uint8_t * defaultOpenLevel);
105+
CHIP_ERROR GetValveFault(BitMask<ValveFaultBitmap> * valveFault);
106+
CHIP_ERROR GetLevelStep(uint8_t * levelStep);
107+
108+
private:
109+
bool mInitialized = false;
110+
111+
Delegate & mClusterDriver;
112+
MatterContext & mMatterContext;
113+
114+
ClusterConformance mConformance;
115+
ClusterState mState;
116+
};
117+
118+
} // namespace ValveConfigurationAndControl
119+
} // namespace Clusters
120+
} // namespace app
121+
} // namespace chip

src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Delegate
3636
public:
3737
Delegate(){};
3838

39+
void Poke() {}
40+
3941
// shall return current level if supported, otherwise null
4042
virtual DataModel::Nullable<chip::Percent> HandleOpenValve(DataModel::Nullable<chip::Percent> level) = 0;
4143
virtual CHIP_ERROR HandleCloseValve() = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <lib/core/CHIPError.h>
22+
// #include <src/lib/core/DataModelTypes.h>
23+
#include <app-common/zap-generated/cluster-enums.h>
24+
25+
namespace chip {
26+
namespace app {
27+
namespace Clusters {
28+
namespace ValveConfigurationAndControl {
29+
30+
/** @brief
31+
* Interface to allow interaction with interaction model and ember layers. Can be faked for unit testing.
32+
*/
33+
class MatterContext
34+
{
35+
public:
36+
// TODO: remove touch on mEndpoint once this is used. I am apparently unable to locate the proper place to turn this off in the
37+
// build file, so whatever, compiler, you win. I've touched it. You happy now?
38+
MatterContext(EndpointId endpoint) : mEndpoint(endpoint) { (void) mEndpoint; }
39+
40+
private:
41+
EndpointId mEndpoint;
42+
};
43+
44+
} // namespace ValveConfigurationAndControl
45+
} // namespace Clusters
46+
} // namespace app
47+
} // namespace chip

src/app/tests/BUILD.gn

+16
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ source_set("thread-border-router-management-test-srcs") {
154154
]
155155
}
156156

157+
source_set("valve-configuration-and-control-test-srcs") {
158+
sources = [
159+
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp",
160+
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h",
161+
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h",
162+
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-matter-context.h",
163+
]
164+
public_deps = [
165+
"${chip_root}/src/app/common:cluster-objects",
166+
"${chip_root}/src/lib/core",
167+
"${chip_root}/src/lib/support",
168+
]
169+
}
170+
157171
source_set("app-test-stubs") {
158172
sources = [
159173
"test-ember-api.cpp",
@@ -220,6 +234,7 @@ chip_test_suite("tests") {
220234
"TestTestEventTriggerDelegate.cpp",
221235
"TestTimeSyncDataProvider.cpp",
222236
"TestTimedHandler.cpp",
237+
"TestValveConfigurationAndControl.cpp",
223238
"TestWriteInteraction.cpp",
224239
]
225240

@@ -233,6 +248,7 @@ chip_test_suite("tests") {
233248
":power-cluster-test-srcs",
234249
":thread-network-directory-test-srcs",
235250
":time-sync-data-provider-test-srcs",
251+
":valve-configuration-and-control-test-srcs",
236252
"${chip_root}/src/app",
237253
"${chip_root}/src/app/codegen-data-model-provider:instance-header",
238254
"${chip_root}/src/app/common:cluster-objects",

0 commit comments

Comments
 (0)