Commit 449edbc8 authored by Jean-Marie Favreau's avatar Jean-Marie Favreau
Browse files

First working evrsion

parent 2ac7fefc
#!/usr/bin/env python3
# coding: utf-8
import argparse
from construct import *
import sys
parser = argparse.ArgumentParser(description="Convert RM42 (UKK) binary log files to CSV format.")
parser.add_argument('input', metavar="INPUT", type=str, help='Input file (.dat format)')
parser.add_argument('output', metavar="OUTPUT", type=str, help='Output file (.csv format)')
args = parser.parse_args()
def binToHexUKK(val):
big = int(val / 16)
little = val % 16
return big * 10 + little
input_file = args.input.strip()
output_file= args.output.strip()
print("Input:", input_file)
print("Output:", output_file)
encoding = Int16sl
d_1sec = Struct(
"aaaa" / Int16ub,
"day" / Int8ub,
"month" / Int8ub,
"year" / Int8ub,
"hour" / Int8ub,
"minutes" / Int8ub,
"seconds" / Int8ub,
"entries" / Array(84, Array(3, encoding)))
original_stdout = sys.stdout
with open(input_file, 'rb') as f_input:
with open(output_file, 'w') as f_output:
print("timestamp;X_ax;Y_ax;Z_ax", file=f_output)
while f_input:
try:
result = d_1sec.parse_stream(f_input)
year = 2000 + binToHexUKK(result.year)
month = binToHexUKK(result.month)
day = binToHexUKK(result.day)
hour = binToHexUKK(result.hour)
minutes = binToHexUKK(result.minutes)
seconds = binToHexUKK(result.seconds)
if year != 2000 or month != 0 or day != 0 or hour != 0 or minutes != 0 or seconds != 0:
for entry in result.entries:
entry_csv = ';'.join([str(e) for e in entry])
print('{:02d}/{:02d}/{:04d} {:02d}:{:02d}:{:02d};{:s}'.format(day, month, year, hour, minutes, seconds, entry_csv), file=f_output)
else:
print("skip wrong entry")
except:
print("Skip end of file")
break
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment