From 9f180a28e54b564546c92cc98ebf6492b04232a7 Mon Sep 17 00:00:00 2001 From: Bdale Garbee Date: Tue, 27 May 2025 17:16:59 -0600 Subject: [PATCH] first rought cut at making a CSV file after each test --- ui/app.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ui/app.py b/ui/app.py index 47b676c..9afe882 100755 --- a/ui/app.py +++ b/ui/app.py @@ -6,6 +6,7 @@ import cherrypy from cherrypy.lib.static import serve_file +import csv import gpiod from gpiod.line import Direction, Value import iio @@ -331,6 +332,7 @@ def runatest(): def endatest(): global loggertask global pyrotask + global test_path cherrypy.log("setting shutdown_flag for each thread") # stop logging data by telling the thread to exit @@ -346,6 +348,26 @@ def endatest(): os.system(shlex.quote("echo 0 > /sys/bus/iio/devices/iio:device0/buffer0/enable")) status = "idle" + # post-process the data we just collected + rawfile_path = test_path + "/rawdata" + csvfile_path = test_path + "/data.csv" + with open(rawfile_path, 'rb') as rawfile: + with open(csvfile_path, 'w', newline='') as csvfile: + csvwriter = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + csvwriter.writerow(['Pressure', 'Thrust', 'Pyro Voltage', 'Battery Voltage', + 'Analog 4', 'Analog 5', 'Analog 6', 'Analog 7']) + rawdata = bytearray(rawfile.read()) + cherrypy.log('read %d bytes of rawdata' % len(rawdata)) + for i in range(0, len(rawdata), 16): + value0 = rawdata[i+1] * 256 + rawdata[i] + value1 = rawdata[i+3] * 256 + rawdata[i+2] + value2 = rawdata[i+5] * 256 + rawdata[i+4] + value3 = rawdata[i+7] * 256 + rawdata[i+6] + value4 = rawdata[i+9] * 256 + rawdata[i+8] + value5 = rawdata[i+11] * 256 + rawdata[i+10] + value6 = rawdata[i+13] * 256 + rawdata[i+12] + value7 = rawdata[i+15] * 256 + rawdata[i+14] + csvwriter.writerow([value0, value1, value2, value3, value4, value5, value6, value7]) if __name__ == '__main__': # initialize hardware -- 2.47.2