tools: remove pandas dependency from can_table, speed up can_print_changes (#39290)

This commit is contained in:
Lukas Heintz
2026-11-28 10:53:54 -06:00
committed by firestar5683
parent 9a28565710
commit e7a4933efc
2 changed files with 11 additions and 11 deletions
+8 -7
View File
@@ -18,23 +18,24 @@ def update(msgs, bus, dat, low_to_high, high_to_low, quiet=False):
for y in x.can:
if y.src == bus:
dat[y.address] = y.dat
addr, d = y.address, y.dat
dat[addr] = d
i = int.from_bytes(y.dat, byteorder='big')
l_h = low_to_high[y.address]
h_l = high_to_low[y.address]
i = int.from_bytes(d, byteorder='big')
l_h = low_to_high[addr]
h_l = high_to_low[addr]
change = None
if (i | l_h) != l_h:
low_to_high[y.address] = i | l_h
low_to_high[addr] = i | l_h
change = "+"
if (~i | h_l) != h_l:
high_to_low[y.address] = ~i | h_l
high_to_low[addr] = ~i | h_l
change = "-"
if change and not quiet:
print(f"{time.monotonic():.2f}\t{hex(y.address)} ({y.address})\t{change}{binascii.hexlify(y.dat)}")
print(f"{time.monotonic():.2f}\t{hex(addr)} ({addr})\t{change}{binascii.hexlify(d)}")
def can_printer(bus=0, init_msgs=None, new_msgs=None, table=False):
+3 -4
View File
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
import argparse
import pandas as pd
import openpilot.cereal.messaging as messaging
from openpilot.common.utils import tabulate
def can_table(dat):
@@ -12,9 +12,8 @@ def can_table(dat):
r += [hex(b)]
rows.append(r)
df = pd.DataFrame(data=rows)
df.columns = [str(n) for n in range(7, -1, -1)] + [' ']
table = df.to_markdown(tablefmt='grid')
headers = [''] + [str(n) for n in range(7, -1, -1)] + [' ']
table = tabulate([[i] + r for i, r in enumerate(rows)], headers, tablefmt='simple_grid')
return table