2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-09-25 13:33:46 +08:00
|
|
|
|
2017-05-28 03:31:29 +08:00
|
|
|
import os
|
2017-06-14 09:50:47 +08:00
|
|
|
import sys
|
2017-05-28 03:31:29 +08:00
|
|
|
import time
|
|
|
|
from collections import defaultdict
|
2018-03-05 03:52:53 +08:00
|
|
|
import binascii
|
2017-06-14 09:50:47 +08:00
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
|
|
|
|
from panda import Panda
|
2017-05-28 03:31:29 +08:00
|
|
|
|
|
|
|
# fake
|
|
|
|
def sec_since_boot():
|
|
|
|
return time.time()
|
|
|
|
|
|
|
|
def can_printer():
|
|
|
|
p = Panda()
|
2018-03-10 06:02:00 +08:00
|
|
|
p.set_safety_mode(0x1337)
|
2017-05-28 03:31:29 +08:00
|
|
|
|
|
|
|
start = sec_since_boot()
|
|
|
|
lp = sec_since_boot()
|
|
|
|
msgs = defaultdict(list)
|
|
|
|
canbus = int(os.getenv("CAN", 0))
|
2017-06-14 09:50:47 +08:00
|
|
|
while True:
|
2017-05-28 03:31:29 +08:00
|
|
|
can_recv = p.can_recv()
|
|
|
|
for address, _, dat, src in can_recv:
|
|
|
|
if src == canbus:
|
|
|
|
msgs[address].append(dat)
|
|
|
|
|
|
|
|
if sec_since_boot() - lp > 0.1:
|
|
|
|
dd = chr(27) + "[2J"
|
|
|
|
dd += "%5.2f\n" % (sec_since_boot() - start)
|
2019-09-25 13:33:46 +08:00
|
|
|
for k,v in sorted(zip(list(msgs.keys()), [binascii.hexlify(x[-1]) for x in list(msgs.values())])):
|
2017-05-28 03:31:29 +08:00
|
|
|
dd += "%s(%6d) %s\n" % ("%04X(%4d)" % (k,k),len(msgs[k]), v)
|
2017-06-14 09:50:47 +08:00
|
|
|
print(dd)
|
2017-05-28 03:31:29 +08:00
|
|
|
lp = sec_since_boot()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
can_printer()
|