From 2a8e0e39cb10b6bae7843f787db396f7eea00286 Mon Sep 17 00:00:00 2001 From: amyloid8 Date: Mon, 17 Oct 2022 12:37:02 -0500 Subject: [PATCH 1/3] be better --- scripts/struct_decoder.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/struct_decoder.py b/scripts/struct_decoder.py index 79eb468..1a72941 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 @@ -9,7 +10,7 @@ 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"] +# 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), @@ -25,12 +26,20 @@ # "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): + 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 +58,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") From d94b0adfbeaabc9e1e5376ee53079d6e20b2b988 Mon Sep 17 00:00:00 2001 From: amyloid8 Date: Mon, 17 Oct 2022 12:38:25 -0500 Subject: [PATCH 2/3] cleanup --- scripts/struct_decoder.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/struct_decoder.py b/scripts/struct_decoder.py index 1a72941..2e2210a 100644 --- a/scripts/struct_decoder.py +++ b/scripts/struct_decoder.py @@ -9,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), @@ -23,7 +18,6 @@ "TC1": (-0.1676, 308.4), "TC2": (0.1611, -250), "TC3": (0.1611, -250), - # "TC4": (0.1611, -250) } keys = cals.keys() From 55b740c1647f4edc251e88bff2c3f3d88a0907e3 Mon Sep 17 00:00:00 2001 From: amyloid8 Date: Mon, 17 Oct 2022 12:48:09 -0500 Subject: [PATCH 3/3] does not read decoded files --- scripts/struct_decoder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/struct_decoder.py b/scripts/struct_decoder.py index 2e2210a..e5132db 100644 --- a/scripts/struct_decoder.py +++ b/scripts/struct_decoder.py @@ -25,7 +25,7 @@ for _, _, names in os.walk(read_filepath): for file in names: - if any(substring in file for substring in keys): + if any(substring in file for substring in keys) and ("Decoded" not in file): filenames.append(file)