@@ -172,6 +172,7 @@ def set_mult_ids(self, mult_ids, mult_lookup):
172172 if mult_ids [i ] in mult_lookup :
173173 unitmult = mult_lookup [mult_ids [i ]]
174174 # Combine the multipler and unit to derive the real unit
175+ self .msg_mults [i ] = unitmult
175176 if unitmult in MULT_TO_PREFIX :
176177 self .units [i ] = MULT_TO_PREFIX [unitmult ]+ self .units [i ]
177178 else :
@@ -293,6 +294,46 @@ def __str__(self):
293294 ret = ret [:- 2 ]
294295 return ret + '}'
295296
297+ def get_multiplied_field_value (self , field ):
298+ v = getattr (self , field )
299+ if getattr (self , "_apply_multiplier" , False ) is True :
300+ return v
301+ # not applied already...
302+ i = self .fmt .colhash [field ]
303+ mult = self .fmt .msg_mults [i ]
304+ if not mult :
305+ return v
306+ # For reasons relating to floating point accuracy, you get a more
307+ # accurate result by dividing by 1e2 or 1e7 than multiplying by
308+ # 1e-2 or 1e-7
309+ if mult > 0.0 and mult < 1.0 :
310+ divisor = 1 / mult
311+ return v / divisor
312+
313+ return v * mult
314+
315+ def get_latitude (self ):
316+ for i in 'Lat' , 'lat' :
317+ try :
318+ return self .get_multiplied_field_value (i )
319+ except AttributeError :
320+ continue
321+ raise AttributeError ("No latitude found" )
322+
323+ def get_longitude (self ):
324+ for i in 'Lon' , 'Lng' , 'lon' , 'lng' :
325+ try :
326+ return self .get_multiplied_field_value (i )
327+ except AttributeError :
328+ continue
329+ raise AttributeError ("No longitude found" )
330+
331+ def get_latlon (self ):
332+ '''return a mavutil.location object for the first location present in
333+ the object'''
334+ latlon = (self .get_latitude (), self .get_longitude ())
335+ return latlon
336+
296337 def dump_verbose_bitmask (self , f , c , val , field_metadata ):
297338 try :
298339 try :
0 commit comments