forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
447 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.../valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
121 changes: 121 additions & 0 deletions
121
...rs/valve-configuration-and-control-server/valve-configuration-and-control-cluster-logic.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
47 changes: 47 additions & 0 deletions
47
...s/valve-configuration-and-control-server/valve-configuration-and-control-matter-context.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.