AceTime
1.1
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
|
A version of SystemClock that mixes in the ace_routine::Coroutine class so that that the non-block methods of mReferenceClock are called. More...
#include <SystemClockCoroutine.h>
Public Member Functions | |
SystemClockCoroutine (Clock *referenceClock, Clock *backupClock, uint16_t syncPeriodSeconds=3600, uint16_t initialSyncPeriodSeconds=5, uint16_t requestTimeoutMillis=1000, common::TimingStats *timingStats=nullptr) | |
Constructor. More... | |
int | runCoroutine () override |
uint8_t | getRequestStatus () const |
Return the current request status. More... | |
![]() | |
void | setup () |
Attempt to retrieve the time from the backupClock if it exists. More... | |
acetime_t | getNow () const override |
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z). More... | |
void | setNow (acetime_t epochSeconds) override |
Set the time to the indicated seconds. More... | |
void | forceSync () |
Force a sync with the mReferenceClock. More... | |
acetime_t | getLastSyncTime () const |
Return the time (seconds since Epoch) of the last valid sync() call. More... | |
bool | isInit () const |
Return true if initialized by setNow() or syncNow(). More... | |
![]() | |
virtual | ~Clock () |
Virtual destructor. More... | |
virtual void | sendRequest () const |
Send a time request asynchronously. More... | |
virtual bool | isResponseReady () const |
Return true if a response is ready. More... | |
virtual acetime_t | readResponse () const |
Returns number of seconds since AceTime epoch (2000-01-01). More... | |
Static Public Attributes | |
static const uint8_t | kStatusUnknown = 0 |
Request state unknown. More... | |
static const uint8_t | kStatusSent = 1 |
Request has been sent and waiting for response. More... | |
static const uint8_t | kStatusOk = 2 |
Request received and valid. More... | |
static const uint8_t | kStatusTimedOut = 3 |
Request timed out. More... | |
![]() | |
static const acetime_t | kInvalidSeconds = LocalTime::kInvalidSeconds |
Friends | |
class | ::SystemClockCoroutineTest_runCoroutine |
Additional Inherited Members | |
![]() | |
SystemClock (const SystemClock &)=delete | |
SystemClock & | operator= (const SystemClock &)=delete |
SystemClock (Clock *referenceClock, Clock *backupClock) | |
Constructor. More... | |
virtual unsigned long | clockMillis () const |
Return the Arduino millis(). More... | |
void | keepAlive () |
Call this (or getNow() every 65.535 seconds or faster to keep the internal counter in sync with millis(). | |
void | backupNow (acetime_t nowSeconds) |
Write the nowSeconds to the backupClock (which can be an RTC that has non-volatile memory, or simply flash memory which emulates a backupClock. | |
void | syncNow (acetime_t epochSeconds) |
Similar to setNow() except that backupNow() is called only if the backupClock is different from the referenceClock. More... | |
![]() | |
Clock *const | mReferenceClock |
Clock *const | mBackupClock |
acetime_t | mEpochSeconds = kInvalidSeconds |
acetime_t | mLastSyncTime = kInvalidSeconds |
uint16_t | mPrevMillis = 0 |
bool | mIsInit = false |
A version of SystemClock that mixes in the ace_routine::Coroutine class so that that the non-block methods of mReferenceClock are called.
This is helpful when the referenceClock issues a network request to an NTP server.
Initially, the class attempts to sync with its referenceClock every initialSyncPeriodSeconds. If the request fails, then it retries with an exponential backoff (doubling the delay every iteration), until the sync period becomes greater than syncPeriodSeconds, then the delay is set permanently to syncPeriodSeconds.
Definition at line 33 of file SystemClockCoroutine.h.
|
inlineexplicit |
Constructor.
referenceClock | The authoritative source of the time. If this is null, the object relies just on clockMillis() and the user to set the proper time using setNow(). |
backupClock | An RTC chip which continues to keep time even when power is lost. Can be null. |
syncPeriodSeconds | seconds between normal sync attempts (default 3600) |
initialSyncPeriodSeconds | seconds between sync attempts when the systemClock is not initialized (default 5) |
requestTimeoutMillis | number of milliseconds before the request to referenceClock times out |
timingStats | internal statistics |
Definition at line 63 of file SystemClockCoroutine.h.
|
inline |
Return the current request status.
Mostly for debugging.
Definition at line 143 of file SystemClockCoroutine.h.
|
inlineoverride |
The CoroutineScheduler will use this method if enabled. Don't forget to call setupCoroutine() (inherited from Coroutine) in the global setup() to register this coroutine into the CoroutineScheduler.
Definition at line 83 of file SystemClockCoroutine.h.
|
static |
Request received and valid.
Definition at line 42 of file SystemClockCoroutine.h.
|
static |
Request has been sent and waiting for response.
For diagnostics only.
Definition at line 39 of file SystemClockCoroutine.h.
|
static |
Request timed out.
Definition at line 45 of file SystemClockCoroutine.h.
|
static |