import cherrypy
from cherrypy.lib.static import serve_file
+import csv
import gpiod
from gpiod.line import Direction, Value
import iio
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
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