From 5a2291ba5e8087875a492c03e12bb2293ab51543 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Fri, 28 Apr 2023 17:01:53 +0200 Subject: [PATCH] changed time logic to be able to set older time but not old than default LastKnownTime --- .../time-synchronization-server.cpp | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index 31e497eff07894..5220697841b9f1 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -466,21 +466,19 @@ static bool utcTimeChanged(uint64_t utcTime) Server::GetInstance().GetFabricTable().GetLastKnownGoodChipEpochTime(lastKnownGoodChipEpoch); System::SystemClock().GetClock_RealTime(realTime); - ChipLogError(Zcl, "UTCTime: %llu Last Known Good Time: %u Real Time: %llu", utcTime, lastKnownGoodChipEpoch.count(), - realTime.count()); chip::UnixEpochToChipEpochTime((uint32_t)(utcTime / chip::kMicrosecondsPerSecond), utcTimetoChipEpoch); + ChipLogProgress(Zcl, "UTC ChipEpoch Time: %u Last Known Good Time: %u Real Time: %llu", utcTimetoChipEpoch, + lastKnownGoodChipEpoch.count(), realTime.count()); - if (utcTimetoChipEpoch >= lastKnownGoodChipEpoch.count()) // update Last Known Good Time if a more recent time is obtained - { - Server::GetInstance().GetFabricTable().SetLastKnownGoodChipEpochTime(System::Clock::Seconds32(utcTimetoChipEpoch)); - System::SystemClock().SetClock_RealTime(System::Clock::Microseconds64(utcTime)); + VerifyOrReturnValue(Server::GetInstance().GetFabricTable().SetLastKnownGoodChipEpochTime( + System::Clock::Seconds32(utcTimetoChipEpoch)) == CHIP_NO_ERROR, + false); + VerifyOrReturnValue(System::SystemClock().SetClock_RealTime(System::Clock::Microseconds64(utcTime)) == CHIP_NO_ERROR, false); - Server::GetInstance().GetFabricTable().GetLastKnownGoodChipEpochTime(lastKnownGoodChipEpoch); - System::SystemClock().GetClock_RealTime(realTime); - ChipLogError(Zcl, " Last Known Good Time: %u Real Time: %llu", lastKnownGoodChipEpoch.count(), realTime.count()); - return true; - } - return false; + Server::GetInstance().GetFabricTable().GetLastKnownGoodChipEpochTime(lastKnownGoodChipEpoch); + System::SystemClock().GetClock_RealTime(realTime); + ChipLogProgress(Zcl, " Last Known Good Time: %u Real Time: %llu", lastKnownGoodChipEpoch.count(), realTime.count()); + return true; } bool emberAfTimeSynchronizationClusterSetUtcTimeCallback(