update time from RTC on manager init (#20678)
* set time on manager init * earlier * handle exception * logging * add to release files * run in launch script too Co-authored-by: Comma Device <device@comma.ai>albatross
parent
529cf08015
commit
1adf34f033
|
@ -165,6 +165,9 @@ function launch {
|
||||||
# Remove orphaned git lock if it exists on boot
|
# Remove orphaned git lock if it exists on boot
|
||||||
[ -f "$DIR/.git/index.lock" ] && rm -f $DIR/.git/index.lock
|
[ -f "$DIR/.git/index.lock" ] && rm -f $DIR/.git/index.lock
|
||||||
|
|
||||||
|
# Pull time from panda
|
||||||
|
$DIR/selfdrive/boardd/set_time.py
|
||||||
|
|
||||||
# Check to see if there's a valid overlay-based update available. Conditions
|
# Check to see if there's a valid overlay-based update available. Conditions
|
||||||
# are as follows:
|
# are as follows:
|
||||||
#
|
#
|
||||||
|
|
|
@ -89,6 +89,7 @@ selfdrive/boardd/panda.cc
|
||||||
selfdrive/boardd/panda.h
|
selfdrive/boardd/panda.h
|
||||||
selfdrive/boardd/pigeon.cc
|
selfdrive/boardd/pigeon.cc
|
||||||
selfdrive/boardd/pigeon.h
|
selfdrive/boardd/pigeon.h
|
||||||
|
selfdrive/boardd/set_time.py
|
||||||
|
|
||||||
selfdrive/car/__init__.py
|
selfdrive/car/__init__.py
|
||||||
selfdrive/car/car_helpers.py
|
selfdrive/car/car_helpers.py
|
||||||
|
|
|
@ -7,18 +7,31 @@ import usb1
|
||||||
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
|
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
|
||||||
MIN_DATE = datetime.datetime(year=2021, month=4, day=1)
|
MIN_DATE = datetime.datetime(year=2021, month=4, day=1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def set_time(logger):
|
||||||
ctx = usb1.USBContext()
|
|
||||||
dev = ctx.openByVendorIDAndProductID(0xbbaa, 0xddcc)
|
|
||||||
if dev is None:
|
|
||||||
print("No panda found")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# Set system time from panda RTC time
|
|
||||||
dat = dev.controlRead(REQUEST_IN, 0xa0, 0, 0, 8)
|
|
||||||
a = struct.unpack("HBBBBBB", dat)
|
|
||||||
panda_time = datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6])
|
|
||||||
sys_time = datetime.datetime.today()
|
sys_time = datetime.datetime.today()
|
||||||
if panda_time > MIN_DATE and sys_time < MIN_DATE:
|
if sys_time > MIN_DATE:
|
||||||
print(f"adjusting time from '{sys_time}' to '{panda_time}'")
|
logger.info("System time valid")
|
||||||
os.system(f"TZ=UTC date -s '{panda_time}'")
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
ctx = usb1.USBContext()
|
||||||
|
dev = ctx.openByVendorIDAndProductID(0xbbaa, 0xddcc)
|
||||||
|
if dev is None:
|
||||||
|
logger.info("No panda found")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Set system time from panda RTC time
|
||||||
|
dat = dev.controlRead(REQUEST_IN, 0xa0, 0, 0, 8)
|
||||||
|
a = struct.unpack("HBBBBBB", dat)
|
||||||
|
panda_time = datetime.datetime(a[0], a[1], a[2], a[4], a[5], a[6])
|
||||||
|
if panda_time > MIN_DATE:
|
||||||
|
logger.info(f"adjusting time from '{sys_time}' to '{panda_time}'")
|
||||||
|
os.system(f"TZ=UTC date -s '{panda_time}'")
|
||||||
|
except Exception:
|
||||||
|
logger.warn("Failed to fetch time from panda")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
set_time(logging)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import selfdrive.crash as crash
|
||||||
from common.basedir import BASEDIR
|
from common.basedir import BASEDIR
|
||||||
from common.params import Params
|
from common.params import Params
|
||||||
from common.text_window import TextWindow
|
from common.text_window import TextWindow
|
||||||
|
from selfdrive.boardd.set_time import set_time
|
||||||
from selfdrive.hardware import HARDWARE
|
from selfdrive.hardware import HARDWARE
|
||||||
from selfdrive.manager.helpers import unblock_stdout
|
from selfdrive.manager.helpers import unblock_stdout
|
||||||
from selfdrive.manager.process import ensure_running
|
from selfdrive.manager.process import ensure_running
|
||||||
|
@ -21,6 +22,10 @@ from selfdrive.version import dirty, version
|
||||||
|
|
||||||
|
|
||||||
def manager_init():
|
def manager_init():
|
||||||
|
|
||||||
|
# update system time from panda
|
||||||
|
set_time(cloudlog)
|
||||||
|
|
||||||
params = Params()
|
params = Params()
|
||||||
params.manager_start()
|
params.manager_start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue