Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
ersa::services::TimeService Class Reference

#include <time_service.h>

Collaboration diagram for ersa::services::TimeService:
Collaboration graph
[legend]

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}
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TimeService()

ersa::services::TimeService::TimeService ( hal::IRtc &  rtc,
events::EventBus &  bus = events::EventBus::instance() 
)
explicit

Bind an RTC HAL and event bus; no hardware is touched until init().

Member Function Documentation

◆ adjust()

Result< void > ersa::services::TimeService::adjust ( const hal::TimePoint &  time)

Adjust using calendar fields when no epoch value is supplied.

◆ getTimezoneOffset()

int16_t ersa::services::TimeService::getTimezoneOffset ( ) const

Read the configured local UTC offset, where east of UTC is positive.

◆ hasSynchronizedTime()

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.

◆ init()

Result< void > ersa::services::TimeService::init ( )

Initialize the RTC, seed minute tracking, and subscribe to time requests.

◆ instance()

TimeService & ersa::services::TimeService::instance ( )
static

Return the process-wide service installed during board initialization.

◆ isRtcHealthy()

bool ersa::services::TimeService::isRtcHealthy ( ) const

Return the RTC HAL's current health report without retrying initialization.

◆ lastMinute()

uint32_t ersa::services::TimeService::lastMinute ( ) const

Return floor(epoch/60) for the most recently observed or written time.

◆ now()

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.

◆ onTimeSyncEvent()

void ersa::services::TimeService::onTimeSyncEvent ( const events::Event &  event,
void *  userData 
)
staticprivate

◆ setEpoch()

Result< void > ersa::services::TimeService::setEpoch ( uint32_t  epochSeconds)

Set time as a manual, highest-priority update after validating its range.

◆ setInstance()

void ersa::services::TimeService::setInstance ( TimeService *  instance)
static

Install a non-owning process-wide pointer for compatibility accessors. The caller must keep the service alive until it replaces or clears it.

◆ setTimezoneOffset()

void ersa::services::TimeService::setTimezoneOffset ( int16_t  offsetMinutes)

Configure local UTC offset used when converting network calendar values.

◆ submitTime()

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.

Returns
True when the RTC accepted and stored the timestamp.

◆ tick()

void ersa::services::TimeService::tick ( uint32_t  currentUptimeMs)

Poll the RTC at a bounded cadence and publish a MinuteTick on rollover.

Parameters
currentUptimeMsMonotonic uptime used for interval tracking.

Member Data Documentation

◆ bus_

events::EventBus& ersa::services::TimeService::bus_
private

◆ lastMinute_

uint32_t ersa::services::TimeService::lastMinute_ {UINT32_MAX}
private

◆ lastPollMs_

uint32_t ersa::services::TimeService::lastPollMs_ {0}
private

◆ rtc_

hal::IRtc& ersa::services::TimeService::rtc_
private

◆ selectedSource_

events::TimeSource ersa::services::TimeService::selectedSource_ {events::TimeSource::Unknown}
private

◆ timeSyncSubscription_

events::SubscriptionId ersa::services::TimeService::timeSyncSubscription_ {0}
private

◆ tzOffsetMin_

int16_t ersa::services::TimeService::tzOffsetMin_ {0}
private

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