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):
|
|
|
|
def __init__(self, position, context):
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self._subscriber = context.socket(zmq.SUB)
|
|
|
|
self._subscriber.connect("inproc://modes-radio-pub")
|
|
|
|
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)
|
|
|
|
self.done = False
|
|
|
|
self.setDaemon(True)
|
|
|
|
self.start()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while not self.done:
|
|
|
|
[address, msg] = self._subscriber.recv_multipart() #blocking
|
|
|
|
try:
|
|
|
|
self._printer.output(msg)
|
|
|
|
except ADSBError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
self._subscriber.close()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
my_position = None
|
2010-10-18 10:45:19 +08:00
|
|
|
usage = "%prog: [options] output filename"
|
|
|
|
parser = OptionParser(option_class=eng_option, usage=usage)
|
2013-05-28 10:50:42 +08:00
|
|
|
parser.add_option("-R", "--subdev", type="string",
|
|
|
|
help="select USRP Rx side A or B", metavar="SUBDEV")
|
2011-07-03 07:44:38 +08:00
|
|
|
parser.add_option("-A", "--antenna", type="string",
|
2013-05-28 10:50:42 +08:00
|
|
|
help="select which antenna to use on daughterboard")
|
2012-07-18 05:30:40 +08:00
|
|
|
parser.add_option("-D", "--args", type="string",
|
2013-05-28 10:50:42 +08:00
|
|
|
help="arguments to pass to radio constructor", default="")
|
2010-10-18 10:45:19 +08:00
|
|
|
parser.add_option("-f", "--freq", type="eng_float", default=1090e6,
|
2010-09-16 06:25:09 +08:00
|
|
|
help="set receive frequency in Hz [default=%default]", metavar="FREQ")
|
2010-10-18 10:45:19 +08:00
|
|
|
parser.add_option("-g", "--gain", type="int", default=None,
|
2010-09-16 06:25:09 +08:00
|
|
|
help="set RF gain", metavar="dB")
|
2011-06-02 07:36:00 +08:00
|
|
|
parser.add_option("-r", "--rate", type="eng_float", default=4000000,
|
2010-09-16 06:25:09 +08:00
|
|
|
help="set ADC sample rate [default=%default]")
|
2012-10-14 11:52:38 +08:00
|
|
|
parser.add_option("-T", "--threshold", type="eng_float", default=5.0,
|
2010-09-16 06:25:09 +08:00
|
|
|
help="set pulse detection threshold above noise in dB [default=%default]")
|
2010-10-18 10:45:19 +08:00
|
|
|
parser.add_option("-F","--filename", type="string", default=None,
|
2013-05-28 10:50:42 +08:00
|
|
|
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")
|
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")
|
2013-05-30 05:18:15 +08:00
|
|
|
parser.add_option("-o","--osmocom", action="store_true", default=False,
|
|
|
|
help="Use gr-osmocom source (RTLSDR or HackRF) instead of UHD source")
|
2012-10-28 02:28:06 +08:00
|
|
|
parser.add_option("-p","--pmf", action="store_true", default=False,
|
|
|
|
help="Use pulse matched filtering")
|
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)
|
|
|
|
tb.start()
|
|
|
|
#tb will publish via ZMQ on the "radio-pub" feed
|
|
|
|
#clients connect to tb socket and do things.
|
|
|
|
#the radio-pub feed is channelized into "dl_data" and (not yet)
|
|
|
|
#"ul_data" which correspond to downlink and uplink data
|
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-01-31 10:50:04 +08:00
|
|
|
#we spawn a thread to run every 30 seconds (or whatever) to generate KML
|
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
|
|
|
|
#tb.subscribe('dl_data', sqldb.output)
|
2010-10-18 10:45:19 +08:00
|
|
|
|
2013-05-30 05:18:15 +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)
|
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:
|
|
|
|
printer = screen_printer(my_position, context)
|
|
|
|
|
|
|
|
# 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 05:18:15 +08:00
|
|
|
#start an updater thread to handle adding/removing TCP connections
|
|
|
|
#TODO this can be removed when we start using 0MQ
|
|
|
|
# updater = threading.Thread(target=timed_callback, args=(updates,))
|
|
|
|
# updater.setDaemon(True)
|
|
|
|
# updater.start()
|
|
|
|
|
2013-05-28 10:50:42 +08:00
|
|
|
tb.wait()
|
2013-05-30 05:18:15 +08:00
|
|
|
|
|
|
|
if printer is not None:
|
|
|
|
printer.done = True
|
|
|
|
#printer.join()
|
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
|
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|