From 1408036e2358aa59bca9b8c2458d3bb1776e627d Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:32:38 -0500 Subject: [PATCH] [ICD] Start the ICD in idle (#30555) * Change init value of mOperationalState so we start in idle mode at bootup * Update TestICDManager test as we now start in Idle --- src/app/icd/ICDManager.cpp | 4 ++-- src/app/icd/ICDManager.h | 3 ++- src/app/tests/TestICDManager.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/app/icd/ICDManager.cpp b/src/app/icd/ICDManager.cpp index 65aca79acda778..3d75b0d4dcf74c 100644 --- a/src/app/icd/ICDManager.cpp +++ b/src/app/icd/ICDManager.cpp @@ -73,7 +73,7 @@ void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricT // VerifyOrDie(kFastPollingInterval.count() < activeModeDuration); UpdateICDMode(); - UpdateOperationState(OperationalState::ActiveMode); + UpdateOperationState(OperationalState::IdleMode); } void ICDManager::Shutdown() @@ -84,7 +84,7 @@ void ICDManager::Shutdown() DeviceLayer::SystemLayer().CancelTimer(OnActiveModeDone, this); DeviceLayer::SystemLayer().CancelTimer(OnTransitionToIdle, this); mICDMode = ICDMode::SIT; - mOperationalState = OperationalState::IdleMode; + mOperationalState = OperationalState::ActiveMode; mStorage = nullptr; mFabricTable = nullptr; mStateObserverPool.ReleaseAll(); diff --git a/src/app/icd/ICDManager.h b/src/app/icd/ICDManager.h index cc262bec52d0ba..75001f8f71e0ca 100644 --- a/src/app/icd/ICDManager.h +++ b/src/app/icd/ICDManager.h @@ -141,7 +141,8 @@ class ICDManager : public ICDListener BitFlags mKeepActiveFlags{ 0 }; - OperationalState mOperationalState = OperationalState::IdleMode; + // Initialize mOperationalState to ActiveMode so the init sequence at bootup triggers the IdleMode behaviour first. + OperationalState mOperationalState = OperationalState::ActiveMode; ICDMode mICDMode = ICDMode::SIT; PersistentStorageDelegate * mStorage = nullptr; FabricTable * mFabricTable = nullptr; diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp index 693d1bc5630f73..7e47996dff78fa 100644 --- a/src/app/tests/TestICDManager.cpp +++ b/src/app/tests/TestICDManager.cpp @@ -141,13 +141,15 @@ class TestICDManager { TestContext * ctx = static_cast(aContext); - // After the init we should be in active mode + // After the init we should be in Idle mode + NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); + AdvanceClockAndRunEventLoop(ctx, secondsToMilliseconds(ICDManagementServer::GetInstance().GetIdleModeDurationSec()) + 1); + // Idle mode interval expired, ICDManager transitioned to the ActiveMode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); AdvanceClockAndRunEventLoop(ctx, ICDManagementServer::GetInstance().GetActiveModeDurationMs() + 1); // Active mode interval expired, ICDManager transitioned to the IdleMode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode); AdvanceClockAndRunEventLoop(ctx, secondsToMilliseconds(ICDManagementServer::GetInstance().GetIdleModeDurationSec()) + 1); - // Idle mode interval expired, ICDManager transitioned to the ActiveMode. NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode); // Events updating the Operation to Active mode can extend the current active mode time by 1 Active mode threshold.