Files
StarPilot/openpilot/selfdrive/navigation/helpers.py
T
2026-10-20 02:19:24 +00:00

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