From 0cf04af227f0965af80e841dc8042f400e193f15 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 11 Dec 2024 20:42:45 -0800 Subject: [PATCH] timed: gate time setting on GPS fix (#34217) --- system/timed.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/system/timed.py b/system/timed.py index 31d0d06588..3eb84353ad 100755 --- a/system/timed.py +++ b/system/timed.py @@ -5,7 +5,7 @@ import time from typing import NoReturn import cereal.messaging as messaging -from openpilot.common.time import system_time_valid +from openpilot.common.time import min_date, system_time_valid from openpilot.common.swaglog import cloudlog from openpilot.common.params import Params from openpilot.common.gps import get_gps_location_service @@ -26,10 +26,10 @@ def set_time(new_time): def main() -> NoReturn: """ - timed has one responsibility: - - getting the current time + timed has two responsibilities: + - getting the current time from GPS + - publishing the time in the logs - GPS directly gives time. AGNOS will also use NTP to update the time. """ @@ -47,14 +47,15 @@ def main() -> NoReturn: pm.send('clocks', msg) gps = sm[gps_location_service] + gps_time = datetime.datetime.fromtimestamp(gps.unixTimestampMillis / 1000.) if not sm.updated[gps_location_service] or (time.monotonic() - sm.logMonoTime[gps_location_service] / 1e9) > 2.0: continue + if not gps.hasFix: + continue + if gps_time < min_date(): + continue - # set time - # TODO: account for unixTimesatmpMillis being a (usually short) time in the past - gps_time = datetime.datetime.fromtimestamp(gps.unixTimestampMillis / 1000.) set_time(gps_time) - time.sleep(10) if __name__ == "__main__":