From aab03bc4b6ab02be7db3fd60f034a84d79ad93b4 Mon Sep 17 00:00:00 2001 From: Radek Date: Wed, 6 Nov 2024 16:09:42 +0000 Subject: [PATCH] Make can_print.py work on a all busses (#2070) * Enable CAN3 printer (#1991) again (cherry picked from commit 2b94e4fef710a22313b99d8c5b723d8db5e9c8bd) * print messages with same address but on different bus --- board/jungle/scripts/can_printer.py | 18 +++++++++++------- tests/can_printer.py | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/board/jungle/scripts/can_printer.py b/board/jungle/scripts/can_printer.py index 05cc802aa..292421a5c 100755 --- a/board/jungle/scripts/can_printer.py +++ b/board/jungle/scripts/can_printer.py @@ -19,20 +19,24 @@ def can_printer(): start = sec_since_boot() lp = sec_since_boot() - msgs = defaultdict(list) + all_msgs = defaultdict(list) + canbus = os.getenv("CAN") + if canbus == "3": + p.set_obd(True) + canbus = "1" + while True: can_recv = p.can_recv() - for address,dat, src in can_recv: - if canbus is None or str(src) == canbus: - msgs[address].append((dat, src)) + for addr, dat, bus in can_recv: + if canbus is None or str(bus) == canbus: + all_msgs[(addr, bus)].append((dat)) if sec_since_boot() - lp > 0.1: dd = chr(27) + "[2J" dd += "%5.2f\n" % (sec_since_boot() - start) - for k, v in sorted(msgs.items()): - last_msg, last_src = v[-1] - dd += "%d: %s(%6d): %s\n" % (last_src, "%04X(%4d)" % (k, k), len(v), binascii.hexlify(last_msg).decode()) + 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()) print(dd) lp = sec_since_boot() diff --git a/tests/can_printer.py b/tests/can_printer.py index 791f8e75d..404bc9dcf 100755 --- a/tests/can_printer.py +++ b/tests/can_printer.py @@ -20,20 +20,24 @@ def can_printer(): start = sec_since_boot() lp = sec_since_boot() - msgs = defaultdict(list) + all_msgs = defaultdict(list) + canbus = os.getenv("CAN") + if canbus == "3": + p.set_obd(True) + canbus = "1" + while True: can_recv = p.can_recv() - for address, dat, src in can_recv: - if canbus is None or str(src) == canbus: - msgs[address].append((dat, src)) + for addr, dat, bus in can_recv: + if canbus is None or str(bus) == canbus: + all_msgs[(addr, bus)].append((dat)) if sec_since_boot() - lp > 0.1: dd = chr(27) + "[2J" dd += "%5.2f\n" % (sec_since_boot() - start) - for k, v in sorted(msgs.items()): - last_msg, last_src = v[-1] - dd += "%d: %s(%6d): %s\n" % (last_src, "%04X(%4d)" % (k, k), len(v), binascii.hexlify(last_msg).decode()) + 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()) print(dd) lp = sec_since_boot()