1 #ifndef ACE_TIME_SYSTEM_TIME_KEEPER_H 2 #define ACE_TIME_SYSTEM_TIME_KEEPER_H 6 #include "../common/TimingStats.h" 7 #include "../common/logger.h" 8 #include "TimeKeeper.h" 58 mSyncTimeProvider(syncTimeProvider),
59 mBackupTimeKeeper(backupTimeKeeper) {}
62 if (mBackupTimeKeeper !=
nullptr) {
68 if (!mIsInit)
return kInvalidSeconds;
70 while ((uint16_t) ((uint16_t)
millis() - mPrevMillis) >= 1000) {
77 void setNow(acetime_t epochSeconds)
override {
78 if (epochSeconds == kInvalidSeconds)
return;
80 mEpochSeconds = epochSeconds;
83 backupNow(epochSeconds);
96 void sync(acetime_t epochSeconds) {
97 if (epochSeconds == kInvalidSeconds)
return;
98 if (mEpochSeconds == epochSeconds)
return;
100 mEpochSeconds = epochSeconds;
103 mLastSyncTime = epochSeconds;
105 if (mBackupTimeKeeper != mSyncTimeProvider) {
106 backupNow(epochSeconds);
115 return mLastSyncTime;
123 virtual unsigned long millis()
const { return ::millis(); }
134 void backupNow(acetime_t nowSeconds) {
135 if (mBackupTimeKeeper !=
nullptr) {
136 mBackupTimeKeeper->
setNow(nowSeconds);
143 mutable acetime_t mEpochSeconds = 0;
144 mutable uint16_t mPrevMillis = 0;
145 bool mIsInit =
false;
146 acetime_t mLastSyncTime = 0;
SystemTimeKeeper(TimeProvider *syncTimeProvider, TimeKeeper *backupTimeKeeper)
virtual unsigned long millis() const
Return the Arduino millis().
bool isInit() const
Return true if initialized by setNow() or sync().
A TimeProvider whose time can be set by the end-user.
void sync(acetime_t epochSeconds)
Similar to setNow() except that backupNow() is called only if the backupTimeKeeper is different from ...
virtual acetime_t getNow() const =0
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
void setNow(acetime_t epochSeconds) override
Set the time to the indicated seconds.
A TimeKeeper that uses the Arduino millis() function to advance the time returned to the user...
acetime_t getLastSyncTime() const
Return the time (seconds since Epoch) of the last valid sync() call.
A class that periodically that syncs the SystemTimeKeeper with its syncTimeProvider.
Base class for objects that provide a source of time whose time cannot be changed by the end-user...
virtual void setNow(acetime_t epochSeconds)=0
Set the time to the indicated seconds.
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
A coroutine that syncs the SystemTimeKeeper with its syncTimeProvider.