Fix your laziness in breaking the CPR parser. Still don't like how KMLgen is done, needs to be consolidated so all db work is in one file.

This commit is contained in:
Nick Foster 2012-02-25 16:50:15 -08:00
parent 622249ba5b
commit c16886c4c1
3 changed files with 17 additions and 14 deletions

View File

@ -189,9 +189,9 @@ def range_bearing(loc_a, loc_b):
class cpr_decoder: class cpr_decoder:
def __init__(self, my_location): def __init__(self, my_location):
self.my_location = my_location self.my_location = my_location
self.lkplist = [] self.lkplist = {}
self.evenlist = [] self.evenlist = {}
self.oddlist = [] self.oddlist = {}
def set_location(new_location): def set_location(new_location):
self.my_location = new_location self.my_location = new_location
@ -202,13 +202,13 @@ class cpr_decoder:
if time.time() - item[2] > 900: if time.time() - item[2] > 900:
del poslist[key] del poslist[key]
def decode(icao24, encoded_lat, encoded_lon, cpr_format, surface): def decode(self, icao24, encoded_lat, encoded_lon, cpr_format, surface):
#def cpr_decode(my_location, icao24, encoded_lat, encoded_lon, cpr_format, evenlist, oddlist, lkplist, surface): #def cpr_decode(my_location, icao24, encoded_lat, encoded_lon, cpr_format, evenlist, oddlist, lkplist, surface):
#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:
oddlist[icao24] = [encoded_lat, encoded_lon, time.time()] self.oddlist[icao24] = [encoded_lat, encoded_lon, time.time()]
else: else:
evenlist[icao24] = [encoded_lat, encoded_lon, time.time()] self.evenlist[icao24] = [encoded_lat, encoded_lon, time.time()]
[decoded_lat, decoded_lon] = [None, None] [decoded_lat, decoded_lon] = [None, None]

View File

@ -38,12 +38,15 @@ class modes_kml(threading.Thread):
def run(self): def run(self):
while self.done is False: while self.done is False:
self.output() self.write()
time.sleep(self._timeout) time.sleep(self._timeout)
self.done = True self.done = True
def output(self): def output(self, string):
self._sqlobj.insert(string)
def write(self):
self._db = sqlite3.connect(self._dbname) self._db = sqlite3.connect(self._dbname)
kmlstr = self.genkml() kmlstr = self.genkml()
if kmlstr is not None: if kmlstr is not None:

View File

@ -23,13 +23,13 @@
import time, os, sys import time, os, sys
from string import split, join from string import split, join
from altitude import decode_alt from altitude import decode_alt
from cpr import cpr_decode from cpr import cpr_decoder
import math import math
class modes_parse: class modes_parse:
def __init__(self, mypos): def __init__(self, mypos):
self.my_location = mypos self.my_location = mypos
self.cpr_decoder = cpr_decoder(self.my_location) self.cpr = cpr_decoder(self.my_location)
def parse0(self, shortdata, parity, ecc): def parse0(self, shortdata, parity, ecc):
# shortdata = long(shortdata, 16) # shortdata = long(shortdata, 16)
@ -160,12 +160,12 @@ class modes_parse:
altitude = decode_alt(enc_alt, False) altitude = decode_alt(enc_alt, False)
[decoded_lat, decoded_lon, rnge, bearing] = cpr_decoder.decode(icao24, encoded_lat, encoded_lon, cpr_format, 0) [decoded_lat, decoded_lon, rnge, bearing] = self.cpr.decode(icao24, encoded_lat, encoded_lon, cpr_format, 0)
return [altitude, decoded_lat, decoded_lon, rnge, bearing] return [altitude, decoded_lat, decoded_lon, rnge, bearing]
#welp turns out it looks like there's only 17 bits in the BDS0,6 ground packet after all. fuck. #welp turns out it looks like there's only 17 bits in the BDS0,6 ground packet after all.
def parseBDS06(self, shortdata, longdata, parity, ecc): def parseBDS06(self, shortdata, longdata, parity, ecc):
icao24 = shortdata & 0xFFFFFF icao24 = shortdata & 0xFFFFFF
@ -177,7 +177,7 @@ class modes_parse:
altitude = 0 altitude = 0
[decoded_lat, decoded_lon, rnge, bearing] = cpr_decoder.decode(icao24, encoded_lat, encoded_lon, cpr_format, 1) [decoded_lat, decoded_lon, rnge, bearing] = self.cpr.decode(icao24, encoded_lat, encoded_lon, cpr_format, 1)
return [altitude, decoded_lat, decoded_lon, rnge, bearing] return [altitude, decoded_lat, decoded_lon, rnge, bearing]