From a80a11d7570719bbf9bac17ceb0c1c698c57bf0c Mon Sep 17 00:00:00 2001 From: Shreyas Bhandare Date: Fri, 21 Feb 2025 19:27:01 +0000 Subject: [PATCH 1/6] Start new cycle when RVC Run Mode is changed from idle to cleaning/mapping --- .../chef/common/chef-rvc-mode-delegate.cpp | 34 +++++++++++++++++++ .../chef-rvc-operational-state-delegate.cpp | 3 +- .../chef-rvc-operational-state-delegate.h | 3 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index e5444e03737c32..4e0cb54a4f8b4c 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -29,6 +29,11 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER #include + +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER +#include +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + using namespace chip::app::Clusters::RvcRunMode; static std::unique_ptr gRvcRunModeDelegate; @@ -51,7 +56,35 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands: return; } +#ifdef MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + OperationalState::GenericOperationalError err(to_underlying(OperationalState::ErrorStateEnum::kNoError)); + if (NewMode == RvcRunMode::ModeIdle) + { + if (currentMode != RvcRunMode::ModeIdle) + { // Stop existing cycle when going from cleaning/mapping to idle. + ChipLogProgress(DeviceLayer, "Stopping RVC cycle: %d", currentMode); + gRvcOperationalStateDelegate->HandleStopStateCallback(err); + } + } + else + { + if (currentMode == RvcRunMode::ModeIdle) + { // Start a new cycle when going from idle to clening/mapping. + ChipLogProgress(DeviceLayer, "Starting new RVC cycle: %d", NewMode); + gRvcOperationalStateDelegate->HandleStartStateCallback(err); + } + } + if (err.IsEqual(OperationalState::GenericOperationalError(to_underlying(OperationalState::ErrorStateEnum::kNoError)))) + { + response.status = to_underlying(ModeBase::StatusCode::kSuccess); + } + else + { + response.status = to_underlying(ModeBase::StatusCode::kGenericFailure); + } +#else response.status = to_underlying(ModeBase::StatusCode::kSuccess); +#endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER } CHIP_ERROR RvcRunModeDelegate::GetModeLabelByIndex(uint8_t modeIndex, chip::MutableCharSpan & label) @@ -296,3 +329,4 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) 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 9b4118732ee165..4654c43cf7cd82 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -28,7 +28,7 @@ using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; -static std::unique_ptr gRvcOperationalStateDelegate; +std::unique_ptr gRvcOperationalStateDelegate; static std::unique_ptr gRvcOperationalStateInstance; static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); @@ -327,3 +327,4 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) 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 7aca1a86ed95fa..bf4287f13dd304 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -121,6 +121,8 @@ void Shutdown(); } // namespace app } // namespace chip +extern std::unique_ptr gRvcOperationalStateDelegate; + chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); @@ -128,3 +130,4 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); #endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER + From ec69e2a422acbb4c9ee945d5dca5c1229785d908 Mon Sep 17 00:00:00 2001 From: Shreyas Bhandare Date: Sat, 22 Feb 2025 03:46:22 +0000 Subject: [PATCH 2/6] Fix bug : Last call to onOperationalStateTimeTick happens after state is already set to Stopped resulting in dereferencing a null pointer. Fix this by returning from function if state is stopped --- examples/chef/common/chef-rvc-operational-state-delegate.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 4654c43cf7cd82..26aae4c10a4397 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -176,6 +176,11 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data OperationalState::OperationalStateEnum state = static_cast(instance->GetCurrentOperationalState()); + if (state == OperationalState::OperationalStateEnum::kStopped) // Do not continue the timer when RVC has stopped. + { + return; + } + if (gRvcOperationalStateDelegate->mCountdownTime.IsNull()) { if (state == OperationalState::OperationalStateEnum::kRunning) From fc67454e7b6a0245d2a4cc42eaadb75c1e465123 Mon Sep 17 00:00:00 2001 From: Shreyas Bhandare Date: Sat, 22 Feb 2025 07:08:47 +0000 Subject: [PATCH 3/6] Change RunMode to Idle after cleaning cycle completes --- examples/chef/common/chef-rvc-mode-delegate.cpp | 2 +- examples/chef/common/chef-rvc-mode-delegate.h | 3 +++ .../chef/common/chef-rvc-operational-state-delegate.cpp | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index a93c2c92f32a44..60464100604dcc 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -37,7 +37,7 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T using namespace chip::app::Clusters::RvcRunMode; static std::unique_ptr gRvcRunModeDelegate; -static std::unique_ptr gRvcRunModeInstance; +std::unique_ptr gRvcRunModeInstance; CHIP_ERROR RvcRunModeDelegate::Init() { diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index 359c90c5a08162..7468c5b790540b 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -122,6 +122,8 @@ void Shutdown(); } // namespace chip #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER +extern std::unique_ptr gRvcRunModeInstance; + chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer); @@ -138,3 +140,4 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End 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 26aae4c10a4397..6421833c214fc4 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -28,6 +28,10 @@ using namespace chip::app::Clusters::OperationalState; using namespace chip::app::Clusters::RvcOperationalState; using chip::Protocols::InteractionModel::Status; +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER +#include +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + std::unique_ptr gRvcOperationalStateDelegate; static std::unique_ptr gRvcOperationalStateInstance; @@ -228,6 +232,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data gRvcOperationalStateDelegate->mRunningTime = 0; gRvcOperationalStateDelegate->mPausedTime = 0; gRvcOperationalStateDelegate->mCountdownTime.SetNull(); + +#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER + gRvcRunModeInstance->UpdateCurrentMode(RvcRunMode::ModeIdle); +#endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER } } } From fd92b12f82c35adf225efdf468f9580dd2d0faf4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sat, 22 Feb 2025 07:34:31 +0000 Subject: [PATCH 4/6] Restyled by whitespace --- examples/chef/common/chef-rvc-mode-delegate.cpp | 1 - examples/chef/common/chef-rvc-mode-delegate.h | 1 - examples/chef/common/chef-rvc-operational-state-delegate.cpp | 1 - examples/chef/common/chef-rvc-operational-state-delegate.h | 1 - 4 files changed, 4 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 60464100604dcc..2af784bd42b191 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -329,4 +329,3 @@ void emberAfRvcCleanModeClusterInitCallback(chip::EndpointId endpointId) gRvcCleanModeInstance->Init(); } #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 7468c5b790540b..9f0ccf5a57103d 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -140,4 +140,3 @@ chip::Protocols::InteractionModel::Status chefRvcCleanModeReadCallback(chip::End 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 6421833c214fc4..4c30adb2d47c34 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -340,4 +340,3 @@ void emberAfRvcOperationalStateClusterInitCallback(chip::EndpointId endpointId) 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 8fab46246fbb3e..2fd93d847e228b 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -131,4 +131,3 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateReadCallback(ch const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer, uint16_t maxReadLength); #endif // MATTER_DM_PLUGIN_RVC_OPERATIONAL_STATE_SERVER - From 154ae8d421a241e4efc99cd9a008a7b62d938c0f Mon Sep 17 00:00:00 2001 From: Shreyas Bhandare Date: Sun, 23 Feb 2025 04:05:51 +0000 Subject: [PATCH 5/6] Fix tags list for Mapping mode --- examples/chef/common/chef-rvc-mode-delegate.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index 9f0ccf5a57103d..63674a9787e24b 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -42,6 +42,7 @@ class RvcRunModeDelegate : public ModeBase::Delegate using ModeTagStructType = detail::Structs::ModeTagStruct::Type; ModeTagStructType ModeTagsIdle[1] = { { .value = to_underlying(ModeTag::kIdle) } }; ModeTagStructType ModeTagsCleaning[1] = { { .value = to_underlying(ModeTag::kCleaning) } }; + ModeTagStructType ModeTagsMapping[1] = { { .value = to_underlying(ModeTag::kMapping) } }; const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = { detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Idle"), @@ -52,7 +53,7 @@ class RvcRunModeDelegate : public ModeBase::Delegate .modeTags = DataModel::List(ModeTagsCleaning) }, detail::Structs::ModeOptionStruct::Type{ .label = CharSpan::fromCharString("Mapping"), .mode = ModeMapping, - .modeTags = DataModel::List(ModeTagsIdle) }, + .modeTags = DataModel::List(ModeTagsMapping) }, }; CHIP_ERROR Init() override; From 80ce7091ec3bca01865c374bb2f6cf9b345a7eb7 Mon Sep 17 00:00:00 2001 From: Shreyas Balakrishna Bhandare Date: Mon, 24 Feb 2025 10:39:28 -0800 Subject: [PATCH 6/6] use getters instead of extern --- examples/chef/common/chef-rvc-mode-delegate.cpp | 11 ++++++++--- examples/chef/common/chef-rvc-mode-delegate.h | 2 +- .../common/chef-rvc-operational-state-delegate.cpp | 9 +++++++-- .../chef/common/chef-rvc-operational-state-delegate.h | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/chef/common/chef-rvc-mode-delegate.cpp b/examples/chef/common/chef-rvc-mode-delegate.cpp index 2af784bd42b191..b275d08e21d474 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.cpp +++ b/examples/chef/common/chef-rvc-mode-delegate.cpp @@ -37,7 +37,12 @@ using ModeTagStructType = chip::app::Clusters::detail::Structs::ModeTagStruct::T using namespace chip::app::Clusters::RvcRunMode; static std::unique_ptr gRvcRunModeDelegate; -std::unique_ptr gRvcRunModeInstance; +static std::unique_ptr gRvcRunModeInstance; + +chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance() +{ + return gRvcRunModeInstance.get(); +} CHIP_ERROR RvcRunModeDelegate::Init() { @@ -63,7 +68,7 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands: if (currentMode != RvcRunMode::ModeIdle) { // Stop existing cycle when going from cleaning/mapping to idle. ChipLogProgress(DeviceLayer, "Stopping RVC cycle: %d", currentMode); - gRvcOperationalStateDelegate->HandleStopStateCallback(err); + getRvcOperationalStateDelegate()->HandleStopStateCallback(err); } } else @@ -71,7 +76,7 @@ void RvcRunModeDelegate::HandleChangeToMode(uint8_t NewMode, ModeBase::Commands: if (currentMode == RvcRunMode::ModeIdle) { // Start a new cycle when going from idle to clening/mapping. ChipLogProgress(DeviceLayer, "Starting new RVC cycle: %d", NewMode); - gRvcOperationalStateDelegate->HandleStartStateCallback(err); + getRvcOperationalStateDelegate()->HandleStartStateCallback(err); } } if (err.IsEqual(OperationalState::GenericOperationalError(to_underlying(OperationalState::ErrorStateEnum::kNoError)))) diff --git a/examples/chef/common/chef-rvc-mode-delegate.h b/examples/chef/common/chef-rvc-mode-delegate.h index 63674a9787e24b..f5b155cd718b79 100644 --- a/examples/chef/common/chef-rvc-mode-delegate.h +++ b/examples/chef/common/chef-rvc-mode-delegate.h @@ -123,7 +123,7 @@ void Shutdown(); } // namespace chip #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER -extern std::unique_ptr gRvcRunModeInstance; +chip::app::Clusters::ModeBase::Instance * getRvcRunModeInstance(); chip::Protocols::InteractionModel::Status chefRvcRunModeWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata, diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.cpp b/examples/chef/common/chef-rvc-operational-state-delegate.cpp index 4c30adb2d47c34..1a1cf0696c2074 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.cpp +++ b/examples/chef/common/chef-rvc-operational-state-delegate.cpp @@ -32,9 +32,14 @@ using chip::Protocols::InteractionModel::Status; #include #endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER -std::unique_ptr gRvcOperationalStateDelegate; +static std::unique_ptr gRvcOperationalStateDelegate; static std::unique_ptr gRvcOperationalStateInstance; +RvcOperationalStateDelegate * getRvcOperationalStateDelegate() +{ + return gRvcOperationalStateDelegate.get(); +} + static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data); DataModel::Nullable RvcOperationalStateDelegate::GetCountdownTime() @@ -234,7 +239,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data gRvcOperationalStateDelegate->mCountdownTime.SetNull(); #ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER - gRvcRunModeInstance->UpdateCurrentMode(RvcRunMode::ModeIdle); + getRvcRunModeInstance()->UpdateCurrentMode(RvcRunMode::ModeIdle); #endif // MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER } } diff --git a/examples/chef/common/chef-rvc-operational-state-delegate.h b/examples/chef/common/chef-rvc-operational-state-delegate.h index 2fd93d847e228b..d551182787dc36 100644 --- a/examples/chef/common/chef-rvc-operational-state-delegate.h +++ b/examples/chef/common/chef-rvc-operational-state-delegate.h @@ -122,7 +122,7 @@ void Shutdown(); } // namespace app } // namespace chip -extern std::unique_ptr gRvcOperationalStateDelegate; +chip::app::Clusters::RvcOperationalState::RvcOperationalStateDelegate * getRvcOperationalStateDelegate(); chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, const EmberAfAttributeMetadata * attributeMetadata,