Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

Betterlogging #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions scripts/struct_decoder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import struct
import os

"""
File for converting binary logs on the Pi into human-readable logs. The format string
Expand All @@ -8,29 +9,31 @@
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),
"PT4": (-0.3178, 1108.7),
"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()
Expand All @@ -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")