diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index bd63503a10493f..b5fc34484ea8ff 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -46,7 +46,7 @@ using Status = Protocols::InteractionModel::Status; uint16_t ReadHandler::GetPublisherSelectedIntervalLimit() { #if CHIP_CONFIG_ENABLE_ICD_SERVER - return static_cast(ICDConfigurationData::GetInstance().GetIdleModeDurationSec()); + return std::chrono::duration_cast(ICDConfigurationData::GetInstance().GetIdleModeDuration()).count(); #else return kSubscriptionMaxIntervalPublisherLimit; #endif diff --git a/src/app/SubscriptionsInfoProvider.h b/src/app/SubscriptionsInfoProvider.h index ef792904fc4bce..cb8d470cbb234d 100644 --- a/src/app/SubscriptionsInfoProvider.h +++ b/src/app/SubscriptionsInfoProvider.h @@ -42,6 +42,7 @@ class SubscriptionsInfoProvider * * @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 @@ class SubscriptionsInfoProvider * * @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 e748030f1da9d3..c3efce64f04cd0 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::Read(const ConcreteReadAttributePath & 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 21bcc336b0d357..b94f70107b0d85 100644 --- a/src/app/icd/server/ICDCheckInSender.cpp +++ b/src/app/icd/server/ICDCheckInSender.cpp @@ -64,7 +64,10 @@ CHIP_ERROR ICDCheckInSender::SendCheckInMsg(const Transport::PeerAddress & addr) size_t writtenBytes = 0; Encoding::LittleEndian::BufferWriter writer(activeModeThresholdBuffer, sizeof(activeModeThresholdBuffer)); - writer.Put16(ICDConfigurationData::GetInstance().GetActiveModeThresholdMs()); + uint16_t activeModeThreshold_ms = + std::chrono::duration_cast(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 332e7bbebc88b4..cfd2325671ea0f 100644 --- a/src/app/icd/server/ICDConfigurationData.cpp +++ b/src/app/icd/server/ICDConfigurationData.cpp @@ -37,20 +37,24 @@ System::Clock::Milliseconds32 ICDConfigurationData::GetSlowPollingInterval() return mSlowPollingInterval; } -CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional activeModeDuration_ms, Optional idleModeDuration_ms) +CHIP_ERROR ICDConfigurationData::SetModeDurations(Optional activeModeDuration, + Optional 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(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 6668bdd216f0ca..89344b71db6065 100644 --- a/src/app/icd/server/ICDConfigurationData.h +++ b/src/app/icd/server/ICDConfigurationData.h @@ -54,11 +54,11 @@ class ICDConfigurationData 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::Milliseconds32 GetActiveModeThreshold() { return mActiveThreshold; } uint32_t GetICDCounter() { return mICDCounter; } @@ -68,7 +68,7 @@ class ICDConfigurationData System::Clock::Milliseconds32 GetFastPollingInterval() { return mFastPollingInterval; } - uint32_t GetMinLitActiveModeThresholdMs() { return kMinLitActiveModeThreshold_ms; } + System::Clock::Milliseconds32 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 @@ class ICDConfigurationData 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::Milliseconds32 kMinLitActiveModeThreshold = System::Clock::Milliseconds32(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 @@ class ICDConfigurationData * is returned if no valid values are provided * CHIP_NO_ERROR is returned if the new intervals were set */ - CHIP_ERROR SetModeDurations(Optional activeModeDuration_ms, Optional idleModeDuration_ms); + CHIP_ERROR SetModeDurations(Optional activeModeDuration, + Optional 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::Milliseconds32 mActiveThreshold = System::Clock::Milliseconds32(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 2fbf7ae8fb39b9..86c46bdf129d89 100644 --- a/src/app/icd/server/ICDManager.cpp +++ b/src/app/icd/server/ICDManager.cpp @@ -55,8 +55,8 @@ void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricT "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,10 +280,9 @@ void ICDManager::UpdateOperationState(OperationalState state) // 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() > System::Clock::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(); @@ -305,21 +304,24 @@ void ICDManager::UpdateOperationState(OperationalState state) // 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; + System::Clock::Milliseconds32 activeModeDuration = ICDConfigurationData::GetInstance().GetActiveModeDuration(); - if (activeModeDuration == 0 && !mKeepActiveFlags.HasAny()) + if (activeModeDuration == System::Clock::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); + System::Clock::Milliseconds32 activeModeJitterInterval = System::Clock::Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS); + activeModeJitterInterval = (activeModeDuration >= activeModeJitterInterval) + ? activeModeDuration - activeModeJitterInterval + : System::Clock::kZero; + + DeviceLayer::SystemLayer().StartTimer(activeModeJitterInterval, OnTransitionToIdle, this); CHIP_ERROR err = DeviceLayer::ConnectivityMgr().SetPollingInterval(ICDConfigurationData::GetInstance().GetFastPollingInterval()); @@ -337,14 +339,17 @@ void ICDManager::UpdateOperationState(OperationalState state) } 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; + System::Clock::Milliseconds32 activeModeThreshold = ICDConfigurationData::GetInstance().GetActiveModeThreshold(); + DeviceLayer::SystemLayer().ExtendTimerTo(activeModeThreshold, OnActiveModeDone, this); + + System::Clock::Milliseconds32 activeModeJitterThreshold = System::Clock::Milliseconds32(ICD_ACTIVE_TIME_JITTER_MS); + activeModeJitterThreshold = (activeModeThreshold >= activeModeJitterThreshold) + ? activeModeThreshold - activeModeJitterThreshold + : System::Clock::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 823a98a490df7c..6973da82e1def4 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 @@ class TestICDManager * * @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 @@ class TestICDManager // 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 @@ class TestICDManager ctx->mSubManager.SetReturnValue(false); // Set New durations for test case - uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs(); - icdConfigData.SetModeDurations(MakeOptional(static_cast(0)), NullOptional); + Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration(); + icdConfigData.SetModeDurations(MakeOptional(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_ms32); 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 @@ class TestICDManager 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_ms32); 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 @@ class TestICDManager 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_ms32); 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 @@ class TestICDManager ctx->mSubManager.SetReturnValue(true); // Set New durations for test case - uint32_t oldActiveModeDuration_ms = icdConfigData.GetActiveModeDurationMs(); - icdConfigData.SetModeDurations(MakeOptional(static_cast(0)), NullOptional); + Milliseconds32 oldActiveModeDuration = icdConfigData.GetActiveModeDuration(); + icdConfigData.SetModeDurations(MakeOptional(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_ms32); 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 @@ class TestICDManager 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_ms32); 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 @@ class TestICDManager 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_ms32); 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); } static void TestKeepActivemodeRequests(nlTestSuite * aSuite, void * aContext) @@ -359,7 +361,7 @@ class TestICDManager 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 @@ class TestICDManager // 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 @@ class TestICDManager 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 @@ class TestICDManager 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 67e199779c3bcd..e27ff717b20980 100644 --- a/src/messaging/ReliableMessageProtocolConfig.cpp +++ b/src/messaging/ReliableMessageProtocolConfig.cpp @@ -76,7 +76,8 @@ Optional GetLocalMRPConfig() // 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 = + std::chrono::duration_cast(ICDConfigurationData::GetInstance().GetIdleModeDuration()); #endif #if CONFIG_BUILD_FOR_HOST_UNIT_TEST