In development. It changes without notice.
Topic
GPS Time Sync
The time from a GPS receiver: one sync when the owner asks for it, and the receiver at rest otherwise.
A task opens the receiver, accepts a time only from a valid fix, and sets the clock. The receiver's supply is not switched with the board, so a sync and a sleep both end by parking it: putting it in its lowest state and hearing it fall silent. On a board without a receiver every function is there and does nothing.
Files | |
| file | src/ |
| Pure one-shot GPS time-sync state machine (host-testable core). | |
| file | src/ |
| One-shot GPS time-sync engine (device wiring over kleidos:: | |
Classes | |
| class | kleidos:: |
| One-shot GPS time-sync state machine (pure logic; see file docs). More about kleidos:: | |
| struct | kleidos:: |
| What the last verified park found, for a diagnostic. More about kleidos:: | |
| class | kleidos:: |
| A held-open receiver, parked again when the scope ends. More about kleidos:: | |
| struct | kleidos:: |
| Live receiver-state snapshot gathered by diagnose. More about kleidos:: | |
Typedefs | |
| using | kleidos:: |
| Callback invoked once per raw NMEA line (NUL-terminated, CRLF stripped). | |
| using | kleidos:: |
Enumerations | |
| enum class | kleidos:: |
| Lifecycle phase of a one-shot GPS time sync. More about kleidos:: | |
| enum class | kleidos:: |
| What a park may spend to find out which standby frame to send. More about kleidos:: | |
Functions | |
| bool | kleidos:: |
| True when this board has a GPS receiver with wired UART pins. | |
| bool | kleidos:: |
| True while something holds the receiver's UART port open. | |
| bool | kleidos:: |
| True while a one-shot time sync owns the receiver. | |
| bool | kleidos:: |
| True while the module is in standby, as the verified park last heard it. | |
| bool | kleidos:: |
| Park the receiver, and know it is parked. | |
| bool | kleidos:: |
| Park before a deep sleep, waiting for the proof within a budget. | |
| ParkReport | kleidos:: |
| Report what the last verified park found. | |
| bool | kleidos:: |
| Re-open the receiver after park, without arming a sync. | |
| bool | kleidos:: |
| Forget the persisted receiver identity, port-safely. | |
| bool | kleidos:: |
| Power the receiver and arm a one-shot sync attempt. | |
| SyncPhase | kleidos:: |
| Drain pending UART bytes, advance the machine, commit + power down. | |
| void | kleidos:: |
| Cancel a running sync immediately and power the receiver down. | |
| uint32_t | kleidos:: |
| Milliseconds elapsed since syncBegin (clamped to the timeout). | |
| uint32_t | kleidos:: |
| The deadline configured by syncBegin. | |
| GpsDiag | kleidos:: |
| Power the receiver, probe its live state for a bounded window, off. | |
Variables | |
| constexpr uint32_t | kleidos:: |
| Default sync deadline: generous headroom over a cold-start TTFF. | |
Accepted fix year range | |
Mirrors the manual set-clock widget range ( | |
| constexpr uint16_t | kleidos:: |
| Oldest acceptable fix year. | |
| constexpr uint16_t | kleidos:: |
| Newest acceptable fix year. | |
Typedef Documentation
GpsDiagProgressSink #
Callback invoked at each progress tick with the elapsed ms and running tally — turns diagnose into a live acquisition monitor over a long window.
Enumeration Type Documentation
ParkCost #
What a park may spend to find out which standby frame to send.
| Enumerator | |
|---|---|
| Cheap | One step of the verified park per call (gps_ |
| Resolved | Resolve the fitted model through the factory first, which may listen (a fast-path window, or a full baud sweep of up to four rates), then prove the park, blocking for up to a few seconds. For an operator who asked for one. |
SyncPhase #
Function Documentation
available() #
True when this board has a GPS receiver with wired UART pins.
- Return values
-
Value Meaning true HAS_GPSbuild with valid TX/RX pin assignments.false No receiver on this variant (all other calls are no-ops).
diagnose() #
Power the receiver, probe its live state for a bounded window, off.
One-shot read-only diagnostic (does NOT set the clock). Powers the GPS UART, polls a UBX-MON-VER identity request, then for windowMs reads the stream: echoes every raw NMEA line through onLine (may be nullptr) and tallies the returned GpsDiag. Always powers the receiver back down on exit, on every path (mirrors the sync power contract). Refuses (GpsDiag::busy) while a real syncBegin is active.
- Parameters
-
Name Direction Meaning windowMs in Capture window in milliseconds. onLine in Per-line sink for raw NMEA echo, or nullptr.baudOverride in UART baud to probe at, or 0 for the driver default ( 9600) — lets the console sweep candidate rates when a module ships at a non-default baud.onProgress in Progress sink called ~every 5 s of the window with the running tally, or nullptr— lets a long window act as a live acquisition monitor without power-cycling the receiver between reads.
- Returns
- The gathered snapshot.
< NMEA 0183 maximum sentence length.
forgetIdentity() #
Forget the persisted receiver identity, port-safely.
What a re-detect wants: the receiver is parked and its port closed first, so the next createGps sweeps a free UART instead of re-opening one this unit still believes it holds. Erases the stored receiver model and baud rate.
Refused while a sync owns the receiver, rather than cancelling it as a side effect: the park this runs first would otherwise abort a time sync the user started, and the surface that asked for a re-detect would report one it did not do. The refusal lives here instead of in each caller, because three of the four had no guard of their own.
- Return values
-
Value Meaning true The identity is gone and the receiver is parked. false A sync is in flight; nothing was erased or touched.
lastPark() #
Report what the last verified park found.
- Returns
- The report; a default one where no receiver is fitted.
park() #
Park the receiver, and know it is parked.
Independent of a sync, and the only thing that takes the module out of acquisition — no rail the board switches reaches the receiver's supply. A sync in flight is cancelled first (so the machine is never left latched in SyncPhase::), and a held port is powered down; either sends the standby frame, and the following calls prove it landed. Free while parked holds — it returns at once without touching the bus.
- Parameters
-
Name Direction Meaning cost in What this park may spend (ParkCost). No default: ParkCost:: Resolved blocks for seconds, so a caller states what it is willing to spend.
- Return values
-
Value Meaning true Parked, or (ParkCost:: Cheap) a park is under way. false No receiver on this board, the port could not be opened, or the receiver kept talking through every standby frame.
parkBeforeSleep() #
Park before a deep sleep, waiting for the proof within a budget.
Steps the verified park until the receiver is heard silent, feeding the task watchdog, for at most budgetMs, then releases the port whatever the outcome. Stores no identity it learns (the sleep path must not open NVS). Nearly always free: the idle tick verified the park long before the board went idle enough to sleep.
- Parameters
-
Name Direction Meaning budgetMs in Longest wait, in milliseconds.
- Return values
-
Value Meaning true The receiver sleeps parked. false It could not be heard silent in time, or no receiver is fitted.
parked() #
True while the module is in standby, as the verified park last heard it.
Set only by a park that listened and heard the receiver silent (gps_
- Return values
-
Value Meaning true The receiver was heard silent and nothing has driven it since. false It is awake, not yet verified, or no receiver is fitted.
portOpen() #
True while something holds the receiver's UART port open.
The one predicate that is safe to gate a park on: it reads this unit's own bookkeeping and touches no bus. True for a running sync, for a live Session, and after a resume — which is the distinction syncActive does not make, and the reason the two are separate names.
- Return values
-
Value Meaning true The port is held; the module is awake. false Nothing holds it (parked, or never opened).
resume() #
Re-open the receiver after park, without arming a sync.
Re-resolves the driver, which re-opens the UART and nudges a u-blox module out of backup. A genuine restore rather than a rail poke: the receiver is answering again when this returns true, and portOpen says so, so the idle park stands off until something closes it again.
- Return values
-
Value Meaning true The port is open and the module answered. false No receiver on this board, something already holds the port, or the open failed.
syncActive() #
syncBegin() #
Power the receiver and arm a one-shot sync attempt.
- Parameters
-
Name Direction Meaning timeoutMs in Deadline in milliseconds (see kDefaultSyncTimeoutMs).
- Return values
-
Value Meaning true UART up, machine armed; poll with syncPoll. false Already active, something else holds the port, no GPS on this board, or UART begin failed (the pins are restored to their idle input state).
syncCancel() #
Cancel a running sync immediately and power the receiver down.
- Note
- Not self-serializing: every sync call — including the deep-sleep hook's cancel — runs on the owning Core-1 loop task.
syncElapsedMs() #
Milliseconds elapsed since syncBegin (clamped to the timeout).
- Returns
- Elapsed milliseconds of the current/last sync attempt.
syncPoll() #
Drain pending UART bytes, advance the machine, commit + power down.
On the first valid fix: atomic rtc:: write, source tag rtc::, then power-down. On timeout: power-down. Call from the owning task's loop while the phase is SyncPhase::.
- Returns
- The phase after this poll (terminal phases are latched).
syncTimeoutMs() #
The deadline configured by syncBegin.
- Returns
- Timeout in milliseconds (0 when never started).