[ICD] Refactor ICDManager to use System::Clock types (#31881)
* Refactor time members
* add using namespace
* Fix ActiveModeThreshold type and cast
diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp
index bd63503..b5fc344 100644
--- a/src/app/ReadHandler.cpp
+++ b/src/app/ReadHandler.cpp
@@ -46,7 +46,7 @@
uint16_t ReadHandler::GetPublisherSelectedIntervalLimit()
{
#if CHIP_CONFIG_ENABLE_ICD_SERVER
- return static_cast<uint16_t>(ICDConfigurationData::GetInstance().GetIdleModeDurationSec());
+ return std::chrono::duration_cast<System::Clock::Seconds16>(ICDConfigurationData::GetInstance().GetIdleModeDuration()).count();
#else
return kSubscriptionMaxIntervalPublisherLimit;
#endif
diff --git a/src/app/SubscriptionsInfoProvider.h b/src/app/SubscriptionsInfoProvider.h
index ef792904..cb8d470 100644
--- a/src/app/SubscriptionsInfoProvider.h
+++ b/src/app/SubscriptionsInfoProvider.h
@@ -42,6 +42,7 @@
*
* @param[in] aFabricIndex fabric index of the subject
* @param[in] subjectID NodeId of the subject
+ * subjectID may encode a CAT in the reserved section of the NodeID.
*
* @return true subject has at least one active subscription with the device
* false subject doesn't have any active subscription with the device
@@ -54,6 +55,7 @@
*
* @param[in] aFabricIndex fabric index of the subject
* @param[in] subjectID NodeId of the subject
+ * subjectID may encode a CAT in the reserved section of the NodeID
*
* @return true subject has at least one persisted subscription with the device
* false subject doesn't have any persisted subscription with the device
diff --git a/src/app/clusters/icd-management-server/icd-management-server.cpp b/src/app/clusters/icd-management-server/icd-management-server.cpp
index e748030..c3efce6 100644
--- a/src/app/clusters/icd-management-server/icd-management-server.cpp
+++ b/src/app/clusters/icd-management-server/icd-management-server.cpp
@@ -101,17 +101,17 @@
CHIP_ERROR IcdManagementAttributeAccess::ReadIdleModeDuration(EndpointId endpoint, AttributeValueEncoder & encoder)
{
- return encoder.Encode(mICDConfigurationData->GetIdleModeDurationSec());
+ return encoder.Encode(mICDConfigurationData->GetIdleModeDuration().count());
}
CHIP_ERROR IcdManagementAttributeAccess::ReadActiveModeDuration(EndpointId endpoint, AttributeValueEncoder & encoder)
{
- return encoder.Encode(mICDConfigurationData->GetActiveModeDurationMs());
+ return encoder.Encode(mICDConfigurationData->GetActiveModeDuration().count());
}
CHIP_ERROR IcdManagementAttributeAccess::ReadActiveModeThreshold(EndpointId endpoint, AttributeValueEncoder & encoder)
{
- return encoder.Encode(mICDConfigurationData->GetActiveModeThresholdMs());
+ return encoder.Encode(mICDConfigurationData->GetActiveModeThreshold().count());
}
CHIP_ERROR IcdManagementAttributeAccess::ReadRegisteredClients(EndpointId endpoint, AttributeValueEncoder & encoder)
diff --git a/src/app/icd/server/ICDCheckInSender.cpp b/src/app/icd/server/ICDCheckInSender.cpp
index 21bcc33..0321fb1 100644
--- a/src/app/icd/server/ICDCheckInSender.cpp
+++ b/src/app/icd/server/ICDCheckInSender.cpp
@@ -64,7 +64,8 @@
size_t writtenBytes = 0;
Encoding::LittleEndian::BufferWriter writer(activeModeThresholdBuffer, sizeof(activeModeThresholdBuffer));
- writer.Put16(ICDConfigurationData::GetInstance().GetActiveModeThresholdMs());
+ uint16_t activeModeThreshold_ms = ICDConfigurationData::GetInstance().GetActiveModeThreshold().count();
+ writer.Put16(activeModeThreshold_ms);
VerifyOrReturnError(writer.Fit(writtenBytes), CHIP_ERROR_INTERNAL);
ByteSpan activeModeThresholdByteSpan(writer.Buffer(), writtenBytes);
diff --git a/src/app/icd/server/ICDConfigurationData.cpp b/src/app/icd/server/ICDConfigurationData.cpp
index 332e7bb..cfd2325 100644
--- a/src/app/icd/server/ICDConfigurationData.cpp
+++ b/src/app/icd/server/ICDConfigurationData.cpp
@@ -37,20 +37,24 @@
return mSlowPollingInterval;
}
-CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional<uint32_t> activeModeDuration_ms, Optional<uint32_t> idleModeDuration_ms)
+CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
+ Optional<System::Clock::Milliseconds32> idleModeDuration)
{
- VerifyOrReturnError(activeModeDuration_ms.HasValue() || idleModeDuration_ms.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrReturnError(activeModeDuration.HasValue() || idleModeDuration.HasValue(), CHIP_ERROR_INVALID_ARGUMENT);
- uint32_t tmpIdleModeDuration_s =
- idleModeDuration_ms.HasValue() ? (idleModeDuration_ms.Value() / kMillisecondsPerSecond) : mIdleModeDuration_s;
- uint32_t tmpActiveModeDuration_ms = activeModeDuration_ms.HasValue() ? activeModeDuration_ms.Value() : mActiveModeDuration_ms;
+ // Convert idleModeDuration to seconds for the correct precision
+ System::Clock::Seconds32 tmpIdleModeDuration = idleModeDuration.HasValue()
+ ? std::chrono::duration_cast<System::Clock::Seconds32>(idleModeDuration.Value())
+ : mIdleModeDuration;
- VerifyOrReturnError(tmpActiveModeDuration_ms <= (tmpIdleModeDuration_s * kMillisecondsPerSecond), CHIP_ERROR_INVALID_ARGUMENT);
- VerifyOrReturnError(tmpIdleModeDuration_s <= kMaxIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
- VerifyOrReturnError(tmpIdleModeDuration_s >= kMinIdleModeDuration_s, CHIP_ERROR_INVALID_ARGUMENT);
+ System::Clock::Milliseconds32 tmpActiveModeDuration = activeModeDuration.ValueOr(mActiveModeDuration);
- mIdleModeDuration_s = tmpIdleModeDuration_s;
- mActiveModeDuration_ms = tmpActiveModeDuration_ms;
+ VerifyOrReturnError(tmpActiveModeDuration <= tmpIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrReturnError(tmpIdleModeDuration <= kMaxIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
+ VerifyOrReturnError(tmpIdleModeDuration >= kMinIdleModeDuration, CHIP_ERROR_INVALID_ARGUMENT);
+
+ mIdleModeDuration = tmpIdleModeDuration;
+ mActiveModeDuration = tmpActiveModeDuration;
return CHIP_NO_ERROR;
}
diff --git a/src/app/icd/server/ICDConfigurationData.h b/src/app/icd/server/ICDConfigurationData.h
index 6668bdd..896df5f 100644
--- a/src/app/icd/server/ICDConfigurationData.h
+++ b/src/app/icd/server/ICDConfigurationData.h
@@ -54,11 +54,11 @@
static ICDConfigurationData & GetInstance() { return instance; };
- uint32_t GetIdleModeDurationSec() { return mIdleModeDuration_s; }
+ System::Clock::Seconds32 GetIdleModeDuration() { return mIdleModeDuration; }
- uint32_t GetActiveModeDurationMs() { return mActiveModeDuration_ms; }
+ System::Clock::Milliseconds32 GetActiveModeDuration() { return mActiveModeDuration; }
- uint16_t GetActiveModeThresholdMs() { return mActiveThreshold_ms; }
+ System::Clock::Milliseconds16 GetActiveModeThreshold() { return mActiveThreshold; }
uint32_t GetICDCounter() { return mICDCounter; }
@@ -68,7 +68,7 @@
System::Clock::Milliseconds32 GetFastPollingInterval() { return mFastPollingInterval; }
- uint32_t GetMinLitActiveModeThresholdMs() { return kMinLitActiveModeThreshold_ms; }
+ System::Clock::Milliseconds16 GetMinLitActiveModeThreshold() { return kMinLitActiveModeThreshold; }
/**
* If ICD_ENFORCE_SIT_SLOW_POLL_LIMIT is set to 0, function will always return the configured Slow Polling interval
@@ -103,14 +103,14 @@
void SetSlowPollingInterval(System::Clock::Milliseconds32 slowPollInterval) { mSlowPollingInterval = slowPollInterval; };
void SetFastPollingInterval(System::Clock::Milliseconds32 fastPollInterval) { mFastPollingInterval = fastPollInterval; };
- static constexpr uint32_t kMinLitActiveModeThreshold_ms = 5000;
+ static constexpr System::Clock::Milliseconds16 kMinLitActiveModeThreshold = System::Clock::Milliseconds16(5000);
/**
* @brief Change the ActiveModeDuration or the IdleModeDuration value
* If only one value is provided, check will be done agaisn't the other already set value.
*
- * @param[in] activeModeDuration_ms new ActiveModeDuration value
- * @param[in] idleModeDuration_ms new IdleModeDuration value
+ * @param[in] activeModeDuration new ActiveModeDuration value
+ * @param[in] idleModeDuration new IdleModeDuration value
* The precision of the IdleModeDuration must be seconds.
* @return CHIP_ERROR CHIP_ERROR_INVALID_ARGUMENT is returned if idleModeDuration_ms is smaller than activeModeDuration_ms
* is returned if idleModeDuration_ms is greater than 64800000 ms
@@ -118,22 +118,24 @@
* is returned if no valid values are provided
* CHIP_NO_ERROR is returned if the new intervals were set
*/
- CHIP_ERROR SetModeDurations(Optional<uint32_t> activeModeDuration_ms, Optional<uint32_t> idleModeDuration_ms);
+ CHIP_ERROR SetModeDurations(Optional<System::Clock::Milliseconds32> activeModeDuration,
+ Optional<System::Clock::Milliseconds32> idleModeDuration);
- static constexpr uint32_t kMaxIdleModeDuration_s = (18 * kSecondsPerHour);
- static constexpr uint32_t kMinIdleModeDuration_s = 1;
+ static constexpr System::Clock::Seconds32 kMaxIdleModeDuration = System::Clock::Seconds32(18 * kSecondsPerHour);
+ static constexpr System::Clock::Seconds32 kMinIdleModeDuration = System::Clock::Seconds32(1);
- static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) <= kMaxIdleModeDuration_s,
+ static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) <= kMaxIdleModeDuration.count(),
"Spec requires the IdleModeDuration to be equal or inferior to 64800s.");
- static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) >= kMinIdleModeDuration_s,
+ static_assert((CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC) >= kMinIdleModeDuration.count(),
"Spec requires the IdleModeDuration to be equal or greater to 1s.");
- uint32_t mIdleModeDuration_s = CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC;
+ System::Clock::Seconds32 mIdleModeDuration = System::Clock::Seconds32(CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC);
- static_assert((CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS) <= (CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC * kMillisecondsPerSecond),
+ static_assert(System::Clock::Milliseconds32(CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS) <=
+ System::Clock::Seconds32(CHIP_CONFIG_ICD_IDLE_MODE_DURATION_SEC),
"Spec requires the IdleModeDuration be equal or greater to the ActiveModeDuration.");
- uint32_t mActiveModeDuration_ms = CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS;
+ System::Clock::Milliseconds32 mActiveModeDuration = System::Clock::Milliseconds32(CHIP_CONFIG_ICD_ACTIVE_MODE_DURATION_MS);
- uint16_t mActiveThreshold_ms = CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS;
+ System::Clock::Milliseconds16 mActiveThreshold = System::Clock::Milliseconds16(CHIP_CONFIG_ICD_ACTIVE_MODE_THRESHOLD_MS);
uint32_t mICDCounter = 0;
diff --git a/src/app/icd/server/ICDManager.cpp b/src/app/icd/server/ICDManager.cpp
index 2fbf7ae..a8b663d 100644
--- a/src/app/icd/server/ICDManager.cpp
+++ b/src/app/icd/server/ICDManager.cpp
@@ -35,6 +35,7 @@
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::Clusters::IcdManagement;
+using namespace System::Clock;
static_assert(UINT8_MAX >= CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS,
"ICDManager::mOpenExchangeContextCount cannot hold count for the max exchange count");
@@ -55,8 +56,8 @@
"The CheckIn protocol feature is required for LIT support.");
VerifyOrDieWithMsg(SupportsFeature(Feature::kUserActiveModeTrigger), AppServer,
"The user ActiveMode trigger feature is required for LIT support.");
- VerifyOrDieWithMsg(ICDConfigurationData::GetInstance().GetMinLitActiveModeThresholdMs() <=
- ICDConfigurationData::GetInstance().GetActiveModeThresholdMs(),
+ VerifyOrDieWithMsg(ICDConfigurationData::GetInstance().GetMinLitActiveModeThreshold() <=
+ ICDConfigurationData::GetInstance().GetActiveModeThreshold(),
AppServer, "The minimum ActiveModeThreshold value for a LIT ICD is 5 seconds.");
// Disabling check until LIT support is compelte
// VerifyOrDieWithMsg((GetSlowPollingInterval() <= GetSITPollingThreshold()) , AppServer,
@@ -280,13 +281,12 @@
// When the active mode interval is 0, we stay in idleMode until a notification brings the icd into active mode
// unless the device would need to send Check-In messages
// TODO(#30281) : Verify how persistent subscriptions affects this at ICDManager::Init
- if (ICDConfigurationData::GetInstance().GetActiveModeDurationMs() > 0 || CheckInMessagesWouldBeSent())
+ if (ICDConfigurationData::GetInstance().GetActiveModeDuration() > kZero || CheckInMessagesWouldBeSent())
{
- uint32_t idleModeDuration = ICDConfigurationData::GetInstance().GetIdleModeDurationSec();
- DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds32(idleModeDuration), OnIdleModeDone, this);
+ DeviceLayer::SystemLayer().StartTimer(ICDConfigurationData::GetInstance().GetIdleModeDuration(), OnIdleModeDone, this);
}
- System::Clock::Milliseconds32 slowPollInterval = ICDConfigurationData::GetInstance().GetSlowPollingInterval();
+ Milliseconds32 slowPollInterval = ICDConfigurationData::GetInstance().GetSlowPollingInterval();
// Going back to Idle, all Check-In messages are sent
mICDSenderPool.ReleaseAll();
@@ -305,21 +305,23 @@
// Make sure the idle mode timer is stopped
DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this);
- mOperationalState = OperationalState::ActiveMode;
- uint32_t activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDurationMs();
+ mOperationalState = OperationalState::ActiveMode;
+ Milliseconds32 activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDuration();
- if (activeModeDuration == 0 && !mKeepActiveFlags.HasAny())
+ if (activeModeDuration == kZero && !mKeepActiveFlags.HasAny())
{
// A Network Activity triggered the active mode and activeModeDuration is 0.
// Stay active for at least Active Mode Threshold.
- activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeThresholdMs();
+ activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeThreshold();
}
- DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(activeModeDuration), OnActiveModeDone, this);
+ DeviceLayer::SystemLayer().StartTimer(activeModeDuration, OnActiveModeDone, this);
- uint32_t activeModeJitterInterval =
- (activeModeDuration >= ICD_ACTIVE_TIME_JITTER_MS) ? activeModeDuration - ICD_ACTIVE_TIME_JITTER_MS : 0;
- DeviceLayer::SystemLayer().StartTimer(System::Clock::Timeout(activeModeJitterInterval), OnTransitionToIdle, this);
+ Milliseconds32 activeModeJitterInterval = Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS);
+ activeModeJitterInterval =
+ (activeModeDuration >= activeModeJitterInterval) ? activeModeDuration - activeModeJitterInterval : kZero;
+
+ DeviceLayer::SystemLayer().StartTimer(activeModeJitterInterval, OnTransitionToIdle, this);
CHIP_ERROR err =
DeviceLayer::ConnectivityMgr().SetPollingInterval(ICDConfigurationData::GetInstance().GetFastPollingInterval());
@@ -337,14 +339,16 @@
}
else
{
- uint16_t activeModeThreshold = ICDConfigurationData::GetInstance().GetActiveModeThresholdMs();
- DeviceLayer::SystemLayer().ExtendTimerTo(System::Clock::Timeout(activeModeThreshold), OnActiveModeDone, this);
- uint16_t activeModeJitterThreshold =
- (activeModeThreshold >= ICD_ACTIVE_TIME_JITTER_MS) ? activeModeThreshold - ICD_ACTIVE_TIME_JITTER_MS : 0;
+ Milliseconds16 activeModeThreshold = ICDConfigurationData::GetInstance().GetActiveModeThreshold();
+ DeviceLayer::SystemLayer().ExtendTimerTo(activeModeThreshold, OnActiveModeDone, this);
+
+ Milliseconds32 activeModeJitterThreshold = Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS);
+ activeModeJitterThreshold =
+ (activeModeThreshold >= activeModeJitterThreshold) ? activeModeThreshold - activeModeJitterThreshold : kZero;
+
if (!mTransitionToIdleCalled)
{
- DeviceLayer::SystemLayer().ExtendTimerTo(System::Clock::Timeout(activeModeJitterThreshold), OnTransitionToIdle,
- this);
+ DeviceLayer::SystemLayer().ExtendTimerTo(activeModeJitterThreshold, OnTransitionToIdle, this);
}
}
}
diff --git a/src/app/tests/TestICDManager.cpp b/src/app/tests/TestICDManager.cpp
index 823a98a..e25d821 100644
--- a/src/app/tests/TestICDManager.cpp
+++ b/src/app/tests/TestICDManager.cpp
@@ -36,6 +36,8 @@
using namespace chip;
using namespace chip::app;
using namespace chip::System;
+using namespace chip::System::Clock;
+using namespace chip::System::Clock::Literals;
using TestSessionKeystoreImpl = Crypto::DefaultSessionKeystore;
@@ -148,9 +150,9 @@
*
* @param time_ms: Value in milliseconds.
*/
- static void AdvanceClockAndRunEventLoop(TestContext * ctx, uint64_t time_ms)
+ static void AdvanceClockAndRunEventLoop(TestContext * ctx, Milliseconds64 time)
{
- ctx->mMockClock.AdvanceMonotonic(System::Clock::Timeout(time_ms));
+ ctx->mMockClock.AdvanceMonotonic(time);
ctx->GetIOContext().DriveIO();
}
@@ -160,23 +162,23 @@
// After the init we should be in Idle mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(ICDConfigurationData::GetInstance().GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetIdleModeDuration() + 1_s);
// Idle mode Duration expired, ICDManager transitioned to the ActiveMode.
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);
// Active mode Duration expired, ICDManager transitioned to the IdleMode.
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(ICDConfigurationData::GetInstance().GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetIdleModeDuration() + 1_s);
// Idle mode Duration 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.
// Kick an active Threshold just before the end of the ActiveMode duration and validate that the active mode is extended.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() - 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() - 1_ms32);
ICDNotifier::GetInstance().NotifyNetworkActivityNotification();
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThresholdMs() / 2);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThreshold() / 2);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThresholdMs());
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeThreshold());
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
}
@@ -197,22 +199,22 @@
ctx->mSubManager.SetReturnValue(false);
// Set New durations for test case
- uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs();
- icdConfigData.SetModeDurations(MakeOptional(static_cast<uint32_t>(0)), NullOptional);
+ Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration();
+ icdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
// Verify That ICDManager starts in Idle
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Reset IdleModeInterval since it was started before the ActiveModeDuration change
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Force the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is now 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire Idle mode duration; ICDManager should remain in IdleMode since it has no message to send
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Add an entry to the ICDMonitoringTable
@@ -236,11 +238,11 @@
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Return the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire IdleModeDuration - Device should be in ActiveMode since it has an ICDM registration
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Remove entry from the fabric - ICDManager won't have any messages to send
@@ -248,15 +250,15 @@
NL_TEST_ASSERT(aSuite, table.IsEmpty());
// Return the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire Idle mode duration; ICDManager should remain in IdleMode since it has no message to send
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Reset Old durations
- icdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration_ms), NullOptional);
+ icdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration), NullOptional);
}
/**
@@ -276,22 +278,22 @@
ctx->mSubManager.SetReturnValue(true);
// Set New durations for test case
- uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs();
- icdConfigData.SetModeDurations(MakeOptional(static_cast<uint32_t>(0)), NullOptional);
+ Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration();
+ icdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(0), NullOptional);
// Verify That ICDManager starts in Idle
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Reset IdleModeInterval since it was started before the ActiveModeDuration change
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Force the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is now 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire Idle mode duration; ICDManager should remain in IdleMode since it has no message to send
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Add an entry to the ICDMonitoringTable
@@ -315,11 +317,11 @@
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Return the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire IdleModeDuration - Device stay in IdleMode since it has an active subscription for the ICDM entry
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Remove entry from the fabric
@@ -338,15 +340,15 @@
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Return the device to return to IdleMode - Increase time by ActiveModeThreshold since ActiveModeDuration is 0
- AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThresholdMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetActiveModeThreshold() + 1_ms16);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Expire Idle mode duration; ICDManager should remain in IdleMode since it has no message to send
- AdvanceClockAndRunEventLoop(ctx, SecondsToMilliseconds(icdConfigData.GetIdleModeDurationSec()) + 1);
+ AdvanceClockAndRunEventLoop(ctx, icdConfigData.GetIdleModeDuration() + 1_s);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Reset Old durations
- icdConfigData.SetModeDurations(MakeOptional(oldActiveModeDuration_ms), NullOptional);
+ icdConfigData.SetModeDurations(MakeOptional<Milliseconds32>(oldActiveModeDuration), NullOptional);
}
static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext)
@@ -359,7 +361,7 @@
notifier.NotifyActiveRequestNotification(ActiveFlag::kCommissioningWindowOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Advance time so active mode duration expires.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);
// Requirement flag still set. We stay in active mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
@@ -373,12 +375,12 @@
// Advance time, but by less than the active mode duration and remove the requirement.
// We should stay in active mode.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() / 2);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() / 2);
notifier.NotifyActiveRequestWithdrawal(ActiveFlag::kFailSafeArmed);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// Advance time again, The activemode duration is completed.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
// Set two requirements
@@ -386,7 +388,7 @@
notifier.NotifyActiveRequestNotification(ActiveFlag::kExchangeContextOpen);
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
// advance time so the active mode duration expires.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);
// A requirement flag is still set. We stay in active mode.
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::ActiveMode);
@@ -526,7 +528,7 @@
notifier.NotifySubscriptionReport();
// Advance time so active mode interval expires.
- AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDurationMs() + 1);
+ AdvanceClockAndRunEventLoop(ctx, ICDConfigurationData::GetInstance().GetActiveModeDuration() + 1_ms32);
// After the init we should be in Idle mode
NL_TEST_ASSERT(aSuite, ctx->mICDManager.mOperationalState == ICDManager::OperationalState::IdleMode);
diff --git a/src/messaging/ReliableMessageProtocolConfig.cpp b/src/messaging/ReliableMessageProtocolConfig.cpp
index 67e1997..86c95b1 100644
--- a/src/messaging/ReliableMessageProtocolConfig.cpp
+++ b/src/messaging/ReliableMessageProtocolConfig.cpp
@@ -76,7 +76,7 @@
// which the device can be at sleep and not be able to receive any messages).
config.mIdleRetransTimeout += ICDConfigurationData::GetInstance().GetSlowPollingInterval();
config.mActiveRetransTimeout += ICDConfigurationData::GetInstance().GetFastPollingInterval();
- config.mActiveThresholdTime = System::Clock::Milliseconds16(ICDConfigurationData::GetInstance().GetActiveModeThresholdMs());
+ config.mActiveThresholdTime = ICDConfigurationData::GetInstance().GetActiveModeThreshold();
#endif
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST