Add TCP raw data server for mlat purposes

This commit is contained in:
Nick Foster 2011-07-27 10:59:04 -07:00
parent a7e26c5960
commit 86903898cf
2 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,52 @@
#
# Copyright 2010 Nick Foster
#
# 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.
#
import time, os, sys, socket
from string import split, join
from datetime import *
class modes_raw_server:
def __init__(self):
self._s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._s.bind(('', 9988))
self._s.listen(1)
self._s.setblocking(0) #nonblocking
self._conns = [] #list of active connections
def __del__(self):
self._s.close()
def output(self, msg):
for conn in self._conns[:]: #iterate over a copy of the list
try:
conn.send(msg)
except socket.error:
self._conns.remove(conn)
print "Connections: ", len(self._conns)
def add_pending_conns(self):
try:
conn, addr = self._s.accept()
self._conns.append(conn)
print "Connections: ", len(self._conns)
except socket.error:
pass

View File

@ -33,6 +33,7 @@ from modes_print import modes_output_print
from modes_sql import modes_output_sql from modes_sql import modes_output_sql
from modes_sbs1 import modes_output_sbs1 from modes_sbs1 import modes_output_sbs1
from modes_kml import modes_kml from modes_kml import modes_kml
from modes_raw_server import modes_raw_server
import gnuradio.gr.gr_threading as _threading import gnuradio.gr.gr_threading as _threading
import csv import csv
@ -133,6 +134,8 @@ if __name__ == '__main__':
help="filename for Google Earth KML output") help="filename for Google Earth KML output")
parser.add_option("-P","--sbs1", action="store_true", default=False, parser.add_option("-P","--sbs1", action="store_true", default=False,
help="open an SBS-1-compatible server on port 30003") 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, parser.add_option("-n","--no-print", action="store_true", default=False,
help="disable printing decoded packets to stdout") help="disable printing decoded packets to stdout")
parser.add_option("-l","--location", type="string", default=None, parser.add_option("-l","--location", type="string", default=None,
@ -162,12 +165,17 @@ if __name__ == '__main__':
if options.no_print is not True: if options.no_print is not True:
outputs.append(modes_output_print(my_position).parse) outputs.append(modes_output_print(my_position).parse)
if options.raw is True:
rawport = modes_raw_server()
outputs.append(rawport.output)
updates.append(rawport.add_pending_conns)
fg = adsb_rx_block(options, args, queue) fg = adsb_rx_block(options, args, queue)
runner = top_block_runner(fg) runner = top_block_runner(fg)
while 1: while 1:
try: try:
#the update registry is really for the SBS1 plugin -- we're looking for new TCP connections. #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 #i think we have to do this here rather than in the output handler because otherwise connections will stack up
#until the next output arrives #until the next output arrives
for update in updates: for update in updates: