|
Ersa Wearable Platform
Embedded smartwatch firmware and application framework
|
#include <time_service.h>

Public Member Functions | |
| TimeService (hal::IRtc &rtc, events::EventBus &bus=events::EventBus::instance()) | |
| Result< void > | init () |
| void | tick (uint32_t currentUptimeMs) |
| hal::TimePoint | now () |
| Result< void > | setEpoch (uint32_t epochSeconds) |
| bool | submitTime (events::TimeSource source, uint32_t epochSeconds) |
| Result< void > | adjust (const hal::TimePoint &time) |
| bool | isRtcHealthy () const |
| bool | hasSynchronizedTime () const |
| uint32_t | lastMinute () const |
| void | setTimezoneOffset (int16_t offsetMinutes) |
| int16_t | getTimezoneOffset () const |
Static Public Member Functions | |
| static TimeService & | instance () |
| static void | setInstance (TimeService *instance) |
Static Private Member Functions | |
| static void | onTimeSyncEvent (const events::Event &event, void *userData) |
Private Attributes | |
| hal::IRtc & | rtc_ |
| events::EventBus & | bus_ |
| int16_t | tzOffsetMin_ {0} |
| uint32_t | lastMinute_ {UINT32_MAX} |
| uint32_t | lastPollMs_ {0} |
| events::TimeSource | selectedSource_ {events::TimeSource::Unknown} |
| events::SubscriptionId | timeSyncSubscription_ {0} |
Coordinates wall-clock state, source priority, and minute notifications.
The RTC is the immediate timekeeper; this service validates all external timestamps before writing it and prevents lower-trust sources from undoing a stronger update. The default event subscription keeps BLE/network adapters decoupled from RTC hardware while producing one normalized minute event for watchfaces and apps.
|
explicit |
Bind an RTC HAL and event bus; no hardware is touched until init().
| Result< void > ersa::services::TimeService::adjust | ( | const hal::TimePoint & | time | ) |
Adjust using calendar fields when no epoch value is supplied.
| int16_t ersa::services::TimeService::getTimezoneOffset | ( | ) | const |
Read the configured local UTC offset, where east of UTC is positive.
| bool ersa::services::TimeService::hasSynchronizedTime | ( | ) | const |
Return whether a valid manual, phone, or network timestamp was accepted since boot; a responding RTC alone does not count as synchronization.
| Result< void > ersa::services::TimeService::init | ( | ) |
Initialize the RTC, seed minute tracking, and subscribe to time requests.
|
static |
Return the process-wide service installed during board initialization.
| bool ersa::services::TimeService::isRtcHealthy | ( | ) | const |
Return the RTC HAL's current health report without retrying initialization.
| uint32_t ersa::services::TimeService::lastMinute | ( | ) | const |
Return floor(epoch/60) for the most recently observed or written time.
| hal::TimePoint ersa::services::TimeService::now | ( | ) |
Read current RTC wall time. The RTC stores the local wall clock chosen by this firmware, so the timezone offset is metadata for network conversions and display policy rather than an extra offset applied on every read.
|
staticprivate |
| Result< void > ersa::services::TimeService::setEpoch | ( | uint32_t | epochSeconds | ) |
Set time as a manual, highest-priority update after validating its range.
|
static |
Install a non-owning process-wide pointer for compatibility accessors. The caller must keep the service alive until it replaces or clears it.
| void ersa::services::TimeService::setTimezoneOffset | ( | int16_t | offsetMinutes | ) |
Configure local UTC offset used when converting network calendar values.
| bool ersa::services::TimeService::submitTime | ( | events::TimeSource | source, |
| uint32_t | epochSeconds | ||
| ) |
Validate and apply an external timestamp if its source has sufficient priority. Manual > BLE/companion > network prevents delayed NTP responses from replacing a newer phone-provided clock value.
| void ersa::services::TimeService::tick | ( | uint32_t | currentUptimeMs | ) |
Poll the RTC at a bounded cadence and publish a MinuteTick on rollover.
| currentUptimeMs | Monotonic uptime used for interval tracking. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |