diff --git a/scripts/struct_decoder.py b/scripts/struct_decoder.py index 79eb468..e5132db 100644 --- a/scripts/struct_decoder.py +++ b/scripts/struct_decoder.py @@ -1,4 +1,5 @@ import struct +import os """ File for converting binary logs on the Pi into human-readable logs. The format string @@ -8,13 +9,8 @@ format_string = "h6xQ" read_filepath = "./" write_filepath = "./" -# filenames = ["LC1", "LC2", "LC3", "LC4", "LC5", "PT1", "PT2", "PT3", "PT4", "TC1", "TC2", "TC3", "TC4"] -filenames = ["LC1", "PT1", "PT2", "PT3", "PT4", "TC1", "TC2", "TC3"] -cals = {"LC1": (0.4321, -304.38), - # "LC2": (-0.0044 * 2.20462, -2.5306 * 2.20462), - # "LC3": (-0.0043 * 2.20462, 16.128 * 2.20462), - # "LC4": (1, 0), - # "LC5": (1, 0), + +cals = {"LC1": (0.4321, -304.38), "PT1": (0.378, -250.33), "PT2": (-0.2834, 1020.2), "PT3": (-0.3431, 1277.0), @@ -22,15 +18,22 @@ "TC1": (-0.1676, 308.4), "TC2": (0.1611, -250), "TC3": (0.1611, -250), - # "TC4": (0.1611, -250) } +keys = cals.keys() +filenames = [] + +for _, _, names in os.walk(read_filepath): + for file in names: + if any(substring in file for substring in keys) and ("Decoded" not in file): + filenames.append(file) + for i in range(len(filenames)): filename = filenames[i] # mtype = bytes([9 + i]) - with open(read_filepath + filename + '.log', 'rb') as f, open(write_filepath + filename + '_Decoded.log', 'w') as p: + with open(read_filepath + filename, 'rb') as f, open(write_filepath + filename[:-4] + '_Decoded.log', 'w') as p: f.seek(0, 2) file_size = f.tell() @@ -49,6 +52,6 @@ for i in range(256 // 16): d, t = struct.unpack(format_string, bytes(data[i*16:i*16+16])) - cal = cals[filename][0] * d + cals[filename][1] + cal = cals[filename[:3]][0] * d + cals[filename[:3]][1] p.write(str(t) + " " + str(d) + " " + str(cal) + "\n")