mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-27 17:42:04 +08:00
can_printer.py: default no ascii
old-commit-hash: 6d16b0c02bff72323df24dae929583478d34f8c1
This commit is contained in:
@@ -7,7 +7,7 @@ import cereal.messaging as messaging
|
||||
from common.realtime import sec_since_boot
|
||||
|
||||
|
||||
def can_printer(bus, max_msg, addr):
|
||||
def can_printer(bus, max_msg, addr, ascii_decode):
|
||||
logcan = messaging.sub_sock('can', addr=addr)
|
||||
|
||||
start = sec_since_boot()
|
||||
@@ -24,10 +24,10 @@ def can_printer(bus, max_msg, addr):
|
||||
dd = chr(27) + "[2J"
|
||||
dd += f"{sec_since_boot() - start:5.2f}\n"
|
||||
for addr in sorted(msgs.keys()):
|
||||
a = msgs[addr][-1].decode('ascii', 'backslashreplace')
|
||||
a = f"\"{msgs[addr][-1].decode('ascii', 'backslashreplace')}\"" if ascii_decode else ""
|
||||
x = binascii.hexlify(msgs[addr][-1]).decode('ascii')
|
||||
if max_msg is None or addr < max_msg:
|
||||
dd += "%04X(%4d)(%6d) %s \"%s\"\n" % (addr, addr, len(msgs[addr]), x.ljust(20), a)
|
||||
dd += "%04X(%4d)(%6d) %s %s\n" % (addr, addr, len(msgs[addr]), x.ljust(20), a)
|
||||
print(dd)
|
||||
lp = sec_since_boot()
|
||||
|
||||
@@ -36,8 +36,9 @@ if __name__ == "__main__":
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
|
||||
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("--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)
|
||||
can_printer(args.bus, args.max_msg, args.addr, args.ascii)
|
||||
|
||||
Reference in New Issue
Block a user