2019-09-18 05:13:51 +08:00
|
|
|
#!/usr/bin/env python3
|
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
|
2013-06-19 08:34:11 +08:00
|
|
|
from gnuradio.gr.pubsub import pubsub
|
2010-09-16 06:25:09 +08:00
|
|
|
from optparse import OptionParser
|
2013-06-19 08:34:11 +08:00
|
|
|
import time, os, sys, threading, math
|
2011-12-15 02:17:16 +08:00
|
|
|
import air_modes
|
2019-09-18 05:13:51 +08:00
|
|
|
from air_modes.modes_types import *
|
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]"
|
2013-06-19 08:34:11 +08:00
|
|
|
optparser = OptionParser(option_class=eng_option, usage=usage)
|
|
|
|
air_modes.modes_radio.add_radio_options(optparser)
|
2013-06-09 03:24:23 +08:00
|
|
|
|
2013-06-19 08:34:11 +08:00
|
|
|
optparser.add_option("-l","--location", type="string", default=None,
|
|
|
|
help="GPS coordinates of receiving station in format xx.xxxxx,xx.xxxxx")
|
2013-06-09 03:24:23 +08:00
|
|
|
#data source options
|
2013-06-19 08:34:11 +08:00
|
|
|
optparser.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://....")
|
|
|
|
optparser.add_option("-n","--no-print", action="store_true", default=False,
|
|
|
|
help="disable printing decoded packets to stdout")
|
2013-06-09 03:24:23 +08:00
|
|
|
#output plugins
|
2013-06-19 08:34:11 +08:00
|
|
|
optparser.add_option("-K","--kml", type="string", default=None,
|
|
|
|
help="filename for Google Earth KML output")
|
|
|
|
optparser.add_option("-P","--sbs1", action="store_true", default=False,
|
|
|
|
help="open an SBS-1-compatible server on port 30003")
|
|
|
|
optparser.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
|
|
|
|
2013-06-19 08:34:11 +08:00
|
|
|
(options, args) = optparser.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-06-19 08:34:11 +08:00
|
|
|
publisher = pubsub()
|
2013-06-19 12:49:07 +08:00
|
|
|
relay.subscribe("dl_data", air_modes.make_parser(publisher))
|
2013-06-19 08:34:11 +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
|
|
|
|
2013-06-19 08:47:13 +08:00
|
|
|
#CPR decoder obj to handle getting position from BDS0,5 and BDS0,6 pkts
|
2013-06-19 12:49:07 +08:00
|
|
|
cpr_dec = air_modes.cpr_decoder(my_position)
|
2013-06-19 08:47:13 +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()
|
2013-06-19 09:57:24 +08:00
|
|
|
sqldb = air_modes.output_sql(cpr_dec, dbname, lock, publisher) #input into the db
|
2013-06-03 21:07:36 +08:00
|
|
|
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
|
|
|
if options.no_print is not True:
|
2013-06-19 08:47:13 +08:00
|
|
|
printer = air_modes.output_print(cpr_dec, publisher)
|
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(':')
|
2013-06-19 10:06:30 +08:00
|
|
|
fgout = air_modes.output_flightgear(cpr_dec, fghost, int(fgport), publisher)
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2013-06-09 04:06:42 +08:00
|
|
|
if options.sbs1 is True:
|
2013-06-19 09:57:24 +08:00
|
|
|
sbs1port = air_modes.output_sbs1(cpr_dec, 30003, publisher)
|
2013-06-09 04:06:42 +08:00
|
|
|
|
2013-05-30 15:58:03 +08:00
|
|
|
tb.run()
|
2013-08-06 07:26:22 +08:00
|
|
|
time.sleep(0.2)
|
2013-06-10 23:24:42 +08:00
|
|
|
tb.close()
|
2013-08-06 07:26:22 +08:00
|
|
|
time.sleep(0.2)
|
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()
|