]> git.gag.com Git - fw/quantimotor/commitdiff
first rought cut at making a CSV file after each test
authorBdale Garbee <bdale@gag.com>
Tue, 27 May 2025 23:16:59 +0000 (17:16 -0600)
committerBdale Garbee <bdale@gag.com>
Tue, 27 May 2025 23:16:59 +0000 (17:16 -0600)
ui/app.py

index 47b676cb376f921560ed58d9f774dc28406800b1..9afe88240b56a182cc1661594768851a039c6469 100755 (executable)
--- 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