Expand description
NTP client for VeridianOS time synchronization
Implements NTPv4 (RFC 5905) client mode with:
- 48-byte NTP packet serialization/deserialization
- Clock offset and round-trip delay calculation (integer-only)
- Marzullo’s algorithm for multi-source time selection
- Clock filter (best-of-8 by minimum delay)
- Drift compensation via integer linear regression
- RTC integration for system clock adjustment
Structs§
- Clock
Filter - Clock filter: keeps the last CLOCK_FILTER_SIZE samples and selects the one with the smallest round-trip delay as the best estimate.
- Drift
Estimator - Drift estimator using integer linear regression over recent measurements.
- NtpClient
- NTP client managing time synchronization with one or more servers.
- NtpMeasurement
- Result of processing an NTP response.
- NtpPacket
- NTPv4 packet (48 bytes, RFC 5905).
- NtpTimestamp
- NTP timestamp: 32-bit seconds since 1900-01-01 + 32-bit fraction.
- Time
Interval - An interval from a time source for Marzullo’s algorithm.
Enums§
- Leap
Indicator - Leap indicator values (2-bit field)
Constants§
- CLOCK_
FILTER_ SIZE - Number of samples in the clock filter
- MAX_
POLL_ INTERVAL - Maximum poll interval in seconds (2^10 = 1024s)
- MIN_
POLL_ INTERVAL - Minimum poll interval in seconds (2^6 = 64s)
- NTP_
PACKET_ SIZE - NTP packet size in bytes
- NTP_
PORT - NTP UDP port
- NTP_
UNIX_ OFFSET - Seconds between NTP epoch (1900-01-01) and Unix epoch (1970-01-01) 70 years including 17 leap years: (70*365 + 17) * 86400
Functions§
- boot_
sync - Trigger a boot-time NTP synchronization.
- calculate_
offset_ delay - Calculate clock offset and round-trip delay from NTP timestamps.
- get_
last_ sync_ epoch - Get the last NTP sync time as Unix epoch seconds (0 = never synced).
- get_
ntp_ offset_ ms - Get the last NTP-computed offset in milliseconds.
- get_
poll_ interval - Get the current poll interval in seconds.
- marzullo_
select - Run Marzullo’s algorithm on a set of time intervals to find the tightest intersection supported by a majority of sources.
- record_
sync - Record that a successful NTP sync occurred at the given Unix epoch time.