From 3163fca47abcbdb0dc16fdd70a16e1d179759faf Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Mon, 16 Jul 2012 19:27:09 -0700 Subject: [PATCH] Renamed everything in python/ for consistent namespace --- apps/modes_gui | 16 ++--- apps/modes_rx | 14 ++-- python/CMakeLists.txt | 18 ++--- python/__init__.py | 15 ++-- python/altitude.py | 2 +- python/cpr.py | 2 +- python/{modes_exceptions.py => exceptions.py} | 0 python/{modes_flightgear.py => flightgear.py} | 15 ++-- python/{modes_gui_model.py => gui_model.py} | 6 +- python/{modes_kml.py => kml.py} | 2 +- python/modes_datamodel.py | 71 ------------------- python/{modes_print.py => msprint.py} | 10 +-- python/{modes_parse.py => parse.py} | 6 +- python/{modes_raw_server.py => raw_server.py} | 2 +- python/{modes_sbs1.py => sbs1.py} | 10 +-- python/{modes_sql.py => sql.py} | 10 +-- 16 files changed, 65 insertions(+), 134 deletions(-) rename python/{modes_exceptions.py => exceptions.py} (100%) rename python/{modes_flightgear.py => flightgear.py} (96%) rename python/{modes_gui_model.py => gui_model.py} (97%) rename python/{modes_kml.py => kml.py} (99%) delete mode 100644 python/modes_datamodel.py rename python/{modes_print.py => msprint.py} (97%) rename python/{modes_parse.py => parse.py} (99%) rename python/{modes_raw_server.py => raw_server.py} (98%) rename python/{modes_sbs1.py => sbs1.py} (97%) rename python/{modes_sql.py => sql.py} (95%) diff --git a/apps/modes_gui b/apps/modes_gui index 085f19d..f08c881 100755 --- a/apps/modes_gui +++ b/apps/modes_gui @@ -25,9 +25,9 @@ from PyQt4.Qwt5 import Qwt from gnuradio import gr, gru, optfir, eng_notation, blks2 import gnuradio.gr.gr_threading as _threading import air_modes -from air_modes.modes_exceptions import * +from air_modes.exceptions import * from air_modes.modes_rx_ui import Ui_MainWindow -from air_modes.modes_gui_model import * +from air_modes.gui_model import * import sqlite3 class mainwindow(QtGui.QMainWindow): @@ -254,32 +254,32 @@ class mainwindow(QtGui.QMainWindow): #output options to populate outputs, updates if self.ui.check_kml.checkState(): #we spawn a thread to run every 30 seconds (or whatever) to generate KML - self.kmlgen = air_modes.modes_kml(self.ui.line_kmlfilename.text(), self.dbname, my_position) #create a KML generating thread + self.kmlgen = air_modes.output_kml(self.ui.line_kmlfilename.text(), self.dbname, my_position) #create a KML generating thread if self.ui.check_sbs1.checkState(): sbs1port = int(self.ui.line_sbs1port.text()) - sbs1out = air_modes.modes_output_sbs1(my_position, sbs1port) + sbs1out = air_modes.output_sbs1(my_position, sbs1port) self.outputs.append(sbs1out.output) self.updates.append(sbs1out.add_pending_conns) if self.ui.check_fgfs.checkState(): fghost = "127.0.0.1" #TODO FIXME fgport = self.ui.line_fgfsport.currentText() - fgout = air_modes.modes_flightgear(my_position, fghost, int(fgport)) + fgout = air_modes.output_flightgear(my_position, fghost, int(fgport)) self.outputs.append(fgout.output) if self.ui.check_raw.checkState(): - rawport = air_modes.modes_raw_server(int(self.ui.line_raw.text())) + rawport = air_modes.raw_server(int(self.ui.line_raw.text())) self.outputs.append(rawport.output) self.updates.append(rawport.add_pending_conns) - self.livedata = air_modes.modes_output_print(my_position) + self.livedata = air_modes.output_print(my_position) #add output for live data box #TODO: this doesn't handle large volumes of data well; i get segfaults. #self.outputs.append(self.output_live_data) #create SQL database for KML and dashboard displays - self.dbwriter = air_modes.modes_output_sql(my_position, self.dbname) + self.dbwriter = air_modes.output_sql(my_position, self.dbname) self.outputs.append(self.dbwriter.output) #now the db will update itself #output to update reports/sec widget diff --git a/apps/modes_rx b/apps/modes_rx index a65818a..a999659 100755 --- a/apps/modes_rx +++ b/apps/modes_rx @@ -29,7 +29,7 @@ from string import split, join import air_modes import gnuradio.gr.gr_threading as _threading import csv -from air_modes.modes_exceptions import * +from air_modes.exceptions import * class top_block_runner(_threading.Thread): def __init__(self, tb): @@ -184,7 +184,7 @@ if __name__ == '__main__': updates = [] #registry of plugin update functions if options.raw is True: - rawport = air_modes.modes_raw_server(9988) #port + rawport = air_modes.raw_server(9988) #port outputs.append(rawport.output) outputs.append(printraw) updates.append(rawport.add_pending_conns) @@ -192,21 +192,21 @@ if __name__ == '__main__': if options.kml is not None: #we spawn a thread to run every 30 seconds (or whatever) to generate KML dbname = 'adsb.db' - sqldb = air_modes.modes_output_sql(my_position, dbname) #input into the db - kmlgen = air_modes.modes_kml(options.kml, dbname, my_position) #create a KML generating thread to read from the db + sqldb = air_modes.output_sql(my_position, dbname) #input into the db + kmlgen = air_modes.output_kml(options.kml, dbname, my_position) #create a KML generating thread to read from the db outputs.append(sqldb.output) if options.sbs1 is True: - sbs1port = air_modes.modes_output_sbs1(my_position, 30003) + sbs1port = air_modes.output_sbs1(my_position, 30003) outputs.append(sbs1port.output) updates.append(sbs1port.add_pending_conns) if options.no_print is not True: - outputs.append(air_modes.modes_output_print(my_position).output) + outputs.append(air_modes.output_print(my_position).output) if options.multiplayer is not None: [fghost, fgport] = options.multiplayer.split(':') - fgout = air_modes.modes_flightgear(my_position, fghost, int(fgport)) + fgout = air_modes.output_flightgear(my_position, fghost, int(fgport)) outputs.append(fgout.output) fg = adsb_rx_block(options, args, queue) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 1c89e2b..98444b7 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -34,15 +34,15 @@ GR_PYTHON_INSTALL( altitude.py cpr.py mlat.py - modes_exceptions.py - modes_flightgear.py - modes_gui_model.py - modes_kml.py - modes_parse.py - modes_print.py - modes_raw_server.py - modes_sbs1.py - modes_sql.py + exceptions.py + flightgear.py + gui_model.py + kml.py + parse.py + msprint.py + raw_server.py + sbs1.py + sql.py Quaternion.py DESTINATION ${GR_PYTHON_DIR}/air_modes ) diff --git a/python/__init__.py b/python/__init__.py index d292494..045e4c7 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -51,15 +51,16 @@ from air_modes_swig import * # import any pure python here # -from modes_print import modes_output_print -from modes_sql import modes_output_sql -from modes_sbs1 import modes_output_sbs1 -from modes_kml import modes_kml -from modes_raw_server import modes_raw_server -from modes_exceptions import * +from parse import parse,modes_reply +from msprint import output_print +from sql import output_sql +from sbs1 import output_sbs1 +from kml import output_kml +from raw_server import raw_server +from exceptions import * #this is try/excepted in case the user doesn't have numpy installed try: - from modes_flightgear import modes_flightgear + from flightgear import output_flightgear from Quaternion import * except ImportError: print "gr-air-modes warning: numpy+scipy not installed, FlightGear interface not supported" diff --git a/python/altitude.py b/python/altitude.py index 6c2d120..1824194 100755 --- a/python/altitude.py +++ b/python/altitude.py @@ -23,7 +23,7 @@ # For reference into the methodology used to decode altitude, # see RTCA DO-181D p.42 -from modes_exceptions import * +from air_modes.exceptions import * def decode_alt(alt, bit13): mbit = alt & 0x0040 diff --git a/python/cpr.py b/python/cpr.py index 66ed474..5115bf5 100755 --- a/python/cpr.py +++ b/python/cpr.py @@ -21,7 +21,7 @@ # import math, time -from modes_exceptions import * +from air_modes.exceptions import * #this implements CPR position decoding and encoding. #the decoder is implemented as a class, cpr_decoder, which keeps state for local decoding. #the encoder is cpr_encode([lat, lon], type (even=0, odd=1), and surface (0 for surface, 1 for airborne)) diff --git a/python/modes_exceptions.py b/python/exceptions.py similarity index 100% rename from python/modes_exceptions.py rename to python/exceptions.py diff --git a/python/modes_flightgear.py b/python/flightgear.py similarity index 96% rename from python/modes_flightgear.py rename to python/flightgear.py index 2a50e95..b28c3c6 100755 --- a/python/modes_flightgear.py +++ b/python/flightgear.py @@ -5,17 +5,18 @@ import struct import socket -from air_modes import mlat, modes_parse +import air_modes +from air_modes import mlat import sqlite3 import string, threading, math, time -from air_modes.modes_sql import modes_output_sql +from air_modes.sql import output_sql from Quaternion import Quat import numpy -from modes_exceptions import * +from air_modes.exceptions import * -class modes_flightgear(modes_parse.modes_parse): +class output_flightgear(air_modes.parse): def __init__(self, localpos, hostname, port): - modes_parse.modes_parse.__init__(self, localpos) + air_modes.parse.__init__(self, localpos) self.hostname = hostname self.port = port self.localpos = localpos @@ -28,7 +29,7 @@ class modes_flightgear(modes_parse.modes_parse): def output(self, message): [data, ecc, reference, timestamp] = message.split() - data = modes_parse.modes_reply(long(data, 16)) + data = air_modes.modes_reply(long(data, 16)) try: msgtype = data["df"] @@ -204,7 +205,7 @@ if __name__ == '__main__': localpos = [37.409066,-122.077836] hostname = "localhost" port = 5000 - fgout = modes_flightgear(localpos, hostname, port) + fgout = output_flightgear(localpos, hostname, port) for line in iof: timetosend = float(line.split()[6]) diff --git a/python/modes_gui_model.py b/python/gui_model.py similarity index 97% rename from python/modes_gui_model.py rename to python/gui_model.py index 1a661d5..93b87e1 100644 --- a/python/modes_gui_model.py +++ b/python/gui_model.py @@ -140,13 +140,13 @@ class dashboard_data_model(QtCore.QAbstractTableModel): self.endRemoveRows() self.lock.release() -class dashboard_output(air_modes.modes_parse.modes_parse): +class dashboard_output(air_modes.parse): def __init__(self, mypos, model): - air_modes.modes_parse.modes_parse.__init__(self, mypos) + air_modes.parse.__init__(self, mypos) self.model = model def output(self, msg): [data, ecc, reference, timestamp] = msg.split() - data = air_modes.modes_parse.modes_reply(long(data, 16)) + data = air_modes.modes_reply(long(data, 16)) ecc = long(ecc, 16) rssi = 10.*math.log10(float(reference)) msgtype = data["df"] diff --git a/python/modes_kml.py b/python/kml.py similarity index 99% rename from python/modes_kml.py rename to python/kml.py index b6d103f..0eca9e9 100644 --- a/python/modes_kml.py +++ b/python/kml.py @@ -22,7 +22,7 @@ import sqlite3 import string, math, threading, time -class modes_kml(threading.Thread): +class output_kml(threading.Thread): def __init__(self, filename, dbname, localpos, timeout=5): threading.Thread.__init__(self) self._dbname = dbname diff --git a/python/modes_datamodel.py b/python/modes_datamodel.py deleted file mode 100644 index acfb4e7..0000000 --- a/python/modes_datamodel.py +++ /dev/null @@ -1,71 +0,0 @@ - -#so, not to be a dick or anything, but this thing could be entirely -#replaced with a clever SQL join or just a separate SQL table flattened -#in modes_sql and designed specifically for this. you can keep the older -#ones, too. this would let you access indices by column name, too. bonus. -#you wouldn't get the nice hierarchical tree view, though. what does that lose you? -#you'd need a different datamodel for the tree view, that's all. -class modes_datamodel(QtCore.QAbstractItemModel): - def __init__(self, db): - QtCore.QAbstractItemModel.__init__(self) - self.db = db - - def rowCount(self, parent=QtCore.QModelIndex()): - icaoquery = "select count(distinct icao) from positions" - query = QtSql.QSqlQuery() - query.exec_(icaoquery) - query.next() - return query.value(0).toInt()[0] - - def columnCount(self, parent=QtCore.QModelIndex()): - return 5 - - #for future use - def flags(self, index): - return QtCore.QAbstractItemModel.flags(self, index) - - def data(self, index, role=QtCore.Qt.DisplayRole): - if not index.isValid(): - return QtCore.QVariant() - if index.row() >= self.rowCount(): - return QtCore.QVariant() - if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole: - #get ICAO of current index - query = QtSql.QSqlQuery() - #TODO: limit this to aircraft seen in last 600 seconds? or make a spinbox for this limit. - icaoquery = "select distinct icao from positions order by icao limit %i,1" % index.row() - query.exec_(icaoquery) - query.next() - icao = query.value(0).toInt()[0] - #TODO figure out how to grab multiple records in one query and return them all? - if index.column() == 0: #ICAO - return "%06x" % icao - elif index.column() == 1: #last seen - seenquery = "select seen from positions where icao = %i order by seen desc limit 1" % icao - query.exec_(seenquery) - return "" if query.next() is False else query.value(0).toString() - elif index.column() == 2: #ident - identquery = "select ident from ident where icao = %i" % icao - query.exec_(identquery) - return "" if query.next() is False else query.value(0).toString() - elif index.column() == 3: #altitude - querystr = "select alt from positions where icao = %i order by seen desc limit 1" % icao - query.exec_(querystr) - return "" if query.next() is False else "%i" % query.value(0).toInt()[0] - elif index.column() == 4: #latitude - querystr = "select lat from positions where icao = %i order by seen desc limit 1" % icao - query.exec_(querystr) - return "" if query.next() is False else "%.6f" % query.value(0).toFloat()[0] - elif index.column() == 5: #longitude - querystr = "select lon from positions where icao = %i order by seen desc limit 1" % icao - query.exec_(querystr) - return "" if query.next() is False else "%.6f" % query.value(0).toFloat()[0] - - else: - return QtCore.QVariant() - - def index(self, row, column, parent=QtCore.QModelIndex()): - return self.createIndex(row, column) - - def parent(self, child): - return QtCore.QModelIndex() diff --git a/python/modes_print.py b/python/msprint.py similarity index 97% rename from python/modes_print.py rename to python/msprint.py index 3f419bc..5f726e2 100644 --- a/python/modes_print.py +++ b/python/msprint.py @@ -21,13 +21,13 @@ import time, os, sys from string import split, join -import modes_parse -from modes_exceptions import * +import air_modes +from air_modes.exceptions import * import math -class modes_output_print(modes_parse.modes_parse): +class output_print(air_modes.parse): def __init__(self, mypos): - modes_parse.modes_parse.__init__(self, mypos) + air_modes.parse.__init__(self, mypos) def parse(self, message): [data, ecc, reference, timestamp] = message.split() @@ -44,7 +44,7 @@ class modes_output_print(modes_parse.modes_parse): output = "(%.0f %.10f) " % (refdb, timestamp); try: - data = modes_parse.modes_reply(long(data, 16)) + data = air_modes.modes_reply(long(data, 16)) msgtype = data["df"] if msgtype == 0: output += self.print0(data, ecc) diff --git a/python/modes_parse.py b/python/parse.py similarity index 99% rename from python/modes_parse.py rename to python/parse.py index 3af9486..b76cf8c 100644 --- a/python/modes_parse.py +++ b/python/parse.py @@ -22,9 +22,9 @@ import time, os, sys from string import split, join from altitude import decode_alt -import cpr import math -from modes_exceptions import * +from air_modes.exceptions import * +from air_modes import cpr #this implements a packet class which can retrieve its own fields. class data_field: @@ -213,7 +213,7 @@ class modes_reply(data_field): def get_type(self): return self.get_bits(1,5) -class modes_parse: +class parse: def __init__(self, mypos): self.my_location = mypos self.cpr = cpr.cpr_decoder(self.my_location) diff --git a/python/modes_raw_server.py b/python/raw_server.py similarity index 98% rename from python/modes_raw_server.py rename to python/raw_server.py index b4e414a..53fa67e 100644 --- a/python/modes_raw_server.py +++ b/python/raw_server.py @@ -24,7 +24,7 @@ import time, os, sys, socket from string import split, join from datetime import * -class modes_raw_server: +class raw_server: def __init__(self, port): self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._s.bind(('', port)) diff --git a/python/modes_sbs1.py b/python/sbs1.py similarity index 97% rename from python/modes_sbs1.py rename to python/sbs1.py index dde1f10..3077de2 100644 --- a/python/modes_sbs1.py +++ b/python/sbs1.py @@ -22,13 +22,13 @@ import time, os, sys, socket from string import split, join -import modes_parse +import air_modes from datetime import * -from modes_exceptions import * +from air_modes.exceptions import * -class modes_output_sbs1(modes_parse.modes_parse): +class output_sbs1(air_modes.parse): def __init__(self, mypos, port): - modes_parse.modes_parse.__init__(self, mypos) + air_modes.parse.__init__(self, mypos) self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._s.bind(('', port)) @@ -106,7 +106,7 @@ class modes_output_sbs1(modes_parse.modes_parse): [data, ecc, reference, timestamp] = message.split() - data = modes_parse.modes_reply(long(data, 16)) + data = air_modes.modes_reply(long(data, 16)) ecc = long(ecc, 16) msgtype = data["df"] outmsg = None diff --git a/python/modes_sql.py b/python/sql.py similarity index 95% rename from python/modes_sql.py rename to python/sql.py index 4c68bc8..94d3a67 100644 --- a/python/modes_sql.py +++ b/python/sql.py @@ -21,13 +21,13 @@ import time, os, sys from string import split, join -import modes_parse +import air_modes import sqlite3 -from modes_exceptions import * +from air_modes.exceptions import * -class modes_output_sql(modes_parse.modes_parse): +class output_sql(air_modes.parse): def __init__(self, mypos, filename): - modes_parse.modes_parse.__init__(self, mypos) + air_modes.parse.__init__(self, mypos) #create the database self.filename = filename self.db = sqlite3.connect(filename) @@ -85,7 +85,7 @@ class modes_output_sql(modes_parse.modes_parse): #this version ignores anything that isn't Type 17 for now, because we just don't care [data, ecc, reference, timestamp] = message.split() - data = modes_parse.modes_reply(long(data, 16)) + data = air_modes.modes_reply(long(data, 16)) ecc = long(ecc, 16) # reference = float(reference)