Renamed everything in python/ for consistent namespace

This commit is contained in:
Nick Foster 2012-07-16 19:27:09 -07:00
parent 5442cba206
commit 3163fca47a
16 changed files with 65 additions and 134 deletions

View File

@ -25,9 +25,9 @@ from PyQt4.Qwt5 import Qwt
from gnuradio import gr, gru, optfir, eng_notation, blks2 from gnuradio import gr, gru, optfir, eng_notation, blks2
import gnuradio.gr.gr_threading as _threading import gnuradio.gr.gr_threading as _threading
import air_modes 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_rx_ui import Ui_MainWindow
from air_modes.modes_gui_model import * from air_modes.gui_model import *
import sqlite3 import sqlite3
class mainwindow(QtGui.QMainWindow): class mainwindow(QtGui.QMainWindow):
@ -254,32 +254,32 @@ class mainwindow(QtGui.QMainWindow):
#output options to populate outputs, updates #output options to populate outputs, updates
if self.ui.check_kml.checkState(): if self.ui.check_kml.checkState():
#we spawn a thread to run every 30 seconds (or whatever) to generate KML #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(): if self.ui.check_sbs1.checkState():
sbs1port = int(self.ui.line_sbs1port.text()) 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.outputs.append(sbs1out.output)
self.updates.append(sbs1out.add_pending_conns) self.updates.append(sbs1out.add_pending_conns)
if self.ui.check_fgfs.checkState(): if self.ui.check_fgfs.checkState():
fghost = "127.0.0.1" #TODO FIXME fghost = "127.0.0.1" #TODO FIXME
fgport = self.ui.line_fgfsport.currentText() 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) self.outputs.append(fgout.output)
if self.ui.check_raw.checkState(): 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.outputs.append(rawport.output)
self.updates.append(rawport.add_pending_conns) 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 #add output for live data box
#TODO: this doesn't handle large volumes of data well; i get segfaults. #TODO: this doesn't handle large volumes of data well; i get segfaults.
#self.outputs.append(self.output_live_data) #self.outputs.append(self.output_live_data)
#create SQL database for KML and dashboard displays #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 self.outputs.append(self.dbwriter.output) #now the db will update itself
#output to update reports/sec widget #output to update reports/sec widget

View File

@ -29,7 +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 * from air_modes.exceptions import *
class top_block_runner(_threading.Thread): class top_block_runner(_threading.Thread):
def __init__(self, tb): def __init__(self, tb):
@ -184,7 +184,7 @@ if __name__ == '__main__':
updates = [] #registry of plugin update functions updates = [] #registry of plugin update functions
if options.raw is True: 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(rawport.output)
outputs.append(printraw) outputs.append(printraw)
updates.append(rawport.add_pending_conns) updates.append(rawport.add_pending_conns)
@ -192,21 +192,21 @@ if __name__ == '__main__':
if options.kml is not None: if options.kml is not None:
#we spawn a thread to run every 30 seconds (or whatever) to generate KML #we spawn a thread to run every 30 seconds (or whatever) to generate KML
dbname = 'adsb.db' dbname = 'adsb.db'
sqldb = air_modes.modes_output_sql(my_position, dbname) #input into the db sqldb = air_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 kmlgen = air_modes.output_kml(options.kml, dbname, my_position) #create a KML generating thread to read from the db
outputs.append(sqldb.output) outputs.append(sqldb.output)
if options.sbs1 is True: 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) outputs.append(sbs1port.output)
updates.append(sbs1port.add_pending_conns) updates.append(sbs1port.add_pending_conns)
if options.no_print is not True: 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: if options.multiplayer is not None:
[fghost, fgport] = options.multiplayer.split(':') [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) outputs.append(fgout.output)
fg = adsb_rx_block(options, args, queue) fg = adsb_rx_block(options, args, queue)

View File

@ -34,15 +34,15 @@ GR_PYTHON_INSTALL(
altitude.py altitude.py
cpr.py cpr.py
mlat.py mlat.py
modes_exceptions.py exceptions.py
modes_flightgear.py flightgear.py
modes_gui_model.py gui_model.py
modes_kml.py kml.py
modes_parse.py parse.py
modes_print.py msprint.py
modes_raw_server.py raw_server.py
modes_sbs1.py sbs1.py
modes_sql.py sql.py
Quaternion.py Quaternion.py
DESTINATION ${GR_PYTHON_DIR}/air_modes DESTINATION ${GR_PYTHON_DIR}/air_modes
) )

View File

@ -51,15 +51,16 @@ from air_modes_swig import *
# import any pure python here # import any pure python here
# #
from modes_print import modes_output_print from parse import parse,modes_reply
from modes_sql import modes_output_sql from msprint import output_print
from modes_sbs1 import modes_output_sbs1 from sql import output_sql
from modes_kml import modes_kml from sbs1 import output_sbs1
from modes_raw_server import modes_raw_server from kml import output_kml
from modes_exceptions import * from raw_server import raw_server
from exceptions import *
#this is try/excepted in case the user doesn't have numpy installed #this is try/excepted in case the user doesn't have numpy installed
try: try:
from modes_flightgear import modes_flightgear from flightgear import output_flightgear
from Quaternion import * from Quaternion import *
except ImportError: except ImportError:
print "gr-air-modes warning: numpy+scipy not installed, FlightGear interface not supported" print "gr-air-modes warning: numpy+scipy not installed, FlightGear interface not supported"

View File

@ -23,7 +23,7 @@
# For reference into the methodology used to decode altitude, # For reference into the methodology used to decode altitude,
# see RTCA DO-181D p.42 # see RTCA DO-181D p.42
from modes_exceptions import * from air_modes.exceptions import *
def decode_alt(alt, bit13): def decode_alt(alt, bit13):
mbit = alt & 0x0040 mbit = alt & 0x0040

View File

@ -21,7 +21,7 @@
# #
import math, time import math, time
from modes_exceptions import * from air_modes.exceptions import *
#this implements CPR position decoding and encoding. #this implements CPR position decoding and encoding.
#the decoder is implemented as a class, cpr_decoder, which keeps state for local decoding. #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)) #the encoder is cpr_encode([lat, lon], type (even=0, odd=1), and surface (0 for surface, 1 for airborne))

View File

@ -5,17 +5,18 @@
import struct import struct
import socket import socket
from air_modes import mlat, modes_parse import air_modes
from air_modes import mlat
import sqlite3 import sqlite3
import string, threading, math, time 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 from Quaternion import Quat
import numpy 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): def __init__(self, localpos, hostname, port):
modes_parse.modes_parse.__init__(self, localpos) air_modes.parse.__init__(self, localpos)
self.hostname = hostname self.hostname = hostname
self.port = port self.port = port
self.localpos = localpos self.localpos = localpos
@ -28,7 +29,7 @@ class modes_flightgear(modes_parse.modes_parse):
def output(self, message): def output(self, message):
[data, ecc, reference, timestamp] = message.split() [data, ecc, reference, timestamp] = message.split()
data = modes_parse.modes_reply(long(data, 16)) data = air_modes.modes_reply(long(data, 16))
try: try:
msgtype = data["df"] msgtype = data["df"]
@ -204,7 +205,7 @@ if __name__ == '__main__':
localpos = [37.409066,-122.077836] localpos = [37.409066,-122.077836]
hostname = "localhost" hostname = "localhost"
port = 5000 port = 5000
fgout = modes_flightgear(localpos, hostname, port) fgout = output_flightgear(localpos, hostname, port)
for line in iof: for line in iof:
timetosend = float(line.split()[6]) timetosend = float(line.split()[6])

View File

@ -140,13 +140,13 @@ class dashboard_data_model(QtCore.QAbstractTableModel):
self.endRemoveRows() self.endRemoveRows()
self.lock.release() self.lock.release()
class dashboard_output(air_modes.modes_parse.modes_parse): class dashboard_output(air_modes.parse):
def __init__(self, mypos, model): def __init__(self, mypos, model):
air_modes.modes_parse.modes_parse.__init__(self, mypos) air_modes.parse.__init__(self, mypos)
self.model = model self.model = model
def output(self, msg): def output(self, msg):
[data, ecc, reference, timestamp] = msg.split() [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) ecc = long(ecc, 16)
rssi = 10.*math.log10(float(reference)) rssi = 10.*math.log10(float(reference))
msgtype = data["df"] msgtype = data["df"]

View File

@ -22,7 +22,7 @@
import sqlite3 import sqlite3
import string, math, threading, time import string, math, threading, time
class modes_kml(threading.Thread): class output_kml(threading.Thread):
def __init__(self, filename, dbname, localpos, timeout=5): def __init__(self, filename, dbname, localpos, timeout=5):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self._dbname = dbname self._dbname = dbname

View File

@ -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()

View File

@ -21,13 +21,13 @@
import time, os, sys import time, os, sys
from string import split, join from string import split, join
import modes_parse import air_modes
from modes_exceptions import * from air_modes.exceptions import *
import math import math
class modes_output_print(modes_parse.modes_parse): class output_print(air_modes.parse):
def __init__(self, mypos): def __init__(self, mypos):
modes_parse.modes_parse.__init__(self, mypos) air_modes.parse.__init__(self, mypos)
def parse(self, message): def parse(self, message):
[data, ecc, reference, timestamp] = message.split() [data, ecc, reference, timestamp] = message.split()
@ -44,7 +44,7 @@ class modes_output_print(modes_parse.modes_parse):
output = "(%.0f %.10f) " % (refdb, timestamp); output = "(%.0f %.10f) " % (refdb, timestamp);
try: try:
data = modes_parse.modes_reply(long(data, 16)) data = air_modes.modes_reply(long(data, 16))
msgtype = data["df"] msgtype = data["df"]
if msgtype == 0: if msgtype == 0:
output += self.print0(data, ecc) output += self.print0(data, ecc)

View File

@ -22,9 +22,9 @@
import time, os, sys import time, os, sys
from string import split, join from string import split, join
from altitude import decode_alt from altitude import decode_alt
import cpr
import math 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. #this implements a packet class which can retrieve its own fields.
class data_field: class data_field:
@ -213,7 +213,7 @@ class modes_reply(data_field):
def get_type(self): def get_type(self):
return self.get_bits(1,5) return self.get_bits(1,5)
class modes_parse: class parse:
def __init__(self, mypos): def __init__(self, mypos):
self.my_location = mypos self.my_location = mypos
self.cpr = cpr.cpr_decoder(self.my_location) self.cpr = cpr.cpr_decoder(self.my_location)

View File

@ -24,7 +24,7 @@ import time, os, sys, socket
from string import split, join from string import split, join
from datetime import * from datetime import *
class modes_raw_server: class raw_server:
def __init__(self, port): def __init__(self, port):
self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._s.bind(('', port)) self._s.bind(('', port))

View File

@ -22,13 +22,13 @@
import time, os, sys, socket import time, os, sys, socket
from string import split, join from string import split, join
import modes_parse import air_modes
from datetime import * 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): 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 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self._s.bind(('', port)) self._s.bind(('', port))
@ -106,7 +106,7 @@ class modes_output_sbs1(modes_parse.modes_parse):
[data, ecc, reference, timestamp] = message.split() [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) ecc = long(ecc, 16)
msgtype = data["df"] msgtype = data["df"]
outmsg = None outmsg = None

View File

@ -21,13 +21,13 @@
import time, os, sys import time, os, sys
from string import split, join from string import split, join
import modes_parse import air_modes
import sqlite3 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): def __init__(self, mypos, filename):
modes_parse.modes_parse.__init__(self, mypos) air_modes.parse.__init__(self, mypos)
#create the database #create the database
self.filename = filename self.filename = filename
self.db = sqlite3.connect(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 #this version ignores anything that isn't Type 17 for now, because we just don't care
[data, ecc, reference, timestamp] = message.split() [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) ecc = long(ecc, 16)
# reference = float(reference) # reference = float(reference)