@@ -89,7 +89,7 @@ def mean(nums):
8989 if len (t ) != 0 :
9090 x = ord (t )
9191 if x == 64 : # 64(@) is start of garmin g3x GPS sentence.
92- msg = self .ser .read ( 56 )
92+ msg = self .ser .readline ( )
9393 if (isinstance (msg ,str )): msg = msg .encode () # if read from file then convert to bytes
9494 aircraft .msg_last = msg
9595 if len (msg ) == 56 :
@@ -153,7 +153,7 @@ def mean(nums):
153153 SentID = self .ser .read (1 ) # get message id
154154 if (not isinstance (SentID ,str )): SentID = SentID .decode ('utf-8' )
155155 if SentID == "1" : # atittude/air data message
156- msg = self .ser .read ( 57 )
156+ msg = self .ser .readline ( )
157157 aircraft .msg_last = msg
158158 if len (msg ) == 57 :
159159 if (isinstance (msg ,str )): msg = msg .encode () # if read from file then convert to bytes
@@ -204,12 +204,43 @@ def mean(nums):
204204 else :
205205 aircraft .msg_bad += 1
206206 aircraft .debug2 = "bad air data - unkown ver"
207-
207+ elif len (msg ) == 45 :
208+ if (isinstance (msg ,str )): msg = msg .encode () # if read from file then convert to bytes
209+ SentVer , UTCHour , UTCMin , UTCSec , UTCSecFrac , Pitch , Roll , Heading , Airspeed , PressAlt , VertSpeed , OAT , AltSet , Checksum , CRLF = struct .unpack (
210+ "c2s2s2s2s4s5s3s4s6s4s3s3s2s2s" , msg
211+ )
212+ if int (SentVer ) == 1 and CRLF [0 ] == self .EOL :
213+ with suppress (ValueError ):
214+ aircraft .gps .UTCHour = int (UTCHour )
215+ aircraft .gps .UTCMin = int (UTCMin )
216+ aircraft .gps .UTCSec = int (UTCSec )
217+ aircraft .roll = int (Roll ) * 0.1
218+ aircraft .pitch = int (Pitch ) * 0.1
219+ aircraft .ias = int (Airspeed ) * 0.115078 # convert knots to mph * 0.1
220+ aircraft .PALT = int (PressAlt )
221+ aircraft .oat = (int (OAT ) * 1.8 ) + 32 # c to f
222+ if len (self .readings1 ) == self .max_samples1 :
223+ self .readings1 .pop (0 )
224+ aircraft .mag_head = int (Heading )
225+ aircraft .baro = (int (AltSet ) + 2750.0 ) / 100.0
226+ aircraft .baro_diff = aircraft .baro - 29.9213
227+ aircraft .alt = int (
228+ int (PressAlt ) + (aircraft .baro_diff / 0.00108 )
229+ ) # 0.00108 of inches of mercury change per foot.
230+ aircraft .BALT = aircraft .alt
231+ aircraft .vsi = int (VertSpeed ) * 10 # vertical speed in fpm
232+ aircraft .msg_count += 1
233+ if (self .isPlaybackMode ): # if playback mode then add a delay. Else reading a file is way to fast.
234+ time .sleep (0.08 )
235+ if self .output_logFile != None :
236+ Input .addToLog (self ,self .output_logFile ,bytes ([61 ,ord (SentID )]))
237+ Input .addToLog (self ,self .output_logFile ,msg )
238+ return aircraft
208239 else :
209240 aircraft .msg_bad += 1
210241 aircraft .debug2 = "bad air data - wrong len"
211242 elif SentID == "2" :
212- msg = self .ser .read ( 40 )
243+ msg = self .ser .readline ( )
213244 aircraft .msg_last = msg
214245 if len (msg ) == 40 :
215246 if (isinstance (msg ,str )): msg = msg .encode () # if read from file then convert to bytes
@@ -241,7 +272,7 @@ def mean(nums):
241272 else :
242273 aircraft .msg_bad += 1
243274 elif SentID == "7" : # GPS AGL data message
244- msg = self .ser .read ( 20 )
275+ msg = self .ser .readline ( )
245276 if (isinstance (msg ,str )): msg = msg .encode () # if read from file then convert to bytes
246277 aircraft .msg_last = msg
247278 if len (msg ) == 20 :
0 commit comments