Setting up a model-view display for the airframe list.
This commit is contained in:
+59
-13
@@ -8,13 +8,13 @@ import air_modes
|
||||
from air_modes.modes_exceptions import *
|
||||
from air_modes.modes_rx_ui import Ui_MainWindow
|
||||
import csv
|
||||
import sqlite3
|
||||
|
||||
class mainwindow(QtGui.QMainWindow):
|
||||
def __init__(self):
|
||||
QtGui.QMainWindow.__init__(self)
|
||||
self.ui = Ui_MainWindow()
|
||||
self.ui.setupUi(self)
|
||||
self.setObjectName("gr-air-modes Mode S receiver")
|
||||
|
||||
#set defaults
|
||||
#add file, RTL, UHD sources
|
||||
@@ -53,6 +53,13 @@ class mainwindow(QtGui.QMainWindow):
|
||||
self.updates = []
|
||||
self.output_handler = None
|
||||
self.kmlgen = None #necessary bc we stop its thread in shutdown
|
||||
self.dbinput = None
|
||||
|
||||
self.dbname = 'air_modes.db'
|
||||
|
||||
self.datamodel = modes_datamodel(self.dbname)
|
||||
self.ui.list_aircraft.setModel(self.datamodel)
|
||||
self.ui.list_aircraft.show() #TODO remove
|
||||
|
||||
#goes and gets valid antenna, sample rate options from the device and grays out appropriate things
|
||||
def populate_source_options(self):
|
||||
@@ -111,6 +118,8 @@ class mainwindow(QtGui.QMainWindow):
|
||||
if self.runner is not None:
|
||||
self.output_handler.done = True
|
||||
self.output_handler = None
|
||||
self.outputs = []
|
||||
self.updates = []
|
||||
self.fg.stop()
|
||||
self.runner = None
|
||||
self.fg = None
|
||||
@@ -120,6 +129,9 @@ class mainwindow(QtGui.QMainWindow):
|
||||
#self.kmlgen.join()
|
||||
#self.kmlgen = None
|
||||
|
||||
if self.dbinput is not None: self.dbinput.close()
|
||||
self.dbinput = None
|
||||
|
||||
self.ui.button_start.setText("Start")
|
||||
|
||||
else: #we aren't already running, let's get this party started
|
||||
@@ -145,8 +157,7 @@ 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(), my_position) #create a KML generating thread
|
||||
self.outputs.append(self.kmlgen.output)
|
||||
self.kmlgen = air_modes.modes_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())
|
||||
@@ -166,19 +177,57 @@ class mainwindow(QtGui.QMainWindow):
|
||||
self.updates.append(rawport.add_pending_conns)
|
||||
|
||||
self.livedata = air_modes.modes_output_print(my_position)
|
||||
|
||||
#add output for live data box
|
||||
self.outputs.append(self.output_live_data)
|
||||
|
||||
#create output handler
|
||||
#create SQL database for KML and dashboard displays
|
||||
self.dbwriter = air_modes.modes_output_sql(my_position, self.dbname)
|
||||
self.outputs.append(self.dbwriter.output) #now the db will update itself
|
||||
|
||||
#create output handler thread
|
||||
self.output_handler = output_handler(self.outputs, self.updates, self.queue)
|
||||
self.ui.button_start.setText("Stop") #modify button text
|
||||
|
||||
self.ui.button_start.setText("Stop")
|
||||
|
||||
def output_live_data(self, msg):
|
||||
msgstr = self.livedata.parse(msg)
|
||||
if msgstr is not None:
|
||||
self.ui.text_livedata.append(msgstr)
|
||||
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())
|
||||
|
||||
def on_list_aircraft_clicked(self, index):
|
||||
icao = long(str(index.data().toString()), 16)
|
||||
#ok now let's fetch the info for this icao and update the display
|
||||
print icao
|
||||
|
||||
#eventually: set up a QTimer or whatever and have it self-update and emit dataChanged()
|
||||
#better yet just have the SQL interface yell and say hey that line changed.
|
||||
#on selected aircraft or on update for visible aircraft, emit signal to update current dashboard display.
|
||||
class modes_datamodel(QtCore.QAbstractListModel):
|
||||
def __init__(self, dbname):
|
||||
QtCore.QAbstractListModel.__init__(self)
|
||||
self.db = sqlite3.connect(dbname)
|
||||
def rowCount(self, parent=QtCore.QModelIndex()):
|
||||
icaoquery = "select count(distinct icao) from positions"
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute(icaoquery)
|
||||
icaolist = cursor.fetchall()
|
||||
cursor.close()
|
||||
return icaolist[0][0]
|
||||
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:
|
||||
return QtCore.QVariant()
|
||||
|
||||
icaoquery = "select distinct icao from positions order by icao"
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute(icaoquery)
|
||||
icaolist = cursor.fetchall()
|
||||
cursor.close()
|
||||
return "%06x" % icaolist[index.row()][0]
|
||||
|
||||
class output_handler(threading.Thread):
|
||||
def __init__(self, outputs, updates, queue):
|
||||
@@ -205,6 +254,9 @@ class output_handler(threading.Thread):
|
||||
time.sleep(0.1)
|
||||
|
||||
self.done = True
|
||||
self.outputs = None
|
||||
self.updates = None
|
||||
self.queue = None
|
||||
|
||||
|
||||
class top_block_runner(_threading.Thread):
|
||||
@@ -274,17 +326,11 @@ class adsb_rx_block (gr.top_block):
|
||||
self.connect(self.avg, (self.preamble, 1))
|
||||
self.connect(self.preamble, self.slicer)
|
||||
|
||||
class wat_block(gr.top_block):
|
||||
def __init__(self, options, queue):
|
||||
gr.top_block.__init__(self)
|
||||
|
||||
self.src = gr.file_source(gr.sizeof_gr_complex, options["filename"])
|
||||
self.sink = gr.null_sink(gr.sizeof_gr_complex)
|
||||
self.connect(self.src, self.sink)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QtGui.QApplication(sys.argv)
|
||||
window = mainwindow()
|
||||
window.setWindowTitle("Mode S/ADS-B receiver")
|
||||
window.show()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
|
||||
+4
-2
@@ -190,8 +190,10 @@ if __name__ == '__main__':
|
||||
|
||||
if options.kml is not None:
|
||||
#we spawn a thread to run every 30 seconds (or whatever) to generate KML
|
||||
kmlgen = air_modes.modes_kml(options.kml, my_position) #create a KML generating thread
|
||||
outputs.append(kmlgen.output)
|
||||
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
|
||||
outputs.append(sqldb.output)
|
||||
|
||||
if options.sbs1 is True:
|
||||
sbs1port = air_modes.modes_output_sbs1(my_position, 30003)
|
||||
|
||||
Reference in New Issue
Block a user