gr-air-modes/apps/modes_rx

98 lines
3.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env python
# 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.
#
from gnuradio.eng_option import eng_option
from optparse import OptionParser
2010-10-18 15:14:28 +08:00
import time, os, sys, threading
from string import split, join
import air_modes
from air_modes.exceptions import *
import zmq
#todo: maybe move plugins to separate programs (flightgear, SBS1, etc.)
def main():
my_position = None
usage = "%prog: [options]"
parser = OptionParser(option_class=eng_option, usage=usage)
air_modes.modes_radio.add_radio_options(parser)
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("-t","--tcp", type="int", default=None,
help="Open a TCP server on this port to publish reports")
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")
parser.add_option("-P","--sbs1", action="store_true", default=False,
help="open an SBS-1-compatible server on port 30003")
parser.add_option("-m","--multiplayer", type="string", default=None,
help="FlightGear server to send aircraft data, in format host:port")
(options, args) = parser.parse_args()
#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"]
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)
2011-06-09 12:44:53 +08:00
if options.location is not None:
my_position = [float(n) for n in options.location.split(",")]
2010-10-18 15:14:28 +08:00
if options.kml is not None:
dbname = 'adsb.db'
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)
if options.no_print is not True:
relay.subscribe("dl_data", air_modes.output_print(my_position).output)
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)
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)
tb.run()
2013-05-30 16:06:53 +08:00
tb.cleanup()
2013-06-09 03:32:24 +08:00
relay.close()
if options.kml is not None:
kmlgen.close()
if __name__ == '__main__':
main()