2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2017-05-28 03:31:29 +08:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
from collections import defaultdict
|
2018-03-05 03:52:53 +08:00
|
|
|
import binascii
|
2017-06-14 09:50:47 +08:00
|
|
|
|
2023-08-07 05:59:22 +08:00
|
|
|
from panda import Panda
|
2017-05-28 03:31:29 +08:00
|
|
|
|
|
|
|
# fake
|
|
|
|
def sec_since_boot():
|
|
|
|
return time.time()
|
|
|
|
|
|
|
|
def can_printer():
|
|
|
|
p = Panda()
|
2024-10-03 03:53:32 +08:00
|
|
|
print(f"Connected to id: {p.get_serial()[0]}: {p.get_version()}")
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
p.can_clear(0xFFFF)
|
2019-10-03 09:20:32 +08:00
|
|
|
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
|
2017-05-28 03:31:29 +08:00
|
|
|
|
|
|
|
start = sec_since_boot()
|
|
|
|
lp = sec_since_boot()
|
2024-11-07 00:09:42 +08:00
|
|
|
all_msgs = defaultdict(list)
|
|
|
|
|
2024-10-03 03:53:32 +08:00
|
|
|
canbus = os.getenv("CAN")
|
2024-11-07 00:09:42 +08:00
|
|
|
if canbus == "3":
|
|
|
|
p.set_obd(True)
|
|
|
|
canbus = "1"
|
|
|
|
|
2017-06-14 09:50:47 +08:00
|
|
|
while True:
|
2017-05-28 03:31:29 +08:00
|
|
|
can_recv = p.can_recv()
|
2024-11-07 00:09:42 +08:00
|
|
|
for addr, dat, bus in can_recv:
|
|
|
|
if canbus is None or str(bus) == canbus:
|
|
|
|
all_msgs[(addr, bus)].append((dat))
|
2017-05-28 03:31:29 +08:00
|
|
|
|
|
|
|
if sec_since_boot() - lp > 0.1:
|
|
|
|
dd = chr(27) + "[2J"
|
|
|
|
dd += "%5.2f\n" % (sec_since_boot() - start)
|
2024-11-07 00:09:42 +08:00
|
|
|
for (addr, bus), dat_log in sorted(all_msgs.items()):
|
|
|
|
dd += "%d: %s(%6d): %s\n" % (bus, "%04X(%4d)" % (addr, addr), len(dat_log), binascii.hexlify(dat_log[-1]).decode())
|
2017-06-14 09:50:47 +08:00
|
|
|
print(dd)
|
2017-05-28 03:31:29 +08:00
|
|
|
lp = sec_since_boot()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
can_printer()
|