ECLIPTIC :app — the cockpit GPS sourcing

:app · the cockpit

GPS sourcing

Fire tablets have no built-in GNSS, and the fleet is four tablets in one vehicle today, so a single shared sensor hub broadcasts on the car's WiFi rather than per-tablet receivers. The architecture is a pluggable LocationSource, parallel to the transport adapter pattern — except that unlike the transports, these are real.

The interface

LocationSource is type + StateFlow<LocationSourceState> + start() / stop(). LocationSourceState is Disconnected / Searching / Active(GpsFix) / Error(detail, kind).

TypeImplementationNotes
FAKEFakeLocationSourceIntegrating dead-reckoner around the Golden Spike, driven by the debug chips; 500 ms tick
SYSTEMSystemLocationSourceAndroid LocationManager GPS_PROVIDER behind an injectable handle; 1 s / 0 m — no displacement filter: at BRC 2026 a 1 m filter withheld fixes from a parked vehicle and the readout flapped FIX/NO FIX
BLEBleLocationSourceBluetooth Classic SPP despite the name; matches paired device names against a GPS-receiver regex
USBUsbLocationSourceusb-serial-for-android, 9600 8N1, lines reassembled by NmeaLineAssembler
NETNetworkLocationSourceThe fleet path — shipped and verified end to end

RoutedLocationSource + LocationSourceRegistry do the runtime selection. FixFreshness (5 s) demotes a stale Active back to Searching — and only Active, never an Error.

Errors name their own fix

LocationSourceError categorises every failure by what the operator would do about it, rendered under the GPS chips as ⊘ PERMISSION / ⊘ ADAPTER OFF / ? NO DEVICE / ✕ I/O, with the free-text detail going to the rolling log.

NetworkLocationSource — the fleet path

Binds the wildcard address on 10110, sets reuseAddress, joins 239.7.7.10, and holds a MulticastLock behind an injectable handle so unit tests get a no-op.

It tracks three independent liveness clocks:

ClockFed byOn silence
PositionGGA / RMCStandard staleness demotion
HeadingHDTAfter 8 s, heading demotes to GPS course — without also making the position look stale
Beaconthe $Z* channelsAfter 12 s, the sensor readings clear

Separating them is the point: a dead compass must not take the position down with it.

  • start() is idempotent.
  • stop() joins the listener before clearing state, so an in-flight read cannot repopulate it.
  • A socket failure is not terminal: the source rebuilds the socket on exponential backoff (1 s → 30 s cap).
  • A socket that has heard nothing for 20 s is rebuilt too, because rebuilding is the only way to re-join a group after a router reboot.
Resolved

BleLocationSource and UsbLocationSource now self-heal on the same capped exponential backoff as NET; an I/O error is no longer terminal.

Failover

FailoverLocationSource wraps NET with SYSTEM, presents itself as NET (so the chip and the persisted preference stay honest), and keeps both running so the fallback is warm.

Drop to fallback
After 3 s of an unhealthy primary — on top of the 5 s staleness window, so ~8 s total blind
Recover to primary
Only after 10 s of health
Why asymmetric
So a half-alive beacon cannot flap the source
Armed on
Only devices that report FEATURE_LOCATION_GPS — asked of the hardware rather than assumed by model
Why SYSTEM also carries FixFreshness

The failover judges its fallback usable by that fallback's state being Active. SystemLocationSource originally had no freshness check, so a frozen fix would satisfy the liveness test forever: beacon dies → failover engages correctly → the tablet loses sky (dash mount, dust) → the last fix stays Active indefinitely, and by the original no-badge decision nothing on screen said you were on backup. (That decision was later reversed: the source line now reads ◐ LOCAL BACKUP while failover is engaged, ● ON BEACON otherwise.) It now carries FixFreshness plus a watchdog on the BLE pattern, with an injectable clock. Provider-disabled is surfaced distinctly as Error(ADAPTER_UNAVAILABLE) rather than as staleness — staleness is transient and may self-heal, a switched-off provider will not.

NMEA parsing

data/sensor/nmea/NmeaParser is talker-agnostic (it dispatches on the last three characters, so $GP / $GN / $GL / $GA / $GB all match) and validates the XOR checksum on every entry point, accepting one or two hex digits.

Handled: GGA (position, fix quality, HDOP→accuracy), RMC (position, speed in knots→kph, course), HDT (true heading), and the five proprietary channels plus ZTLM. Field-level detail →

VTG, HDG and HDM are deliberately not handled

VTG is GPS course, not compass. Android GNSS chips emit it every epoch and the beacon forwards raw NMEA verbatim, so treating VTG as heading would interleave with the synthesized $GPHDT and flip-flop a stopped vehicle's heading — and would keep the heading clock fresh, defeating the dead-compass watchdog. HDG / HDM are magnetic heading, roughly 13° east of true at Black Rock City, so applying them as true heading would be silently wrong by that much.

This was previously a bug with a test asserting it — the fifth time in this project a test was found defending the code's mistake.

How NET was proven

Earlier bring-up used a spare iPhone running GPS2IP, which validated NetworkLocationSource end to end before the beacon app existed. The hub is the :beacon app on the XCover Pro today; a Pi Zero 2 W with a u-blox USB GNSS and a roof antenna is the planned replacement. The travel router keeps the AP / DHCP role either way.

Converted from
ARCHITECTURE.md §4.5, §4.6 · CLAUDE.md · docs/AUDIT-2026-08-09.md A3 (private dev repo) · tasks/open.md (private dev repo)