mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-28 01:52:06 +08:00
timed: gate time setting on GPS fix (#34217)
This commit is contained in:
+9
-8
@@ -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__":
|
||||
|
||||
Reference in New Issue
Block a user