2010-10-20 01:05:33 +08:00
|
|
|
#!/usr/bin/env python
|
2013-05-28 10:50:42 +08:00
|
|
|
# Copyright 2010, 2013 Nick Foster
|
2010-10-19 00:59:08 +08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2010-09-16 06:25:09 +08:00
|
|
|
from gnuradio.eng_option import eng_option
|
|
|
|
from optparse import OptionParser
|
2010-10-18 15:14:28 +08:00
|
|
|
import time, os, sys, threading
|
2010-09-16 06:25:09 +08:00
|
|
|
from string import split, join
|
2011-12-15 02:17:16 +08:00
|
|
|
import air_modes
|
2011-06-09 12:44:53 +08:00
|
|
|
import csv
|
2012-07-17 10:27:09 +08:00
|
|
|
from air_modes.exceptions import *
|
2013-05-30 05:18:15 +08:00
|
|
|
import zmq
|
2010-09-16 06:25:09 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
class screen_printer(threading.Thread):
|
2013-06-03 20:38:26 +08:00
|
|
|
def __init__(self, position, context, addr=None, port=None):
|
2013-05-30 05:18:15 +08:00
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self._subscriber = context.socket(zmq.SUB)
|
2013-05-30 15:58:03 +08:00
|
|
|
if addr is not None:
|
2013-06-03 20:38:26 +08:00
|
|
|
self._subscriber.connect("tcp://%s:%i" % (addr, port))
|
2013-05-30 15:58:03 +08:00
|
|
|
else:
|
|
|
|
self._subscriber.connect("inproc://modes-radio-pub")
|
2013-05-30 05:18:15 +08:00
|
|
|
self._subscriber.setsockopt(zmq.SUBSCRIBE, "dl_data")
|
2011-08-28 05:40:01 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
self._printer = air_modes.output_print(position)
|
2013-05-30 15:58:03 +08:00
|
|
|
self.done = threading.Event()
|
|
|
|
self.finished = threading.Event()
|
2013-05-30 05:18:15 +08:00
|
|
|
self.setDaemon(True)
|
|
|
|
self.start()
|
|
|
|
|
|
|
|
def run(self):
|
2013-05-30 15:58:03 +08:00
|
|
|
while not self.done.is_set():
|
2013-05-30 05:18:15 +08:00
|
|
|
[address, msg] = self._subscriber.recv_multipart() #blocking
|
|
|
|
try:
|
|
|
|
self._printer.output(msg)
|
|
|
|
except ADSBError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self._subscriber.close()
|
2013-05-30 15:58:03 +08:00
|
|
|
self.finished.set()
|
2013-05-30 05:18:15 +08:00
|
|
|
|
|
|
|
def main():
|
|
|
|
my_position = None
|
2013-05-30 15:58:03 +08:00
|
|
|
usage = "%prog: [options]"
|
2010-10-18 10:45:19 +08:00
|
|
|
parser = OptionParser(option_class=eng_option, usage=usage)
|
2013-05-30 15:58:03 +08:00
|
|
|
air_modes.modes_radio.add_radio_options(parser)
|
2010-10-18 15:14:28 +08:00
|
|
|
parser.add_option("-K","--kml", type="string", default=None,
|
|
|
|
help="filename for Google Earth KML output")
|
2010-10-18 10:45:19 +08:00
|
|
|
parser.add_option("-P","--sbs1", action="store_true", default=False,
|
|
|
|
help="open an SBS-1-compatible server on port 30003")
|
2011-07-28 01:59:04 +08:00
|
|
|
parser.add_option("-w","--raw", action="store_true", default=False,
|
|
|
|
help="open a server outputting raw timestamped data on port 9988")
|
2010-10-18 10:45:19 +08:00
|
|
|
parser.add_option("-n","--no-print", action="store_true", default=False,
|
|
|
|
help="disable printing decoded packets to stdout")
|
2011-06-09 12:44:53 +08:00
|
|
|
parser.add_option("-l","--location", type="string", default=None,
|
|
|
|
help="GPS coordinates of receiving station in format xx.xxxxx,xx.xxxxx")
|
2012-06-13 22:49:22 +08:00
|
|
|
parser.add_option("-u","--udp", type="int", default=None,
|
|
|
|
help="Use UDP source on specified port")
|
|
|
|
parser.add_option("-m","--multiplayer", type="string", default=None,
|
|
|
|
help="FlightGear server to send aircraft data, in format host:port")
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
(options, args) = parser.parse_args()
|
2013-05-28 10:50:42 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
#construct the radio
|
|
|
|
context = zmq.Context(1)
|
|
|
|
tb = air_modes.modes_radio(options, context)
|
2013-06-03 20:38:26 +08:00
|
|
|
relay = air_modes.zmq_pubsub_iface(context, subaddr="inproc://modes-radio-pub", pubaddr=None)
|
2013-05-28 10:50:42 +08:00
|
|
|
|
2011-06-09 12:44:53 +08:00
|
|
|
if options.location is not None:
|
2011-12-13 01:38:34 +08:00
|
|
|
reader = csv.reader([options.location], quoting=csv.QUOTE_NONNUMERIC)
|
2011-06-09 12:44:53 +08:00
|
|
|
my_position = reader.next()
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2010-10-18 15:14:28 +08:00
|
|
|
if options.kml is not None:
|
2012-07-06 14:52:00 +08:00
|
|
|
dbname = 'adsb.db'
|
2013-05-30 05:18:15 +08:00
|
|
|
sqldb = air_modes.output_sql(my_position, dbname, context) #input into the db
|
|
|
|
#kmlgen = air_modes.output_kml(options.kml, dbname, my_position, lock) #create a KML generating thread to read from the db
|
2012-06-13 22:49:22 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
printer = None
|
|
|
|
if options.no_print is not True:
|
2013-06-03 20:38:26 +08:00
|
|
|
relay.subscribe("dl_data", air_modes.output_print(my_position).output)
|
|
|
|
#printer = screen_printer(my_position, context)
|
2013-05-30 05:18:15 +08:00
|
|
|
|
|
|
|
# if options.multiplayer is not None:
|
|
|
|
# [fghost, fgport] = options.multiplayer.split(':')
|
|
|
|
# fgout = air_modes.output_flightgear(my_position, fghost, int(fgport))
|
|
|
|
# tb.subscribe('dl_data', fgout.output)
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2013-05-30 15:58:03 +08:00
|
|
|
# if options.sbs1 is True:
|
|
|
|
# sbs1port = air_modes.output_sbs1(my_position, 30003)
|
|
|
|
# tb.subscribe('dl_data', sbs1port.output)
|
|
|
|
#updates.append(sbs1port.add_pending_conns)
|
|
|
|
tb.run()
|
2013-05-30 16:06:53 +08:00
|
|
|
tb.cleanup()
|
2013-05-30 05:18:15 +08:00
|
|
|
|
2013-06-03 20:38:26 +08:00
|
|
|
relay.shutdown.set()
|
|
|
|
relay.finished.wait(0.2)
|
|
|
|
|
2013-05-28 10:50:42 +08:00
|
|
|
if options.kml is not None:
|
2013-05-30 05:18:15 +08:00
|
|
|
sqldb.done = True
|
|
|
|
#sqldb.join()
|
2013-05-28 10:50:42 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|