-
Notifications
You must be signed in to change notification settings - Fork 0
/
can_logger.py
executable file
·54 lines (42 loc) · 1.46 KB
/
can_logger.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
from __future__ import print_function
import binascii
import csv
import sys
from panda import Panda
def can_logger():
try:
print("Trying to connect to Panda over USB...")
p = Panda()
except AssertionError:
print("USB connection failed. Trying WiFi...")
try:
p = Panda("WIFI")
except:
print("WiFi connection timed out. Please make sure your Panda is connected and try again.")
sys.exit(0)
try:
outputfile = open('output.csv', 'wb')
csvwriter = csv.writer(outputfile)
#Write Header
csvwriter.writerow(['Bus', 'MessageID', 'Message', 'MessageLength'])
print("Writing csv file output.csv. Press Ctrl-C to exit...\n")
bus0_msg_cnt = 0
bus1_msg_cnt = 0
bus2_msg_cnt = 0
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:
csvwriter.writerow([str(src), str(hex(address)), "0x" + binascii.hexlify(dat), len(dat)])
if src == 0:
bus0_msg_cnt += 1
elif src == 1:
bus1_msg_cnt += 1
elif src == 2:
bus2_msg_cnt += 1
print("Message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt), end='\r')
except KeyboardInterrupt:
print("\nNow exiting. Final message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt))
outputfile.close()
if __name__ == "__main__":
can_logger()