Make can_print.py work on a all busses (#2070)

* Enable CAN3 printer (#1991) again

(cherry picked from commit 2b94e4fef7)

* print messages with same address but on different bus
This commit is contained in:
Radek 2024-11-06 16:09:42 +00:00 committed by GitHub
parent 991c844731
commit aab03bc4b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 14 deletions

View File

@ -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()

View File

@ -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()