Fixed GUI live print and reports/sec widget.

This commit is contained in:
Nick Foster 2013-07-18 17:46:50 -07:00
parent b594fe2799
commit 4174658f0d
2 changed files with 31 additions and 27 deletions

View File

@ -179,7 +179,8 @@ class mainwindow(QtGui.QMainWindow):
try: try:
from gnuradio import uhd from gnuradio import uhd
self.src = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1) self.src = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1)
self.rates = [rate.start() for rate in self.src.get_samp_rates() if (rate.start() % 2.e6) == 0] self.rates = [rate.start() for rate in self.src.get_samp_rates()
if (rate.start() % 2.e6) == 0 and rate >= 4e6]
self.antennas = self.src.get_antennas() self.antennas = self.src.get_antennas()
self.src = None #deconstruct UHD source for now self.src = None #deconstruct UHD source for now
self.ui.combo_ant.setEnabled(True) self.ui.combo_ant.setEnabled(True)
@ -224,8 +225,9 @@ class mainwindow(QtGui.QMainWindow):
self.ui.combo_ant.clear() self.ui.combo_ant.clear()
self.ui.combo_ant.addItems(self.antennas) self.ui.combo_ant.addItems(self.antennas)
if 4e6 in self.rates: #set up recommended sample rate
self.ui.combo_rate.setCurrentIndex(self.rates.index(4e6)) lowest_rate_valid = min(x for x in self.rates if x >= 4e6)
self.ui.combo_rate.setCurrentIndex(self.rates.index(lowest_rate_valid))
################ action handlers #################### ################ action handlers ####################
def on_combo_source_currentIndexChanged(self, index): def on_combo_source_currentIndexChanged(self, index):
@ -302,9 +304,9 @@ class mainwindow(QtGui.QMainWindow):
self._htmlfile = open("/tmp/mode_s.html", 'wb+')#tempfile.NamedTemporaryFile() self._htmlfile = open("/tmp/mode_s.html", 'wb+')#tempfile.NamedTemporaryFile()
self._jsonfile = tempfile.NamedTemporaryFile() self._jsonfile = tempfile.NamedTemporaryFile()
self.livedata = air_modes.output_print(self._cpr_dec, self._publisher) self.livedata = air_modes.output_print(self._cpr_dec,
#add output for live data box self._publisher,
#self._relay.subscribe("dl_data", self.output_live_data) self.live_data_changed_signal.emit)
#create SQL database for KML and dashboard displays #create SQL database for KML and dashboard displays
self.dbwriter = air_modes.output_sql(self._cpr_dec, self.dbname, self.lock, self._publisher) self.dbwriter = air_modes.output_sql(self._cpr_dec, self.dbname, self.lock, self._publisher)
@ -322,7 +324,9 @@ class mainwindow(QtGui.QMainWindow):
#output to update reports/sec widget #output to update reports/sec widget
self._relay.subscribe("dl_data", self.increment_reportspersec) self._relay.subscribe("dl_data", self.increment_reportspersec)
#self.updates.append(self.update_reportspersec) #TODO FIXME self._rps_timer = QtCore.QTimer()
self._rps_timer.timeout.connect(self.update_reportspersec)
self._rps_timer.start(1000)
#start the flowgraph #start the flowgraph
self._radio.start() self._radio.start()
@ -336,6 +340,7 @@ class mainwindow(QtGui.QMainWindow):
self._radio.close() self._radio.close()
self._relay = None self._relay = None
self._radio = None self._radio = None
self._rps_timer = None
try: try:
self.kmlgen.done = True self.kmlgen.done = True
#TODO FIXME need a way to kill kmlgen safely without delay #TODO FIXME need a way to kill kmlgen safely without delay
@ -357,14 +362,6 @@ class mainwindow(QtGui.QMainWindow):
self.ui.text_livedata.append(msgstr) self.ui.text_livedata.append(msgstr)
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum()) self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())
def output_live_data(self, msg):
try:
msgstr = self.livedata.parse(msg)
if msgstr is not None:
self.live_data_changed_signal.emit(msgstr)
except ADSBError:
pass
if __name__ == '__main__': if __name__ == '__main__':
app = QtGui.QApplication(sys.argv) app = QtGui.QApplication(sys.argv)
window = mainwindow() window = mainwindow()

View File

@ -28,9 +28,10 @@ import math
#TODO get rid of class and convert to functions #TODO get rid of class and convert to functions
#no need for class here #no need for class here
class output_print: class output_print:
def __init__(self, cpr, publisher): def __init__(self, cpr, publisher, callback=None):
self._cpr = cpr self._cpr = cpr
#sub to every function that starts with "print" self._callback = callback
#sub to every function that starts with "handle"
self._fns = [int(l[6:]) for l in dir(self) if l.startswith("handle")] self._fns = [int(l[6:]) for l in dir(self) if l.startswith("handle")]
for i in self._fns: for i in self._fns:
publisher.subscribe("type%i_dl" % i, getattr(self, "handle%i" % i)) publisher.subscribe("type%i_dl" % i, getattr(self, "handle%i" % i))
@ -41,6 +42,12 @@ class output_print:
def prefix(msg): def prefix(msg):
return "(%i %.8f) " % (msg.rssi, msg.timestamp) return "(%i %.8f) " % (msg.rssi, msg.timestamp)
def _print(self, msg):
if self._callback is None:
print msg
else:
self._callback(msg)
def catch_nohandler(self, msg): def catch_nohandler(self, msg):
if msg.data.get_type() not in self._fns: if msg.data.get_type() not in self._fns:
retstr = output_print.prefix(msg) retstr = output_print.prefix(msg)
@ -49,7 +56,7 @@ class output_print:
retstr += " from %.6x" % msg.ecc retstr += " from %.6x" % msg.ecc
else: else:
retstr += " from %.6x" % msg.data["aa"] retstr += " from %.6x" % msg.data["aa"]
print retstr self._print(retstr)
def handle0(self, msg): def handle0(self, msg):
try: try:
@ -77,7 +84,7 @@ class output_print:
if msg.data["vs"] is 1: if msg.data["vs"] is 1:
retstr += " (aircraft is on the ground)" retstr += " (aircraft is on the ground)"
print retstr self._print(retstr)
@staticmethod @staticmethod
def fs_text(fs): def fs_text(fs):
@ -101,7 +108,7 @@ class output_print:
retstr += output_print.fs_text(msg.data["fs"]) retstr += output_print.fs_text(msg.data["fs"])
except ADSBError: except ADSBError:
return return
print retstr self._print(retstr)
def handle5(self, msg): def handle5(self, msg):
try: try:
@ -110,7 +117,7 @@ class output_print:
retstr += output_print.fs_text(msg.data["fs"]) retstr += output_print.fs_text(msg.data["fs"])
except ADSBError: except ADSBError:
return return
print retstr self._print(retstr)
def handle11(self, msg): def handle11(self, msg):
try: try:
@ -118,7 +125,7 @@ class output_print:
retstr += "Type 11 (all call reply) from %x in reply to interrogator %i with capability level %i" % (msg.data["aa"], msg.ecc & 0xF, msg.data["ca"]+1) retstr += "Type 11 (all call reply) from %x in reply to interrogator %i with capability level %i" % (msg.data["aa"], msg.ecc & 0xF, msg.data["ca"]+1)
except ADSBError: except ADSBError:
return return
print retstr self._print(retstr)
#the only one which requires state #the only one which requires state
def handle17(self, msg): def handle17(self, msg):
@ -170,7 +177,7 @@ class output_print:
except ADSBError: except ADSBError:
return return
print retstr self._print(retstr)
def printTCAS(self, msg): def printTCAS(self, msg):
msgtype = msg.data["df"] msgtype = msg.data["df"]
@ -223,7 +230,7 @@ class output_print:
else: else:
retstr += " ident %x" % air_modes.decode_id(msg.data["id"]) retstr += " ident %x" % air_modes.decode_id(msg.data["id"])
print retstr self._print(retstr)
handle16 = printTCAS handle16 = printTCAS
handle20 = printTCAS handle20 = printTCAS