From 4d93b8f821d98471e5d25976b0cb4681e4fd3891 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Sat, 23 Oct 2010 18:00:58 -0700 Subject: [PATCH] Collected all the local position stuff so it's specified once in uhd_modes.py. Should probably add in a command-line parameter to specify this. --- src/python/cpr.py | 4 ++-- src/python/modes_kml.py | 4 ++-- src/python/modes_parse.py | 5 ++++- src/python/modes_print.py | 3 +++ src/python/modes_sbs1.py | 3 ++- src/python/modes_sql.py | 3 ++- src/python/uhd_modes.py | 10 ++++++---- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/python/cpr.py b/src/python/cpr.py index b60991e..285dc9c 100644 --- a/src/python/cpr.py +++ b/src/python/cpr.py @@ -157,7 +157,7 @@ def cpr_resolve_global(evenpos, oddpos, mostrecent, surface): #ok this is consid return [rlat, rlon] -def cpr_decode(icao24, encoded_lat, encoded_lon, cpr_format, evenlist, oddlist, lkplist, surface, longdata): +def cpr_decode(my_location, icao24, encoded_lat, encoded_lon, cpr_format, evenlist, oddlist, lkplist, surface, longdata): #this is a stopgap measure to catch those packets which aren't really position packets. what gives? # if encoded_lat == 0 or encoded_lon == 0: #print "debug: lat or lon zero for longdata %x" % (longdata,) @@ -208,7 +208,7 @@ def cpr_decode(icao24, encoded_lat, encoded_lon, cpr_format, evenlist, oddlist, else: #no LKP available #print "debug: icao %x not found. attempting local decode." % icao24 - [local_lat, local_lon] = cpr_resolve_local([my_lat, my_lon], [encoded_lat, encoded_lon], cpr_format, surface) #try local decoding + [local_lat, local_lon] = cpr_resolve_local(my_location, [encoded_lat, encoded_lon], cpr_format, surface) #try local decoding # print "debug: local resolve gives %.6f, %.6f" % (local_lat, local_lon) [rnge, bearing] = range_bearing([my_lat, my_lon], [local_lat, local_lon]) if rnge < validrange: #if the local decoding can be guaranteed valid diff --git a/src/python/modes_kml.py b/src/python/modes_kml.py index 7068bf4..22e22d6 100644 --- a/src/python/modes_kml.py +++ b/src/python/modes_kml.py @@ -23,11 +23,11 @@ import sqlite3 import string, math, threading, time class modes_kml(threading.Thread): - def __init__(self, dbfile, filename, timeout=5): + def __init__(self, dbfile, filename, localpos, timeout=5): threading.Thread.__init__(self) self._filename = filename self._dbfile = dbfile - self.my_coords = [37.76225, -122.44254] #there has got to be a better way of getting your coords in here + self.my_coords = localpos self._timeout = timeout self.done = False self.setDaemon(1) diff --git a/src/python/modes_parse.py b/src/python/modes_parse.py index b33656f..1353457 100644 --- a/src/python/modes_parse.py +++ b/src/python/modes_parse.py @@ -27,6 +27,9 @@ from cpr import cpr_decode import math class modes_parse: + def __init__(self, mypos): + self.my_location = mypos + def parse0(self, shortdata, parity, ecc): # shortdata = long(shortdata, 16) #parity = long(parity) @@ -166,7 +169,7 @@ class modes_parse: altitude = decode_alt(enc_alt, False) - [decoded_lat, decoded_lon, rnge, bearing] = cpr_decode(icao24, encoded_lat, encoded_lon, cpr_format, self._evenlist, self._oddlist, self._lkplist, 0, longdata) + [decoded_lat, decoded_lon, rnge, bearing] = cpr_decode(self.my_location, icao24, encoded_lat, encoded_lon, cpr_format, self._evenlist, self._oddlist, self._lkplist, 0, longdata) return [altitude, decoded_lat, decoded_lon, rnge, bearing] diff --git a/src/python/modes_print.py b/src/python/modes_print.py index 284cb3f..fee6cdc 100644 --- a/src/python/modes_print.py +++ b/src/python/modes_print.py @@ -26,6 +26,9 @@ import modes_parse import math class modes_output_print(modes_parse.modes_parse): + def __init__(self, mypos): + modes_parse.modes_parse.__init__(self, mypos) + def parse(self, message): [msgtype, shortdata, longdata, parity, ecc, reference] = message.split() diff --git a/src/python/modes_sbs1.py b/src/python/modes_sbs1.py index a79ed9c..cd8eb93 100644 --- a/src/python/modes_sbs1.py +++ b/src/python/modes_sbs1.py @@ -26,7 +26,8 @@ import modes_parse from datetime import * class modes_output_sbs1(modes_parse.modes_parse): - def __init__(self): + def __init__(self, mypos): + modes_parse.modes_parse.__init__(self, mypos) self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._s.bind(('', 30003)) self._s.listen(1) diff --git a/src/python/modes_sql.py b/src/python/modes_sql.py index f8f312f..64accf1 100644 --- a/src/python/modes_sql.py +++ b/src/python/modes_sql.py @@ -25,7 +25,8 @@ import modes_parse import sqlite3 class modes_output_sql(modes_parse.modes_parse): - def __init__(self, filename): + def __init__(self, mypos, filename): + modes_parse.modes_parse.__init__(self, mypos) #create the database self.db = sqlite3.connect(filename) #now execute a schema to create the tables you need diff --git a/src/python/uhd_modes.py b/src/python/uhd_modes.py index 12ca79f..6ff8cd2 100755 --- a/src/python/uhd_modes.py +++ b/src/python/uhd_modes.py @@ -19,6 +19,8 @@ # Boston, MA 02110-1301, USA. # +my_position = [37.76225, -122.44254] + from gnuradio import gr, gru, optfir, eng_notation, blks2, air from gnuradio import uhd from gnuradio.eng_option import eng_option @@ -149,18 +151,18 @@ if __name__ == '__main__': updates = [] #registry of plugin update functions if options.kml is not None: - sqlport = modes_output_sql('adsb.db') #create a SQL parser to push stuff into SQLite + sqlport = modes_output_sql(my_position, 'adsb.db') #create a SQL parser to push stuff into SQLite outputs.append(sqlport.insert) #also we spawn a thread to run every 30 seconds (or whatever) to generate KML - kmlgen = modes_kml('adsb.db', options.kml) #create a KML generating thread which reads the database + kmlgen = modes_kml('adsb.db', options.kml, my_position) #create a KML generating thread which reads the database if options.sbs1 is True: - sbs1port = modes_output_sbs1() + sbs1port = modes_output_sbs1(my_position) outputs.append(sbs1port.output) updates.append(sbs1port.add_pending_conns) if options.no_print is not True: - outputs.append(modes_output_print().parse) + outputs.append(modes_output_print(my_position).parse) fg = adsb_rx_block(options, args, queue) runner = top_block_runner(fg)