Skip to content

Commit

Permalink
timed: gate time setting on GPS fix (#34217)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh authored Dec 12, 2024
1 parent 7a2af78 commit 0cf04af
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions system/timed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand All @@ -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.
"""

Expand All @@ -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__":
Expand Down

0 comments on commit 0cf04af

Please sign in to comment.