From 802b86167962f0bc3538ef0adbec81c5a4dc4cc0 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Thu, 2 May 2024 02:50:22 +0800 Subject: [PATCH 01/18] Enable chef robotic vacuum cleaner device --- .../chef/common/chef-rvc-mode-delegate.cpp | 94 +++++- examples/chef/common/chef-rvc-mode-delegate.h | 18 ++ .../chef-rvc-operational-state-delegate.cpp | 180 ++++++++---- .../chef-rvc-operational-state-delegate.h | 77 ++--- examples/chef/common/stubs.cpp | 39 +++ ...ode_roboticvacuumcleaner_1807ff0c49.matter | 276 ++++++++++++++++++ ...otnode_roboticvacuumcleaner_1807ff0c49.zap | 245 +++++++++++++++- integrations/cloudbuild/chef.yaml | 2 +- .../app-common/zap-generated/cluster-enums.h | 2 + 9 files changed, 822 insertions(+), 111 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 20f3afbbd5592d..11e02b24de34a1 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -18,13 +18,15 @@ #include #include +using namespace chip; +using namespace chip::app; using namespace chip::app::Clusters; using chip::Protocols::InteractionModel::Status; template using List = chip::app::DataModel::List; using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::Type; -#ifdef ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER #include using namespace chip::app::Clusters::RvcRunMode; static RvcRunModeDelegate * gRvcRunModeDelegate = nullptr; @@ -106,17 +108,60 @@ void RvcRunMode::Shutdown() } } +chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +{ + chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. + VerifyOrDie(gRvcRunModeInstance != nullptr); + + ModeBase::Instance * clusterInstance = gRvcRunModeInstance; + chip::AttributeId attributeId = attributeMetadata->attributeId; + + switch (attributeId) + { + case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { + uint8_t m = static_cast(buffer[0]); + chip::Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m); + if (chip::Protocols::InteractionModel::Status::Success == status) + { + break; + } + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast(status)); + } + break; + default: + ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); + break; + } + + return ret; +} + +chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength) +{ + + return chip::Protocols::InteractionModel::Status::Success; +} + void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr); gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate; gRvcRunModeInstance = - new ModeBase::Instance(gRvcRunModeDelegate, 0x1, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff)); + new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff)); gRvcRunModeInstance->Init(); } -#ifdef ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + +#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER #include using namespace chip::app::Clusters::RvcCleanMode; static RvcCleanModeDelegate * gRvcCleanModeDelegate = nullptr; @@ -197,6 +242,46 @@ void RvcCleanMode::Shutdown() } } +chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +{ + chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. + VerifyOrDie(gRvcCleanModeInstance != nullptr); + + ModeBase::Instance * clusterInstance = gRvcCleanModeInstance; + chip::AttributeId attributeId = attributeMetadata->attributeId; + + switch (attributeId) + { + case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: { + uint8_t m = static_cast(buffer[0]); + Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m); + if (Protocols::InteractionModel::Status::Success == status) + { + break; + } + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast(status)); + } + break; + default: + ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); + break; + } + + return ret; +} + +chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength) +{ + return chip::Protocols::InteractionModel::Status::Success; +} + void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. @@ -206,5 +291,4 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff)); gRvcCleanModeInstance->Init(); } -#endif // ZCL_USING_RVC_CLEAN_MODE_CLUSTER_SERVER -#endif // ZCL_USING_RVC_RUN_MODE_CLUSTER_SERVER +#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index 5f96957420a441..ddd28c56577632 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -23,6 +23,8 @@ #include #include +using chip::Protocols::InteractionModel::Status; + namespace chip { namespace app { namespace Clusters { @@ -118,3 +120,19 @@ void Shutdown(); } // namespace Clusters } // namespace app } // namespace chip + +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER +chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); +chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength); +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + +#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER +chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); +chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength); +#endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 9ea4e610e64fb1..3e45a6e41eabf5 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -17,17 +17,32 @@ */ #include #include - -#ifdef ZCL_USING_OPERATIONAL_STATE_RVC_CLUSTER_SERVER #include +#include using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; +using chip::Protocols::InteractionModel::Status; + +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr; +static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; -CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) + +static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); + +DataModel::Nullable RvcOperationalStateDelegate::GetCountdownTime() +{ + if (mCountDownTime.IsNull()) + return DataModel::NullNullable; + + return DataModel::MakeNullable((uint32_t) (mCountDownTime.Value() - mRunningTime)); +} + +CHIP_ERROR RvcOperationalStateDelegate::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) { if (index >= mOperationalStateList.size()) { @@ -37,7 +52,7 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalStateAtIndex(size_ return CHIP_NO_ERROR; } -CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) +CHIP_ERROR RvcOperationalStateDelegate::GetOperationalPhaseAtIndex(size_t index, MutableCharSpan & operationalPhase) { if (index >= mOperationalPhaseList.size()) { @@ -46,100 +61,115 @@ CHIP_ERROR GenericOperationalStateDelegateImpl::GetOperationalPhaseAtIndex(size_ return CopyCharSpanToMutableCharSpan(mOperationalPhaseList[index], operationalPhase); } -void GenericOperationalStateDelegateImpl::HandlePauseStateCallback(GenericOperationalError & err) +void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalError & err) { // placeholder implementation auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused)); if (error == CHIP_NO_ERROR) { - err.Set(to_underlying(ErrorStateEnum::kNoError)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError)); } else { - err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation)); } } -void GenericOperationalStateDelegateImpl::HandleResumeStateCallback(GenericOperationalError & err) +void RvcOperationalStateDelegate::HandleResumeStateCallback(GenericOperationalError & err) { // placeholder implementation - auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); + auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) { - err.Set(to_underlying(ErrorStateEnum::kNoError)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError)); } else { - err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation)); } } -void GenericOperationalStateDelegateImpl::HandleStartStateCallback(GenericOperationalError & err) +void RvcOperationalStateDelegate::HandleStartStateCallback(GenericOperationalError & err) { + OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError)); + GetInstance()->GetCurrentOperationalError(current_err); + + if (current_err.errorStateID != to_underlying(OperationalState::ErrorStateEnum::kNoError)) + { + err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume)); + return; + } + // placeholder implementation - auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kRunning)); + auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)); if (error == CHIP_NO_ERROR) { - err.Set(to_underlying(ErrorStateEnum::kNoError)); + (void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, this); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError)); } else { - err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation)); } } -void GenericOperationalStateDelegateImpl::HandleStopStateCallback(GenericOperationalError & err) +void RvcOperationalStateDelegate::HandleStopStateCallback(GenericOperationalError & err) { // placeholder implementation - auto error = GetInstance()->SetOperationalState(to_underlying(OperationalStateEnum::kStopped)); + auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); if (error == CHIP_NO_ERROR) { - err.Set(to_underlying(ErrorStateEnum::kNoError)); + (void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, this); + + OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError)); + GetInstance()->GetCurrentOperationalError(current_err); + + Optional> totalTime((DataModel::Nullable(mRunningTime + mPausedTime))); + Optional> pausedTime((DataModel::Nullable(mPausedTime))); + + GetInstance()->OnOperationCompletionDetected(static_cast(current_err.errorStateID), totalTime, pausedTime); + + mRunningTime = 0; + mPausedTime = 0; + err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError)); } else { - err.Set(to_underlying(ErrorStateEnum::kUnableToCompleteOperation)); + err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToCompleteOperation)); } } +static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data) +{ + RvcOperationalStateDelegate * delegate = reinterpret_cast(data); -// Init Operational State cluster + OperationalState::Instance * instance = gRvcOperationalStateInstance; + OperationalState::OperationalStateEnum state = + static_cast(instance->GetCurrentOperationalState()); -static OperationalState::Instance * gOperationalStateInstance = nullptr; -static OperationalStateDelegate * gOperationalStateDelegate = nullptr; + auto countdown_time = delegate->GetCountdownTime(); -void OperationalState::Shutdown() -{ - if (gOperationalStateInstance != nullptr) + if (countdown_time.IsNull() || (!countdown_time.IsNull() && countdown_time.Value() > 0)) { - delete gOperationalStateInstance; - gOperationalStateInstance = nullptr; + if (state == OperationalState::OperationalStateEnum::kRunning) + { + delegate->mRunningTime++; + } + else if (state == OperationalState::OperationalStateEnum::kPaused) + { + delegate->mPausedTime++; + } } - if (gOperationalStateDelegate != nullptr) + + if (state == OperationalState::OperationalStateEnum::kRunning || state == OperationalState::OperationalStateEnum::kPaused) { - delete gOperationalStateDelegate; - gOperationalStateDelegate = nullptr; + (void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, delegate); + } + else + { + (void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, delegate); } } -void emberAfOperationalStateClusterInitCallback(chip::EndpointId endpointId) -{ - VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. - VerifyOrDie(gOperationalStateInstance == nullptr && gOperationalStateDelegate == nullptr); - - gOperationalStateDelegate = new OperationalStateDelegate; - EndpointId operationalStateEndpoint = 0x01; - gOperationalStateInstance = new OperationalState::Instance(gOperationalStateDelegate, operationalStateEndpoint); - - gOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); - - gOperationalStateInstance->Init(); -} - -// Init RVC Operational State cluster - -static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr; -static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; - void RvcOperationalState::Shutdown() { if (gRvcOperationalStateInstance != nullptr) @@ -154,12 +184,62 @@ void RvcOperationalState::Shutdown() } } +chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +{ + chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; + VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. + VerifyOrDie(gRvcOperationalStateInstance != nullptr); + chip::AttributeId attributeId = attributeMetadata->attributeId; + + switch (attributeId) + { + case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { + uint8_t m = static_cast(buffer[0]); + DataModel::Nullable aPhase(m); + CHIP_ERROR err = gRvcOperationalStateInstance->SetCurrentPhase(aPhase); + if (CHIP_NO_ERROR == err) + { + break; + } + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format()); + } + break; + case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: { + uint8_t m = static_cast(buffer[0]); + CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m); + if (CHIP_NO_ERROR == err) + { + break; + } + ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format()); + } + break; + default: + ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); + break; + } + + return ret; +} + +chip::Protocols::InteractionModel::Status +chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength) +{ + return chip::Protocols::InteractionModel::Status::Success; +} + void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr); - gRvcOperationalStateDelegate = new RvcOperationalStateDelegate; + gRvcOperationalStateDelegate = new chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate(); EndpointId operationalStateEndpoint = 0x01; gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint); diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index f487e38000771d..f33da259fdf639 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -23,21 +23,30 @@ #include +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +using chip::Protocols::InteractionModel::Status; + namespace chip { namespace app { namespace Clusters { -namespace OperationalState { +namespace RvcOperationalState { // This is an application level delegate to handle operational state commands according to the specific business logic. -class GenericOperationalStateDelegateImpl : public Delegate +class RvcOperationalStateDelegate : public RvcOperationalState::Delegate { public: + + RvcOperationalStateDelegate() + { + mOperationalStateList = Span(rvcOpStateList); + } + /** * Get the countdown time. This attribute is not used in this application. * @return The current countdown time. */ - app::DataModel::Nullable GetCountdownTime() override { return {}; }; + app::DataModel::Nullable GetCountdownTime() override; /** * Fills in the provided GenericOperationalState with the state at index `index` if there is one, @@ -47,7 +56,7 @@ class GenericOperationalStateDelegateImpl : public Delegate * @param index The index of the state, with 0 representing the first state. * @param operationalState The GenericOperationalState is filled. */ - CHIP_ERROR GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) override; + CHIP_ERROR GetOperationalStateAtIndex(size_t index, OperationalState::GenericOperationalState & operationalState) override; /** * Fills in the provided MutableCharSpan with the phase at index `index` if there is one, @@ -68,59 +77,33 @@ class GenericOperationalStateDelegateImpl : public Delegate * Handle Command Callback in application: Pause * @param[out] get operational error after callback. */ - void HandlePauseStateCallback(GenericOperationalError & err) override; + void HandlePauseStateCallback(OperationalState::GenericOperationalError & err) override; /** * Handle Command Callback in application: Resume * @param[out] get operational error after callback. */ - void HandleResumeStateCallback(GenericOperationalError & err) override; + void HandleResumeStateCallback(OperationalState::GenericOperationalError & err) override; /** * Handle Command Callback in application: Start * @param[out] get operational error after callback. */ - void HandleStartStateCallback(GenericOperationalError & err) override; + void HandleStartStateCallback(OperationalState::GenericOperationalError & err) override; /** * Handle Command Callback in application: Stop * @param[out] get operational error after callback. */ - void HandleStopStateCallback(GenericOperationalError & err) override; + void HandleStopStateCallback(OperationalState::GenericOperationalError & err) override; -protected: - Span mOperationalStateList; - Span mOperationalPhaseList; -}; - -// This is an application level delegate to handle operational state commands according to the specific business logic. -class OperationalStateDelegate : public GenericOperationalStateDelegateImpl -{ + uint32_t mRunningTime = 0; + uint32_t mPausedTime = 0; + app::DataModel::Nullable mCountDownTime; private: - const GenericOperationalState opStateList[4] = { - GenericOperationalState(to_underlying(OperationalStateEnum::kStopped)), - GenericOperationalState(to_underlying(OperationalStateEnum::kRunning)), - GenericOperationalState(to_underlying(OperationalStateEnum::kPaused)), - GenericOperationalState(to_underlying(OperationalStateEnum::kError)), - }; - -public: - OperationalStateDelegate() - { - GenericOperationalStateDelegateImpl::mOperationalStateList = Span(opStateList); - } -}; - -void Shutdown(); - -} // namespace OperationalState - -namespace RvcOperationalState { + Span mOperationalStateList; + Span mOperationalPhaseList; -// This is an application level delegate to handle operational state commands according to the specific business logic. -class RvcOperationalStateDelegate : public OperationalState::GenericOperationalStateDelegateImpl -{ -private: const OperationalState::GenericOperationalState rvcOpStateList[7] = { OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)), OperationalState::GenericOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning)), @@ -131,13 +114,6 @@ class RvcOperationalStateDelegate : public OperationalState::GenericOperationalS OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kCharging)), OperationalState::GenericOperationalState(to_underlying(Clusters::RvcOperationalState::OperationalStateEnum::kDocked)), }; - -public: - RvcOperationalStateDelegate() - { - GenericOperationalStateDelegateImpl::mOperationalStateList = - Span(rvcOpStateList); - } }; void Shutdown(); @@ -146,3 +122,12 @@ void Shutdown(); } // namespace Clusters } // namespace app } // namespace chip + +chip::Protocols::InteractionModel::Status +chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); +chip::Protocols::InteractionModel::Status +chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, + uint16_t maxReadLength); +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER \ No newline at end of file diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index 5756aaa35b7e26..4f63e68557cfa0 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -19,6 +19,15 @@ #include "chef-concentration-measurement.h" #endif +#if defined(MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER) || \ + defined(MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER) +#include "chef-rvc-mode-delegate.h" +#endif + +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +#include "chef-rvc-operational-state-delegate.h" +#endif + using chip::app::DataModel::Nullable; using namespace chip; @@ -56,6 +65,21 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin case chip::app::Clusters::RadonConcentrationMeasurement::Id: case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); +#endif +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + case chip::app::Clusters::RvcRunMode::Id: + return chefRvcRunModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); + break; +#endif +#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER + case chip::app::Clusters::RvcCleanMode::Id: + return chefRvcCleanModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); + break; +#endif +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + case chip::app::Clusters::RvcOperationalState::Id: + return chefRvcOperationalStateReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); + break; #endif default: break; @@ -104,6 +128,21 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi case chip::app::Clusters::RadonConcentrationMeasurement::Id: case chip::app::Clusters::TotalVolatileOrganicCompoundsConcentrationMeasurement::Id: return chefConcentrationMeasurementWriteCallback(endpoint, clusterId, attributeMetadata, buffer); +#endif +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + case chip::app::Clusters::RvcRunMode::Id: + return chefRvcRunModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer); + break; +#endif +#ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER + case chip::app::Clusters::RvcCleanMode::Id: + return chefRvcCleanModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer); + break; +#endif +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + case chip::app::Clusters::RvcOperationalState::Id: + return chefRvcOperationalStateWriteCallback(endpoint, clusterId, attributeMetadata, buffer); + break; #endif default: break; diff --git a/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.matter b/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.matter index f2ab0c354ca1cf..0d5013c6b8d29c 100644 --- a/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.matter +++ b/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.matter @@ -333,6 +333,265 @@ cluster BasicInformation = 40 { command MfgSpecificPing(): DefaultSuccess = 0; } +/** This cluster is used to describe the configuration and capabilities of a physical power source that provides power to the Node. */ +cluster PowerSource = 47 { + revision 1; // NOTE: Default/not specifically set + + enum BatApprovedChemistryEnum : enum16 { + kUnspecified = 0; + kAlkaline = 1; + kLithiumCarbonFluoride = 2; + kLithiumChromiumOxide = 3; + kLithiumCopperOxide = 4; + kLithiumIronDisulfide = 5; + kLithiumManganeseDioxide = 6; + kLithiumThionylChloride = 7; + kMagnesium = 8; + kMercuryOxide = 9; + kNickelOxyhydride = 10; + kSilverOxide = 11; + kZincAir = 12; + kZincCarbon = 13; + kZincChloride = 14; + kZincManganeseDioxide = 15; + kLeadAcid = 16; + kLithiumCobaltOxide = 17; + kLithiumIon = 18; + kLithiumIonPolymer = 19; + kLithiumIronPhosphate = 20; + kLithiumSulfur = 21; + kLithiumTitanate = 22; + kNickelCadmium = 23; + kNickelHydrogen = 24; + kNickelIron = 25; + kNickelMetalHydride = 26; + kNickelZinc = 27; + kSilverZinc = 28; + kSodiumIon = 29; + kSodiumSulfur = 30; + kZincBromide = 31; + kZincCerium = 32; + } + + enum BatChargeFaultEnum : enum8 { + kUnspecified = 0; + kAmbientTooHot = 1; + kAmbientTooCold = 2; + kBatteryTooHot = 3; + kBatteryTooCold = 4; + kBatteryAbsent = 5; + kBatteryOverVoltage = 6; + kBatteryUnderVoltage = 7; + kChargerOverVoltage = 8; + kChargerUnderVoltage = 9; + kSafetyTimeout = 10; + } + + enum BatChargeLevelEnum : enum8 { + kOK = 0; + kWarning = 1; + kCritical = 2; + } + + enum BatChargeStateEnum : enum8 { + kUnknown = 0; + kIsCharging = 1; + kIsAtFullCharge = 2; + kIsNotCharging = 3; + } + + enum BatCommonDesignationEnum : enum16 { + kUnspecified = 0; + kAAA = 1; + kAA = 2; + kC = 3; + kD = 4; + k4v5 = 5; + k6v0 = 6; + k9v0 = 7; + k12AA = 8; + kAAAA = 9; + kA = 10; + kB = 11; + kF = 12; + kN = 13; + kNo6 = 14; + kSubC = 15; + kA23 = 16; + kA27 = 17; + kBA5800 = 18; + kDuplex = 19; + k4SR44 = 20; + k523 = 21; + k531 = 22; + k15v0 = 23; + k22v5 = 24; + k30v0 = 25; + k45v0 = 26; + k67v5 = 27; + kJ = 28; + kCR123A = 29; + kCR2 = 30; + k2CR5 = 31; + kCRP2 = 32; + kCRV3 = 33; + kSR41 = 34; + kSR43 = 35; + kSR44 = 36; + kSR45 = 37; + kSR48 = 38; + kSR54 = 39; + kSR55 = 40; + kSR57 = 41; + kSR58 = 42; + kSR59 = 43; + kSR60 = 44; + kSR63 = 45; + kSR64 = 46; + kSR65 = 47; + kSR66 = 48; + kSR67 = 49; + kSR68 = 50; + kSR69 = 51; + kSR516 = 52; + kSR731 = 53; + kSR712 = 54; + kLR932 = 55; + kA5 = 56; + kA10 = 57; + kA13 = 58; + kA312 = 59; + kA675 = 60; + kAC41E = 61; + k10180 = 62; + k10280 = 63; + k10440 = 64; + k14250 = 65; + k14430 = 66; + k14500 = 67; + k14650 = 68; + k15270 = 69; + k16340 = 70; + kRCR123A = 71; + k17500 = 72; + k17670 = 73; + k18350 = 74; + k18500 = 75; + k18650 = 76; + k19670 = 77; + k25500 = 78; + k26650 = 79; + k32600 = 80; + } + + enum BatFaultEnum : enum8 { + kUnspecified = 0; + kOverTemp = 1; + kUnderTemp = 2; + } + + enum BatReplaceabilityEnum : enum8 { + kUnspecified = 0; + kNotReplaceable = 1; + kUserReplaceable = 2; + kFactoryReplaceable = 3; + } + + enum PowerSourceStatusEnum : enum8 { + kUnspecified = 0; + kActive = 1; + kStandby = 2; + kUnavailable = 3; + } + + enum WiredCurrentTypeEnum : enum8 { + kAC = 0; + kDC = 1; + } + + enum WiredFaultEnum : enum8 { + kUnspecified = 0; + kOverVoltage = 1; + kUnderVoltage = 2; + } + + bitmap Feature : bitmap32 { + kWired = 0x1; + kBattery = 0x2; + kRechargeable = 0x4; + kReplaceable = 0x8; + } + + struct BatChargeFaultChangeType { + BatChargeFaultEnum current[] = 0; + BatChargeFaultEnum previous[] = 1; + } + + struct BatFaultChangeType { + BatFaultEnum current[] = 0; + BatFaultEnum previous[] = 1; + } + + struct WiredFaultChangeType { + WiredFaultEnum current[] = 0; + WiredFaultEnum previous[] = 1; + } + + info event WiredFaultChange = 0 { + WiredFaultEnum current[] = 0; + WiredFaultEnum previous[] = 1; + } + + info event BatFaultChange = 1 { + BatFaultEnum current[] = 0; + BatFaultEnum previous[] = 1; + } + + info event BatChargeFaultChange = 2 { + BatChargeFaultEnum current[] = 0; + BatChargeFaultEnum previous[] = 1; + } + + readonly attribute PowerSourceStatusEnum status = 0; + readonly attribute int8u order = 1; + readonly attribute char_string<60> description = 2; + readonly attribute optional nullable int32u wiredAssessedInputVoltage = 3; + readonly attribute optional nullable int16u wiredAssessedInputFrequency = 4; + readonly attribute optional WiredCurrentTypeEnum wiredCurrentType = 5; + readonly attribute optional nullable int32u wiredAssessedCurrent = 6; + readonly attribute optional int32u wiredNominalVoltage = 7; + readonly attribute optional int32u wiredMaximumCurrent = 8; + readonly attribute optional boolean wiredPresent = 9; + readonly attribute optional WiredFaultEnum activeWiredFaults[] = 10; + readonly attribute optional nullable int32u batVoltage = 11; + readonly attribute optional nullable int8u batPercentRemaining = 12; + readonly attribute optional nullable int32u batTimeRemaining = 13; + readonly attribute optional BatChargeLevelEnum batChargeLevel = 14; + readonly attribute optional boolean batReplacementNeeded = 15; + readonly attribute optional BatReplaceabilityEnum batReplaceability = 16; + readonly attribute optional boolean batPresent = 17; + readonly attribute optional BatFaultEnum activeBatFaults[] = 18; + readonly attribute optional char_string<60> batReplacementDescription = 19; + readonly attribute optional BatCommonDesignationEnum batCommonDesignation = 20; + readonly attribute optional char_string<20> batANSIDesignation = 21; + readonly attribute optional char_string<20> batIECDesignation = 22; + readonly attribute optional BatApprovedChemistryEnum batApprovedChemistry = 23; + readonly attribute optional int32u batCapacity = 24; + readonly attribute optional int8u batQuantity = 25; + readonly attribute optional BatChargeStateEnum batChargeState = 26; + readonly attribute optional nullable int32u batTimeToFullCharge = 27; + readonly attribute optional boolean batFunctionalWhileCharging = 28; + readonly attribute optional nullable int32u batChargingCurrent = 29; + readonly attribute optional BatChargeFaultEnum activeBatChargeFaults[] = 30; + readonly attribute endpoint_no endpointList[] = 31; + readonly attribute command_id generatedCommandList[] = 65528; + readonly attribute command_id acceptedCommandList[] = 65529; + readonly attribute event_id eventList[] = 65530; + readonly attribute attrib_id attributeList[] = 65531; + readonly attribute bitmap32 featureMap = 65532; + readonly attribute int16u clusterRevision = 65533; +} + /** This cluster is used to manage global aspects of the Commissioning flow. */ cluster GeneralCommissioning = 48 { revision 1; // NOTE: Default/not specifically set @@ -1366,6 +1625,7 @@ endpoint 0 { } } endpoint 1 { + device type ma_powersource = 17, version 1; device type ma_robotic_vacuum_cleaner = 116, version 1; @@ -1417,6 +1677,22 @@ endpoint 1 { callback attribute clusterRevision; } + server cluster PowerSource { + ram attribute status; + ram attribute order; + ram attribute description; + ram attribute batPercentRemaining default = 95; + ram attribute batPresent default = 1; + ram attribute batChargeState default = 4; + callback attribute endpointList; + callback attribute generatedCommandList; + callback attribute acceptedCommandList; + callback attribute eventList; + callback attribute attributeList; + ram attribute featureMap default = 0; + ram attribute clusterRevision default = 1; + } + server cluster RvcRunMode { callback attribute supportedModes; callback attribute currentMode; diff --git a/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.zap b/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.zap index 3c058e9910c45d..15c155dbb69d12 100644 --- a/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.zap +++ b/examples/chef/devices/rootnode_roboticvacuumcleaner_1807ff0c49.zap @@ -1,6 +1,6 @@ { "fileFormat": 2, - "featureLevel": 100, + "featureLevel": 102, "creator": "zap", "keyValuePairs": [ { @@ -29,6 +29,7 @@ "pathRelativity": "relativeToZap", "path": "../../../src/app/zap-templates/app-templates.json", "type": "gen-templates-json", + "category": "matter", "version": "chip-v1" } ], @@ -1924,12 +1925,18 @@ "id": 2, "name": "Anonymous Endpoint Type", "deviceTypeRef": { - "code": 116, + "code": 17, "profileId": 259, - "label": "MA-robotic-vacuum-cleaner", - "name": "MA-robotic-vacuum-cleaner" + "label": "MA-powersource", + "name": "MA-powersource" }, "deviceTypes": [ + { + "code": 17, + "profileId": 259, + "label": "MA-powersource", + "name": "MA-powersource" + }, { "code": 116, "profileId": 259, @@ -1938,13 +1945,15 @@ } ], "deviceVersions": [ + 1, 1 ], "deviceIdentifiers": [ + 17, 116 ], - "deviceTypeName": "MA-robotic-vacuum-cleaner", - "deviceTypeCode": 116, + "deviceTypeName": "MA-powersource", + "deviceTypeCode": 17, "deviceTypeProfileId": 259, "clusters": [ { @@ -2342,7 +2351,7 @@ "singleton": 0, "bounded": 0, "defaultValue": null, - "reportable": 1, + "reportable": 0, "minInterval": 1, "maxInterval": 65534, "reportableChange": 0 @@ -2358,7 +2367,7 @@ "singleton": 0, "bounded": 0, "defaultValue": null, - "reportable": 1, + "reportable": 0, "minInterval": 1, "maxInterval": 65534, "reportableChange": 0 @@ -2374,7 +2383,7 @@ "singleton": 0, "bounded": 0, "defaultValue": null, - "reportable": 1, + "reportable": 0, "minInterval": 1, "maxInterval": 65534, "reportableChange": 0 @@ -2477,6 +2486,224 @@ } ] }, + { + "name": "Power Source", + "code": 47, + "mfgCode": null, + "define": "POWER_SOURCE_CLUSTER", + "side": "server", + "enabled": 1, + "attributes": [ + { + "name": "Status", + "code": 0, + "mfgCode": null, + "side": "server", + "type": "PowerSourceStatusEnum", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "Order", + "code": 1, + "mfgCode": null, + "side": "server", + "type": "int8u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "Description", + "code": 2, + "mfgCode": null, + "side": "server", + "type": "char_string", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "BatPercentRemaining", + "code": 12, + "mfgCode": null, + "side": "server", + "type": "int8u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "95", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "BatPresent", + "code": 17, + "mfgCode": null, + "side": "server", + "type": "boolean", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "BatChargeState", + "code": 26, + "mfgCode": null, + "side": "server", + "type": "BatChargeStateEnum", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "4", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EndpointList", + "code": 31, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "GeneratedCommandList", + "code": 65528, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AcceptedCommandList", + "code": 65529, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "EventList", + "code": 65530, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "AttributeList", + "code": 65531, + "mfgCode": null, + "side": "server", + "type": "array", + "included": 1, + "storageOption": "External", + "singleton": 0, + "bounded": 0, + "defaultValue": null, + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "FeatureMap", + "code": 65532, + "mfgCode": null, + "side": "server", + "type": "bitmap32", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "0", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + }, + { + "name": "ClusterRevision", + "code": 65533, + "mfgCode": null, + "side": "server", + "type": "int16u", + "included": 1, + "storageOption": "RAM", + "singleton": 0, + "bounded": 0, + "defaultValue": "1", + "reportable": 1, + "minInterval": 1, + "maxInterval": 65534, + "reportableChange": 0 + } + ] + }, { "name": "RVC Run Mode", "code": 84, diff --git a/integrations/cloudbuild/chef.yaml b/integrations/cloudbuild/chef.yaml index 5a7e98ca56c8d3..71c91ba2c9342a 100644 --- a/integrations/cloudbuild/chef.yaml +++ b/integrations/cloudbuild/chef.yaml @@ -29,7 +29,7 @@ steps: args: - >- perl -i -pe 's/^gdbgui==/# gdbgui==/' /opt/espressif/esp-idf/requirements.txt && - ./examples/chef/chef.py --build_all --build_exclude noip\|roboticvacuumcleaner + ./examples/chef/chef.py --build_all id: CompileAll waitFor: - Bootstrap diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h index 42a54b95ee944f..5aa99576615f54 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h @@ -1832,6 +1832,7 @@ enum class StatusCode : uint8_t enum class Feature : uint32_t { kNoFeatures = 0x0, + kOnOff = 0x1, }; } // namespace RvcRunMode @@ -1865,6 +1866,7 @@ enum class StatusCode : uint8_t enum class Feature : uint32_t { kNoFeatures = 0x0, + kOnOff = 0x1, }; } // namespace RvcCleanMode From 76e25cb9ae03f0dde4c73a2f1361a8df5c0db5ec Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 1 May 2024 18:51:46 +0000 Subject: [PATCH 02/18] Restyled by whitespace --- examples/chef/common/chef-rvc-operational-state-delegate.cpp | 4 ++-- examples/chef/common/chef-rvc-operational-state-delegate.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 3e45a6e41eabf5..af6303753f0f16 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -197,7 +197,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { uint8_t m = static_cast(buffer[0]); DataModel::Nullable aPhase(m); - CHIP_ERROR err = gRvcOperationalStateInstance->SetCurrentPhase(aPhase); + CHIP_ERROR err = gRvcOperationalStateInstance->SetCurrentPhase(aPhase); if (CHIP_NO_ERROR == err) { break; @@ -226,7 +226,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c return ret; } -chip::Protocols::InteractionModel::Status +chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index f33da259fdf639..b956345f705294 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -123,11 +123,11 @@ void Shutdown(); } // namespace app } // namespace chip -chip::Protocols::InteractionModel::Status +chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); -#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER \ No newline at end of file +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER From e9fe6f835fcca19f1729f18af5b979c35d831cc5 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 1 May 2024 18:51:47 +0000 Subject: [PATCH 03/18] Restyled by clang-format --- .../chef/common/chef-rvc-mode-delegate.cpp | 22 +++++++++-------- examples/chef/common/chef-rvc-mode-delegate.h | 14 ++++++----- .../chef-rvc-operational-state-delegate.cpp | 24 +++++++++---------- .../chef-rvc-operational-state-delegate.h | 20 +++++++--------- examples/chef/common/stubs.cpp | 3 +-- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 11e02b24de34a1..d5a85a68682456 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -109,7 +109,8 @@ void RvcRunMode::Shutdown() } chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer) { chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; @@ -117,12 +118,12 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp VerifyOrDie(gRvcRunModeInstance != nullptr); ModeBase::Instance * clusterInstance = gRvcRunModeInstance; - chip::AttributeId attributeId = attributeMetadata->attributeId; + chip::AttributeId attributeId = attributeMetadata->attributeId; switch (attributeId) { case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { - uint8_t m = static_cast(buffer[0]); + uint8_t m = static_cast(buffer[0]); chip::Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m); if (chip::Protocols::InteractionModel::Status::Success == status) { @@ -142,8 +143,8 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp } chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength) + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength) { return chip::Protocols::InteractionModel::Status::Success; @@ -243,7 +244,8 @@ void RvcCleanMode::Shutdown() } chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer) { chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; @@ -251,12 +253,12 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::En VerifyOrDie(gRvcCleanModeInstance != nullptr); ModeBase::Instance * clusterInstance = gRvcCleanModeInstance; - chip::AttributeId attributeId = attributeMetadata->attributeId; + chip::AttributeId attributeId = attributeMetadata->attributeId; switch (attributeId) { case chip::app::Clusters::RvcCleanMode::Attributes::CurrentMode::Id: { - uint8_t m = static_cast(buffer[0]); + uint8_t m = static_cast(buffer[0]); Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m); if (Protocols::InteractionModel::Status::Success == status) { @@ -276,8 +278,8 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::En } chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength) + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength) { return chip::Protocols::InteractionModel::Status::Success; } diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index ddd28c56577632..359c90c5a08162 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -123,16 +123,18 @@ void Shutdown(); #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer); chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength); + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength); #endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER #ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer); chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength); + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength); #endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index af6303753f0f16..6639e72b1fac01 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -31,7 +31,6 @@ using chip::Protocols::InteractionModel::Status; static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr; static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; - static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); DataModel::Nullable RvcOperationalStateDelegate::GetCountdownTime() @@ -184,19 +183,21 @@ void RvcOperationalState::Shutdown() } } -chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpointId, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) +chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpointId, + chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer) { chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcOperationalStateInstance != nullptr); - chip::AttributeId attributeId = attributeMetadata->attributeId; + chip::AttributeId attributeId = attributeMetadata->attributeId; switch (attributeId) { case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { - uint8_t m = static_cast(buffer[0]); - DataModel::Nullable aPhase(m); + uint8_t m = static_cast(buffer[0]); + DataModel::Nullable aPhase(m); CHIP_ERROR err = gRvcOperationalStateInstance->SetCurrentPhase(aPhase); if (CHIP_NO_ERROR == err) { @@ -207,7 +208,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c } break; case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: { - uint8_t m = static_cast(buffer[0]); + uint8_t m = static_cast(buffer[0]); CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m); if (CHIP_NO_ERROR == err) { @@ -226,10 +227,9 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c return ret; } -chip::Protocols::InteractionModel::Status -chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength) +chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength) { return chip::Protocols::InteractionModel::Status::Success; } @@ -239,7 +239,7 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr); - gRvcOperationalStateDelegate = new chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate(); + gRvcOperationalStateDelegate = new chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate(); EndpointId operationalStateEndpoint = 0x01; gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint); diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index b956345f705294..75d719f47e0774 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -36,11 +36,7 @@ namespace RvcOperationalState { class RvcOperationalStateDelegate : public RvcOperationalState::Delegate { public: - - RvcOperationalStateDelegate() - { - mOperationalStateList = Span(rvcOpStateList); - } + RvcOperationalStateDelegate() { mOperationalStateList = Span(rvcOpStateList); } /** * Get the countdown time. This attribute is not used in this application. @@ -100,6 +96,7 @@ class RvcOperationalStateDelegate : public RvcOperationalState::Delegate uint32_t mRunningTime = 0; uint32_t mPausedTime = 0; app::DataModel::Nullable mCountDownTime; + private: Span mOperationalStateList; Span mOperationalPhaseList; @@ -123,11 +120,10 @@ void Shutdown(); } // namespace app } // namespace chip -chip::Protocols::InteractionModel::Status -chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); -chip::Protocols::InteractionModel::Status -chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, - const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, - uint16_t maxReadLength); +chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer); +chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, + const EmberAfAttributeMetadata * attributeMetadata, + uint8_t * buffer, uint16_t maxReadLength); #endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index 4f63e68557cfa0..bbb6660c292a24 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -19,8 +19,7 @@ #include "chef-concentration-measurement.h" #endif -#if defined(MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER) || \ - defined(MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER) +#if defined(MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER) || defined(MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER) #include "chef-rvc-mode-delegate.h" #endif From ab0da73404f8c83e3209e80bdafc74f56f7bd1cb Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Thu, 2 May 2024 14:58:00 +0800 Subject: [PATCH 04/18] remove old rvc feature --- examples/chef/common/chef-rvc-mode-delegate.cpp | 2 +- .../app-common/app-common/zap-generated/cluster-enums.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index d5a85a68682456..d5415e1970eed6 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -156,7 +156,7 @@ void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr); gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate; gRvcRunModeInstance = - new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kOnOff)); + new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kNoFeatures)); gRvcRunModeInstance->Init(); } diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h index 5aa99576615f54..42a54b95ee944f 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h @@ -1832,7 +1832,6 @@ enum class StatusCode : uint8_t enum class Feature : uint32_t { kNoFeatures = 0x0, - kOnOff = 0x1, }; } // namespace RvcRunMode @@ -1866,7 +1865,6 @@ enum class StatusCode : uint8_t enum class Feature : uint32_t { kNoFeatures = 0x0, - kOnOff = 0x1, }; } // namespace RvcCleanMode From 83bf599a9950ce1880ec3ae9a14276e30c80a794 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 2 May 2024 06:58:31 +0000 Subject: [PATCH 05/18] Restyled by clang-format --- examples/chef/common/chef-rvc-mode-delegate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index d5415e1970eed6..8984e0c82d0435 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -155,8 +155,8 @@ void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcRunModeDelegate == nullptr && gRvcRunModeInstance == nullptr); gRvcRunModeDelegate = new RvcRunMode::RvcRunModeDelegate; - gRvcRunModeInstance = - new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, chip::to_underlying(RvcRunMode::Feature::kNoFeatures)); + gRvcRunModeInstance = new ModeBase::Instance(gRvcRunModeDelegate, endpointId, RvcRunMode::Id, + chip::to_underlying(RvcRunMode::Feature::kNoFeatures)); gRvcRunModeInstance->Init(); } From 080d80ce24b7e12eb6ff7d96c969c364e5da3c7e Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Fri, 3 May 2024 20:23:35 +0800 Subject: [PATCH 06/18] update return status --- .../chef/common/chef-rvc-mode-delegate.cpp | 21 ++++++++++++------- .../chef-rvc-operational-state-delegate.cpp | 6 ++---- examples/chef/common/stubs.cpp | 6 ------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 8984e0c82d0435..bc216eee64a7dd 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -112,9 +112,12 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) { - chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + // this cluster is only enabled for endpoint 1 + if(endpointId != 1) { + return chip::Protocols::InteractionModel::Status::UnsupportedEndpoint; + } - VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. + chip::Protocols::InteractionModel::Status ret; VerifyOrDie(gRvcRunModeInstance != nullptr); ModeBase::Instance * clusterInstance = gRvcRunModeInstance; @@ -124,13 +127,12 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp { case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { uint8_t m = static_cast(buffer[0]); - chip::Protocols::InteractionModel::Status status = clusterInstance->UpdateCurrentMode(m); - if (chip::Protocols::InteractionModel::Status::Success == status) + ret = clusterInstance->UpdateCurrentMode(m); + if (chip::Protocols::InteractionModel::Status::Success != ret) { + ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast(ret)); break; } - ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; - ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast(status)); } break; default: @@ -247,11 +249,14 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::En const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer) { - chip::Protocols::InteractionModel::Status ret = Protocols::InteractionModel::Status::Success; + // this cluster is only enabled for endpoint 1 + if(endpointId != 1) { + return chip::Protocols::InteractionModel::Status::UnsupportedEndpoint; + } - VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcCleanModeInstance != nullptr); + chip::Protocols::InteractionModel::Status ret; ModeBase::Instance * clusterInstance = gRvcCleanModeInstance; chip::AttributeId attributeId = attributeMetadata->attributeId; diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 6639e72b1fac01..2ddd328576262f 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -27,7 +27,6 @@ using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; -#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr; static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; @@ -147,7 +146,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data auto countdown_time = delegate->GetCountdownTime(); - if (countdown_time.IsNull() || (!countdown_time.IsNull() && countdown_time.Value() > 0)) + if (countdown_time.ValueOr(1) > 0) { if (state == OperationalState::OperationalStateEnum::kRunning) { @@ -246,5 +245,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); gRvcOperationalStateInstance->Init(); -} -#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +} \ No newline at end of file diff --git a/examples/chef/common/stubs.cpp b/examples/chef/common/stubs.cpp index bbb6660c292a24..266018f42acd29 100644 --- a/examples/chef/common/stubs.cpp +++ b/examples/chef/common/stubs.cpp @@ -68,17 +68,14 @@ Protocols::InteractionModel::Status emberAfExternalAttributeReadCallback(Endpoin #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER case chip::app::Clusters::RvcRunMode::Id: return chefRvcRunModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); - break; #endif #ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER case chip::app::Clusters::RvcCleanMode::Id: return chefRvcCleanModeReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); - break; #endif #ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER case chip::app::Clusters::RvcOperationalState::Id: return chefRvcOperationalStateReadCallback(endpoint, clusterId, attributeMetadata, buffer, maxReadLength); - break; #endif default: break; @@ -131,17 +128,14 @@ Protocols::InteractionModel::Status emberAfExternalAttributeWriteCallback(Endpoi #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER case chip::app::Clusters::RvcRunMode::Id: return chefRvcRunModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer); - break; #endif #ifdef MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER case chip::app::Clusters::RvcCleanMode::Id: return chefRvcCleanModeWriteCallback(endpoint, clusterId, attributeMetadata, buffer); - break; #endif #ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER case chip::app::Clusters::RvcOperationalState::Id: return chefRvcOperationalStateWriteCallback(endpoint, clusterId, attributeMetadata, buffer); - break; #endif default: break; From 9c3b9e7a9524a1cbb1afe7405144f4b285ab1dd6 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 3 May 2024 12:24:04 +0000 Subject: [PATCH 07/18] Restyled by whitespace --- examples/chef/common/chef-rvc-operational-state-delegate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 2ddd328576262f..30c4ebf6e8eb4c 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -245,4 +245,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); gRvcOperationalStateInstance->Init(); -} \ No newline at end of file +} From 4ffc4a910eadb4102d77e85da8aad789927240e1 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 3 May 2024 12:24:05 +0000 Subject: [PATCH 08/18] Restyled by clang-format --- examples/chef/common/chef-rvc-mode-delegate.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index bc216eee64a7dd..37ae8ac2bfaabb 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -113,7 +113,8 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp uint8_t * buffer) { // this cluster is only enabled for endpoint 1 - if(endpointId != 1) { + if (endpointId != 1) + { return chip::Protocols::InteractionModel::Status::UnsupportedEndpoint; } @@ -126,8 +127,8 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::Endp switch (attributeId) { case chip::app::Clusters::RvcRunMode::Attributes::CurrentMode::Id: { - uint8_t m = static_cast(buffer[0]); - ret = clusterInstance->UpdateCurrentMode(m); + uint8_t m = static_cast(buffer[0]); + ret = clusterInstance->UpdateCurrentMode(m); if (chip::Protocols::InteractionModel::Status::Success != ret) { ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast(ret)); @@ -250,7 +251,8 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeWriteCallback(chip::En uint8_t * buffer) { // this cluster is only enabled for endpoint 1 - if(endpointId != 1) { + if (endpointId != 1) + { return chip::Protocols::InteractionModel::Status::UnsupportedEndpoint; } From 98ac87e871af25afdb41a1d986e19160d5bfd2b3 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Tue, 7 May 2024 13:13:43 +0800 Subject: [PATCH 09/18] add back ifdef; remove old feature flag --- examples/chef/common/chef-rvc-mode-delegate.cpp | 2 +- examples/chef/common/chef-rvc-operational-state-delegate.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 37ae8ac2bfaabb..1b5e95b324a5b6 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -297,7 +297,7 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr); gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate; gRvcCleanModeInstance = - new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kOnOff)); + new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kNoFeatures)); gRvcCleanModeInstance->Init(); } #endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 30c4ebf6e8eb4c..c73fb7e19dec2f 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -20,6 +20,7 @@ #include #include +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER using namespace chip; using namespace chip::app; using namespace chip::app::Clusters; @@ -246,3 +247,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) gRvcOperationalStateInstance->Init(); } +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER From 3f9becaf7d19a6fe2e10ddc3b2ba286b454e3e31 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 7 May 2024 05:20:38 +0000 Subject: [PATCH 10/18] Restyled by clang-format --- examples/chef/common/chef-rvc-mode-delegate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 1b5e95b324a5b6..0fbfbd0b4adc05 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -296,8 +296,8 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. VerifyOrDie(gRvcCleanModeDelegate == nullptr && gRvcCleanModeInstance == nullptr); gRvcCleanModeDelegate = new RvcCleanMode::RvcCleanModeDelegate; - gRvcCleanModeInstance = - new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, chip::to_underlying(RvcCleanMode::Feature::kNoFeatures)); + gRvcCleanModeInstance = new ModeBase::Instance(gRvcCleanModeDelegate, 0x1, RvcCleanMode::Id, + chip::to_underlying(RvcCleanMode::Feature::kNoFeatures)); gRvcCleanModeInstance->Init(); } #endif // MATTER_DM_PLUGIN_RVC_CLEAN_MODE_SERVER From 9c84e0892e85c5099d40f2f7b6cee9eefb9e61f9 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Sat, 11 May 2024 16:45:13 +0800 Subject: [PATCH 11/18] write read attributes into buffer --- examples/chef/common/chef-rvc-mode-delegate.cpp | 13 ++++++++++--- .../common/chef-rvc-operational-state-delegate.cpp | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 0fbfbd0b4adc05..e20d7ccb93f8f9 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -149,8 +149,11 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::Endpo const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - - return chip::Protocols::InteractionModel::Status::Success; + if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); + return chip::Protocols::InteractionModel::Status::Success; + } + return chip::Protocols::InteractionModel::Status::ResourceExhausted; } void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) @@ -288,7 +291,11 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - return chip::Protocols::InteractionModel::Status::Success; + if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); + return chip::Protocols::InteractionModel::Status::Success; + } + return chip::Protocols::InteractionModel::Status::ResourceExhausted; } void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index c73fb7e19dec2f..6cbdbabbc5315b 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -231,7 +231,11 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - return chip::Protocols::InteractionModel::Status::Success; + if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); + return chip::Protocols::InteractionModel::Status::Success; + } + return chip::Protocols::InteractionModel::Status::ResourceExhausted; } void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) From 11b4c03b8ed7ad1e35403bb233f45cad92c5ef59 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 11 May 2024 08:45:51 +0000 Subject: [PATCH 12/18] Restyled by clang-format --- examples/chef/common/chef-rvc-mode-delegate.cpp | 6 ++++-- .../chef/common/chef-rvc-operational-state-delegate.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index e20d7ccb93f8f9..1ef8476aab5844 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -149,7 +149,8 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::Endpo const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + if (sizeof(*attributeMetadata) <= sizeof(buffer)) + { memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); return chip::Protocols::InteractionModel::Status::Success; } @@ -291,7 +292,8 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + if (sizeof(*attributeMetadata) <= sizeof(buffer)) + { memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); return chip::Protocols::InteractionModel::Status::Success; } diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 6cbdbabbc5315b..82b1f7ad67affc 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -231,7 +231,8 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if(sizeof(*attributeMetadata) <= sizeof(buffer)) { + if (sizeof(*attributeMetadata) <= sizeof(buffer)) + { memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); return chip::Protocols::InteractionModel::Status::Success; } From e6006a8cbcd69b335476cc09f0b4c3d7c2cc9222 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Wed, 15 May 2024 23:00:37 +0800 Subject: [PATCH 13/18] update readCallback write buffer --- .../chef/common/chef-rvc-mode-delegate.cpp | 20 ++++++++----------- .../chef-rvc-operational-state-delegate.cpp | 10 ++++------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 1ef8476aab5844..c9f11c22412f27 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -149,12 +149,10 @@ chip::Protocols::InteractionModel::Status chefRvcRunModeReadCallback(chip::Endpo const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if (sizeof(*attributeMetadata) <= sizeof(buffer)) - { - memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); - return chip::Protocols::InteractionModel::Status::Success; - } - return chip::Protocols::InteractionModel::Status::ResourceExhausted; + uint8_t m = gRvcRunModeInstance->GetCurrentMode(); + memcpy(buffer, &m, sizeof(m)); + + return chip::Protocols::InteractionModel::Status::Success; } void emberAfRvcRunModeClusterInitCallback(chip::EndpointId endpointId) @@ -292,12 +290,10 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if (sizeof(*attributeMetadata) <= sizeof(buffer)) - { - memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); - return chip::Protocols::InteractionModel::Status::Success; - } - return chip::Protocols::InteractionModel::Status::ResourceExhausted; + uint8_t m = gRvcCleanModeInstance->GetCurrentMode(); + memcpy(buffer, &m, sizeof(m)); + + return chip::Protocols::InteractionModel::Status::Success; } void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 82b1f7ad67affc..84eb75e3e4527b 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -231,12 +231,10 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - if (sizeof(*attributeMetadata) <= sizeof(buffer)) - { - memcpy(buffer, &attributeMetadata, sizeof(attributeMetadata)); - return chip::Protocols::InteractionModel::Status::Success; - } - return chip::Protocols::InteractionModel::Status::ResourceExhausted; + app::DataModel::Nullable m = gRvcOperationalStateInstance->GetCurrentPhase(); + memcpy(buffer, &m, sizeof(m)); + + return chip::Protocols::InteractionModel::Status::Success; } void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) From efcab14279939e17fb065bd808f753a06ded9764 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 15 May 2024 15:01:07 +0000 Subject: [PATCH 14/18] Restyled by whitespace --- examples/chef/common/chef-rvc-mode-delegate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index c9f11c22412f27..1c318f35fe27ef 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -292,7 +292,7 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End { uint8_t m = gRvcCleanModeInstance->GetCurrentMode(); memcpy(buffer, &m, sizeof(m)); - + return chip::Protocols::InteractionModel::Status::Success; } From 1bc1757723c0c297844b4f15acf291d7c3e5af37 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Wed, 29 May 2024 02:52:08 +0800 Subject: [PATCH 15/18] update buffer read in read call back --- .../chef/common/chef-rvc-mode-delegate.cpp | 5 ++- .../chef-rvc-operational-state-delegate.cpp | 35 ++++++++++++++----- .../chef-rvc-operational-state-delegate.h | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 1c318f35fe27ef..f999c14562fdde 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -290,9 +290,8 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - uint8_t m = gRvcCleanModeInstance->GetCurrentMode(); - memcpy(buffer, &m, sizeof(m)); - + VerifyOrReturnValue(maxReadLength > 0, chip::Protocols::InteractionModel::Status::ResourceExhausted); + buffer[0] = gRvcCleanModeInstance->GetCurrentMode(); return chip::Protocols::InteractionModel::Status::Success; } diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 84eb75e3e4527b..3b2c5a84e386a2 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -35,10 +35,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data DataModel::Nullable RvcOperationalStateDelegate::GetCountdownTime() { - if (mCountDownTime.IsNull()) + if (mRunningTime > mPhaseDuration.Value()) return DataModel::NullNullable; - return DataModel::MakeNullable((uint32_t) (mCountDownTime.Value() - mRunningTime)); + return DataModel::MakeNullable((uint32_t) (mPhaseDuration.Value() - mRunningTime)); } CHIP_ERROR RvcOperationalStateDelegate::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState) @@ -203,7 +203,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c { break; } - ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ret = chip::Protocols::InteractionModel::Status::ConstraintError; ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format()); } break; @@ -214,7 +214,7 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c { break; } - ret = chip::Protocols::InteractionModel::Status::UnsupportedWrite; + ret = chip::Protocols::InteractionModel::Status::ConstraintError; ChipLogError(DeviceLayer, "Invalid Attribute Update status: %" CHIP_ERROR_FORMAT, err.Format()); } break; @@ -231,10 +231,30 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength) { - app::DataModel::Nullable m = gRvcOperationalStateInstance->GetCurrentPhase(); - memcpy(buffer, &m, sizeof(m)); + chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; + chip::AttributeId attributeId = attributeMetadata->attributeId; + switch(attributeId) { + case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { - return chip::Protocols::InteractionModel::Status::Success; + app::DataModel::Nullable currentPhase = gRvcOperationalStateInstance->GetCurrentPhase(); + if(currentPhase.IsNull()) + { + ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; + break; + } + *buffer = currentPhase.Value(); + } + break; + case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: { + *buffer = gRvcOperationalStateInstance->GetCurrentOperationalState(); + } + break; + default: + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); + break; + } + + return ret; } void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) @@ -247,7 +267,6 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint); gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); - gRvcOperationalStateInstance->Init(); } #endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index 75d719f47e0774..33b01d55201466 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -95,7 +95,7 @@ class RvcOperationalStateDelegate : public RvcOperationalState::Delegate uint32_t mRunningTime = 0; uint32_t mPausedTime = 0; - app::DataModel::Nullable mCountDownTime; + app::DataModel::Nullable mPhaseDuration; private: Span mOperationalStateList; From 27ef48077b9203774507d59f864a2ff669b34584 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 28 May 2024 18:55:15 +0000 Subject: [PATCH 16/18] Restyled by clang-format --- .../chef-rvc-operational-state-delegate.cpp | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 3b2c5a84e386a2..24a1b909fe2999 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -232,26 +232,27 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch uint8_t * buffer, uint16_t maxReadLength) { chip::Protocols::InteractionModel::Status ret = chip::Protocols::InteractionModel::Status::Success; - chip::AttributeId attributeId = attributeMetadata->attributeId; - switch(attributeId) { - case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { + chip::AttributeId attributeId = attributeMetadata->attributeId; + switch (attributeId) + { + case chip::app::Clusters::RvcOperationalState::Attributes::CurrentPhase::Id: { - app::DataModel::Nullable currentPhase = gRvcOperationalStateInstance->GetCurrentPhase(); - if(currentPhase.IsNull()) - { - ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; - break; - } - *buffer = currentPhase.Value(); - } - break; - case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: { - *buffer = gRvcOperationalStateInstance->GetCurrentOperationalState(); + app::DataModel::Nullable currentPhase = gRvcOperationalStateInstance->GetCurrentPhase(); + if (currentPhase.IsNull()) + { + ret = chip::Protocols::InteractionModel::Status::UnsupportedAttribute; + break; } + *buffer = currentPhase.Value(); + } + break; + case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: { + *buffer = gRvcOperationalStateInstance->GetCurrentOperationalState(); + } + break; + default: + ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); break; - default: - ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast(attributeId)); - break; } return ret; From e7ed1253ddbb126f9b30e8cbde09f8b81658d438 Mon Sep 17 00:00:00 2001 From: Sting Chang Date: Wed, 29 May 2024 05:07:37 +0800 Subject: [PATCH 17/18] use static instance --- .../chef-rvc-operational-state-delegate.cpp | 27 ++++++------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 24a1b909fe2999..235e65aa972d5d 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -28,8 +28,8 @@ using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; -static RvcOperationalState::Instance * gRvcOperationalStateInstance = nullptr; -static RvcOperationalStateDelegate * gRvcOperationalStateDelegate = nullptr; +static std::unique_ptr gRvcOperationalStateDelegate; +static std::unique_ptr gRvcOperationalStateInstance; static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); @@ -141,7 +141,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data { RvcOperationalStateDelegate * delegate = reinterpret_cast(data); - OperationalState::Instance * instance = gRvcOperationalStateInstance; + OperationalState::Instance * instance = gRvcOperationalStateInstance.get(); OperationalState::OperationalStateEnum state = static_cast(instance->GetCurrentOperationalState()); @@ -171,16 +171,8 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data void RvcOperationalState::Shutdown() { - if (gRvcOperationalStateInstance != nullptr) - { - delete gRvcOperationalStateInstance; - gRvcOperationalStateInstance = nullptr; - } - if (gRvcOperationalStateDelegate != nullptr) - { - delete gRvcOperationalStateDelegate; - gRvcOperationalStateDelegate = nullptr; - } + gRvcOperationalStateInstance.reset(); + gRvcOperationalStateDelegate.reset(); } chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpointId, @@ -261,13 +253,10 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) { VerifyOrDie(endpointId == 1); // this cluster is only enabled for endpoint 1. - VerifyOrDie(gRvcOperationalStateInstance == nullptr && gRvcOperationalStateDelegate == nullptr); - - gRvcOperationalStateDelegate = new chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate(); - EndpointId operationalStateEndpoint = 0x01; - gRvcOperationalStateInstance = new RvcOperationalState::Instance(gRvcOperationalStateDelegate, operationalStateEndpoint); + VerifyOrDie(!gRvcOperationalStateDelegate && !gRvcOperationalStateInstance); - gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped)); + gRvcOperationalStateDelegate = std::make_unique(); + gRvcOperationalStateInstance = std::make_unique(gRvcOperationalStateDelegate.get(), endpointId); gRvcOperationalStateInstance->Init(); } #endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER From 284644f8a382afe5988e18f7521f5a60abd0d527 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 28 May 2024 21:08:12 +0000 Subject: [PATCH 18/18] Restyled by clang-format --- examples/chef/common/chef-rvc-operational-state-delegate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 235e65aa972d5d..36ff3e88fcd181 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -29,7 +29,7 @@ using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; static std::unique_ptr gRvcOperationalStateDelegate; -static std::unique_ptr gRvcOperationalStateInstance; +static std::unique_ptr gRvcOperationalStateInstance; static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data);