In development. It changes without notice.
Topic
GPS Receiver Drivers
The GPS receivers the LILYGO T-Deck can carry, the probe that finds which one is fitted, and the park that keeps it asleep.
A u-blox M10 and a CASIC L76K. A time is accepted only from a valid fix. A receiver runs only when the owner asks for a sync (GPS Time Sync); otherwise it is parked, and a park counts only once the receiver is heard to fall silent.
- See also
- GPS Time Sync, Clock & Time Zone
Files | |
| file | src/ |
| CASIC L76K concrete kleidos:: | |
| file | src/ |
| Datasheet-comprehensive u-blox M10 UBX-CFG configuration key map. | |
| file | src/ |
| NVS-cached auto-probe factory for the GPS receiver driver. | |
| file | src/ |
| Pure, verified GPS park: listen, send only to a module that is talking, and call it parked only once it has gone silent. | |
| file | src/ |
| Pure UBX-vs-NMEA stream-identity decision for GPS receiver auto-probe. | |
| file | src/ |
| Shared plain-old-data types for the GPS driver layer. | |
| file | src/ |
| Abstract GPS receiver driver contract. | |
| file | src/ |
| In-house NMEA 0183 time parser for one-shot GPS clock sync. | |
| file | src/ |
| u-blox M10 concrete kleidos:: | |
| file | src/ |
| In-house u-blox UBX binary protocol codec (frames, checksum, CFG). | |
Functions | |
| const UbxCfgKey * | kleidos:: |
| The datasheet-comprehensive u-blox M10 UBX-CFG key table. | |
| size_t | kleidos:: |
| Number of configuration keys in table(). | |
| const UbxCfgKey * | kleidos:: |
| Find a key descriptor by its 32-bit key id (linear scan). | |
| const UbxCfgKey * | kleidos:: |
| Find a key descriptor by its canonical name (linear scan). | |
| IGps * | kleidos:: |
| Resolve and return the fitted GPS receiver driver. | |
| IGps * | kleidos:: |
| The singleton driver for one receiver family, not opened. | |
| bool | kleidos:: |
Read the persisted {model,baud} identity without verifying it. | |
| void | kleidos:: |
| Store an identity learned somewhere other than the factory's sweep. | |
| void | kleidos:: |
| Erase the persisted GPS identity and clear the RAM cache. | |
| constexpr bool | kleidos:: |
| Whether a verdict means the receiver is in standby. | |
| void | kleidos:: |
| Fold one just-completed sentence into the evidence. | |
| void | kleidos:: |
| Accumulate identity evidence from one chunk of receiver bytes. | |
| GpsModel | kleidos:: |
| Decide the receiver family from accumulated stream evidence. | |
| bool | kleidos:: |
| Validate a full NMEA sentence checksum ("$...*hh"). | |
| std:: | kleidos:: |
Return comma-separated field idx of body (empty when absent). | |
| bool | kleidos:: |
| Parse an unsigned decimal field (digits only, non-empty). | |
| bool | kleidos:: |
Parse an NMEA hhmmss(.sss) time field into RtcTime. | |
| bool | kleidos:: |
Parse a GxRMC payload (valid fixes only) into a UTC instant. | |
| bool | kleidos:: |
| Validate the checksum of a full sentence and parse it as an RMC fix. | |
| void | kleidos:: |
| Compute the UBX 8-bit Fletcher checksum over a frame body. | |
| size_t | kleidos:: |
| Assemble a complete UBX frame into a caller-supplied buffer. | |
| size_t | kleidos:: |
| Build the UBX-MON-VER poll frame (empty payload). | |
| size_t | kleidos:: |
| Build a UBX-CFG-VALGET frame requesting one configuration key. | |
| size_t | kleidos:: |
| Number of value bytes carried by a UBX-CFG storage type. | |
| size_t | kleidos:: |
| Build a UBX-CFG-VALSET frame writing one configuration key/value. | |
| size_t | kleidos:: |
| Build the UBX-RXM-PMREQ frame that puts an M10 in software standby until an edge on its UART RX line wakes it. | |
| UbxType | kleidos:: |
| Decode the width-class of a 32-bit UBX configuration key. | |
| bool | kleidos:: |
| Decode a little-endian UBX value into a GpsCfgValue. | |
Variables | |
| constexpr auto | kleidos:: |
| UBX-MON-HW aStatus antenna-supervisor states (decode for MonHwLayout:: | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| How long a module that is talking gets to answer a UBX MON-VER poll. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| Silence after the settle that proves standby: longer than one output period. | |
| constexpr uint8_t | kleidos:: |
| Standby frames sent at one rate before the park gives up. | |
| constexpr std::array< uint32_t, 3 > | kleidos:: |
| Line rates tried when no identity is stored, after the board's own. | |
| constexpr uint8_t | kleidos:: |
| UBX frame sync byte 1 (u-blox interface manual "UBX frame structure"). | |
| constexpr uint8_t | kleidos:: |
| UBX frame sync byte 2 (u-blox interface manual "UBX frame structure"). | |
| constexpr size_t | kleidos:: |
| NMEA 0183 maximum sentence length; longer assemblies are dropped as garbage. | |
| constexpr uint8_t | kleidos:: |
| UBX sync char 1 (frame preamble byte 0). | |
| constexpr uint8_t | kleidos:: |
| UBX sync char 2 (frame preamble byte 1). | |
| constexpr uint8_t | kleidos:: |
| UBX-MON-VER poll: message class (Monitoring). | |
| constexpr uint8_t | kleidos:: |
| UBX-MON-VER poll: message id. | |
| constexpr uint8_t | kleidos:: |
| UBX-RXM-PMREQ: message class (Receiver Manager). | |
| constexpr uint8_t | kleidos:: |
| UBX-RXM-PMREQ: message id (power management request). | |
| constexpr uint8_t | kleidos:: |
| UBX-CFG: message class (Configuration). | |
| constexpr uint8_t | kleidos:: |
| UBX-CFG-VALGET: message id. | |
| constexpr uint8_t | kleidos:: |
| UBX-CFG-VALSET: message id. | |
| constexpr uint8_t | kleidos:: |
UBX-CFG-VALGET layer selector (a single enum value): volatile RAM = 0. | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| UBX-RXM-PMREQ flags: enter backup (low-power) mode (bit 1). | |
| constexpr uint8_t | kleidos:: |
| constexpr uint8_t | kleidos:: |
| UBX-RXM-PMREQ wakeupSources: an edge on the UART RX line wakes it (bit 3). | |
| constexpr uint16_t | kleidos:: |
| UBX-RXM-PMREQ payload length of the one form the M10 documents. | |
| constexpr size_t | kleidos:: |
| Fixed frame overhead: sync(2) + class(1) + id(1) + length(2) + checksum(2). | |
Enumeration Type Documentation
Action #
The one thing the caller does for a Machine::step.
| Enumerator | |
|---|---|
| None | Nothing this step: call again on a later tick. |
| Open | Open the port at Machine::baud, writing nothing to it. |
| SendProbe | Write the UBX MON-VER poll (a talking module is identified). |
| SendStandby | Write Machine:: |
| FlushInput | Discard what arrived while the module stopped. |
| Close | Close the port and return the pads to idle. |
Verdict #
Function Documentation
buildFrame() #
Assemble a complete UBX frame into a caller-supplied buffer.
- Parameters
-
Name Direction Meaning cls in UBX message class. id in UBX message id. payload in Payload bytes (may be nullptrwhenlenis 0).len in Payload length in bytes. out out Destination buffer. outCap in Capacity of outin bytes.
- Returns
- Total bytes written (
kFrameOverhead+len), or 0 on overflow.
buildMonVerPoll() #
Build the UBX-MON-VER poll frame (empty payload).
- Parameters
-
Name Direction Meaning out out Destination buffer. cap in Capacity of outin bytes.
- Returns
- Bytes written (8), or 0 on overflow.
buildPmreqBackup() #
Build the UBX-RXM-PMREQ frame that puts an M10 in software standby until an edge on its UART RX line wakes it.
The 16-byte form, the only one the M10 interface description defines: version 0, three reserved bytes, a duration of 0 (no timed wake), the backup and force flags, and UART RX as the one wake source. Without force the receiver is not required to enter standby at all. Entering it clears the receiver's RAM, configuration included, so it wakes on its defaults.
- Parameters
-
Name Direction Meaning out out Destination buffer. cap in Capacity of outin bytes.
- Returns
- Bytes written (24), or 0 on overflow.
buildValGet() #
Build a UBX-CFG-VALGET frame requesting one configuration key.
- Parameters
-
Name Direction Meaning key in 32-bit UBX configuration key id. out out Destination buffer. cap in Capacity of outin bytes.
- Returns
- Bytes written (16), or 0 on overflow.
buildValSet() #
Build a UBX-CFG-VALSET frame writing one configuration key/value.
- Parameters
-
Name Direction Meaning key in 32-bit UBX configuration key id. v in Typed value (little-endian bits in GpsCfgValue:: raw). out out Destination buffer. cap in Capacity of outin bytes.
- Returns
- Bytes written, or 0 on overflow.
checksum() #
Compute the UBX 8-bit Fletcher checksum over a frame body.
- Parameters
-
Name Direction Meaning body in Pointer to {class, id, len_lo, len_hi, payload...}. len in Number of bytes in body.ckA out Accumulated checksum A. ckB out Accumulated checksum B.
checksumValid() #
Validate a full NMEA sentence checksum ("$...*hh").
- Parameters
-
Name Direction Meaning sentence in The full sentence from '$' through the two hex digits.
- Return values
-
Value Meaning true XOR of the payload equals the trailing hex pair. false Missing '$'/'*hh', bad hex, or checksum mismatch.
count() #
Number of configuration keys in table().
- Returns
- Key count.
createGps() #
Resolve and return the fitted GPS receiver driver.
Returns the RAM-cached driver if one was already resolved this session; otherwise runs the NVS fast-path (with self-heal) and, failing that, the baud sweep described in the file header. The resolved driver is opened and ready to kleidos::
- Returns
- A ready driver owned by function-local
staticstorage (do not delete), ornullptrwhen no receiver responded (or the board has no GPS). Anullptrresult is not cached — a module attached later can still be found on the next call.
decodeValue() #
Decode a little-endian UBX value into a GpsCfgValue.
Assembles n little-endian bytes into GpsCfgValue::I1..I8) are sign-extended to 64 bits; L / E1 / X* / U* are zero-extended.
- Parameters
-
Name Direction Meaning t in Value type. le in Little-endian value bytes. n in Number of bytes available in le.out out Decoded value (GpsCfgValue:: type set to t).
- Return values
-
Value Meaning true Decoded ( nmatched the type width).false Insufficient bytes / null input.
driverForModel() #
The singleton driver for one receiver family, not opened.
The raw family lookup behind createGps, for the one caller that must not probe: a park sends one model's standby frame and closes the port again, so it needs the driver without the listen window that identifies it. The returned driver lives in function-local static storage (do not delete).
- Parameters
-
Name Direction Meaning model in Receiver family to resolve.
- Returns
- The family's driver, or
nullptrforGpsModel::(and always on a board without a GPS).Unknown
field() #
Return comma-separated field idx of body (empty when absent).
- Parameters
-
Name Direction Meaning body in Sentence payload between '$' and '*'. idx in 0-based field index (field 0 is the sentence id).
- Returns
- The field's characters, or an empty view when the index is past the end.
find() #
Find a key descriptor by its 32-bit key id (linear scan).
- Parameters
-
Name Direction Meaning key in 32-bit UBX configuration key id.
- Returns
- Pointer to the matching descriptor, or nullptr if not present.
findByName() #
Find a key descriptor by its canonical name (linear scan).
- Parameters
-
Name Direction Meaning name in Key name, e.g. "CFG-UART1-BAUDRATE".
- Returns
- Pointer to the matching descriptor, or nullptr if
nameis null or not present.
forgetGpsIdentity() #
Erase the persisted GPS identity and clear the RAM cache.
Removes the stored identity from NVS and drops the file-scope cached driver, forcing the next createGps to re-run a full baud sweep. Used by the self-heal path. No-op on a board without a GPS.
- Note
- It touches no UART, so it cannot close a port a consumer still holds. An explicit re-detect goes through
gps::instead, which closes the receiver first.forgetIdentity
identify() #
Decide the receiver family from accumulated stream evidence.
- Parameters
-
Name Direction Meaning e in Evidence gathered by one or more scan calls.
- Return values
-
Value Meaning GpsModel:: UbloxM10 A UBX sync pair was seen (the receiver speaks UBX). GpsModel:: CasicL76k A checksum-valid NMEA line was seen but no UBX (the one NMEA-only family the factory knows). GpsModel:: Unknown Neither signal was observed.
ingestLine() #
Fold one just-completed sentence into the evidence.
- Parameters
-
Name Direction Meaning sentence in Assembled sentence "$…*hh" (no CR/LF). acc in, out Evidence updated when the checksum validates.
isParked() #
Whether a verdict means the receiver is in standby.
- Parameters
-
Name Direction Meaning v in A verdict.
- Return values
-
Value Meaning true Verdict:: Silent or Verdict:: Parked. false Any other.
parseHms() #
Parse an NMEA hhmmss(.sss) time field into RtcTime.
The fractional part is ignored. A leap-second ss of 60 is clamped to 59 so the value always fits the RtcTime contract (0..59).
- Parameters
-
Name Direction Meaning f in The time field (e.g. "235960.00"). out out Receives hours/ minutes/ seconds on success.
- Return values
-
Value Meaning true Exactly six leading digits with hh<=23, mm<=59, ss<=60. false Wrong length or out-of-range component.
parseRmc() #
Parse a GxRMC payload (valid fixes only) into a UTC instant.
- Parameters
-
Name Direction Meaning body in Payload between '$' and '*' (checksum already verified). out out Receives the UTC date+time on success.
- Return values
-
Value Meaning true RMC with status 'A', six-digit time and ddmmyy date in range. false Not RMC, void fix, or malformed/ out-of-range fields.
parseSentence() #
Validate the checksum of a full sentence and parse it as an RMC fix.
- Parameters
-
Name Direction Meaning sentence in Full sentence "$...*hh" (no CR/LF). out out Receives the UTC date+time on success.
- Return values
-
Value Meaning true A checksum-valid RMC with status A (a fix) and a full date. false Bad checksum, other sentence types, or malformed fields.
parseUint() #
Parse an unsigned decimal field (digits only, non-empty).
- Parameters
-
Name Direction Meaning s in The field characters. out out Receives the parsed value on success.
- Return values
-
Value Meaning true sis one to nine decimal digits.false Empty field, more than nine digits (uint32_t wrap guard), or any non-digit character.
persistedGpsIdentity() #
Read the persisted {model,baud} identity without verifying it.
The identity createGps stores at detection, straight out of flash: no port is opened and no stream is listened to, so this costs nothing and can be wrong (a swapped module, a reconfigured baud). For a park that is enough — a standby frame sent to the wrong model is noise, and the next real createGps still self-heals.
The flash is read at most once per boot: the answer, including a remembered negative, is memoised in RAM and kept honest by forgetGpsIdentity and by the write at detection. That is what lets the deep-sleep teardown park the receiver without opening NVS on a shutdown path.
- Parameters
-
Name Direction Meaning model out The persisted family on success. baud out The persisted line rate on success.
- Return values
-
Value Meaning true A usable identity was stored and both outputs were written. false Nothing cached yet, the stored model byte is not a family, or the board has no GPS.
scan() #
Accumulate identity evidence from one chunk of receiver bytes.
Walks bytes tracking two independent signals: the 0xB5 0x62 UBX sync pair (via the carried previous byte, so it survives a chunk boundary) and '$'-started NMEA lines (reassembled up to kMaxSentence and validated through kleidos::acc.
- Parameters
-
Name Direction Meaning bytes in Pointer to the chunk (may be null only when nis 0).n in Number of bytes in the chunk. acc in, out Evidence accumulator carried across chunks.
storeGpsIdentity() #
Store an identity learned somewhere other than the factory's sweep.
The verified park identifies a module that is talking from its own stream (gps_
- Parameters
-
Name Direction Meaning model in The family the stream identified. baud in The rate it was heard at.
table() #
The datasheet-comprehensive u-blox M10 UBX-CFG key table.
- Returns
- Pointer to the first of count() immutable key descriptors.
typeOfKey() #
Decode the width-class of a 32-bit UBX configuration key.
Bits [30:28] of the key encode the storage size (1=1-bit L, 2=1-byte, 3=2-byte, 4=4-byte, 5=8-byte). This returns the width class; the caller's key map carries the precise signedness/
- Parameters
-
Name Direction Meaning key in 32-bit UBX configuration key id.
- Returns
- The width-class type (
L/U1/U2/U4/U8).
valueBytes() #
Number of value bytes carried by a UBX-CFG storage type.
- Parameters
-
Name Direction Meaning t in Value type.
- Returns
- 1, 2, 4, or 8 bytes (defaults to 1 for unknown inputs).
Variable Documentation
kLayersRam #
UBX-CFG-VALSET layers selector (a bitmask, not an enum): the RAM bit is bit 0 (BBR = bit 1, Flash = bit 2). A VALSET with an all-zero layers mask selects no destination layer, so the receiver applies nothing and never sends an ACK — the write must set the RAM bit here.
kListenMs #
How long the port is listened to before anything is written. Both families talk at 1 Hz by default, so 2.2 s spans two output periods with room for a sentence that started before the port opened.
kPmreqFlagForce #
UBX-RXM-PMREQ flags: force the request (bit 2). The M10 interface description requires it for the receiver to enter software standby at all.
kSettleMs #
Time the module is given to act on its standby frame; what arrives in it is the tail of output already under way and is discarded.