Skip to content

Commit

Permalink
timed: set valid flag (commaai#32061)
Browse files Browse the repository at this point in the history
* timed: set valid flag

* oops
  • Loading branch information
adeebshihadeh authored Mar 31, 2024
1 parent b8f5f50 commit 4383233
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 11 additions & 2 deletions common/time.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import datetime
from pathlib import Path

MIN_DATE = datetime.datetime(year=2024, month=1, day=28)
_MIN_DATE = datetime.datetime(year=2024, month=3, day=30)

def min_date():
# on systemd systems, the default time is the systemd build time
systemd_path = Path("/lib/systemd/systemd")
if systemd_path.exists():
d = datetime.datetime.fromtimestamp(systemd_path.stat().st_mtime)
return d + datetime.timedelta(days=1)
return _MIN_DATE

def system_time_valid():
return datetime.datetime.now() > MIN_DATE
return datetime.datetime.now() > min_date()
4 changes: 3 additions & 1 deletion system/timed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from timezonefinder import TimezoneFinder

import cereal.messaging as messaging
from openpilot.common.time import system_time_valid
from openpilot.common.params import Params
from openpilot.common.swaglog import cloudlog
from openpilot.system.hardware import AGNOS
Expand Down Expand Up @@ -69,7 +70,8 @@ def main() -> NoReturn:
while True:
sm.update(1000)

msg = messaging.new_message('clocks', valid=True)
msg = messaging.new_message('clocks')
msg.valid = system_time_valid()
msg.clocks.wallTimeNanos = time.time_ns()
pm.send('clocks', msg)

Expand Down

0 comments on commit 4383233

Please sign in to comment.