openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
772 B

#!/usr/bin/env python3
import datetime
import os
import struct
import usb1
REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE
MIN_DATE = datetime.datetime(year=2021, month=4, day=1)
if __name__ == "__main__":
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()
if panda_time > MIN_DATE and sys_time < MIN_DATE:
print(f"adjusting time from '{sys_time}' to '{panda_time}'")
os.system(f"TZ=UTC date -s '{panda_time}'")