diff --git a/Dockerfile.agnos b/Dockerfile.agnos index 12da5d2..144db4c 100644 --- a/Dockerfile.agnos +++ b/Dockerfile.agnos @@ -147,6 +147,15 @@ COPY ./userspace/usr/share/fonts/* /usr/share/fonts/ COPY ./userspace/libs/* /usr/lib/aarch64-linux-gnu/ COPY ./userspace/libs32/* /usr/lib/arm-linux-gnueabihf/ +# copy of panda python lib +RUN cd /tmp/ && \ + git clone https://github.com/commaai/panda.git && \ + cd panda && \ + git fetch --all && \ + git checkout 8ba568388176b8fc6443c124ad9ecd4e33174642 && \ + mkdir /usr/comma/panda/ && \ + mv __init__.py python/ /usr/comma/panda/ + # kernel headers for the AGNOS kernel (built on device) COPY ./userspace/files/linux-headers-4.9.103+_4.9.103+-1_arm64.deb /tmp/ RUN dpkg -i /tmp/linux-headers-4.9.103+_4.9.103+-1_arm64.deb diff --git a/userspace/usr/comma/set_time.py b/userspace/usr/comma/set_time.py index b8e17fb..3b2de9c 100755 --- a/userspace/usr/comma/set_time.py +++ b/userspace/usr/comma/set_time.py @@ -1,28 +1,42 @@ #!/usr/bin/env python3 import datetime import os -import struct -import usb1 +import sys from pathlib import Path -REQUEST_IN = usb1.ENDPOINT_IN | usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE +here = os.path.dirname(os.path.realpath(__file__)) +sys.path.insert(0, here) +from panda import Panda # Systemd pushes the system time to the systemd build time if no time is set MIN_DATE = datetime.datetime.fromtimestamp(Path("/lib/systemd/systemd").stat().st_mtime) MIN_DATE += datetime.timedelta(days=1) if __name__ == "__main__": - ctx = usb1.USBContext() - dev = ctx.openByVendorIDAndProductID(0xbbaa, 0xddcc) - if dev is None: - print("No panda found") + sys_time = datetime.datetime.today() + print(f"System time: {sys_time}") + if sys_time > MIN_DATE: + print("System time valid") 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}'") + ps = Panda.list() + if len(ps) == 0: + print("Failed to set time, no pandas found") + exit() + + for s in ps: + with Panda(serial=s) as p: + if not p.is_internal(): + continue + + # Set system time from panda RTC time + panda_time = p.get_datetime() + print(f"panda time: {panda_time}") + if panda_time > MIN_DATE: + print(f"adjusting time from '{sys_time}' to '{panda_time}'") + os.system(f"TZ=UTC date -s '{panda_time}'") + else: + print("panda time invalid") + break + else: + print("No internal pandas found")