Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseData.py
More file actions
Latest commit
140 lines (121 loc) · 4.8 KB
/
Copy pathparseData.py
File metadata and controls
140 lines (121 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
importserial
importtime
importbinascii
importcsv
order='big'
classAvionicsData:
def__init__(self):
self.imu= [0] *9
self.bar= [0] *2
self.gps= [0] *4
self.oxi=-1
self.cmb=-1
self.phs=-1
self.upperVnt=-1
self.injValve=-1
self.lowerVnt=-1
def__str__(self):
phases= ["NA", "PRELAUNCH", "ARM", "BURN", "COAST", "DROGUE_DESCENT", "MAIN_DESCENT", "POSTLAUNCH",
"ABORT_COMMAND_RECEIVED", "ABORT_COMMUNICATION_ERROR", "ABORT_OXIDIZER_PRESSURE", "ABORT_UNSPECIFIED_REASON"]
valveStatus= ["NA","Closed", "Open"]
string="IMU - ACCEL:\t\t"+str(self.imu[0:3])+" mg"+"\n"
string+="IMU - GYRO:\t\t"+str(self.imu[3:6])+" mdps"+"\n"
string+="BAR - PRESS:\t\t"+str(self.bar[0]/100) +" mbar"+"\n"
string+="BAR - TEMP:\t\t"+str(self.bar[1]/100)+" degrees C"+"\n"
string+="OXI - P:\t\t"+str(self.oxi/1000)+" psi"+"\n"
string+="CMB - P:\t\t"+str(self.cmb/1000)+" psi"+"\n"
string+="PHS - PHASE:\t\t"+str(phases[self.phs+1])+"\n"
string+="Inj Valve:\t\t"+str(valveStatus[self.injValve+1])+"\n"
string+="Lower Vent:\t\t"+str(valveStatus[self.lowerVnt+1])+"\n"
withopen('fligthData.csv', 'a') ascsvfile:
spamwriter=csv.writer(csvfile, delimiter=',', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow([str(self.imu[0]), str(self.imu[1]), str(self.imu[2]), str(self.imu[3]), str(self.imu[4]), str(self.imu[5]), str(self.bar[0]), str(self.bar[1])])
returnstring
deftwos_complement(hexstr,bits):
value=int(hexstr,16)
ifvalue& (1<< (bits-1)):
value-=1<<bits
returnvalue
defdisconnect(ser):
ser.close()
time.sleep(1)
returnNone
defreadSerial(ser,data):
line=ser.read(256).hex()
i=0
print(line)
while(i<len(line)):
# IMU Data
if((line[i:i+8]=='31313131') and (len(line)-i>=81)):
if(line[i+80:i+82]=='00'):
print(line[i:i+82])
data.imu[0] =twos_complement(line[i+8:i+16], 32)
data.imu[1] =twos_complement(line[i+16:i+24], 32)
data.imu[2] =twos_complement(line[i+24:i+32], 32)
data.imu[3] =twos_complement(line[i+32:i+40], 32)
data.imu[4] =twos_complement(line[i+40:i+48], 32)
data.imu[5] =twos_complement(line[i+48:i+56], 32)
i+=81
else: i+=1
# Barometer Data
elif((line[i:i+8])=='32323232'andlen(line)-i>=25):
if(line[i+24:i+26]=='00'):
print(line[i:i+26])
data.bar[0] =twos_complement(line[i+8:i+16], 32)
data.bar[1] =twos_complement(line[i+16:i+24], 32)
i+=25
else:
i+=1
#GPS Data
elif((line[i:i+8]=='33333333') and (len(line)-i>=41)):
if(line[i+40:i+42]=='00'):
print(line[i:i+42])
data.gps[0] =twos_complement(line[i+8:i+16], 32)
data.gps[1] =twos_complement(line[i+16:i+24], 32)
data.gps[2] =twos_complement(line[i+24:i+32], 32)
data.gps[3] =twos_complement(line[i+32:i+40], 32)
i+=41
else:
i+=1
#Oxidizer Tank Pressure
elif((line[i:i+8]=='34343434') and (len(line)-i>=17)):
if(line[i+16:i+18]=='00'):
data.oxi=twos_complement(line[i+8:i+16], 32)
i+=17
else: i+=1
#Combustion Chamber Pressure
elif((line[i:i+8]=='35353535') and (len(line)-i>=17)):
if(line[i+16:i+18]=='00'):
data.cmb=twos_complement(line[i+8:i+16], 32)
i+=17
else: i+=1
#Flight Phase
elif((line[i:i+8]=='36363636') and (len(line)-i>=13)):
if(line[i+10:i+12]=='00'):
data.phs=int(line[i+8:i+10], 16)
i+=12
else: i+=1
#Injection Valve Status
elif((line[i:i+8]=='38383838') and (len(line)-i>=13)):
if(line[i+10:i+12]=='00'):
data.injValve=int(line[i+8:i+10], 16)
i+=12
else: i+=1
#Lower Vent Valve
elif((line[i:i+8]=='39393939') and (len(line)-i>=13)):
if(line[i+10:i+12]=='00'):
data.lowerVnt=int(line[i+8:i+10], 16)
i+=12
else: i+=1
#No packet detected
else: i+=1
print(data)
if__name__=="__main__":
ser=None
data=AvionicsData()
while(True):
port=input('Enter a Serial Port to connect to:') #Linux: /dev/ttyUSBx, Windows: COMx
ser=serial.Serial(port, 9600, timeout=0)
while(ser!=None):
time.sleep(1)
readSerial(ser, data)