def __init__(self, verbosity, config, trunk_conf_file=None, terminal_type=None, track_errors=False, udp_player=None): self.verbosity = verbosity gr.top_block.__init__(self) self.device_id_by_name = {} self.msg_types = {} self.terminal_type = terminal_type self.last_process_update = 0 self.last_freq_params = { 'freq': 0.0, 'tgid': None, 'tag': "", 'tdma': None } self.trunk_rx = None self.track_errors = track_errors self.last_change_freq = 0 self.sql_db = sql_dbi() self.input_q = gr.msg_queue(20) self.output_q = gr.msg_queue(20) self.last_voice_channel_id = 0 self.terminal = op25_terminal(self.input_q, self.output_q, terminal_type) self.configure_devices(config['devices']) self.configure_channels(config['channels']) if trunk_conf_file: self.trunk_rx = trunking.rx_ctl(frequency_set=self.change_freq, debug=self.verbosity, conf_file=trunk_conf_file, logfile_workers=[], send_event=self.send_event) self.sinks = [] for chan in self.channels: if len(chan.sinks): self.sinks += chan.sinks if self.is_http_term(): for sink in self.sinks: sink.gnuplot.set_interval(_def_interval) sink.gnuplot.set_output_dir(_def_file_dir) if udp_player: chan = self.find_audio_channel() # find chan used for audio self.audio = audio_thread("127.0.0.1", chan.audio_port, chan.audio_output, False, chan.audio_gain) else: self.audio = None
def __init__(self, options): self.trunk_rx = None self.plot_sinks = [] gr.top_block.__init__(self) self.channel_rate = 0 self.baseband_input = False self.rtl_found = False self.channel_rate = options.sample_rate self.fft_sink = None self.constellation_sink = None self.symbol_sink = None self.eye_sink = None self.mixer_sink = None self.target_freq = 0.0 self.last_freq_params = { 'freq': 0.0, 'tgid': None, 'tag': "", 'tdma': None } self.meta_server = None self.stream_url = "" self.src = None if (not options.ifile) and (not options.input) and ( not options.audio) and (not options.audio_if) and ( not options.symbols): # check if osmocom is accessible try: import osmosdr self.src = osmosdr.source(options.args) except Exception: print "osmosdr source_c creation failure" ignore = True if any(x in options.args.lower() for x in ['rtl', 'airspy', 'hackrf', 'uhd']): #print "'rtl' has been found in options.args (%s)" % (options.args) self.rtl_found = True gain_names = self.src.get_gain_names() for name in gain_names: range = self.src.get_gain_range(name) print "gain: name: %s range: start %d stop %d step %d" % ( name, range[0].start(), range[0].stop(), range[0].step()) if options.gains: for tup in options.gains.split(","): name, gain = tup.split(":") gain = int(gain) print "setting gain %s to %d" % (name, gain) self.src.set_gain(gain, name) rates = self.src.get_sample_rates() try: print 'supported sample rates %d-%d step %d' % ( rates.start(), rates.stop(), rates.step()) except: pass # ignore if options.freq_corr: self.src.set_freq_corr(options.freq_corr) if options.gain_mode is not None: if options.gain_mode: self.src.set_gain_mode(True, 0) else: self.src.set_gain_mode(False, 0) sys.stderr.write("Osmocom driver gain_mode: %s\n" % self.src.get_gain_mode()) if options.audio: self.channel_rate = 48000 self.baseband_input = True if options.audio_if: self.channel_rate = 96000 # setup (read-only) attributes self.symbol_rate = 4800 self.symbol_deviation = 600.0 self.basic_rate = 24000 _default_speed = 4800 self.options = options # self.set_sps(_default_speed) # keep track of flow graph connections self.cnxns = [] self.datascope_raw_input = False self.data_scope_connected = False self.constellation_scope_connected = False for i in xrange(len(speeds)): if speeds[i] == _default_speed: self.current_speed = i self.default_speed_idx = i if options.hamlib_model: self.hamlib_attach(options.hamlib_model) # wait for gdb if options.pause: print 'Ready for GDB to attach (pid = %d)' % (os.getpid(), ) raw_input("Press 'Enter' to continue...") self.input_q = gr.msg_queue(10) self.output_q = gr.msg_queue(10) self.meta_q = gr.msg_queue(10) # configure specified data source if options.input: self.open_file(options.input) elif (self.rtl_found or options.frequency): self.open_usrp() elif options.audio_if: self.open_audio_c(self.channel_rate, options.gain, options.audio_input) elif options.audio: self.open_audio(self.channel_rate, options.gain, options.audio_input) elif options.ifile: self.open_ifile2(self.channel_rate, options.ifile) elif options.symbols: self.open_symbols(self.symbol_rate, options.symbols, options.seek) else: pass # attach terminal thread and make sure currently tuned frequency is displayed self.terminal = op25_terminal(self.input_q, self.output_q, self.options.terminal_type) if self.terminal is None: sys.exit(1) # attach meta server thread if self.options.metacfg is not None: from icemeta import meta_server self.meta_server = meta_server(self.meta_q, self.options.metacfg, debug=self.options.verbosity) try: with open(self.options.metacfg) as json_file: meta_cfg = json.load(json_file) self.stream_url = "http://" + meta_cfg[ 'icecastServerAddress'] + "/" + meta_cfg[ 'icecastMountpoint'] + meta_cfg['icecastMountExt'] sys.stderr.write("streaming server url=\"%s\"\n" % self.stream_url) except (ValueError, KeyError): sys.stderr.write( "error reading metadata config file: %s, streaming server url disabled\n" % self.options.metacfg) else: self.meta_server = None sys.stderr.write("metadata update not enabled\n") # attach audio thread if self.options.udp_player: self.audio = audio_thread("127.0.0.1", self.options.wireshark_port, self.options.audio_output, False, self.options.audio_gain) else: self.audio = None
def __init__(self, options): self.trunk_rx = None self.plot_sinks = [] gr.top_block.__init__(self) self.channel_rate = 0 self.baseband_input = False self.rtl_found = False self.channel_rate = options.sample_rate self.fft_sink = None self.last_error_update = 0 self.error_band = 0 self.tuning_error = 0 self.freq_correction = 0 self.last_set_freq = 0 self.last_set_freq_at = time.time() self.last_change_freq = 0 self.last_change_freq_at = time.time() self.last_freq_params = {'freq' : 0.0, 'tgid' : None, 'tag' : "", 'tdma' : None} self.next_status_png = time.time() self.last_process_update = 0 self.sql_db = sql_dbi() self.last_center_freq = 0 self.last_relative_freq = 0 self.src = None if (not options.input) and (not options.audio) and (not options.audio_if) and (not options.args.startswith('udp:')): # check if osmocom is accessible try: import osmosdr self.src = osmosdr.source(options.args) except Exception: print ("osmosdr source_c creation failure") ignore = True if any(x in options.args.lower() for x in ['rtl', 'airspy', 'hackrf', 'uhd']): #print ("'rtl' has been found in options.args (%s)" % (options.args)) self.rtl_found = True gain_names = self.src.get_gain_names() for name in gain_names: range1 = self.src.get_gain_range(name) print ("gain: name: %s range: start %d stop %d step %d" % (name, range1[0].start(), range1[0].stop(), range1[0].step())) if options.gains: for tup in options.gains.split(","): name, gain = tup.split(":") gain = int(gain) print ("setting gain %s to %d" % (name, gain)) self.src.set_gain(gain, name) rates = self.src.get_sample_rates() try: print ('supported sample rates %d-%d step %d' % (rates.start(), rates.stop(), rates.step())) except: pass # ignore if options.freq_corr: self.src.set_freq_corr(options.freq_corr) elif (not options.input) and (not options.audio) and (not options.audio_if) and options.args.startswith('udp:'): hostinfo = options.args.split(':') hostname = hostinfo[1] udp_port = int(hostinfo[2]) self.src = udp_source_c(hostname, udp_port) sys.stderr.write('started udp listener: %s %s\n' % (hostname, udp_port)) if options.audio: self.channel_rate = 48000 self.baseband_input = True if options.audio_if: self.channel_rate = 96000 if options.ifile: self.channel_rate = 96000 # TODO: fixme # setup (read-only) attributes self.symbol_rate = 4800 self.symbol_deviation = 600.0 self.basic_rate = 24000 _default_speed = 4800 self.options = options # keep track of flow graph connections self.cnxns = [] self.datascope_raw_input = False self.data_scope_connected = False self.constellation_scope_connected = False for i in range(len(speeds)): if speeds[i] == _default_speed: self.current_speed = i self.default_speed_idx = i if options.hamlib_model: self.hamlib_attach(options.hamlib_model) # wait for gdb if options.pause: print ('Ready for GDB to attach (pid = %d)' % (os.getpid(),)) raw_input("Press 'Enter' to continue...") self.input_q = gr.msg_queue(20) self.output_q = gr.msg_queue(10) # configure specified data source if options.input: self.open_file(options.input) elif options.audio_if: self.open_audio_c(self.channel_rate, options.gain, options.audio_input) elif options.audio: self.open_audio(self.channel_rate, options.gain, options.audio_input) elif options.ifile: self.open_ifile(self.channel_rate, options.gain, options.ifile, options.seek) elif (self.rtl_found or options.frequency): self.open_usrp() else: pass # attach terminal thread and make sure currently tuned frequency is displayed self.terminal = op25_terminal(self.input_q, self.output_q, self.options.terminal_type) if self.terminal is None: sys.stderr.write('warning: no terminal attached\n') # attach audio thread if self.options.udp_player: self.audio = audio_thread("127.0.0.1", self.options.wireshark_port, self.options.audio_output, False, self.options.audio_gain) else: self.audio = None