Merge remote-tracking branch 'jcorgan/qtapp_devel' into qtapp

Conflicts:
	lib/air_modes_preamble.cc
This commit is contained in:
Nick Foster 2012-10-07 23:20:19 -07:00
commit f42e2e744d
6 changed files with 35 additions and 25 deletions

View File

@ -1,11 +1,11 @@
INCLUDE(FindPkgConfig) INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(PC_GNURADIO_CORE gnuradio-core QUIET) PKG_CHECK_MODULES(PC_GNURADIO_CORE gnuradio-core)
FIND_PATH( FIND_PATH(
GNURADIO_CORE_INCLUDE_DIRS GNURADIO_CORE_INCLUDE_DIRS
NAMES gr_random.h NAMES gr_random.h
HINTS $ENV{GNURADIO_CORE_DIR}/include/gnuradio HINTS $ENV{GNURADIO_CORE_DIR}/include/gnuradio
${PC_GNURADIO_CORE_INCLUDE_DIR} ${PC_GNURADIO_CORE_INCLUDEDIR}
PATHS /usr/local/include/gnuradio PATHS /usr/local/include/gnuradio
/usr/include/gnuradio /usr/include/gnuradio
) )

View File

@ -1,11 +1,11 @@
INCLUDE(FindPkgConfig) INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(PC_GRUEL gnuradio-core QUIET) PKG_CHECK_MODULES(PC_GRUEL gnuradio-core)
FIND_PATH( FIND_PATH(
GRUEL_INCLUDE_DIRS GRUEL_INCLUDE_DIRS
NAMES gruel/attributes.h NAMES gruel/attributes.h
HINTS $ENV{GRUEL_DIR}/include HINTS $ENV{GRUEL_DIR}/include
${PC_GRUEL_INCLUDE_DIR} ${PC_GRUEL_INCLUDEDIR}
PATHS /usr/local/include PATHS /usr/local/include
/usr/include /usr/include
) )

View File

@ -201,6 +201,7 @@ int air_modes_preamble::general_work(int noutput_items,
//produce only one output per work call -- TODO this should probably change //produce only one output per work call -- TODO this should probably change
if(0) std::cout << "Preamble consumed " << i+240*d_samples_per_chip << "with i=" << i << ", returned 240" << std::endl; if(0) std::cout << "Preamble consumed " << i+240*d_samples_per_chip << "with i=" << i << ", returned 240" << std::endl;
consume_each(i+240*d_samples_per_chip); consume_each(i+240*d_samples_per_chip);
return 240; return 240;
} }

View File

@ -93,14 +93,14 @@ class output_kml(threading.Thread):
#read the database and add KML #read the database and add KML
q = "select distinct icao from positions where seen > datetime('now', '-5 minute')" q = "select distinct icao from positions where seen > datetime('now', '-5 minute')"
c = self._db.cursor() c = self._db.cursor()
c.execute(q) self.locked_execute(c, q)
icaolist = c.fetchall() icaolist = c.fetchall()
#now we have a list icaolist of all ICAOs seen in the last 5 minutes #now we have a list icaolist of all ICAOs seen in the last 5 minutes
for icao in icaolist: for icao in icaolist:
#print "ICAO: %x" % icao #print "ICAO: %x" % icao
q = "select * from positions where icao=%i and seen > datetime('now', '-2 hour') ORDER BY seen DESC" % icao q = "select * from positions where icao=%i and seen > datetime('now', '-2 hour') ORDER BY seen DESC" % icao
c.execute(q) self.locked_execute(c, q)
track = c.fetchall() track = c.fetchall()
#print "Track length: %i" % len(track) #print "Track length: %i" % len(track)
if len(track) != 0: if len(track) != 0:
@ -128,7 +128,7 @@ class output_kml(threading.Thread):
#now get metadata #now get metadata
q = "select ident from ident where icao=%i" % icao q = "select ident from ident where icao=%i" % icao
c.execute(q) self.locked_execute(c, q)
r = c.fetchall() r = c.fetchall()
if len(r) != 0: if len(r) != 0:
ident = r[0][0] ident = r[0][0]
@ -136,7 +136,7 @@ class output_kml(threading.Thread):
#if ident is None: ident = "" #if ident is None: ident = ""
#get most recent speed/heading/vertical #get most recent speed/heading/vertical
q = "select seen, speed, heading, vertical from vectors where icao=%i order by seen desc limit 1" % icao q = "select seen, speed, heading, vertical from vectors where icao=%i order by seen desc limit 1" % icao
c.execute(q) self.locked_execute(c, q)
r = c.fetchall() r = c.fetchall()
if len(r) != 0: if len(r) != 0:
seen = r[0][0] seen = r[0][0]

View File

@ -131,9 +131,9 @@ class output_sbs1(air_modes.parse):
aircraft_id = self.get_aircraft_id(ecc) aircraft_id = self.get_aircraft_id(ecc)
retstr = "MSG,7,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude) retstr = "MSG,7,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude)
if vs: if vs:
retstr += "1\n" retstr += "1\r\n"
else: else:
retstr += "0\n" retstr += "0\r\n"
return retstr return retstr
def pp4(self, shortdata, ecc): def pp4(self, shortdata, ecc):
@ -141,7 +141,7 @@ class output_sbs1(air_modes.parse):
[fs, dr, um, altitude] = self.parse4(shortdata) [fs, dr, um, altitude] = self.parse4(shortdata)
aircraft_id = self.get_aircraft_id(ecc) aircraft_id = self.get_aircraft_id(ecc)
retstr = "MSG,5,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude) retstr = "MSG,5,0,%i,%06X,%i,%s,%s,%s,%s,,%s,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr, altitude)
return retstr + self.decode_fs(fs) + "\n" return retstr + self.decode_fs(fs) + "\r\n"
def pp5(self, shortdata, ecc): def pp5(self, shortdata, ecc):
# I'm not sure what to do with the identiifcation shortdata & 0x1FFF # I'm not sure what to do with the identiifcation shortdata & 0x1FFF
@ -149,13 +149,13 @@ class output_sbs1(air_modes.parse):
[fs, dr, um, ident] = self.parse5(shortdata) [fs, dr, um, ident] = self.parse5(shortdata)
aircraft_id = self.get_aircraft_id(ecc) aircraft_id = self.get_aircraft_id(ecc)
retstr = "MSG,6,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr) retstr = "MSG,6,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,," % (aircraft_id, ecc, aircraft_id+100, datestr, timestr, datestr, timestr)
return retstr + self.decode_fs(fs) + "\n" return retstr + self.decode_fs(fs) + "\r\n"
def pp11(self, shortdata, ecc): def pp11(self, shortdata, ecc):
[datestr, timestr] = self.current_time() [datestr, timestr] = self.current_time()
[icao24, interrogator, ca] = self.parse11(shortdata, ecc) [icao24, interrogator, ca] = self.parse11(shortdata, ecc)
aircraft_id = self.get_aircraft_id(icao24) aircraft_id = self.get_aircraft_id(icao24)
return "MSG,8,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,,,,,\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr) return "MSG,8,0,%i,%06X,%i,%s,%s,%s,%s,,,,,,,,,,,,\r\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr)
def pp17(self, data): def pp17(self, data):
icao24 = data["aa"] icao24 = data["aa"]
@ -170,7 +170,7 @@ class output_sbs1(air_modes.parse):
if bdsreg == 0x08: 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,,,,,,,,,,,\r\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, msg)
elif bdsreg == 0x06: elif bdsreg == 0x06:
# Surface position measurement # Surface position measurement
@ -179,7 +179,7 @@ class output_sbs1(air_modes.parse):
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 = "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\r\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
elif bdsreg == 0x05: elif bdsreg == 0x05:
# Airborne position measurements # Airborne position measurements
@ -188,7 +188,7 @@ class output_sbs1(air_modes.parse):
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 = "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\r\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, altitude, decoded_lat, decoded_lon)
elif bdsreg == 0x09: elif bdsreg == 0x09:
# Airborne velocity measurements # Airborne velocity measurements
@ -197,6 +197,6 @@ class output_sbs1(air_modes.parse):
if subtype == 0 or subtype == 1: if subtype == 0 or subtype == 1:
parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1 parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1
[velocity, heading, vert_spd] = parser(data) [velocity, heading, vert_spd] = parser(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,,,,,\r\n" % (aircraft_id, icao24, aircraft_id+100, datestr, timestr, datestr, timestr, velocity, heading, vert_spd)
return retstr return retstr

View File

@ -19,7 +19,7 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
import time, os, sys import time, os, sys, threading
from string import split, join from string import split, join
import air_modes import air_modes
import sqlite3 import sqlite3
@ -28,6 +28,9 @@ from air_modes.exceptions import *
class output_sql(air_modes.parse): class output_sql(air_modes.parse):
def __init__(self, mypos, filename): def __init__(self, mypos, filename):
air_modes.parse.__init__(self, mypos) air_modes.parse.__init__(self, mypos)
self._lock = threading.Lock()
#create the database #create the database
self.filename = filename self.filename = filename
self.db = sqlite3.connect(filename) self.db = sqlite3.connect(filename)
@ -40,7 +43,7 @@ class output_sql(air_modes.parse):
"lat" REAL, "lat" REAL,
"lon" REAL "lon" REAL
);""" );"""
c.execute(query) self.locked_execute(c, query)
query = """CREATE TABLE IF NOT EXISTS "vectors" ( query = """CREATE TABLE IF NOT EXISTS "vectors" (
"icao" INTEGER KEY NOT NULL, "icao" INTEGER KEY NOT NULL,
"seen" TEXT NOT NULL, "seen" TEXT NOT NULL,
@ -48,12 +51,12 @@ class output_sql(air_modes.parse):
"heading" REAL, "heading" REAL,
"vertical" REAL "vertical" REAL
);""" );"""
c.execute(query) self.locked_execute(c, query)
query = """CREATE TABLE IF NOT EXISTS "ident" ( query = """CREATE TABLE IF NOT EXISTS "ident" (
"icao" INTEGER PRIMARY KEY NOT NULL, "icao" INTEGER PRIMARY KEY NOT NULL,
"ident" TEXT NOT NULL "ident" TEXT NOT NULL
);""" );"""
c.execute(query) self.locked_execute(c, query)
c.close() c.close()
self.db.commit() self.db.commit()
#we close the db conn now to reopen it in the output() thread context. #we close the db conn now to reopen it in the output() thread context.
@ -63,6 +66,10 @@ class output_sql(air_modes.parse):
def __del__(self): def __del__(self):
self.db = None self.db = None
def locked_execute(self, c, query):
with self._lock:
c.execute(query)
def output(self, message): def output(self, message):
try: try:
#we're checking to see if the db is empty, and creating the db object #we're checking to see if the db is empty, and creating the db object
@ -74,10 +81,12 @@ class output_sql(air_modes.parse):
query = self.make_insert_query(message) query = self.make_insert_query(message)
if query is not None: if query is not None:
with self._lock:
c = self.db.cursor() c = self.db.cursor()
c.execute(query) c.execute(query)
c.close() c.close()
self.db.commit() #don't know if this is necessary self.db.commit()
except ADSBError: except ADSBError:
pass pass