From 3c8c60f57fb691028f868c159713db90bb219482 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sun, 14 Oct 2012 17:56:01 -0700 Subject: [PATCH] Removing emitter-centered local decoding from the CPR parser. Using only global decoding. --- python/cpr.py | 27 +++++---------------------- python/msprint.py | 4 +++- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/python/cpr.py b/python/cpr.py index 5115bf5..1d647dd 100755 --- a/python/cpr.py +++ b/python/cpr.py @@ -172,7 +172,6 @@ def range_bearing(loc_a, loc_b): class cpr_decoder: def __init__(self, my_location): self.my_location = my_location - self.lkplist = {} self.evenlist = {} self.oddlist = {} @@ -180,9 +179,9 @@ class cpr_decoder: self.my_location = new_location def weed_poslists(self): - for poslist in [self.lkplist, self.evenlist, self.oddlist]: + for poslist in [self.evenlist, self.oddlist]: for key, item in poslist.items(): - if time.time() - item[2] > 900: + if time.time() - item[2] > 10: del poslist[key] def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface): @@ -194,30 +193,14 @@ class cpr_decoder: [decoded_lat, decoded_lon] = [None, None] - #okay, let's traverse the lists and weed out those entries that are older than 15 minutes, as they're unlikely to be useful. + #okay, let's traverse the lists and weed out those entries that are older than 10 seconds self.weed_poslists() - if icao24 in self.lkplist: - #do emitter-centered local decoding - [decoded_lat, decoded_lon] = cpr_resolve_local(self.lkplist[icao24][0:2], [encoded_lat, encoded_lon], cpr_format, surface) - self.lkplist[icao24] = [decoded_lat, decoded_lon, time.time()] #update the local position for next time - - elif (icao24 in self.evenlist) \ - and (icao24 in self.oddlist) \ - and (abs(self.evenlist[icao24][2] - self.oddlist[icao24][2]) < 10) \ - and (surface == 0): + if (icao24 in self.evenlist) \ + and (icao24 in self.oddlist): newer = (self.oddlist[icao24][2] - self.evenlist[icao24][2]) > 0 #figure out which report is newer [decoded_lat, decoded_lon] = cpr_resolve_global(self.evenlist[icao24][0:2], self.oddlist[icao24][0:2], newer, surface) #do a global decode - self.lkplist[icao24] = [decoded_lat, decoded_lon, time.time()] - #so we really can't guarantee that local decoding will work unless you are POSITIVE that you can't hear more than 180nm out. - #this will USUALLY work, but you can't guarantee it! - #elif surface == 1 and self.my_location is not None: - # [local_lat, local_lon] = cpr_resolve_local(self.my_location, [encoded_lat, encoded_lon], cpr_format, surface) #try local decoding - # [rnge, bearing] = range_bearing(self.my_location, [local_lat, local_lon]) - # if rnge < validrange: #if the local decoding can be guaranteed valid - # self.lkplist[icao24] = [local_lat, local_lon, time.time()] #update the local position for next time - # [decoded_lat, decoded_lon] = [local_lat, local_lon] else: raise CPRNoPositionError diff --git a/python/msprint.py b/python/msprint.py index d613fa4..2349c35 100644 --- a/python/msprint.py +++ b/python/msprint.py @@ -69,7 +69,9 @@ class output_print(air_modes.parse): pass def output(self, msg): - print self.parse(msg) + parsed = self.parse(msg) + if parsed is not None: + print self.parse(msg) def print0(self, shortdata, ecc): [vs, cc, sl, ri, altitude] = self.parse0(shortdata)