|
|
@ -5,7 +5,7 @@ import time |
|
|
|
from typing import NoReturn |
|
|
|
from typing import NoReturn |
|
|
|
|
|
|
|
|
|
|
|
import cereal.messaging as messaging |
|
|
|
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.swaglog import cloudlog |
|
|
|
from openpilot.common.params import Params |
|
|
|
from openpilot.common.params import Params |
|
|
|
from openpilot.common.gps import get_gps_location_service |
|
|
|
from openpilot.common.gps import get_gps_location_service |
|
|
@ -26,10 +26,10 @@ def set_time(new_time): |
|
|
|
|
|
|
|
|
|
|
|
def main() -> NoReturn: |
|
|
|
def main() -> NoReturn: |
|
|
|
""" |
|
|
|
""" |
|
|
|
timed has one responsibility: |
|
|
|
timed has two responsibilities: |
|
|
|
- getting the current time |
|
|
|
- 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. |
|
|
|
AGNOS will also use NTP to update the time. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
@ -47,14 +47,15 @@ def main() -> NoReturn: |
|
|
|
pm.send('clocks', msg) |
|
|
|
pm.send('clocks', msg) |
|
|
|
|
|
|
|
|
|
|
|
gps = sm[gps_location_service] |
|
|
|
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: |
|
|
|
if not sm.updated[gps_location_service] or (time.monotonic() - sm.logMonoTime[gps_location_service] / 1e9) > 2.0: |
|
|
|
continue |
|
|
|
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) |
|
|
|
set_time(gps_time) |
|
|
|
|
|
|
|
|
|
|
|
time.sleep(10) |
|
|
|
time.sleep(10) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|