Skip to content

Commit 365c2fd

Browse files
Improve Error Processing, Fix Bug
Improved error processing of values that could be missing in different configurations. Fixed a Bug where "aircraft" was being returned prematurely
1 parent dbba06d commit 365c2fd

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

lib/inputs/serial_g3x.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def mean(nums):
126126
aircraft.gps.LonDeg,
127127
aircraft.gps.LonMin,
128128
)
129-
# aircraft.gndspeed = _utils.gndspeed(EWVelmag, NSVelmag) * 1.15078 # convert back to mph
129+
#aircraft.gndspeed = _utils.gndspeed(EWVelmag, NSVelmag) * 1.15078 # convert back to mph
130130
aircraft.gndtrack = _utils.gndtrack(
131131
EWVelDir, EWVelmag, NSVelDir, NSVelmag
132132
)
@@ -141,16 +141,15 @@ def mean(nums):
141141
if self.output_logFile != None:
142142
Input.addToLog(self,self.output_logFile,bytes([64]))
143143
Input.addToLog(self,self.output_logFile,msg)
144-
145144
aircraft.gps.msg_count += 1
145+
return aircraft
146146
else:
147147
aircraft.gps.msg_bad += 1
148148

149149
else:
150150
if (self.isPlaybackMode ): # if no bytes read and in playback mode. then reset the file pointer to the start of the file.
151151
self.ser.seek(0)
152-
return aircraft
153-
152+
154153
SentID = self.ser.read(1) # get message id
155154
if(not isinstance(SentID,str)): SentID = SentID.decode('utf-8')
156155
if SentID == "1": # atittude/air data message
@@ -201,6 +200,7 @@ def mean(nums):
201200
if self.output_logFile != None:
202201
Input.addToLog(self,self.output_logFile,bytes([61,ord(SentID)]))
203202
Input.addToLog(self,self.output_logFile,msg)
203+
return aircraft
204204
else:
205205
aircraft.msg_bad += 1
206206
aircraft.debug2 = "bad air data - unkown ver"
@@ -220,17 +220,22 @@ def mean(nums):
220220
while suppress(ValueError):
221221
aircraft.DA = int(DAlt)
222222
aircraft.tas = int(TAS) * 0.115078 # convert knots to mph * 0.1
223-
aircraft.nav.HeadBug = int(HeadingSel)
224-
aircraft.nav.AltBug = int(AltSel)
225-
aircraft.nav.ASIBug = int(AirspeedSel) * 0.115078 # convert knots to mph * 0.1
226-
aircraft.nav.VSIBug = int(VSSel) * 10 # multiply up to hundreds of feet
223+
if(not HeadingSel.decode('utf-8') == ''):
224+
aircraft.nav.HeadBug = int(HeadingSel)
225+
if(not AltSel.decode('utf-8') == ''):
226+
aircraft.nav.AltBug = int(AltSel)
227+
if(not AirspeedSel.decode('utf-8') == '____'):
228+
aircraft.nav.ASIBug = int(AirspeedSel) * 0.115078 # convert knots to mph * 0.1
229+
if(not VSSel.decode('utf-8') == '____'):
230+
aircraft.nav.VSIBug = int(VSSel) * 10 # multiply up to hundreds of feet
227231
aircraft.msg_count += 1
228232
if (self.isPlaybackMode): # if playback mode then add a delay. Else reading a file is way to fast.
229233
time.sleep(0.08)
230234

231235
if self.output_logFile != None:
232236
Input.addToLog(self,self.output_logFile,bytes([61,ord(SentID)]))
233237
Input.addToLog(self,self.output_logFile,msg)
238+
return aircraft
234239
else:
235240
aircraft.msg_bad += 1
236241
else:
@@ -252,6 +257,7 @@ def mean(nums):
252257
if self.output_logFile != None:
253258
Input.addToLog(self,self.output_logFile,bytes([61,ord(SentID)]))
254259
Input.addToLog(self,self.output_logFile,msg)
260+
return aircraft
255261
else:
256262
aircraft.msg_bad += 1
257263
aircraft.debug1 = "bad GPS AGL data - unkown ver"
@@ -269,8 +275,10 @@ def mean(nums):
269275
self.ser.flushInput() # flush the serial after every message else we see delays
270276
return aircraft
271277

272-
except:
278+
except Exception as e:
273279
print("G3X serial exception")
280+
print(type(e))
281+
print(e)
274282
aircraft.errorFoundNeedToExit = True
275283

276284
return aircraft

0 commit comments

Comments
 (0)