Skip to content

Instantly share code, notes, and snippets.

@dmezh
Created April 23, 2023 03:27
Show Gist options
  • Save dmezh/3eef215529d603928fe4fa091dfe7ccb to your computer and use it in GitHub Desktop.
Save dmezh/3eef215529d603928fe4fa091dfe7ccb to your computer and use it in GitHub Desktop.
Convert busmaster log files to candump-style logs
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