diff --git a/apps/modes_gui b/apps/modes_gui index d5d21aa..4ab12c2 100755 --- a/apps/modes_gui +++ b/apps/modes_gui @@ -179,7 +179,8 @@ class mainwindow(QtGui.QMainWindow): try: from gnuradio import uhd 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.src = None #deconstruct UHD source for now self.ui.combo_ant.setEnabled(True) @@ -224,8 +225,9 @@ class mainwindow(QtGui.QMainWindow): self.ui.combo_ant.clear() self.ui.combo_ant.addItems(self.antennas) - if 4e6 in self.rates: - self.ui.combo_rate.setCurrentIndex(self.rates.index(4e6)) + #set up recommended sample rate + 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 #################### 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._jsonfile = tempfile.NamedTemporaryFile() - self.livedata = air_modes.output_print(self._cpr_dec, self._publisher) - #add output for live data box - #self._relay.subscribe("dl_data", self.output_live_data) + self.livedata = air_modes.output_print(self._cpr_dec, + self._publisher, + self.live_data_changed_signal.emit) #create SQL database for KML and dashboard displays 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 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 self._radio.start() @@ -336,6 +340,7 @@ class mainwindow(QtGui.QMainWindow): self._radio.close() self._relay = None self._radio = None + self._rps_timer = None try: self.kmlgen.done = True #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.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__': app = QtGui.QApplication(sys.argv) window = mainwindow() diff --git a/python/msprint.py b/python/msprint.py index 7671a98..e2c8ff0 100644 --- a/python/msprint.py +++ b/python/msprint.py @@ -28,9 +28,10 @@ import math #TODO get rid of class and convert to functions #no need for class here class output_print: - def __init__(self, cpr, publisher): + def __init__(self, cpr, publisher, callback=None): 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")] for i in self._fns: publisher.subscribe("type%i_dl" % i, getattr(self, "handle%i" % i)) @@ -41,6 +42,12 @@ class output_print: def prefix(msg): 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): if msg.data.get_type() not in self._fns: retstr = output_print.prefix(msg) @@ -49,7 +56,7 @@ class output_print: retstr += " from %.6x" % msg.ecc else: retstr += " from %.6x" % msg.data["aa"] - print retstr + self._print(retstr) def handle0(self, msg): try: @@ -77,7 +84,7 @@ class output_print: if msg.data["vs"] is 1: retstr += " (aircraft is on the ground)" - print retstr + self._print(retstr) @staticmethod def fs_text(fs): @@ -101,7 +108,7 @@ class output_print: retstr += output_print.fs_text(msg.data["fs"]) except ADSBError: return - print retstr + self._print(retstr) def handle5(self, msg): try: @@ -110,7 +117,7 @@ class output_print: retstr += output_print.fs_text(msg.data["fs"]) except ADSBError: return - print retstr + self._print(retstr) def handle11(self, msg): 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) except ADSBError: return - print retstr + self._print(retstr) #the only one which requires state def handle17(self, msg): @@ -157,20 +164,20 @@ class output_print: [mag_hdg, vel_src, vel, vert_spd, geo_diff] = air_modes.parseBDS09_3(msg.data) retstr += "Type 17 BDS0,9-%i (air course report) from %x with %s %.0fkt magnetic heading %.0f VS %.0f geo. diff. from baro. alt. %.0fft" \ % (subtype, icao24, vel_src, vel, mag_hdg, vert_spd, geo_diff) - + else: retstr += "Type 17 BDS0,9-%i from %x not implemented" % (subtype, icao24) elif bdsreg == 0x62: emerg_str = air_modes.parseBDS62(data) retstr += "Type 17 BDS6,2 (emergency) from %x type %s" % (icao24, emerg_str) - + else: retstr += "Type 17 with FTC=%i from %x not implemented" % (msg.data["ftc"], icao24) except ADSBError: return - print retstr + self._print(retstr) def printTCAS(self, msg): msgtype = msg.data["df"] @@ -222,8 +229,8 @@ class output_print: retstr += " at %ift" % air_modes.decode_alt(msg.data["ac"], True) else: retstr += " ident %x" % air_modes.decode_id(msg.data["id"]) - - print retstr + + self._print(retstr) handle16 = printTCAS handle20 = printTCAS