2017-11-04 10:01:18 +08:00
|
|
|
#!/usr/bin/env python
|
2017-11-05 05:32:24 +08:00
|
|
|
from __future__ import print_function
|
2017-11-04 10:01:18 +08:00
|
|
|
import binascii
|
|
|
|
import csv
|
2017-11-05 05:32:24 +08:00
|
|
|
import sys
|
2017-11-04 10:01:18 +08:00
|
|
|
from panda import Panda
|
|
|
|
|
|
|
|
def can_logger():
|
|
|
|
|
|
|
|
try:
|
2017-11-05 05:32:24 +08:00
|
|
|
print("Trying to connect to Panda over USB...")
|
2017-11-04 10:01:18 +08:00
|
|
|
p = Panda()
|
2017-11-05 05:32:24 +08:00
|
|
|
|
|
|
|
except AssertionError:
|
2017-11-05 06:37:17 +08:00
|
|
|
print("USB connection failed. Trying WiFi...")
|
2017-11-05 05:32:24 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
p = Panda("WIFI")
|
|
|
|
except:
|
|
|
|
print("WiFi connection timed out. Please make sure your Panda is connected and try again.")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
try:
|
2017-11-04 10:01:18 +08:00
|
|
|
outputfile = open('output.csv', 'wb')
|
|
|
|
csvwriter = csv.writer(outputfile)
|
|
|
|
#Write Header
|
2017-11-05 06:12:31 +08:00
|
|
|
csvwriter.writerow(['Bus', 'MessageID', 'Message', 'MessageLength'])
|
2017-11-05 05:32:24 +08:00
|
|
|
print("Writing csv file output.csv. Press Ctrl-C to exit...\n")
|
|
|
|
|
|
|
|
bus0_msg_cnt = 0
|
|
|
|
bus1_msg_cnt = 0
|
|
|
|
bus2_msg_cnt = 0
|
|
|
|
|
2017-11-04 10:01:18 +08:00
|
|
|
while True:
|
|
|
|
can_recv = p.can_recv()
|
2017-11-05 05:32:24 +08:00
|
|
|
|
2017-11-04 10:01:18 +08:00
|
|
|
for address, _, dat, src in can_recv:
|
2017-11-05 06:37:17 +08:00
|
|
|
csvwriter.writerow([str(src), str(hex(address)), "0x" + binascii.hexlify(dat), len(dat)])
|
2017-11-05 05:32:24 +08:00
|
|
|
|
|
|
|
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')
|
2017-11-04 10:01:18 +08:00
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
2017-11-05 05:32:24 +08:00
|
|
|
print("\nNow exiting. Final message Counts... Bus 0: " + str(bus0_msg_cnt) + " Bus 1: " + str(bus1_msg_cnt) + " Bus 2: " + str(bus2_msg_cnt))
|
2017-11-04 10:01:18 +08:00
|
|
|
outputfile.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
can_logger()
|