2019-09-25 08:50:53 +08:00
|
|
|
#!/usr/bin/env python3
|
2019-09-25 13:33:46 +08:00
|
|
|
|
2017-11-04 10:01:18 +08:00
|
|
|
import csv
|
2023-12-11 03:25:25 +08:00
|
|
|
import time
|
2017-11-04 10:01:18 +08:00
|
|
|
from panda import Panda
|
|
|
|
|
|
|
|
def can_logger():
|
2021-12-07 06:39:28 +08:00
|
|
|
p = Panda()
|
2017-11-05 05:32:24 +08:00
|
|
|
|
|
|
|
try:
|
2019-11-28 03:11:55 +08:00
|
|
|
outputfile = open('output.csv', 'w')
|
2017-11-04 10:01:18 +08:00
|
|
|
csvwriter = csv.writer(outputfile)
|
2020-06-01 16:49:26 +08:00
|
|
|
# Write Header
|
2023-12-11 03:25:25 +08:00
|
|
|
csvwriter.writerow(['Bus', 'MessageID', 'Message', 'MessageLength', 'Time'])
|
2017-11-05 05:32:24 +08:00
|
|
|
print("Writing csv file output.csv. Press Ctrl-C to exit...\n")
|
2017-11-21 14:27:25 +08:00
|
|
|
|
2017-11-05 05:32:24 +08:00
|
|
|
bus0_msg_cnt = 0
|
|
|
|
bus1_msg_cnt = 0
|
|
|
|
bus2_msg_cnt = 0
|
2017-11-21 14:27:25 +08:00
|
|
|
|
2023-12-11 03:25:25 +08:00
|
|
|
start_time = time.time()
|
2017-11-04 10:01:18 +08:00
|
|
|
while True:
|
|
|
|
can_recv = p.can_recv()
|
2017-11-05 05:32:24 +08:00
|
|
|
|
2024-07-31 12:20:48 +08:00
|
|
|
for address, dat, src in can_recv:
|
2023-12-11 03:25:25 +08:00
|
|
|
csvwriter.writerow(
|
|
|
|
[str(src), str(hex(address)), f"0x{dat.hex()}", len(dat), str(time.time() - start_time)])
|
2017-11-21 14:27:25 +08:00
|
|
|
|
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
|
2017-11-21 14:27:25 +08:00
|
|
|
|
2019-11-28 03:11:55 +08:00
|
|
|
print(f"Message Counts... Bus 0: {bus0_msg_cnt} Bus 1: {bus1_msg_cnt} Bus 2: {bus2_msg_cnt}", end='\r')
|
2017-11-04 10:01:18 +08:00
|
|
|
|
|
|
|
except KeyboardInterrupt:
|
2019-11-28 03:11:55 +08:00
|
|
|
print(f"\nNow exiting. Final message Counts... Bus 0: {bus0_msg_cnt} Bus 1: {bus1_msg_cnt} Bus 2: {bus2_msg_cnt}")
|
2017-11-04 10:01:18 +08:00
|
|
|
outputfile.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
can_logger()
|