Merge branch 'parse' into qtapp
Conflicts: python/modes_parse.py
This commit is contained in:
+2
-1
@@ -29,6 +29,7 @@ from string import split, join
|
|||||||
import air_modes
|
import air_modes
|
||||||
import gnuradio.gr.gr_threading as _threading
|
import gnuradio.gr.gr_threading as _threading
|
||||||
import csv
|
import csv
|
||||||
|
from air_modes.modes_exceptions import *
|
||||||
|
|
||||||
class top_block_runner(_threading.Thread):
|
class top_block_runner(_threading.Thread):
|
||||||
def __init__(self, tb):
|
def __init__(self, tb):
|
||||||
@@ -87,7 +88,7 @@ class adsb_rx_block (gr.top_block):
|
|||||||
|
|
||||||
self.u.set_gain_mode(0) #manual gain mode
|
self.u.set_gain_mode(0) #manual gain mode
|
||||||
if options.gain is None:
|
if options.gain is None:
|
||||||
options.gain = 49
|
options.gain = 34
|
||||||
|
|
||||||
self.u.set_gain(options.gain)
|
self.u.set_gain(options.gain)
|
||||||
print "Gain is %i" % self.u.get_gain()
|
print "Gain is %i" % self.u.get_gain()
|
||||||
|
|||||||
+12
-11
@@ -34,31 +34,32 @@ class modes_flightgear(modes_parse.modes_parse):
|
|||||||
msgtype = data["df"]
|
msgtype = data["df"]
|
||||||
if msgtype == 17: #ADS-B report
|
if msgtype == 17: #ADS-B report
|
||||||
icao24 = data["aa"]
|
icao24 = data["aa"]
|
||||||
subtype = data["sub"]
|
bdsreg = data["me"].get_type()
|
||||||
if subtype == 4: #ident packet
|
if bdsreg == 0x08: #ident packet
|
||||||
(ident, actype) = self.parseBDS08(data)
|
(ident, actype) = self.parseBDS08(data)
|
||||||
#select model based on actype
|
#select model based on actype
|
||||||
self.callsigns[icao24] = [ident, actype]
|
self.callsigns[icao24] = [ident, actype]
|
||||||
|
|
||||||
elif 5 <= subtype <= 8: #BDS0,6 pos
|
elif bdsreg == 0x06: #BDS0,6 pos
|
||||||
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
||||||
self.positions[icao24] = [decoded_lat, decoded_lon, 0]
|
self.positions[icao24] = [decoded_lat, decoded_lon, 0]
|
||||||
self.update(icao24)
|
self.update(icao24)
|
||||||
|
|
||||||
elif 9 <= subtype <= 18: #BDS0,5 pos
|
elif bdsreg == 0x05: #BDS0,5 pos
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
||||||
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
self.positions[icao24] = [decoded_lat, decoded_lon, altitude]
|
||||||
self.update(icao24)
|
self.update(icao24)
|
||||||
|
|
||||||
elif subtype == 19: #velocity
|
elif bdsreg == 0x09: #velocity
|
||||||
subsubtype = data["sub"]
|
subtype = data["bds09"].get_type()
|
||||||
if subsubtype == 0:
|
if subtype == 0:
|
||||||
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data)
|
[velocity, heading, vert_spd, turnrate] = self.parseBDS09_0(data)
|
||||||
elif 1 <= subsubtype <= 2:
|
elif subtype == 1:
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
|
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
|
||||||
turnrate = 0
|
turnrate = 0
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.velocities[icao24] = [velocity, heading, vert_spd, turnrate]
|
self.velocities[icao24] = [velocity, heading, vert_spd, turnrate]
|
||||||
|
|
||||||
except ADSBError:
|
except ADSBError:
|
||||||
|
|||||||
+11
-7
@@ -58,7 +58,9 @@ class data_field:
|
|||||||
if len(bits) == 3:
|
if len(bits) == 3:
|
||||||
obj = bits[2](self.get_bits(bits[0], bits[1]))
|
obj = bits[2](self.get_bits(bits[0], bits[1]))
|
||||||
fields.update(obj.parse())
|
fields.update(obj.parse())
|
||||||
fields.update({field: self.get_bits(bits[0], bits[1])})
|
fields.update({field: obj})
|
||||||
|
else:
|
||||||
|
fields.update({field: self.get_bits(bits[0], bits[1])})
|
||||||
else:
|
else:
|
||||||
raise NoHandlerError(mytype)
|
raise NoHandlerError(mytype)
|
||||||
return fields
|
return fields
|
||||||
@@ -75,14 +77,16 @@ class data_field:
|
|||||||
def get_bits(self, *args):
|
def get_bits(self, *args):
|
||||||
startbit = args[0]
|
startbit = args[0]
|
||||||
num = args[1]
|
num = args[1]
|
||||||
bits = 0
|
|
||||||
try:
|
try:
|
||||||
bits = (self.data \
|
bits = (self.data \
|
||||||
>> (self.get_numbits() - startbit - num + self.offset)) \
|
>> (self.get_numbits() - startbit - num + self.offset)) \
|
||||||
& ((1 << num) - 1)
|
& ((1 << num) - 1)
|
||||||
|
#the exception handler catches instances when you try to shift more than
|
||||||
|
#the number of bits. this can happen when a garbage packet gets through
|
||||||
|
#which reports itself as a short packet but of type long.
|
||||||
|
#TODO: should find more productive way to throw this out
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
bits = 0
|
||||||
#print "Got short packet but expected long retrieving bits (%i, %i) with type %i" % (startbit, num, self.get_type())
|
|
||||||
return bits
|
return bits
|
||||||
|
|
||||||
class bds09_reply(data_field):
|
class bds09_reply(data_field):
|
||||||
@@ -136,7 +140,7 @@ class me_reply(data_field):
|
|||||||
return 0x08
|
return 0x08
|
||||||
elif 5 <= ftc <= 8:
|
elif 5 <= ftc <= 8:
|
||||||
return 0x06
|
return 0x06
|
||||||
elif 9 <= ftc <= 18:
|
elif 9 <= ftc <= 18 and ftc != 15: #FTC 15 does not appear to be valid
|
||||||
return 0x05
|
return 0x05
|
||||||
elif ftc == 19:
|
elif ftc == 19:
|
||||||
return 0x09
|
return 0x09
|
||||||
|
|||||||
+16
-18
@@ -138,41 +138,39 @@ class modes_output_print(modes_parse.modes_parse):
|
|||||||
|
|
||||||
def print17(self, data):
|
def print17(self, data):
|
||||||
icao24 = data["aa"]
|
icao24 = data["aa"]
|
||||||
subtype = data["ftc"]
|
bdsreg = data["me"].get_type()
|
||||||
|
|
||||||
retstr = None
|
retstr = None
|
||||||
|
|
||||||
if 1 <= subtype <= 4:
|
if bdsreg == 0x08:
|
||||||
(msg, typestring) = self.parseBDS08(data)
|
(msg, typestring) = self.parseBDS08(data)
|
||||||
retstr = "Type 17 subtype 04 (ident) from %x type %s ident %s" % (icao24, typestring, msg)
|
retstr = "Type 17 BDS0,8 (ident) from %x type %s ident %s" % (icao24, typestring, msg)
|
||||||
|
|
||||||
elif subtype >= 5 and subtype <= 8:
|
elif bdsreg == 0x06:
|
||||||
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
||||||
retstr = "Type 17 subtype 06 (surface report) from %x at (%.6f, %.6f) ground track %i" % (icao24, decoded_lat, decoded_lon, ground_track)
|
retstr = "Type 17 BDS0,6 (surface report) from %x at (%.6f, %.6f) ground track %i" % (icao24, decoded_lat, decoded_lon, ground_track)
|
||||||
if rnge is not None and bearing is not None:
|
if rnge is not None and bearing is not None:
|
||||||
retstr += " (%.2f @ %.0f)" % (rnge, bearing)
|
retstr += " (%.2f @ %.0f)" % (rnge, bearing)
|
||||||
|
|
||||||
elif subtype >= 9 and subtype <= 18:
|
elif bdsreg == 0x05:
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
||||||
retstr = "Type 17 subtype 05 (position report) from %x at (%.6f, %.6f)" % (icao24, decoded_lat, decoded_lon)
|
retstr = "Type 17 BDS0,5 (position report) from %x at (%.6f, %.6f)" % (icao24, decoded_lat, decoded_lon)
|
||||||
if rnge is not None and bearing is not None:
|
if rnge is not None and bearing is not None:
|
||||||
retstr += " (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")"
|
retstr += " (" + "%.2f" % rnge + " @ " + "%.0f" % bearing + ")"
|
||||||
retstr += " at " + str(altitude) + "ft"
|
retstr += " at " + str(altitude) + "ft"
|
||||||
|
|
||||||
elif subtype == 19:
|
elif bdsreg == 0x09:
|
||||||
subsubtype = data["sub"]
|
subtype = data["bds09"].get_type()
|
||||||
if subsubtype == 0:
|
if subtype == 0 or subtype == 1:
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_0(data)
|
parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1
|
||||||
retstr = "Type 17 subtype 09-0 (track report) from %x with velocity %.0fkt heading %.0f VS %.0f" % (icao24, velocity, heading, vert_spd)
|
[velocity, heading, vert_spd] = parser(data)
|
||||||
elif 1 <= subsubtype <= 2:
|
retstr = "Type 17 BDS0,9-%i (track report) from %x with velocity %.0fkt heading %.0f VS %.0f" % (subtype, icao24, velocity, heading, vert_spd)
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
|
|
||||||
retstr = "Type 17 subtype 09-%i (track report) from %x with velocity %.0fkt heading %.0f VS %.0f" % (subsubtype, icao24, velocity, heading, vert_spd)
|
|
||||||
else:
|
else:
|
||||||
retstr = "Type 17 subtype 09-%i from %x not implemented" % (subsubtype, icao24)
|
retstr = "Type 17 BDS0,9-%i from %x not implemented" % (subtype, icao24)
|
||||||
|
|
||||||
elif subtype == 28:
|
elif bdsreg == 0x62:
|
||||||
emerg_str = self.parseBDS62(data)
|
emerg_str = self.parseBDS62(data)
|
||||||
retstr = "Type 17 subtype 28 (emergency) from %x type %s" % (icao24, emerg_str)
|
retstr = "Type 17 BDS6,2 (emergency) from %x type %s" % (icao24, emerg_str)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
retstr = "Type 17 subtype %i from %x not implemented" % (subtype, icao24)
|
retstr = "Type 17 subtype %i from %x not implemented" % (subtype, icao24)
|
||||||
|
|||||||
+9
-12
@@ -159,19 +159,19 @@ class modes_output_sbs1(modes_parse.modes_parse):
|
|||||||
def pp17(self, data):
|
def pp17(self, data):
|
||||||
icao24 = data["aa"]
|
icao24 = data["aa"]
|
||||||
aircraft_id = self.get_aircraft_id(icao24)
|
aircraft_id = self.get_aircraft_id(icao24)
|
||||||
subtype = data["ftc"]
|
bdsreg = data["me"].get_type()
|
||||||
|
|
||||||
retstr = None
|
retstr = None
|
||||||
#we'll get better timestamps later, hopefully with actual VRT time
|
#we'll get better timestamps later, hopefully with actual VRT time
|
||||||
#in them
|
#in them
|
||||||
[datestr, timestr] = self.current_time()
|
[datestr, timestr] = self.current_time()
|
||||||
|
|
||||||
if subtype >= 1 and subtype <= 4:
|
if bdsreg == 0x08:
|
||||||
# Aircraft Identification
|
# Aircraft Identification
|
||||||
(msg, typestring) = self.parseBDS08(data)
|
(msg, typestring) = self.parseBDS08(data)
|
||||||
retstr = "MSG,1,0,%i,%06X,%i,%s,%s,%s,%s,%s,,,,,,,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, msg)
|
retstr = "MSG,1,0,%i,%06X,%i,%s,%s,%s,%s,%s,,,,,,,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, msg)
|
||||||
|
|
||||||
elif subtype >= 5 and subtype <= 8:
|
elif bdsreg == 0x06:
|
||||||
# Surface position measurement
|
# Surface position measurement
|
||||||
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
||||||
altitude = 0
|
altitude = 0
|
||||||
@@ -180,7 +180,7 @@ class modes_output_sbs1(modes_parse.modes_parse):
|
|||||||
else:
|
else:
|
||||||
retstr = "MSG,2,0,%i,%06X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
|
retstr = "MSG,2,0,%i,%06X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
|
||||||
|
|
||||||
elif subtype >= 9 and subtype <= 18:
|
elif bdsreg == 0x05:
|
||||||
# Airborne position measurements
|
# Airborne position measurements
|
||||||
# WRONG (rnge, bearing), is this still true?
|
# WRONG (rnge, bearing), is this still true?
|
||||||
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
||||||
@@ -189,16 +189,13 @@ class modes_output_sbs1(modes_parse.modes_parse):
|
|||||||
else:
|
else:
|
||||||
retstr = "MSG,3,0,%i,%06X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
|
retstr = "MSG,3,0,%i,%06X,%i,%s,%s,%s,%s,,%i,,,%.5f,%.5f,,,,0,0,0\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
|
||||||
|
|
||||||
elif subtype == 19:
|
elif bdsreg == 0x09:
|
||||||
# Airborne velocity measurements
|
# Airborne velocity measurements
|
||||||
# WRONG (heading, vert_spd), Is this still true?
|
# WRONG (heading, vert_spd), Is this still true?
|
||||||
subsubtype = data["sub"]
|
subtype = data["bds09"].get_type()
|
||||||
if subsubtype == 0:
|
if subtype == 0 or subtype == 1:
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_0(data)
|
parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1
|
||||||
retstr = "MSG,4,0,%i,%06X,%i,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd)
|
[velocity, heading, vert_spd] = parser(data)
|
||||||
|
|
||||||
elif 1 <= subsubtype <= 2:
|
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_1(data)
|
|
||||||
retstr = "MSG,4,0,%i,%06X,%i,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd)
|
retstr = "MSG,4,0,%i,%06X,%i,%s,%s,%s,%s,,,%.1f,%.1f,,,%i,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd)
|
||||||
|
|
||||||
return retstr
|
return retstr
|
||||||
|
|||||||
+10
-13
@@ -99,15 +99,15 @@ class modes_output_sql(modes_parse.modes_parse):
|
|||||||
|
|
||||||
def sql17(self, data):
|
def sql17(self, data):
|
||||||
icao24 = data["aa"]
|
icao24 = data["aa"]
|
||||||
subtype = data["ftc"]
|
bdsreg = data["me"].get_type()
|
||||||
|
|
||||||
retstr = None
|
retstr = None
|
||||||
|
|
||||||
if subtype == 4:
|
if bdsreg == 0x08:
|
||||||
(msg, typename) = self.parseBDS08(data)
|
(msg, typename) = self.parseBDS08(data)
|
||||||
retstr = "INSERT OR REPLACE INTO ident (icao, ident) VALUES (" + "%i" % icao24 + ", '" + msg + "')"
|
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)
|
[ground_track, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS06(data)
|
||||||
altitude = 0
|
altitude = 0
|
||||||
if decoded_lat is None: #no unambiguously valid position available
|
if decoded_lat is None: #no unambiguously valid position available
|
||||||
@@ -115,21 +115,18 @@ class modes_output_sql(modes_parse.modes_parse):
|
|||||||
else:
|
else:
|
||||||
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
|
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)
|
[altitude, decoded_lat, decoded_lon, rnge, bearing] = self.parseBDS05(data)
|
||||||
if decoded_lat is None: #no unambiguously valid position available
|
if decoded_lat is None: #no unambiguously valid position available
|
||||||
retstr = None
|
retstr = None
|
||||||
else:
|
else:
|
||||||
retstr = "INSERT INTO positions (icao, seen, alt, lat, lon) VALUES (" + "%i" % icao24 + ", datetime('now'), " + str(altitude) + ", " + "%.6f" % decoded_lat + ", " + "%.6f" % decoded_lon + ")"
|
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:
|
elif bdsreg == 0x09:
|
||||||
subsubtype = data["sub"]
|
subtype = data["bds09"].get_type()
|
||||||
if subsubtype == 0:
|
if subtype == 0 or subtype == 1:
|
||||||
[velocity, heading, vert_spd] = self.parseBDS09_0(data)
|
parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1
|
||||||
retstr = "INSERT INTO vectors (icao, seen, speed, heading, vertical) VALUES (" + "%i" % icao24 + ", datetime('now'), " + "%.0f" % velocity + ", " + "%.0f" % heading + ", " + "%.0f" % vert_spd + ")";
|
[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 + ")"
|
||||||
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 + ")";
|
|
||||||
|
|
||||||
return retstr
|
return retstr
|
||||||
|
|||||||
Reference in New Issue
Block a user