openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

5 years ago
#!/usr/bin/env python3
import argparse
5 years ago
import binascii
import time
5 years ago
from collections import defaultdict
import cereal.messaging as messaging
def can_printer(bus, max_msg, addr, ascii_decode):
5 years ago
logcan = messaging.sub_sock('can', addr=addr)
start = time.monotonic()
lp = time.monotonic()
5 years ago
msgs = defaultdict(list)
while 1:
can_recv = messaging.drain_sock(logcan, wait_for_one=True)
for x in can_recv:
for y in x.can:
if y.src == bus:
5 years ago
msgs[y.address].append(y.dat)
if time.monotonic() - lp > 0.1:
5 years ago
dd = chr(27) + "[2J"
dd += f"{time.monotonic() - start:5.2f}\n"
for addr in sorted(msgs.keys()):
a = f"\"{msgs[addr][-1].decode('ascii', 'backslashreplace')}\"" if ascii_decode else ""
x = binascii.hexlify(msgs[addr][-1]).decode('ascii')
freq = len(msgs[addr]) / (time.monotonic() - start)
if max_msg is None or addr < max_msg:
dd += "%04X(%4d)(%6d)(%3dHz) %s %s\n" % (addr, addr, len(msgs[addr]), freq, x.ljust(20), a)
5 years ago
print(dd)
lp = time.monotonic()
5 years ago
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="simple CAN data viewer",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
4 years ago
parser.add_argument("--bus", type=int, help="CAN bus to print out", default=0)
parser.add_argument("--max_msg", type=int, help="max addr")
parser.add_argument("--ascii", action='store_true', help="decode as ascii")
parser.add_argument("--addr", default="127.0.0.1")
args = parser.parse_args()
can_printer(args.bus, args.max_msg, args.addr, args.ascii)