gr-air-modes/apps/modes_rx

132 lines
5.5 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.
#
my_position = None
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
2011-06-09 12:44:53 +08:00
import csv
from air_modes.exceptions import *
def printraw(msg):
print msg
if __name__ == '__main__':
usage = "%prog: [options] output filename"
parser = OptionParser(option_class=eng_option, usage=usage)
parser.add_option("-R", "--subdev", type="string",
help="select USRP Rx side A or B", metavar="SUBDEV")
parser.add_option("-A", "--antenna", type="string",
help="select which antenna to use on daughterboard")
parser.add_option("-D", "--args", type="string",
help="arguments to pass to radio constructor", default="")
parser.add_option("-f", "--freq", type="eng_float", default=1090e6,
help="set receive frequency in Hz [default=%default]", metavar="FREQ")
parser.add_option("-g", "--gain", type="int", default=None,
help="set RF gain", metavar="dB")
parser.add_option("-r", "--rate", type="eng_float", default=4000000,
help="set ADC sample rate [default=%default]")
parser.add_option("-T", "--threshold", type="eng_float", default=5.0,
help="set pulse detection threshold above noise in dB [default=%default]")
parser.add_option("-a","--output-all", action="store_true", default=False,
help="output all frames")
parser.add_option("-F","--filename", type="string", default=None,
help="read data from file instead of USRP")
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("-w","--raw", action="store_true", default=False,
help="open a server outputting raw timestamped data on port 9988")
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")
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")
parser.add_option("-d","--rtlsdr", action="store_true", default=False,
help="Use RTLSDR dongle instead of UHD source")
parser.add_option("-p","--pmf", action="store_true", default=False,
help="Use pulse matched filtering")
(options, args) = parser.parse_args()
tb = air_modes.modes_radio(options)
updates = []
2011-06-09 12:44:53 +08:00
if options.location is not None:
reader = csv.reader([options.location], quoting=csv.QUOTE_NONNUMERIC)
2011-06-09 12:44:53 +08:00
my_position = reader.next()
if options.raw is True:
rawport = air_modes.raw_server(9988) #port
tb.subscribe('dl_data', rawport.output)
tb.subscribe('dl_data', printraw)
updates.append(rawport.add_pending_conns)
2010-10-18 15:14:28 +08:00
if options.kml is not None:
#we spawn a thread to run every 30 seconds (or whatever) to generate KML
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
tb.subscribe('dl_data', sqldb.output)
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)
if options.no_print is not True:
tb.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))
tb.subscribe('dl_data', fgout.output)
tb.start()
while 1:
try:
#the update registry is really for the SBS1 and raw server plugins -- we're looking for new TCP connections.
#i think we have to do this here rather than in the output handler because otherwise connections will stack up
2010-10-18 13:17:48 +08:00
#until the next output arrives
for update in updates:
update()
time.sleep(0.1)
except KeyboardInterrupt:
break
tb.stop()
tb.wait()
if options.kml is not None:
kmlgen.done = True