CPR decoder: Keep a separate list for sfc and air positions to keep them from stepping on each other.

This commit is contained in:
Nick Foster 2012-10-17 09:24:15 -07:00
parent 0b30db353d
commit a3f2dec1f9

View File

@ -185,6 +185,8 @@ class cpr_decoder:
self.my_location = my_location self.my_location = my_location
self.evenlist = {} self.evenlist = {}
self.oddlist = {} self.oddlist = {}
self.evenlist_sfc = {}
self.oddlist_sfc = {}
def set_location(new_location): def set_location(new_location):
self.my_location = new_location self.my_location = new_location
@ -194,23 +196,34 @@ class cpr_decoder:
for key, item in poslist.items(): for key, item in poslist.items():
if time.time() - item[2] > 10: if time.time() - item[2] > 10:
del poslist[key] del poslist[key]
for poslist in [self.evenlist_sfc, self.oddlist_sfc]:
for key, item in poslist.items():
if time.time() - item[2] > 25:
del poslist[key]
def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface): def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface):
if surface:
oddlist = self.oddlist_sfc
evenlist = self.evenlist_sfc
else:
oddlist = self.oddlist
evenlist = self.evenlist
#add the info to the position reports list for global decoding #add the info to the position reports list for global decoding
if cpr_format==1: if cpr_format==1:
self.oddlist[icao24] = [encoded_lat, encoded_lon, time.time()] oddlist[icao24] = [encoded_lat, encoded_lon, time.time()]
else: else:
self.evenlist[icao24] = [encoded_lat, encoded_lon, time.time()] evenlist[icao24] = [encoded_lat, encoded_lon, time.time()]
[decoded_lat, decoded_lon] = [None, None] [decoded_lat, decoded_lon] = [None, None]
#okay, let's traverse the lists and weed out those entries that are older than 10 seconds #okay, let's traverse the lists and weed out those entries that are older than 10 seconds
self.weed_poslists() self.weed_poslists()
if (icao24 in self.evenlist) \ if (icao24 in evenlist) \
and (icao24 in self.oddlist): and (icao24 in oddlist):
newer = (self.oddlist[icao24][2] - self.evenlist[icao24][2]) > 0 #figure out which report is newer newer = (oddlist[icao24][2] - 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], self.my_location, newer, surface) #do a global decode [decoded_lat, decoded_lon] = cpr_resolve_global(evenlist[icao24][0:2], oddlist[icao24][0:2], self.my_location, newer, surface) #do a global decode
else: else:
raise CPRNoPositionError raise CPRNoPositionError