Created
April 23, 2023 03:27
-
-
Save dmezh/3eef215529d603928fe4fa091dfe7ccb to your computer and use it in GitHub Desktop.
Convert busmaster log files to candump-style logs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from datetime import datetime | |
converted = [] | |
with open(sys.argv[1]) as f: | |
dump = f.readlines() | |
start_time = None | |
today_time = datetime.now() | |
for line in dump: | |
if line.startswith('***'): | |
continue | |
line = line.split() | |
timestamp = datetime.strptime(line[0], "%H:%M:%S:%f") | |
if start_time is None: | |
start_time = timestamp | |
epoch_timestamp = today_time + (timestamp - start_time) | |
id = int(line[3], 0) | |
data = line[6:] | |
converted.append(f"({epoch_timestamp.timestamp()}) can {id:03X}#{''.join(data)}\n") | |
with open(sys.argv[2], 'w') as f: | |
f.writelines(converted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment