Skip to content

Commit

Permalink
Applied suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lpbeliveau-silabs committed Feb 22, 2024
1 parent e7936da commit 62ccf9c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/app/icd/server/ICDConfigurationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ICDConfigurationData

System::Clock::Milliseconds16 GetActiveModeThreshold() { return mActiveThreshold; }

System::Clock::Milliseconds32 GetMaxStayActiveDuration() { return kMaxGuaranteedStayActiveDuration; }
System::Clock::Milliseconds32 GetGuaranteedStayActiveDuration() { return kGuaranteedStayActiveDuration; }

Protocols::SecureChannel::CheckInCounter & GetICDCounter() { return mICDCounter; }

Expand Down Expand Up @@ -127,7 +127,7 @@ class ICDConfigurationData
static constexpr System::Clock::Seconds32 kMinIdleModeDuration = System::Clock::Seconds32(1);
// As defined in the spec, the maximum guaranteed duration for the StayActiveDuration is 30s "Matter Application
// Clusters: 9.17.7.5.1. PromisedActiveDuration Field"
static constexpr System::Clock::Milliseconds32 kMaxGuaranteedStayActiveDuration = System::Clock::Milliseconds32(30000);
static constexpr System::Clock::Milliseconds32 kGuaranteedStayActiveDuration = System::Clock::Milliseconds32(30000);

static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) <= kMaxIdleModeDuration.count(),
"Spec requires the IdleModeDuration to be equal or inferior to 64800s.");
Expand Down
2 changes: 1 addition & 1 deletion src/app/icd/server/ICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ uint32_t ICDManager::StayActiveRequest(uint32_t stayActiveDuration)
VerifyOrReturnValue(mOperationalState == OperationalState::ActiveMode, 0);

uint32_t promisedActiveDuration =
std::min(static_cast<uint32_t>(ICDConfigurationData::GetInstance().GetMaxStayActiveDuration().count()), stayActiveDuration);
std::min(ICDConfigurationData::GetInstance().GetGuaranteedStayActiveDuration().count(), stayActiveDuration);

// If the device is already in ActiveMode, we need to extend the active mode duration
// for whichever is smallest between 30000 milliseconds and stayActiveDuration, taking in account the remaining active time.
Expand Down
4 changes: 2 additions & 2 deletions src/app/icd/server/ICDManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class ICDManager : public ICDListener

protected:
/**
* @brief Hepler function that extends the Active Mode duration by the extendDuration parameter
* as well as the Active Mode Jitter timer for the transition to iddle mode.
* @brief Hepler function that extends the Active Mode duration as well as the Active Mode Jitter timer for the transition to
* iddle mode.
*/
void ExtendActiveMode(System::Clock::Milliseconds16 extendDuration);

Expand Down
16 changes: 8 additions & 8 deletions src/app/tests/TestICDManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time by the ActiveModeDuration - 1
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms);
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms32);
// Confirm ICD manager is in active mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

Expand All @@ -567,48 +567,48 @@ class TestICDManager
NL_TEST_ASSERT(aSuite, stayActivePromisedMs == stayActiveRequestedMs);

// Advance time by the duration of the stay stayActiveRequestedMs - 1 ms
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(stayActiveRequestedMs) - 1_ms);
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(stayActiveRequestedMs) - 1_ms32);
// Confirm ICD manager is in active mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time by 1ms and Confirm ICD manager is in idle mode
AdvanceClockAndRunEventLoop(ctx, 1_ms);
AdvanceClockAndRunEventLoop(ctx, 1_ms32);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

// Trigger a subscription report Put the ICD manager into active mode
notifier.NotifySubscriptionReport();
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time by the duration of the stay active request - 1 ms
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms);
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms32);
stayActiveRequestedMs = 35000;
// Send a stay active request for 35 seconds, which is higher than the maximum stay active duration (30 seconds)
stayActivePromisedMs = ctx->mICDManager.StayActiveRequest(stayActiveRequestedMs);
// confirm the promised time is the maximum stay active duration (30 seconds)
NL_TEST_ASSERT(aSuite, stayActivePromisedMs == 30000);

// Advance time by the duration of the max stay active duration - 1 ms
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(30000) - 1_ms);
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(30000) - 1_ms32);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time by 1ms and Confirm ICD manager is in idle mode
AdvanceClockAndRunEventLoop(ctx, 1_ms);
AdvanceClockAndRunEventLoop(ctx, 1_ms32);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);

// Trigger a subscription report Put the ICD manager into active mode
notifier.NotifySubscriptionReport();
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

// Advance time by the duration of the stay active request - 1 ms
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms);
AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeDuration() - 1_ms32);
stayActiveRequestedMs = 30000;
// Send a stay active request for 30 seconds
stayActivePromisedMs = ctx->mICDManager.StayActiveRequest(stayActiveRequestedMs);
// confirm the promised time is the same as the requested time
NL_TEST_ASSERT(aSuite, stayActivePromisedMs == 30000);

// Advance time by the duration of the stay active request - 20000 ms
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(stayActiveRequestedMs) - 20000_ms);
AdvanceClockAndRunEventLoop(ctx, System::Clock::Milliseconds32(stayActiveRequestedMs) - 20000_ms32);
// Confirm ICD manager is in active mode, we should have 20000 seconds left at that point
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);

Expand Down

0 comments on commit 62ccf9c

Please sign in to comment.