From 396ee330c4c606f9fd4bea27c0d80481816b9bbf Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Fri, 14 Sep 2012 09:06:51 -0700 Subject: [PATCH 1/4] Add carriage returns before linefeeds in SBS1 feed. --- python/modes_sbs1.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/modes_sbs1.py b/python/modes_sbs1.py index 20d6457..070fd35 100644 --- a/python/modes_sbs1.py +++ b/python/modes_sbs1.py @@ -131,9 +131,9 @@ class modes_output_sbs1(modes_parse.modes_parse): 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) if vs: - retstr += "1\n" + retstr += "1\r\n" else: - retstr += "0\n" + retstr += "0\r\n" return retstr def pp4(self, shortdata, ecc): @@ -141,7 +141,7 @@ class modes_output_sbs1(modes_parse.modes_parse): [fs, dr, um, altitude] = self.parse4(shortdata) 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) - return retstr + self.decode_fs(fs) + "\n" + return retstr + self.decode_fs(fs) + "\r\n" def pp5(self, shortdata, ecc): # I'm not sure what to do with the identiifcation shortdata & 0x1FFF @@ -149,13 +149,13 @@ class modes_output_sbs1(modes_parse.modes_parse): [fs, dr, um, ident] = self.parse5(shortdata) 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) - return retstr + self.decode_fs(fs) + "\n" + return retstr + self.decode_fs(fs) + "\r\n" def pp11(self, shortdata, ecc): [datestr, timestr] = self.current_time() [icao24, interrogator, ca] = self.parse11(shortdata, ecc) 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): icao24 = data["aa"] @@ -170,7 +170,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if bdsreg == 0x08: # Aircraft Identification (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: # Surface position measurement @@ -179,7 +179,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if decoded_lat is None: #no unambiguously valid position available retstr = None 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: # Airborne position measurements @@ -188,7 +188,7 @@ class modes_output_sbs1(modes_parse.modes_parse): if decoded_lat is None: #no unambiguously valid position available retstr = None 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: # Airborne velocity measurements @@ -197,6 +197,6 @@ class modes_output_sbs1(modes_parse.modes_parse): if subtype == 0 or subtype == 1: parser = self.parseBDS09_0 if subtype == 0 else self.parseBDS09_1 [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 From f1a5c676b7840bd8ea03cfa0332d62390b6b8171 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sun, 30 Sep 2012 11:47:50 -0700 Subject: [PATCH 2/4] Fixed erroneous include dir variable FindGnuradioCore was only working if GNU Radio was installed in typical paths, since the pkg-config variable was wrong. This was fixed in GNU Radio HOWTO a while back. --- cmake/Modules/FindGnuradioCore.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/Modules/FindGnuradioCore.cmake b/cmake/Modules/FindGnuradioCore.cmake index 34e85db..87012ab 100644 --- a/cmake/Modules/FindGnuradioCore.cmake +++ b/cmake/Modules/FindGnuradioCore.cmake @@ -5,7 +5,7 @@ FIND_PATH( GNURADIO_CORE_INCLUDE_DIRS NAMES gr_random.h HINTS $ENV{GNURADIO_CORE_DIR}/include/gnuradio - ${PC_GNURADIO_CORE_INCLUDE_DIR} + ${PC_GNURADIO_CORE_INCLUDEDIR} PATHS /usr/local/include/gnuradio /usr/include/gnuradio ) From c0d24f12c96ca52dd38f08d42d6bdedf69474bba Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 6 Oct 2012 08:44:33 -0700 Subject: [PATCH 3/4] modes_kml: fix case where KML generation thread dies SQLite does not deal well with concurrency. Avoid database locked errors by synchronizing database access using a threading.Lock(). --- python/modes_kml.py | 8 ++++---- python/modes_sql.py | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/python/modes_kml.py b/python/modes_kml.py index c324373..d3b1ba0 100644 --- a/python/modes_kml.py +++ b/python/modes_kml.py @@ -93,14 +93,14 @@ class modes_kml(threading.Thread, modes_output_sql): #read the database and add KML q = "select distinct icao from positions where seen > datetime('now', '-5 minute')" c = self._db.cursor() - c.execute(q) + self.locked_execute(c, q) icaolist = c.fetchall() #now we have a list icaolist of all ICAOs seen in the last 5 minutes for icao in icaolist: #print "ICAO: %x" % 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() #print "Track length: %i" % len(track) if len(track) != 0: @@ -128,7 +128,7 @@ class modes_kml(threading.Thread, modes_output_sql): #now get metadata q = "select ident from ident where icao=%i" % icao - c.execute(q) + self.locked_execute(c, q) r = c.fetchall() if len(r) != 0: ident = r[0][0] @@ -136,7 +136,7 @@ class modes_kml(threading.Thread, modes_output_sql): #if ident is None: ident = "" #get most recent speed/heading/vertical 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() if len(r) != 0: seen = r[0][0] diff --git a/python/modes_sql.py b/python/modes_sql.py index 54385d2..be2316f 100644 --- a/python/modes_sql.py +++ b/python/modes_sql.py @@ -19,7 +19,7 @@ # Boston, MA 02110-1301, USA. # -import time, os, sys +import time, os, sys, threading from string import split, join import modes_parse import sqlite3 @@ -28,6 +28,8 @@ from modes_exceptions import * class modes_output_sql(modes_parse.modes_parse): def __init__(self, mypos, filename): modes_parse.modes_parse.__init__(self, mypos) + + self._lock = threading.Lock() #create the database self.db = sqlite3.connect(filename) #now execute a schema to create the tables you need @@ -39,7 +41,7 @@ class modes_output_sql(modes_parse.modes_parse): "lat" REAL, "lon" REAL );""" - c.execute(query) + self.locked_execute(c, query) query = """CREATE TABLE IF NOT EXISTS "vectors" ( "icao" INTEGER KEY NOT NULL, "seen" TEXT NOT NULL, @@ -47,26 +49,31 @@ class modes_output_sql(modes_parse.modes_parse): "heading" REAL, "vertical" REAL );""" - c.execute(query) + self.locked_execute(c, query) query = """CREATE TABLE IF NOT EXISTS "ident" ( "icao" INTEGER PRIMARY KEY NOT NULL, "ident" TEXT NOT NULL );""" - c.execute(query) + self.locked_execute(c, query) c.close() self.db.commit() def __del__(self): self.db.close() + def locked_execute(self, c, query): + with self._lock: + c.execute(query) + def output(self, message): try: query = self.make_insert_query(message) if query is not None: - c = self.db.cursor() - c.execute(query) - c.close() - self.db.commit() + with self._lock: + c = self.db.cursor() + c.execute(query) + c.close() + self.db.commit() except ADSBError: pass From 20630ec6d1eac18ddcd09a074c1edf18c4e9f27f Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 6 Oct 2012 07:57:18 -0700 Subject: [PATCH 4/4] cmake: additional fixes from GNU Radio HOWTO * Fix include dir in FindGruel * Remove QUIET option that requires CMake 2.8.2, not yet on all distros --- cmake/Modules/FindGnuradioCore.cmake | 2 +- cmake/Modules/FindGruel.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/FindGnuradioCore.cmake b/cmake/Modules/FindGnuradioCore.cmake index 87012ab..3773588 100644 --- a/cmake/Modules/FindGnuradioCore.cmake +++ b/cmake/Modules/FindGnuradioCore.cmake @@ -1,5 +1,5 @@ INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(PC_GNURADIO_CORE gnuradio-core QUIET) +PKG_CHECK_MODULES(PC_GNURADIO_CORE gnuradio-core) FIND_PATH( GNURADIO_CORE_INCLUDE_DIRS diff --git a/cmake/Modules/FindGruel.cmake b/cmake/Modules/FindGruel.cmake index 190c2e3..c7a10a4 100644 --- a/cmake/Modules/FindGruel.cmake +++ b/cmake/Modules/FindGruel.cmake @@ -1,11 +1,11 @@ INCLUDE(FindPkgConfig) -PKG_CHECK_MODULES(PC_GRUEL gnuradio-core QUIET) +PKG_CHECK_MODULES(PC_GRUEL gnuradio-core) FIND_PATH( GRUEL_INCLUDE_DIRS NAMES gruel/attributes.h HINTS $ENV{GRUEL_DIR}/include - ${PC_GRUEL_INCLUDE_DIR} + ${PC_GRUEL_INCLUDEDIR} PATHS /usr/local/include /usr/include )