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
|
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-06-06 03:56:09 +08:00
|
|
|
#todo: maybe move plugins to separate programs (flightgear, SBS1, etc.)
|
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)
|
2013-06-09 03:24:23 +08:00
|
|
|
|
|
|
|
parser.add_option("-l","--location", type="string", default=None,
|
|
|
|
help="GPS coordinates of receiving station in format xx.xxxxx,xx.xxxxx")
|
|
|
|
#data source options
|
|
|
|
parser.add_option("-a","--remote", type="string", default=None,
|
|
|
|
help="specify additional servers from which to take data in format tcp://x.x.x.x:y,tcp://....")
|
|
|
|
parser.add_option("-n","--no-print", action="store_true", default=False,
|
|
|
|
help="disable printing decoded packets to stdout")
|
|
|
|
#output plugins
|
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")
|
2012-06-13 22:49:22 +08:00
|
|
|
parser.add_option("-m","--multiplayer", type="string", default=None,
|
|
|
|
help="FlightGear server to send aircraft data, in format host:port")
|
2013-06-09 03:24:23 +08:00
|
|
|
|
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-06 04:05:14 +08:00
|
|
|
servers = ["inproc://modes-radio-pub"]
|
2013-06-09 03:24:23 +08:00
|
|
|
if options.remote is not None:
|
|
|
|
servers += options.remote.split(",")
|
2013-06-06 04:05:14 +08:00
|
|
|
relay = air_modes.zmq_pubsub_iface(context, subaddr=servers, pubaddr=None)
|
2013-05-28 10:50:42 +08:00
|
|
|
|
2011-06-09 12:44:53 +08:00
|
|
|
if options.location is not None:
|
2013-06-06 03:56:09 +08:00
|
|
|
my_position = [float(n) for n in options.location.split(",")]
|
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-06-03 21:07:36 +08:00
|
|
|
lock = threading.Lock()
|
|
|
|
sqldb = air_modes.output_sql(my_position, dbname, lock) #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
|
|
|
|
relay.subscribe("dl_data", sqldb.insert)
|
2012-06-13 22:49:22 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
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)
|
2013-05-30 05:18:15 +08:00
|
|
|
|
2013-06-03 21:07:36 +08:00
|
|
|
if options.multiplayer is not None:
|
|
|
|
[fghost, fgport] = options.multiplayer.split(':')
|
|
|
|
fgout = air_modes.output_flightgear(my_position, fghost, int(fgport))
|
|
|
|
relay.subscribe("dl_data", fgout.output)
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2013-06-09 04:06:42 +08:00
|
|
|
if options.sbs1 is True:
|
|
|
|
sbs1port = air_modes.output_sbs1(my_position, 30003)
|
|
|
|
relay.subscribe("dl_data", sbs1port.output)
|
|
|
|
|
2013-05-30 15:58:03 +08:00
|
|
|
tb.run()
|
2013-06-10 23:24:42 +08:00
|
|
|
tb.close()
|
2013-05-30 05:18:15 +08:00
|
|
|
|
2013-06-09 03:32:24 +08:00
|
|
|
relay.close()
|
2013-06-03 20:38:26 +08:00
|
|
|
|
2013-05-28 10:50:42 +08:00
|
|
|
if options.kml is not None:
|
2013-06-03 21:07:36 +08:00
|
|
|
kmlgen.close()
|
|
|
|
|
2013-05-28 10:50:42 +08:00
|
|
|
|
2013-05-30 05:18:15 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|