Parser returns objects for subfields instead of flat data. Lets you use get_type to resolve BDS registers, etc.

Printer takes advantage of this. Now printing BDS reg instead of "subtype".
This commit is contained in:
Nick Foster
2012-07-16 09:16:48 -07:00
parent fe6aa0c6de
commit 4750d20044
5 changed files with 51 additions and 56 deletions

View File

@@ -88,15 +88,15 @@ class modes_output_sql(modes_parse.modes_parse):
def sql17(self, data):
icao24 = data["aa"]
subtype = data["ftc"]
bdsreg = data["me"].get_type()
retstr = None
if subtype == 4:
if bdsreg == 0x08:
(msg, typename) = self.parseBDS08(data)
retstr = "INSERT OR REPLACE INTO ident (icao, ident) VALUES (" + "%i" % icao24 + ", '" + msg + "')"
elif subtype >= 5 and subtype <= 8:
elif bdsreg == 0x06:
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
altitude = 0
if decoded_lat is None: #no unambiguously valid position available
@@ -104,21 +104,18 @@ class modes_output_sql(modes_parse.modes_parse):
else:
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
elif subtype >= 9 and subtype <= 18 and subtype != 15: #i'm eliminating type 15 records because they don't appear to be valid position reports.
elif bdsreg == 0x05:
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
if decoded_lat is None: #no unambiguously valid position available
retstr = None
else:
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
elif subtype == 19:
subsubtype = data["sub"]
if subsubtype == 0:
[velocity, heading, vert_spd] = self.parseBDS09_0(data)
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")";
elif 1 <= subsubtype <= 2:
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")";
elif bdsreg == 0x09:
subtype = data["bds09"].get_type()
if subtype == 0 or subtype == 1:
parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1
[velocity, heading, vert_spd] = parser(data)
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")"
return retstr