2012-07-17 10:10:23 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright 2012 Nick Foster
|
|
|
|
#
|
|
|
|
# This file is part of gr-air-modes
|
|
|
|
#
|
|
|
|
# gr-air-modes is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
#
|
|
|
|
# gr-air-modes is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with gr-air-modes; see the file COPYING. If not, write to
|
|
|
|
# the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
# Boston, MA 02110-1301, USA.
|
|
|
|
#
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
import os, sys, time, threading, datetime, math, csv, tempfile, ConfigParser
|
2013-06-10 23:57:12 +08:00
|
|
|
from optparse import OptionParser
|
2013-06-21 14:05:41 +08:00
|
|
|
from PyQt4 import QtCore,QtGui,QtWebKit
|
2012-07-12 15:02:11 +08:00
|
|
|
from PyQt4.Qwt5 import Qwt
|
2013-07-18 12:46:25 +08:00
|
|
|
from gnuradio import gr, eng_notation
|
2013-06-10 23:57:12 +08:00
|
|
|
from gnuradio.eng_option import eng_option
|
2013-06-20 02:24:11 +08:00
|
|
|
from gnuradio.gr.pubsub import pubsub
|
2012-07-03 09:55:05 +08:00
|
|
|
import air_modes
|
2012-07-17 10:27:09 +08:00
|
|
|
from air_modes.exceptions import *
|
2012-07-06 02:10:27 +08:00
|
|
|
from air_modes.modes_rx_ui import Ui_MainWindow
|
2012-07-17 10:27:09 +08:00
|
|
|
from air_modes.gui_model import *
|
2012-07-06 14:52:00 +08:00
|
|
|
import sqlite3
|
2013-06-10 23:57:12 +08:00
|
|
|
import zmq
|
2012-07-03 09:55:05 +08:00
|
|
|
|
|
|
|
class mainwindow(QtGui.QMainWindow):
|
2012-10-09 09:44:52 +08:00
|
|
|
live_data_changed_signal = QtCore.pyqtSignal(QtCore.QString, name='liveDataChanged')
|
2012-07-03 09:55:05 +08:00
|
|
|
def __init__(self):
|
|
|
|
QtGui.QMainWindow.__init__(self)
|
|
|
|
self.ui = Ui_MainWindow()
|
|
|
|
self.ui.setupUi(self)
|
|
|
|
|
|
|
|
#set defaults
|
|
|
|
#add file, RTL, UHD sources
|
2013-06-10 23:57:12 +08:00
|
|
|
self.ui.combo_source.addItems(["UHD", "Osmocom", "File/UDP"])
|
2012-07-03 22:45:34 +08:00
|
|
|
self.ui.combo_source.setCurrentIndex(0)
|
2012-07-03 09:55:05 +08:00
|
|
|
|
|
|
|
#populate antenna, rate combo boxes based on source
|
|
|
|
self.populate_source_options()
|
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
defaults = self.get_defaults()
|
|
|
|
|
2012-07-03 09:55:05 +08:00
|
|
|
#should round to actual achieved gain
|
2013-07-24 02:37:52 +08:00
|
|
|
self.ui.line_gain.insert(defaults["gain"])
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2012-10-14 11:52:38 +08:00
|
|
|
#default to 5dB
|
2013-07-24 02:37:52 +08:00
|
|
|
self.ui.line_threshold.insert(defaults["threshold"])
|
|
|
|
|
|
|
|
if defaults["pmf"] is not None:
|
|
|
|
self.ui.check_pmf.setChecked(bool(defaults["pmf"]))
|
|
|
|
if defaults["samplerate"] is not None:
|
|
|
|
self.ui.combo_rate.setCurrentIndex(self.rates.index(int(defaults["samplerate"])))
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2013-06-10 23:57:12 +08:00
|
|
|
self.ui.prog_rssi.setMinimum(0)
|
|
|
|
self.ui.prog_rssi.setMaximum(40)
|
2012-07-12 15:02:11 +08:00
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
if defaults["antenna"] is None:
|
|
|
|
self.ui.combo_ant.setCurrentIndex(self.ui.combo_ant.findText("RX2"))
|
|
|
|
else:
|
|
|
|
self.ui.combo_ant.setCurrentIndex(self.ui.combo_ant.findText(defaults["antenna"]))
|
2012-07-03 09:55:05 +08:00
|
|
|
|
|
|
|
#check KML by default, leave the rest unchecked.
|
2013-07-24 02:37:52 +08:00
|
|
|
self.ui.check_sbs1.setChecked(bool(defaults["sbs1"] == "1"))
|
|
|
|
self.ui.check_raw.setChecked(bool(defaults["raw"] == "1"))
|
|
|
|
self.ui.check_fgfs.setChecked(bool(defaults["fgfs"] == "1"))
|
|
|
|
self.ui.check_kml.setChecked(bool(defaults["kml"] == "1"))
|
|
|
|
|
|
|
|
self.ui.line_sbs1port.insert(defaults["sbs1port"])#"30003")
|
|
|
|
self.ui.line_rawport.insert(defaults["rawport"])#"9988")
|
|
|
|
self.ui.line_fgfsport.insert(defaults["fgfsport"])#"5500")
|
|
|
|
self.ui.line_kmlfilename.insert(defaults["kmlfile"])#"modes.kml")
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
if defaults["latitude"] is not None:
|
|
|
|
self.ui.line_my_lat.insert(defaults["latitude"])
|
|
|
|
if defaults["longitude"] is not None:
|
|
|
|
self.ui.line_my_lon.insert(defaults["longitude"])
|
2012-07-03 09:55:05 +08:00
|
|
|
|
|
|
|
#disable by default
|
|
|
|
self.ui.check_adsbonly.setCheckState(QtCore.Qt.Unchecked)
|
2013-07-18 12:41:55 +08:00
|
|
|
|
2013-06-21 14:05:41 +08:00
|
|
|
#set up the radio stuff
|
2012-07-03 22:45:34 +08:00
|
|
|
self.queue = gr.msg_queue(10)
|
2013-06-10 23:57:12 +08:00
|
|
|
self.running = False
|
2012-07-03 22:45:34 +08:00
|
|
|
self.kmlgen = None #necessary bc we stop its thread in shutdown
|
2012-07-15 05:44:36 +08:00
|
|
|
self.dbname = "air_modes.db"
|
2012-07-17 09:19:05 +08:00
|
|
|
self.num_reports = 0
|
|
|
|
self.last_report = 0
|
2013-06-10 23:57:12 +08:00
|
|
|
self.context = zmq.Context(1)
|
2012-07-06 14:52:00 +08:00
|
|
|
|
2012-07-14 00:43:22 +08:00
|
|
|
self.datamodel = dashboard_data_model(None)
|
2012-07-06 14:52:00 +08:00
|
|
|
self.ui.list_aircraft.setModel(self.datamodel)
|
2012-07-11 00:17:53 +08:00
|
|
|
self.ui.list_aircraft.setModelColumn(0)
|
2012-07-12 15:02:11 +08:00
|
|
|
|
2012-10-10 23:20:07 +08:00
|
|
|
self.az_model = air_modes.az_map_model(None)
|
|
|
|
self.ui.azimuth_map.setModel(self.az_model)
|
|
|
|
|
2012-07-12 15:02:11 +08:00
|
|
|
#set up dashboard views
|
2012-07-11 07:08:24 +08:00
|
|
|
self.icaodelegate = ICAOViewDelegate()
|
|
|
|
self.ui.list_aircraft.setItemDelegate(self.icaodelegate)
|
2012-07-12 00:15:05 +08:00
|
|
|
self.dashboard_mapper = QtGui.QDataWidgetMapper()
|
|
|
|
self.dashboard_mapper.setModel(self.datamodel)
|
2012-07-15 06:43:09 +08:00
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_icao, 0)
|
2012-07-12 15:02:11 +08:00
|
|
|
#self.dashboard_mapper.addMapping(self.ui.prog_rssi, 2)
|
2012-07-12 10:18:40 +08:00
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_latitude, 3)
|
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_longitude, 4)
|
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_alt, 5)
|
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_speed, 6)
|
2012-07-16 03:59:41 +08:00
|
|
|
#self.dashboard_mapper.addMapping(self.ui.compass_heading, 7)
|
2012-07-12 10:18:40 +08:00
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_climb, 8)
|
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_ident, 9)
|
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_type, 10)
|
2012-07-16 03:59:41 +08:00
|
|
|
self.dashboard_mapper.addMapping(self.ui.line_range, 11)
|
2012-07-12 10:18:40 +08:00
|
|
|
|
2012-07-12 15:02:11 +08:00
|
|
|
compass_palette = QtGui.QPalette()
|
|
|
|
compass_palette.setColor(QtGui.QPalette.Foreground, QtCore.Qt.white)
|
|
|
|
self.ui.compass_heading.setPalette(compass_palette)
|
2012-07-16 03:59:41 +08:00
|
|
|
self.ui.compass_bearing.setPalette(compass_palette)
|
2012-07-14 00:43:22 +08:00
|
|
|
#TODO: change the needle to an aircraft silhouette
|
2012-07-12 15:02:11 +08:00
|
|
|
self.ui.compass_heading.setNeedle(Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Ray, False, QtCore.Qt.black))
|
2012-07-16 03:59:41 +08:00
|
|
|
self.ui.compass_bearing.setNeedle(Qwt.QwtDialSimpleNeedle(Qwt.QwtDialSimpleNeedle.Ray, False, QtCore.Qt.black))
|
2012-07-12 15:02:11 +08:00
|
|
|
|
2012-07-12 10:18:40 +08:00
|
|
|
#hook up the update signal
|
2012-07-12 03:55:30 +08:00
|
|
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.dashboard_mapper.setCurrentModelIndex)
|
2012-07-15 13:24:18 +08:00
|
|
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_heading_widget)
|
2012-07-16 03:59:41 +08:00
|
|
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_bearing_widget)
|
2012-07-12 15:02:11 +08:00
|
|
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_rssi_widget)
|
2013-07-19 00:45:09 +08:00
|
|
|
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_map_highlight)
|
|
|
|
self.datamodel.dataChanged.connect(self.unmapped_widgets_dataChanged)
|
2012-07-12 15:02:11 +08:00
|
|
|
|
2012-10-09 09:44:52 +08:00
|
|
|
#hook up live data text box update signal
|
|
|
|
self.live_data_changed_signal.connect(self.on_append_live_data)
|
|
|
|
|
2013-07-23 09:23:05 +08:00
|
|
|
self._last_live_data_update = time.time()
|
|
|
|
self._pending_msgstr = ""
|
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
self.prefs = None
|
|
|
|
|
2012-07-17 10:10:23 +08:00
|
|
|
############ widget update functions for non-mapped widgets ############
|
2012-07-12 15:02:11 +08:00
|
|
|
def update_heading_widget(self, index):
|
2012-07-15 13:24:18 +08:00
|
|
|
if index.model() is not None:
|
2012-07-16 03:59:41 +08:00
|
|
|
heading = index.model().data(index.model().index(index.row(), self.datamodel._colnames.index("heading"))).toDouble()[0]
|
2012-07-15 13:24:18 +08:00
|
|
|
self.ui.compass_heading.setValue(heading)
|
|
|
|
|
2012-07-16 03:59:41 +08:00
|
|
|
def update_bearing_widget(self, index):
|
|
|
|
if index.model() is not None:
|
|
|
|
bearing = index.model().data(index.model().index(index.row(), self.datamodel._colnames.index("bearing"))).toDouble()[0]
|
|
|
|
self.ui.compass_bearing.setValue(bearing)
|
|
|
|
|
2012-07-17 13:43:02 +08:00
|
|
|
def unmapped_widgets_dataChanged(self, startIndex, endIndex):
|
2012-07-15 13:24:18 +08:00
|
|
|
index = self.ui.list_aircraft.selectionModel().currentIndex()
|
2012-07-16 03:59:41 +08:00
|
|
|
if index.row() in range(startIndex.row(), endIndex.row()+1): #the current aircraft was affected
|
|
|
|
if self.datamodel._colnames.index("heading") in range(startIndex.column(), endIndex.column()+1):
|
|
|
|
self.update_heading_widget(index)
|
|
|
|
if self.datamodel._colnames.index("bearing") in range(startIndex.column(), endIndex.column()+1):
|
|
|
|
self.update_bearing_widget(index)
|
2012-07-17 13:43:02 +08:00
|
|
|
if self.datamodel._colnames.index("rssi") in range(startIndex.column(), endIndex.column()+1):
|
|
|
|
self.update_rssi_widget(index)
|
2012-07-12 15:02:11 +08:00
|
|
|
|
|
|
|
def update_rssi_widget(self, index):
|
2012-07-15 13:24:18 +08:00
|
|
|
if index.model() is not None:
|
|
|
|
rssi = index.model().data(index.model().index(index.row(), 2)).toDouble()[0]
|
|
|
|
self.ui.prog_rssi.setValue(rssi)
|
2013-07-19 00:45:09 +08:00
|
|
|
|
2012-07-17 10:10:23 +08:00
|
|
|
def increment_reportspersec(self, msg):
|
|
|
|
self.num_reports += 1
|
|
|
|
|
|
|
|
def update_reportspersec(self):
|
|
|
|
dt = time.time() - self.last_report
|
|
|
|
if dt >= 1.0:
|
|
|
|
self.last_report = time.time()
|
|
|
|
self.ui.line_reports.setText("%i" % self.num_reports)
|
|
|
|
self.num_reports = 0
|
2012-07-12 15:02:11 +08:00
|
|
|
|
2013-07-19 00:45:09 +08:00
|
|
|
def update_map_highlight(self, index):
|
|
|
|
if index.model() is not None:
|
|
|
|
icaostr = index.model().data(index.model().index(index.row(), self.datamodel._colnames.index("icao"))).toString()
|
|
|
|
icao = int(str(icaostr), 16)
|
|
|
|
self.jsonpgen.set_highlight(icao)
|
|
|
|
|
2012-07-17 10:10:23 +08:00
|
|
|
##################### dynamic option population ########################
|
2012-07-03 09:55:05 +08:00
|
|
|
#goes and gets valid antenna, sample rate options from the device and grays out appropriate things
|
|
|
|
def populate_source_options(self):
|
2012-07-03 22:45:34 +08:00
|
|
|
sourceid = self.ui.combo_source.currentText()
|
2012-07-03 09:55:05 +08:00
|
|
|
self.rates = []
|
|
|
|
self.ratetext = []
|
|
|
|
self.antennas = []
|
2013-07-19 00:45:09 +08:00
|
|
|
|
2013-06-10 23:57:12 +08:00
|
|
|
if sourceid == "UHD":
|
2012-07-03 09:55:05 +08:00
|
|
|
try:
|
|
|
|
from gnuradio import uhd
|
|
|
|
self.src = uhd.single_usrp_source("", uhd.io_type_t.COMPLEX_FLOAT32, 1)
|
2013-07-19 08:46:50 +08:00
|
|
|
self.rates = [rate.start() for rate in self.src.get_samp_rates()
|
|
|
|
if (rate.start() % 2.e6) == 0 and rate >= 4e6]
|
2012-07-03 09:55:05 +08:00
|
|
|
self.antennas = self.src.get_antennas()
|
|
|
|
self.src = None #deconstruct UHD source for now
|
|
|
|
self.ui.combo_ant.setEnabled(True)
|
|
|
|
self.ui.combo_rate.setEnabled(True)
|
2012-07-03 22:45:34 +08:00
|
|
|
self.ui.stack_source.setCurrentIndex(0)
|
2012-07-03 09:55:05 +08:00
|
|
|
except:
|
|
|
|
self.rates = []
|
|
|
|
self.antennas = []
|
|
|
|
self.ui.combo_ant.setEnabled(False)
|
|
|
|
self.ui.combo_rate.setEnabled(False)
|
2012-07-03 22:45:34 +08:00
|
|
|
self.ui.stack_source.setCurrentIndex(0)
|
2013-07-19 00:45:09 +08:00
|
|
|
|
2013-06-10 23:57:12 +08:00
|
|
|
elif sourceid == "Osmocom":
|
|
|
|
try:
|
|
|
|
import osmosdr
|
|
|
|
self.src = osmosdr.source_c("")
|
|
|
|
self.rates = [rate.start() for rate in self.src.get_sample_rates() if (rate.start() % 2.e6) == 0]
|
|
|
|
self.antennas = ["RX"]
|
|
|
|
self.src = None
|
|
|
|
self.ui.combo_ant.setEnabled(False)
|
|
|
|
self.ui.combo_rate.setEnabled(True)
|
|
|
|
self.ui.stack_source.setCurrentIndex(0)
|
|
|
|
except:
|
|
|
|
self.rates = []
|
|
|
|
self.antennas = []
|
|
|
|
self.ui.combo_ant.setEnabled(False)
|
|
|
|
self.ui.combo_rate.setEnabled(False)
|
|
|
|
self.ui.stack_source.setCurrentIndex(0)
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2013-06-10 23:57:12 +08:00
|
|
|
elif sourceid == "File/UDP":
|
|
|
|
self.rates = [2e6*i for i in range(2,13)]
|
2012-07-03 09:55:05 +08:00
|
|
|
self.antennas = ["None"]
|
|
|
|
self.ui.combo_ant.setEnabled(False)
|
|
|
|
self.ui.combo_rate.setEnabled(True)
|
2012-07-03 22:45:34 +08:00
|
|
|
self.ui.stack_source.setCurrentIndex(1)
|
2012-07-03 09:55:05 +08:00
|
|
|
|
|
|
|
self.ui.combo_rate.clear()
|
|
|
|
self.ratetext = ["%.3f" % (rate / 1.e6) for rate in self.rates]
|
|
|
|
for rate, text in zip(self.rates, self.ratetext):
|
|
|
|
self.ui.combo_rate.addItem(text, rate)
|
|
|
|
|
|
|
|
self.ui.combo_ant.clear()
|
|
|
|
self.ui.combo_ant.addItems(self.antennas)
|
|
|
|
|
2013-07-19 08:46:50 +08:00
|
|
|
#set up recommended sample rate
|
2013-07-19 09:31:10 +08:00
|
|
|
recommended_rate = min(x for x in self.rates if x >= 4e6 and
|
|
|
|
max(self.rates) % x == 0)
|
|
|
|
if recommended_rate >= 8.e6:
|
|
|
|
self.ui.check_pmf.setChecked(True)
|
|
|
|
self.ui.combo_rate.setCurrentIndex(self.rates.index(recommended_rate))
|
2012-07-03 09:55:05 +08:00
|
|
|
|
2012-07-17 10:10:23 +08:00
|
|
|
################ action handlers ####################
|
2012-07-03 22:45:34 +08:00
|
|
|
def on_combo_source_currentIndexChanged(self, index):
|
2012-07-03 09:55:05 +08:00
|
|
|
self.populate_source_options()
|
|
|
|
|
2012-07-03 22:45:34 +08:00
|
|
|
def on_button_start_released(self):
|
|
|
|
#if we're already running, kill it!
|
2013-06-10 23:57:12 +08:00
|
|
|
if self.running is True:
|
|
|
|
self.on_quit()
|
2012-07-03 22:45:34 +08:00
|
|
|
|
2012-07-17 09:19:05 +08:00
|
|
|
self.num_reports = 0
|
|
|
|
self.ui.line_reports.setText("0")
|
|
|
|
|
2012-07-03 22:45:34 +08:00
|
|
|
self.ui.button_start.setText("Start")
|
2013-06-10 23:57:12 +08:00
|
|
|
self.running = False
|
2012-07-03 22:45:34 +08:00
|
|
|
|
|
|
|
else: #we aren't already running, let's get this party started
|
2013-06-10 23:57:12 +08:00
|
|
|
parser = OptionParser(option_class=eng_option)
|
|
|
|
air_modes.modes_radio.add_radio_options(parser)
|
|
|
|
(options, args) = parser.parse_args() #sets defaults nicely
|
|
|
|
if str(self.ui.combo_source.currentText()) != "File/UDP":
|
|
|
|
options.source = str(self.ui.combo_source.currentText()).lower()
|
|
|
|
else:
|
|
|
|
options.source = str(self.ui.line_inputfile.text())
|
|
|
|
options.rate = float(self.ui.combo_rate.currentText()) * 1e6
|
|
|
|
options.antenna = str(self.ui.combo_ant.currentText())
|
|
|
|
options.gain = float(self.ui.line_gain.text())
|
|
|
|
options.threshold = float(self.ui.line_threshold.text())
|
|
|
|
options.pmf = self.ui.check_pmf.checkState()
|
|
|
|
|
|
|
|
self._servers = ["inproc://modes-radio-pub"] #TODO ADD REMOTES
|
|
|
|
self._relay = air_modes.zmq_pubsub_iface(self.context, subaddr=self._servers, pubaddr=None)
|
|
|
|
|
|
|
|
if self.ui.check_raw.checkState():
|
|
|
|
options.tcp = int(self.ui.line_rawport.text())
|
|
|
|
|
|
|
|
self._radio = air_modes.modes_radio(options, self.context)
|
2013-06-20 02:24:11 +08:00
|
|
|
self._publisher = pubsub()
|
|
|
|
self._relay.subscribe("dl_data", air_modes.make_parser(self._publisher))
|
2012-07-03 22:45:34 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
my_position = [float(self.ui.line_my_lat.text()), float(self.ui.line_my_lon.text())]
|
|
|
|
except:
|
|
|
|
my_position = None
|
|
|
|
|
2013-06-20 02:24:11 +08:00
|
|
|
self._cpr_dec = air_modes.cpr_decoder(my_position)
|
|
|
|
|
|
|
|
self.datamodelout = dashboard_output(self._cpr_dec, self.datamodel, self._publisher)
|
2012-07-15 05:44:36 +08:00
|
|
|
|
2012-10-10 00:26:16 +08:00
|
|
|
self.lock = threading.Lock() #grab a lock to ensure sql and kml don't step on each other
|
2012-07-03 22:45:34 +08:00
|
|
|
|
|
|
|
#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
|
2012-10-10 00:26:16 +08:00
|
|
|
self.kmlgen = air_modes.output_kml(self.ui.line_kmlfilename.text(), self.dbname, my_position, self.lock) #create a KML generating thread
|
2012-07-03 22:45:34 +08:00
|
|
|
|
|
|
|
if self.ui.check_sbs1.checkState():
|
|
|
|
sbs1port = int(self.ui.line_sbs1port.text())
|
2013-06-20 02:24:11 +08:00
|
|
|
sbs1out = air_modes.output_sbs1(self._cpr_dec, sbs1port, self._publisher)
|
2012-07-03 22:45:34 +08:00
|
|
|
|
|
|
|
if self.ui.check_fgfs.checkState():
|
|
|
|
fghost = "127.0.0.1" #TODO FIXME
|
2012-07-19 09:49:13 +08:00
|
|
|
fgport = self.ui.line_fgfsport.text()
|
2013-06-20 02:24:11 +08:00
|
|
|
fgout = air_modes.output_flightgear(self._cpr_dec, fghost, int(fgport), self._publisher)
|
2012-07-03 22:45:34 +08:00
|
|
|
|
2012-10-10 23:20:07 +08:00
|
|
|
#add azimuth map output and hook it up
|
|
|
|
if my_position is not None:
|
2013-06-20 02:24:11 +08:00
|
|
|
self.az_map_output = air_modes.az_map_output(self._cpr_dec, self.az_model, self._publisher)
|
|
|
|
#self._relay.subscribe("dl_data", self.az_map_output.output)
|
2012-10-10 23:20:07 +08:00
|
|
|
|
2013-06-21 14:05:41 +08:00
|
|
|
#set up map
|
2013-06-22 07:28:56 +08:00
|
|
|
#NOTE this is busted on windows. WebKit requires .htm[l] extensions to render,
|
|
|
|
#so using a temp file doesn't work.
|
|
|
|
self._htmlfile = open("/tmp/mode_s.html", 'wb+')#tempfile.NamedTemporaryFile()
|
2013-06-21 14:05:41 +08:00
|
|
|
self._jsonfile = tempfile.NamedTemporaryFile()
|
|
|
|
|
2013-07-19 08:46:50 +08:00
|
|
|
self.livedata = air_modes.output_print(self._cpr_dec,
|
|
|
|
self._publisher,
|
|
|
|
self.live_data_changed_signal.emit)
|
2012-07-03 22:45:34 +08:00
|
|
|
|
2012-07-06 14:52:00 +08:00
|
|
|
#create SQL database for KML and dashboard displays
|
2013-06-20 02:24:11 +08:00
|
|
|
self.dbwriter = air_modes.output_sql(self._cpr_dec, self.dbname, self.lock, self._publisher)
|
2013-06-21 14:05:41 +08:00
|
|
|
self.jsonpgen = air_modes.output_jsonp(self._jsonfile.name, self.dbname, my_position, self.lock, timeout=1)
|
|
|
|
htmlstring = air_modes.html_template(my_position, self._jsonfile.name)
|
|
|
|
self._htmlfile.write(htmlstring)
|
|
|
|
self._htmlfile.flush()
|
|
|
|
class WebPage(QtWebKit.QWebPage):
|
|
|
|
def javaScriptConsoleMessage(self, msg, line, source):
|
|
|
|
print '%s line %d: %s' % (source, line, msg)
|
|
|
|
page = WebPage()
|
|
|
|
self.ui.mapView.setPage(page)
|
2013-06-22 07:28:56 +08:00
|
|
|
self.ui.mapView.load( QtCore.QUrl( QtCore.QUrl.fromLocalFile("/tmp/mode_s.html") ) )
|
2013-06-21 14:05:41 +08:00
|
|
|
self.ui.mapView.show()
|
2012-07-06 14:52:00 +08:00
|
|
|
|
2012-07-17 09:19:05 +08:00
|
|
|
#output to update reports/sec widget
|
2013-06-10 23:57:12 +08:00
|
|
|
self._relay.subscribe("dl_data", self.increment_reportspersec)
|
2013-07-19 08:46:50 +08:00
|
|
|
self._rps_timer = QtCore.QTimer()
|
|
|
|
self._rps_timer.timeout.connect(self.update_reportspersec)
|
|
|
|
self._rps_timer.start(1000)
|
2012-07-17 09:19:05 +08:00
|
|
|
|
2013-06-10 23:57:12 +08:00
|
|
|
#start the flowgraph
|
|
|
|
self._radio.start()
|
2012-10-10 23:20:07 +08:00
|
|
|
|
2012-07-06 14:52:00 +08:00
|
|
|
self.ui.button_start.setText("Stop")
|
2013-06-10 23:57:12 +08:00
|
|
|
self.running = True
|
2012-07-03 22:45:34 +08:00
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
#grab prefs and save them
|
|
|
|
self.prefs = {}
|
|
|
|
self.prefs["samplerate"] = options.rate
|
|
|
|
self.prefs["antenna"] = options.antenna
|
|
|
|
self.prefs["gain"] = options.gain
|
|
|
|
self.prefs["pmf"] = options.pmf
|
|
|
|
self.prefs["source"] = self.ui.combo_source.currentText()
|
|
|
|
self.prefs["threshold"] = options.threshold
|
|
|
|
self.prefs["sbs1"] = self.ui.check_sbs1.isChecked()
|
|
|
|
self.prefs["sbs1port"] = int(self.ui.line_sbs1port.text())
|
|
|
|
self.prefs["fgfs"] = self.ui.check_fgfs.isChecked()
|
|
|
|
self.prefs["fgfsport"] = int(self.ui.line_fgfsport.text())
|
|
|
|
self.prefs["raw"] = self.ui.check_raw.isChecked()
|
|
|
|
self.prefs["rawport"] = int(self.ui.line_rawport.text())
|
|
|
|
self.prefs["kml"] = self.ui.check_kml.isChecked()
|
|
|
|
self.prefs["kmlfile"] = self.ui.line_kmlfilename.text()
|
|
|
|
try:
|
|
|
|
self.prefs["latitude"] = float(self.ui.line_my_lat.text())
|
|
|
|
self.prefs["longitude"] = float(self.ui.line_my_lon.text())
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2012-07-17 13:43:02 +08:00
|
|
|
def on_quit(self):
|
2013-06-10 23:57:12 +08:00
|
|
|
if self.running is True:
|
|
|
|
self._relay.close()
|
|
|
|
self._radio.close()
|
|
|
|
self._relay = None
|
|
|
|
self._radio = None
|
2013-07-19 08:46:50 +08:00
|
|
|
self._rps_timer = None
|
2012-10-11 00:00:54 +08:00
|
|
|
try:
|
2012-07-17 13:43:02 +08:00
|
|
|
self.kmlgen.done = True
|
|
|
|
#TODO FIXME need a way to kill kmlgen safely without delay
|
|
|
|
#self.kmlgen.join()
|
|
|
|
#self.kmlgen = None
|
2012-10-11 00:00:54 +08:00
|
|
|
except:
|
|
|
|
pass
|
2012-07-17 13:43:02 +08:00
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
if self.prefs is not None:
|
|
|
|
self.write_defaults(self.prefs)
|
|
|
|
|
2012-10-09 09:44:52 +08:00
|
|
|
#slot to catch signal emitted by output_live_data (necessary for
|
|
|
|
#thread safety since output_live_data is called by another thread)
|
|
|
|
def on_append_live_data(self, msgstr):
|
2013-07-23 09:23:05 +08:00
|
|
|
self._pending_msgstr += msgstr + "\n"
|
|
|
|
if time.time() - self._last_live_data_update >= 0.1:
|
|
|
|
self._last_live_data_update = time.time()
|
|
|
|
self.update_live_data(self._pending_msgstr)
|
|
|
|
self._pending_msgstr = ""
|
|
|
|
|
|
|
|
def update_live_data(self, msgstr):
|
2012-10-12 14:37:26 +08:00
|
|
|
#limit scrollback buffer size -- is there a faster way?
|
|
|
|
if(self.ui.text_livedata.document().lineCount() > 500):
|
|
|
|
cursor = self.ui.text_livedata.textCursor()
|
|
|
|
cursor.movePosition(QtGui.QTextCursor.Start)
|
|
|
|
cursor.select(QtGui.QTextCursor.LineUnderCursor)
|
|
|
|
cursor.removeSelectedText()
|
2013-07-19 00:45:09 +08:00
|
|
|
|
2012-10-09 09:44:52 +08:00
|
|
|
self.ui.text_livedata.append(msgstr)
|
|
|
|
self.ui.text_livedata.verticalScrollBar().setSliderPosition(self.ui.text_livedata.verticalScrollBar().maximum())
|
|
|
|
|
2013-07-24 02:37:52 +08:00
|
|
|
opt_file = "~/.gr-air-modes/prefs"
|
|
|
|
def get_defaults(self):
|
|
|
|
defaults = {}
|
|
|
|
defaults["samplerate"] = None #let app pick it
|
|
|
|
defaults["pmf"] = None
|
|
|
|
defaults["antenna"] = None
|
|
|
|
defaults["gain"] = "25"
|
|
|
|
defaults["kml"] = "1"
|
|
|
|
defaults["kmlfile"] = "modes.kml"
|
|
|
|
defaults["sbs1"] = "0"
|
|
|
|
defaults["sbs1port"] = "30003"
|
|
|
|
defaults["raw"] = "0"
|
|
|
|
defaults["rawport"] = "9988"
|
|
|
|
defaults["fgfs"] = "0"
|
|
|
|
defaults["fgfsport"] = "5500"
|
|
|
|
defaults["source"] = "UHD"
|
|
|
|
defaults["threshold"] = "5"
|
|
|
|
defaults["latitude"] = None
|
|
|
|
defaults["longitude"] = None
|
|
|
|
|
|
|
|
prefs = ConfigParser.ConfigParser(defaults)
|
|
|
|
prefs.optionxform = str
|
|
|
|
|
|
|
|
try:
|
|
|
|
prefs.read(os.path.expanduser(self.opt_file))
|
|
|
|
for item in prefs.items("GUI"):
|
|
|
|
defaults[item[0]] = item[1]
|
|
|
|
except IOError:
|
|
|
|
print "No preferences file %s found, creating..." % os.path.expanduser(self.opt_file)
|
|
|
|
self.write_defaults(defaults)
|
|
|
|
|
|
|
|
return defaults
|
|
|
|
|
|
|
|
|
|
|
|
def write_defaults(self, defaults):
|
|
|
|
config = ConfigParser.RawConfigParser()
|
|
|
|
config.add_section('GUI')
|
|
|
|
|
|
|
|
for item in defaults:
|
|
|
|
config.set('GUI', item, str(defaults[item]))
|
|
|
|
|
|
|
|
dirname = os.path.dirname(os.path.expanduser(self.opt_file))
|
|
|
|
if not os.path.exists(dirname):
|
|
|
|
os.makedirs(dirname)
|
|
|
|
|
|
|
|
with open(os.path.expanduser(self.opt_file), 'wb') as prefsfile:
|
|
|
|
config.write(prefsfile)
|
|
|
|
|
|
|
|
|
2012-07-03 09:55:05 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
app = QtGui.QApplication(sys.argv)
|
|
|
|
window = mainwindow()
|
2012-07-17 13:43:02 +08:00
|
|
|
app.lastWindowClosed.connect(window.on_quit)
|
2012-07-06 14:52:00 +08:00
|
|
|
window.setWindowTitle("Mode S/ADS-B receiver")
|
2012-07-03 09:55:05 +08:00
|
|
|
window.show()
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|