AceTime  0.5.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.
Public Member Functions | Friends | List of all members
ace_time::clock::SystemClockSyncCoroutine Class Reference

A coroutine that syncs the SystemClock with its mSyncTimeProvider. More...

#include <SystemClockSyncCoroutine.h>

Inheritance diagram for ace_time::clock::SystemClockSyncCoroutine:
Inheritance graph
[legend]
Collaboration diagram for ace_time::clock::SystemClockSyncCoroutine:
Collaboration graph
[legend]

Public Member Functions

 SystemClockSyncCoroutine (SystemClock &systemClock, uint16_t syncPeriodSeconds=3600, uint16_t initialSyncPeriodSeconds=5, uint16_t requestTimeoutMillis=1000, common::TimingStats *timingStats=nullptr)
 Constructor. More...
 
int runCoroutine () override
 

Friends

class ::SystemClockSyncCoroutineTest
 

Detailed Description

A coroutine that syncs the SystemClock with its mSyncTimeProvider.

The call to mSyncTimeProvider is asynchronous, which is helpful when the syncTimeProvider issues a network request to an NTP server.

Initially, the class attempts to sync with its syncTimeProvider 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 31 of file SystemClockSyncCoroutine.h.

Constructor & Destructor Documentation

◆ SystemClockSyncCoroutine()

ace_time::clock::SystemClockSyncCoroutine::SystemClockSyncCoroutine ( SystemClock systemClock,
uint16_t  syncPeriodSeconds = 3600,
uint16_t  initialSyncPeriodSeconds = 5,
uint16_t  requestTimeoutMillis = 1000,
common::TimingStats timingStats = nullptr 
)
inlineexplicit

Constructor.

Parameters
systemClockthe system time keeper to sync up
syncPeriodSecondsseconds between normal sync attempts (default 3600)
initialSyncPeriodSecondsseconds between sync attempts when the systemClock is not initialized (default 5)
requestTimeoutMillisnumber of milliseconds before the request to syncTimeProvider times out
timingStatsinternal statistics

Definition at line 45 of file SystemClockSyncCoroutine.h.

Member Function Documentation

◆ runCoroutine()

int ace_time::clock::SystemClockSyncCoroutine::runCoroutine ( )
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 63 of file SystemClockSyncCoroutine.h.


The documentation for this class was generated from the following file: