Skip to content

Commit

Permalink
check
Browse files Browse the repository at this point in the history
  • Loading branch information
cecille committed Sep 6, 2024
1 parent e96ddd9 commit de69ea7
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ template("chip_data_model") {
"${_app_root}/clusters/${cluster}/ArlEncoder.cpp",
"${_app_root}/clusters/${cluster}/ArlEncoder.h",
]
} else if (cluster == "valve-configuration-and-control-server") {
sources += [
"${_app_root}/clusters/${cluster}/${cluster}.cpp",
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-cluster-logic.cpp",
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-cluster-logic.h",
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-delegate.h",
"${_app_root}/clusters/${cluster}/valve-configuration-and-control-matter-context.h",
]
cflags += [ "-Wno-unused-private-field" ]
} else {
sources += [ "${_app_root}/clusters/${cluster}/${cluster}.cpp" ]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
*
* 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.
*/
/**
* @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint.
*/

#include "valve-configuration-and-control-cluster-logic.h"
#include <lib/core/CHIPError.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ValveConfigurationAndControl {

CHIP_ERROR ClusterLogic::Init(const ClusterConformance & conformance, const ClusterState & initialState)
{
if (!conformance.Valid())
{
return CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR;
}
mConformance = conformance;
mState = initialState;
mInitialized = true;
return CHIP_NO_ERROR;
}

// All Get functions:
// Return CHIP_ERROR_INVALID_STATE if the class has not been initialized.
// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance.
// Return CHIP_NO_ERROR and set the parameter value otherwise
CHIP_ERROR ClusterLogic::GetOpenDuration(DataModel::Nullable<uint32_t> * openDuration)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
*openDuration = mState.openDuration;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetDefaultOpenDuration(DataModel::Nullable<uint32_t> * defaultOpenDuration)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
*defaultOpenDuration = mState.openDuration;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetAutoCloseTime(DataModel::Nullable<uint64_t> * autoCloseTime)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.HasFeature(Feature::kTimeSync), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*autoCloseTime = mState.autoCloseTime;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetRemainingDuration(DataModel::Nullable<uint32_t> * remainingDuration)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
*remainingDuration = mState.remainingDuration;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetCurrentState(DataModel::Nullable<ValveStateEnum> * currentState)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
*currentState = mState.currentState;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetTargetState(DataModel::Nullable<ValveStateEnum> * targetState)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
*targetState = mState.targetState;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetCurrentLevel(DataModel::Nullable<uint8_t> * currentLevel)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*currentLevel = mState.currentLevel;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetTargetLevel(DataModel::Nullable<uint8_t> * targetLevel)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*targetLevel = mState.targetLevel;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetDefaultOpenLevel(uint8_t * defaultOpenLevel)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
VerifyOrReturnError(mConformance.supportsDefaultOpenLevel, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*defaultOpenLevel = mState.defaultOpenLevel;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetValveFault(BitMask<ValveFaultBitmap> * valveFault)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.supportsValveFault, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*valveFault = mState.valveFault;
return CHIP_NO_ERROR;
}
CHIP_ERROR ClusterLogic::GetLevelStep(uint8_t * levelStep)
{
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(mConformance.HasFeature(Feature::kLevel), CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
VerifyOrReturnError(mConformance.supportsLevelStep, CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE);
*levelStep = mState.levelStep;
return CHIP_NO_ERROR;
}

} // namespace ValveConfigurationAndControl
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/**
*
* 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.
*/
/**
* @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint.
*/

#pragma once

#include "valve-configuration-and-control-delegate.h"
#include "valve-configuration-and-control-matter-context.h"
#include <lib/core/CHIPError.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ValveConfigurationAndControl {

struct ClusterConformance
{
inline bool HasFeature(Feature feature) const { return featureMap & to_underlying(feature); }
uint32_t featureMap;
bool supportsDefaultOpenLevel;
bool supportsValveFault;
bool supportsLevelStep;
bool Valid() const
{
bool supportsLvl = HasFeature(Feature::kLevel);
if (supportsDefaultOpenLevel & !supportsLvl)
{
ChipLogError(Zcl,
"Invalid Valve configuration and control conformance - DefaultOpenLevel is not supported without LVL");
return false;
}
if (supportsLevelStep & !supportsLvl)
{
ChipLogError(Zcl, "Invalid Valve configuration and control conformance - LevelStep is not supported without LVL");
return false;
}
return true;
}
};

struct ClusterState
{
DataModel::Nullable<uint32_t> openDuration = DataModel::NullNullable;
DataModel::Nullable<uint32_t> defaultOpenDuration = DataModel::NullNullable;
DataModel::Nullable<uint64_t> autoCloseTime = DataModel::NullNullable;
DataModel::Nullable<uint32_t> remainingDuration = DataModel::NullNullable;
DataModel::Nullable<ValveStateEnum> currentState = DataModel::NullNullable;
DataModel::Nullable<ValveStateEnum> targetState = DataModel::NullNullable;
DataModel::Nullable<uint8_t> currentLevel = DataModel::NullNullable;
DataModel::Nullable<uint8_t> targetLevel = DataModel::NullNullable;
uint8_t defaultOpenLevel = 100u;
BitMask<ValveFaultBitmap> valveFault = 0u;
uint8_t levelStep = 1u;
};

class ClusterLogic
{
public:
// Instantiates a ClusterLogic class. The caller maintains ownership of the driver and the context, but provides them for use by
// the ClusterLogic class.
ClusterLogic(Delegate & clusterDriver, MatterContext & matterContext) :
mClusterDriver(clusterDriver), mMatterContext(matterContext)
{
// TODO: remove these once the fields are used properly
(void) mClusterDriver;
(void) mMatterContext;
}

// Validates the conformance and performs initialization.
// Returns CHIP_ERROR_INVALID_STATE if the cluster has already been initialized.
// Returns CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR if the conformance is incorrect.
CHIP_ERROR Init(const ClusterConformance & conformance, const ClusterState & initialState = ClusterState());
// CHIP_ERROR HandleOpen();
// CHIP_ERROR HandleClose();

// All Get functions:
// Return CHIP_ERROR_INVALID_STATE if the class has not been initialized.
// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance.
// Return CHIP_NO_ERROR and set the parameter value otherwise
CHIP_ERROR GetOpenDuration(DataModel::Nullable<uint32_t> * openDuration);
CHIP_ERROR GetDefaultOpenDuration(DataModel::Nullable<uint32_t> * defaultOpenDuration);
CHIP_ERROR GetAutoCloseTime(DataModel::Nullable<uint64_t> * autoCloseTime);
CHIP_ERROR GetRemainingDuration(DataModel::Nullable<uint32_t> * remainingDuration);
CHIP_ERROR GetCurrentState(DataModel::Nullable<ValveStateEnum> * currentState);
CHIP_ERROR GetTargetState(DataModel::Nullable<ValveStateEnum> * targetState);
CHIP_ERROR GetCurrentLevel(DataModel::Nullable<uint8_t> * currentLevel);
CHIP_ERROR GetTargetLevel(DataModel::Nullable<uint8_t> * targetLevel);
CHIP_ERROR GetDefaultOpenLevel(uint8_t * defaultOpenLevel);
CHIP_ERROR GetValveFault(BitMask<ValveFaultBitmap> * valveFault);
CHIP_ERROR GetLevelStep(uint8_t * levelStep);

private:
bool mInitialized = false;

Delegate & mClusterDriver;
MatterContext & mMatterContext;

ClusterConformance mConformance;
ClusterState mState;
};

} // namespace ValveConfigurationAndControl
} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Delegate
public:
Delegate(){};

void Poke() {}

// shall return current level if supported, otherwise null
virtual DataModel::Nullable<chip::Percent> HandleOpenValve(DataModel::Nullable<chip::Percent> level) = 0;
virtual CHIP_ERROR HandleCloseValve() = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright (c) 2024 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 <lib/core/CHIPError.h>
// #include <src/lib/core/DataModelTypes.h>
#include <app-common/zap-generated/cluster-enums.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ValveConfigurationAndControl {

/** @brief
* Interface to allow interaction with interaction model and ember layers. Can be faked for unit testing.
*/
class MatterContext
{
public:
// TODO: remove touch on mEndpoint once this is used. I am apparently unable to locate the proper place to turn this off in the
// build file, so whatever, compiler, you win. I've touched it. You happy now?
MatterContext(EndpointId endpoint) : mEndpoint(endpoint) { (void) mEndpoint; }

private:
EndpointId mEndpoint;
};

} // namespace ValveConfigurationAndControl
} // namespace Clusters
} // namespace app
} // namespace chip
16 changes: 16 additions & 0 deletions src/app/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ source_set("thread-border-router-management-test-srcs") {
]
}

source_set("valve-configuration-and-control-test-srcs") {
sources = [
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp",
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h",
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-delegate.h",
"${chip_root}/src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-matter-context.h",
]
public_deps = [
"${chip_root}/src/app/common:cluster-objects",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
]
}

source_set("app-test-stubs") {
sources = [
"test-ember-api.cpp",
Expand Down Expand Up @@ -220,6 +234,7 @@ chip_test_suite("tests") {
"TestTestEventTriggerDelegate.cpp",
"TestTimeSyncDataProvider.cpp",
"TestTimedHandler.cpp",
"TestValveConfigurationAndControl.cpp",
"TestWriteInteraction.cpp",
]

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

0 comments on commit de69ea7

Please sign in to comment.