mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
10 lines
363 B
Python
10 lines
363 B
Python
import time
|
|
|
|
|
|
def latest_gps_source(sm) -> str | None:
|
|
"""The service with the freshest usable GPS fix, or None."""
|
|
now = time.monotonic()
|
|
sources = [s for s in ('gpsLocation', 'gpsLocationExternal')
|
|
if sm.valid[s] and sm[s].hasFix and 0 <= now - sm.recv_time[s] < 2]
|
|
return max(sources, key=lambda s: sm.logMonoTime[s]) if sources else None
|