Skip to content

Commit

Permalink
[ICD] Start the ICD in idle (#30555)
Browse files Browse the repository at this point in the history
* Change init value of mOperationalState so we start in idle mode at bootup

* Update TestICDManager test as we now start in Idle
  • Loading branch information
jmartinez-silabs authored and pull[bot] committed Jan 25, 2024
1 parent dccaeab commit 1408036
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/icd/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/app/icd/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class ICDManager : public ICDListener

BitFlags<KeepActiveFlags> 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;
Expand Down
6 changes: 4 additions & 2 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ class TestICDManager
{
TestContext * ctx = static_cast<TestContext *>(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.
Expand Down

0 comments on commit 1408036

Please sign in to comment.