def __init__(self, rx_callback, options): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._log = options.log self._rx_callback = rx_callback # this callback is fired when there's a packet available # receiver self.ofdm_rx = digital.ofdm_demod(options, callback=self._rx_callback) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) self.connect(self, self.ofdm_rx) self.connect(self.ofdm_rx, self.probe) # Display some information about the setup if self._verbose: self._print_verbage()
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) #options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._rx_callback = rx_callback # this callback is fired when a packet arrives self._demod_class = demod_class # the demodulator_class we're using self._chbw_factor = options.chbw_factor # channel filter bandwidth factor # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Build the demodulator self.demodulator = self._demod_class(**demod_kwargs) # Make sure the channel BW factor is between 1 and sps/2 # or the filter won't work. if(self._chbw_factor < 1.0 or self._chbw_factor > self.samples_per_symbol()/2): sys.stderr.write("Channel bandwidth factor ({0}) must be within the range [1.0, {1}].\n".format(self._chbw_factor, self.samples_per_symbol()/2)) sys.exit(1) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = filter.firdes.low_pass(1.0, # gain sw_decim * self.samples_per_symbol(), # sampling rate self._chbw_factor, # midpoint of trans. band 0.5, # width of trans. band filter.firdes.WIN_HANN) # filter type self.channel_filter = filter.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ digital.demod_pkts(self.demodulator, access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) # Display some information about the setup if self._verbose: self._print_verbage() # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver)
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__(self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._rx_callback = rx_callback # this callback is fired when a packet arrives self._demod_class = demod_class # the demodulator_class we're using self._chbw_factor = options.chbw_factor # channel filter bandwidth factor # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Build the demodulator self.demodulator = self._demod_class(**demod_kwargs) # Make sure the channel BW factor is between 1 and sps/2 # or the filter won't work. if(self._chbw_factor < 1.0 or self._chbw_factor > self.samples_per_symbol()/2): sys.stderr.write("Channel bandwidth factor ({0}) must be within the range [1.0, {1}].\n".format(self._chbw_factor, self.samples_per_symbol()/2)) sys.exit(1) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = filter.firdes.low_pass(1.0, # gain sw_decim * self.samples_per_symbol(), # sampling rate self._chbw_factor, # midpoint of trans. band 0.5, # width of trans. band filter.firdes.WIN_HANN) # filter type self.channel_filter = filter.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ digital.demod_pkts(self.demodulator, access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) # Display some information about the setup if self._verbose: self._print_verbage() # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver)
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Sensado") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.umbral = umbral = 0 self.samp_rate = samp_rate = 44000 self.fc = fc = 0 ################################################## # Blocks ################################################## self.usando_power_squelch = analog.pwr_squelch_cc(umbral, 1, 100, False) self.uhd_usrp_source_0 = uhd.usrp_source( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(fc, 0) self.uhd_usrp_source_0.set_gain(0, 0) self.sensado_primario = analog.probe_avg_mag_sqrd_c(0, 1) ################################################## # Connections ################################################## self.connect((self.usando_power_squelch, 0), (self.sensado_primario, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.usando_power_squelch, 0))
def __init__(self, demod_class, rx_callback, options): gr.hier_block2.__init__( self, "receive_path", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy( options) # make a copy so we can destructively modify self._verbose = options.verbose self._bitrate = options.bitrate # desired bit rate self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) # Design filter to get actual channel we want sw_decim = 1 chan_coeffs = filter.firdes.low_pass( 1.0, # gain sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band filter.firdes.WIN_HANN) # filter type self.channel_filter = filter.fft_filter_ccc(sw_decim, chan_coeffs) # receiver self.packet_receiver = \ digital.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = analog.probe_avg_mag_sqrd_c(thresh, alpha) # Display some information about the setup if self._verbose: self._print_verbage() # connect block input to channel filter self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe) # connect channel filter to the packet receiver self.connect(self.channel_filter, self.packet_receiver)
def __init__(self, bw_clock_sync=2*math.pi/100, bw_fll=math.pi/1600, bw_costas=2*math.pi/100, n_filts=32, len_sym_srrc=7, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=3, alfa=0.35, bits_per_sym=2, alpha_probe=0.1, th_probe=0): gr.hier_block2.__init__( self, "Hier Rx", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_char*1), ) ################################################## # Parameters ################################################## self.bw_clock_sync = bw_clock_sync self.bw_fll = bw_fll self.bw_costas = bw_costas self.n_filts = n_filts self.len_sym_srrc = len_sym_srrc self.constellation = constellation self.samp_per_sym = samp_per_sym self.alfa = alfa self.bits_per_sym = bits_per_sym self.alpha_probe = alpha_probe self.th_probe = th_probe ################################################## # Variables ################################################## self.filtro_srrc = filtro_srrc = firdes.root_raised_cosine(n_filts,samp_per_sym*n_filts,1.0,alfa,samp_per_sym*len_sym_srrc*n_filts) ################################################## # Blocks ################################################## self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(samp_per_sym, bw_clock_sync, (filtro_srrc), n_filts, 16, 5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(samp_per_sym, alfa, len_sym_srrc*samp_per_sym, bw_fll) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2**bits_per_sym) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(bw_costas, 2**bits_per_sym) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_sym) self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c(th_probe, alpha_probe) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0_0, 0)) self.connect((self, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self, 0)) self.connect((self, 0), (self.analog_probe_avg_mag_sqrd_x_0, 0))
def __init__(self, squelch_rate, squelch_threshold=-100): alpha = 80.0 / squelch_rate self.__squelch = analog.simple_squelch_cc(squelch_threshold, alpha) self.__probe = analog.probe_avg_mag_sqrd_c(0, alpha=alpha) self.squelch_block = gr.hier_block2( defaultstr('SquelchMixin bundle'), gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.squelch_block.connect(self.squelch_block, self.__squelch, self.squelch_block) self.squelch_block.connect(self.squelch_block, self.__probe)
def test_c_001(self): alpha = 0.0001 src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j, 7.0+7.0j, 8.0+8.0j, 9.0+9.0j, 10.0+10.0j] expected_result = avg_mag_sqrd_c(src_data, alpha)[-1] src = blocks.vector_source_c(src_data) op = analog.probe_avg_mag_sqrd_c(0, alpha) self.tb.connect(src, op) self.tb.run() result_data = op.level() self.assertAlmostEqual(expected_result, result_data, 5)
def test_c_001(self): alpha = 0.0001 src_data = [ 1.0 + 1.0j, 2.0 + 2.0j, 3.0 + 3.0j, 4.0 + 4.0j, 5.0 + 5.0j, 6.0 + 6.0j, 7.0 + 7.0j, 8.0 + 8.0j, 9.0 + 9.0j, 10.0 + 10.0j ] expected_result = avg_mag_sqrd_c(src_data, alpha)[-1] src = blocks.vector_source_c(src_data) op = analog.probe_avg_mag_sqrd_c(0, alpha) self.tb.connect(src, op) self.tb.run() result_data = op.level() self.assertAlmostEqual(expected_result, result_data, 5)
def __init__(self, squelch_rate, squelch_threshold=-100): alpha = 80.0 / squelch_rate self.__squelch = analog.simple_squelch_cc(squelch_threshold, alpha) self.__probe = analog.probe_avg_mag_sqrd_c(0, alpha=alpha) self.squelch_block = gr.hier_block2( defaultstr('SquelchMixin bundle'), gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.squelch_block.connect( self.squelch_block, self.__squelch, self.squelch_block) self.squelch_block.connect( self.squelch_block, self.__probe)
def __init__(self, modulator, options): gr.top_block.__init__(self) if(options.tx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = modulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / modulator(**args).bits_per_symbol() self.sink = uhd_transmitter(options.args, symbol_rate, options.samples_per_symbol, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) options.samples_per_symbol = self.sink._sps elif(options.to_file is not None): sys.stderr.write(("Saving samples to '%s'.\n\n" % (options.to_file))) self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: sys.stderr.write("No sink defined, dumping samples to null sink.\n\n") self.sink = blocks.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = transmit_path(modulator, options) alpha = 0.001 thresh = 20 self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) self.source = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.source.set_samp_rate(self.sink._rate) self.source.set_center_freq(uhd.tune_request(options.tx_freq,0)) self.source.set_gain(options.tx_gain) self.connect(self.source, self.probe) self.connect(self.txpath, self.sink) print >> sys.stderr, options
def __init__(self, squelch_rate, squelch_threshold=-100): alpha = 80.0 / squelch_rate self.rf_squelch_block = analog.simple_squelch_cc(squelch_threshold, alpha) self.rf_probe_block = analog.probe_avg_mag_sqrd_c(0, alpha=alpha)
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 1 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source( args=options.args ) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36./25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) self.connect((self.channelizer, ch), (squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "Power level for squelch % 5.1f" % pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "err: %f\tfreq: %f" % (err, freq, ) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self, bw_clock_sync=2*math.pi/100, bw_fll=math.pi/1600, bits_per_sym=2, bw_costas=2*math.pi/100, n_filts=32, len_sym_srrc=7, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=3, alfa=0.35): gr.hier_block2.__init__( self, "Hier Rx", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_char*1), ) ################################################## # Parameters ################################################## self.bw_clock_sync = bw_clock_sync self.bw_fll = bw_fll self.bits_per_sym = bits_per_sym self.bw_costas = bw_costas self.n_filts = n_filts self.len_sym_srrc = len_sym_srrc self.constellation = constellation self.samp_per_sym = samp_per_sym self.alfa = alfa ################################################## # Variables ################################################## self.filtro_srrc = filtro_srrc = firdes.root_raised_cosine(n_filts,samp_per_sym*n_filts,1.0,alfa,samp_per_sym*len_sym_srrc*n_filts) ################################################## # Blocks ################################################## self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(samp_per_sym, bw_clock_sync, (filtro_srrc), n_filts, 16, 5, 1) self.digital_fll_band_edge_cc_0 = digital.fll_band_edge_cc(samp_per_sym, alfa, len_sym_srrc*samp_per_sym, bw_fll) self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(2**bits_per_sym) self.digital_costas_loop_cc_0_0_0 = digital.costas_loop_cc(bw_costas, 2**bits_per_sym) self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation) self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(bits_per_sym) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0)) self.connect((self.digital_constellation_decoder_cb_0, 0), (self.digital_diff_decoder_bb_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.digital_fll_band_edge_cc_0, 0)) self.connect((self.digital_fll_band_edge_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0)) self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_costas_loop_cc_0_0_0, 0)) self.connect((self, 0), (self.analog_agc2_xx_0, 0)) self.connect((self.digital_costas_loop_cc_0_0_0, 0), (self.digital_constellation_decoder_cb_0, 0)) self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self, 0)) sw_decim = 1 self._chbw_factor=1 chan_coeffs = filter.firdes.low_pass (1.0, # gain sw_decim * self.samp_per_sym, # sampling rate self._chbw_factor, # midpoint of trans. band 0.5, # width of trans. band filter.firdes.WIN_HANN) # filter type self.channel_filter = filter.fft_filter_ccc(sw_decim, chan_coeffs) # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust self.probe = analog.probe_avg_mag_sqrd_c(thresh,alpha) self.connect(self, self.channel_filter) # connect the channel input filter to the carrier power detector self.connect(self.channel_filter, self.probe)
def _setup_top_block(self): self.tb = gr.top_block() samp_rate = 96000 oversample = 10 # Radio receiver, initial downsampling args = "rtl=%d,buffers=16" % (self.device, ) if self.osmosdr_args: args += ",%s" % (self.osmosdr_args, ) osmosdr_source = osmosdr.source(args=args) osmosdr_source.set_sample_rate(samp_rate * oversample) osmosdr_source.set_center_freq(self.freq, 0) osmosdr_source.set_freq_corr(0, 0) osmosdr_source.set_gain_mode(True, 0) osmosdr_source.set_gain(0, 0) taps = filter.firdes.low_pass(1, samp_rate * oversample, 90e3, 8e3, filter.firdes.WIN_HAMMING, 6.76) low_pass_filter = filter.fir_filter_ccf(oversample, taps) self.tb.connect((osmosdr_source, 0), (low_pass_filter, 0)) # Squelch self.noise_probe = analog.probe_avg_mag_sqrd_c(0, 1.0 / samp_rate / 1e2) self.squelch = analog.simple_squelch_cc(self.noise_level, 1) noise_probe_thread = threading.Thread(target=self._noise_probe_thread) noise_probe_thread.start() self.threads.append(noise_probe_thread) self.tb.connect((low_pass_filter, 0), (self.noise_probe, 0)) self.tb.connect((low_pass_filter, 0), (self.squelch, 0)) # FM demodulation quadrature_demod = analog.quadrature_demod_cf(1) self.tb.connect((self.squelch, 0), (quadrature_demod, 0)) # Binary slicing, transformation into capture-compatible format add_offset = blocks.add_const_vff((-1e-3, )) binary_slicer = digital.binary_slicer_fb() char_to_float = blocks.char_to_float(1, 1) multiply_const = blocks.multiply_const_vff((255, )) float_to_uchar = blocks.float_to_uchar() pipe_sink = blocks.file_sink(gr.sizeof_char * 1, self.pipe) pipe_sink.set_unbuffered(False) self.tb.connect((quadrature_demod, 0), (add_offset, 0)) self.tb.connect((add_offset, 0), (binary_slicer, 0)) self.tb.connect((binary_slicer, 0), (char_to_float, 0)) self.tb.connect((char_to_float, 0), (multiply_const, 0)) self.tb.connect((multiply_const, 0), (float_to_uchar, 0)) self.tb.connect((float_to_uchar, 0), (pipe_sink, 0))
def __init__(self): gr.top_block.__init__(self, "bladeRF_transceiver") ################################################## # Variables ################################################## self.symbole_rate = symbole_rate = 10e3 self.samp_rate = samp_rate = 1e6 self.rat_interop = rat_interop = 8 self.rat_decim = rat_decim = 5 self.firdes_transition_width = firdes_transition_width = 15000 self.firdes_decim = firdes_decim = 4 self.firdes_cuttoff = firdes_cuttoff = 21e3 self.tx_valve_value = tx_valve_value = False self.tx_rf_gain = tx_rf_gain = 10 self.tx_bb_gain = tx_bb_gain = -20 self.samp_per_sym_source = samp_per_sym_source = ( (samp_rate / 2 / firdes_decim) * rat_interop / rat_decim) / symbole_rate self.samp_per_sym = samp_per_sym = int(samp_rate / symbole_rate) self.rx_valve_value = rx_valve_value = False self.rx_rf_gain = rx_rf_gain = 3 self.rx_bb_gain = rx_bb_gain = 20 self.preamble = preamble = '0101010101010101' self.msg_source_msgq_in = msg_source_msgq_in = gr.msg_queue(2) self.msg_sink_msgq_out = msg_sink_msgq_out = gr.msg_queue(2) self.frequency_tx = frequency_tx = 450e6 self.frequency_shift = frequency_shift = 520000 self.frequency_rx = frequency_rx = 450.0e6 self.firdes_filter = firdes_filter = firdes.low_pass( 1, samp_rate / 2, firdes_cuttoff, firdes_transition_width) self.bit_per_sym = bit_per_sym = 1 self.bandwith = bandwith = 6e6 self.access_code = access_code = '11010011100100011101001110010001' ################################################## # Blocks ################################################## self.xlating_fir_filter_1 = filter.freq_xlating_fir_filter_ccc( 2, (1, ), frequency_shift, samp_rate) self.xlating_fir_filter_0 = filter.freq_xlating_fir_filter_ccc( firdes_decim, (firdes_filter), 0, samp_rate / 2) self.tx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex * 1, open=bool(tx_valve_value)) self.throttle = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate / 2, True) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( 0.05, 1) self.rx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex * 1, open=bool(rx_valve_value)) self.rational_resampler = filter.rational_resampler_ccc( interpolation=rat_interop, decimation=rat_decim, taps=None, fractional_bw=None, ) self.quadrature_demod = analog.quadrature_demod_cf(2) self.probe_signal_2 = blocks.probe_signal_f() self.probe_signal_1 = blocks.probe_signal_f() self.osmosdr_source = osmosdr.source(args="numchan=" + str(1) + " " + "bladerf=0") self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(frequency_rx - frequency_shift, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(2, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(rx_rf_gain, 0) self.osmosdr_source.set_if_gain(0, 0) self.osmosdr_source.set_bb_gain(rx_bb_gain, 0) self.osmosdr_source.set_antenna("", 0) self.osmosdr_source.set_bandwidth(bandwith, 0) self.osmosdr_sink = osmosdr.sink(args="numchan=" + str(1) + " " + "bladerf=0") self.osmosdr_sink.set_sample_rate(samp_rate) self.osmosdr_sink.set_center_freq(frequency_tx, 0) self.osmosdr_sink.set_freq_corr(0, 0) self.osmosdr_sink.set_gain(tx_rf_gain, 0) self.osmosdr_sink.set_if_gain(0, 0) self.osmosdr_sink.set_bb_gain(tx_bb_gain, 0) self.osmosdr_sink.set_antenna("", 0) self.osmosdr_sink.set_bandwidth(bandwith, 0) self.nlog10_ff = blocks.nlog10_ff(10, 1, 0) self.gmsk_mod = digital.gmsk_mod( samples_per_symbol=int(samp_per_sym), bt=0.5, verbose=False, log=False, ) self.correlate_access_code = digital.correlate_access_code_bb( access_code, 4) self.clock_recovery = digital.clock_recovery_mm_ff( samp_per_sym_source * (1 + 0.0), 0.25 * 0.175 * 0.175, 0.5, 0.175, 0.005) self.cc1111_packet_encoder = cc1111.cc1111_packet_mod_base( cc1111.cc1111_packet_encoder(samples_per_symbol=samp_per_sym, bits_per_symbol=bit_per_sym, preamble=preamble, access_code=access_code, pad_for_usrp=True, do_whitening=True, add_crc=True), source_queue=msg_source_msgq_in) self.cc1111_packet_decoder = cc1111.cc1111_packet_decoder( msg_sink_msgq_out, True, True, False, True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char * 1) self.blocks_keep_one_in_n = blocks.keep_one_in_n( gr.sizeof_float * 1, int(samp_rate / 30)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, 1000) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.binary_slicer = digital.binary_slicer_fb() self.avg_mag_sqrd = analog.probe_avg_mag_sqrd_c(0, 1) ################################################## # Connections ################################################## self.connect((self.binary_slicer, 0), (self.correlate_access_code, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.probe_signal_2, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.osmosdr_sink, 0)) self.connect((self.blocks_keep_one_in_n, 0), (self.nlog10_ff, 0)) self.connect((self.cc1111_packet_decoder, 0), (self.blocks_null_sink_0, 0)) self.connect((self.cc1111_packet_encoder, 0), (self.gmsk_mod, 0)) self.connect((self.clock_recovery, 0), (self.binary_slicer, 0)) self.connect((self.correlate_access_code, 0), (self.cc1111_packet_decoder, 0)) self.connect((self.gmsk_mod, 0), (self.tx_valve, 0)) self.connect((self.nlog10_ff, 0), (self.probe_signal_1, 0)) self.connect((self.osmosdr_source, 0), (self.rx_valve, 0)) self.connect((self.quadrature_demod, 0), (self.clock_recovery, 0)) self.connect((self.rational_resampler, 0), (self.quadrature_demod, 0)) self.connect((self.rx_valve, 0), (self.avg_mag_sqrd, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.rx_valve, 0), (self.xlating_fir_filter_1, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n, 0)) self.connect((self.throttle, 0), (self.xlating_fir_filter_0, 0)) self.connect((self.tx_valve, 0), (self.blocks_delay_0, 0)) self.connect((self.xlating_fir_filter_0, 0), (self.rational_resampler, 0)) self.connect((self.xlating_fir_filter_1, 0), (self.throttle, 0))
def __init__(self, min_errors=100, noise=0, samp_per_sym=50, tcola_m=32, tcola_r=1): gr.top_block.__init__(self, "BER 4FSK TCOLA") ################################################## # Parameters ################################################## self.min_errors = min_errors self.noise = noise self.samp_per_sym = samp_per_sym self.tcola_m = tcola_m self.tcola_r = tcola_r ################################################## # Variables ################################################## self.symb_rate = symb_rate = 4800 self.rrc_taps = rrc_taps = samp_per_sym * 6 + 1 self.symbol_delay = symbol_delay = rrc_taps / samp_per_sym - 1 self.samp_rate = samp_rate = symb_rate * samp_per_sym self.fsk_deviation_hz = fsk_deviation_hz = 648 self.bits_skip = bits_skip = 10000 self.bits_per_sym = bits_per_sym = 2 ################################################## # Blocks ################################################## self.delay = blocks.delay(gr.sizeof_char * 1, (symbol_delay + symb_rate) * bits_per_sym) self.vco = blocks.vco_c(samp_rate, fsk_deviation_hz * 2 * math.pi, 1) self.tcola_time_compression_0 = tcola.time_compression_c( tcola_m, tcola_r, ()) self.tcola_overlap_add_0 = tcola.overlap_add_c(tcola_m, tcola_r, ()) self.sample_counter = sample_counter() self.quadrature_demod = analog.quadrature_demod_cf( samp_rate / (2 * math.pi * fsk_deviation_hz)) self.probe_avg_power = analog.probe_avg_mag_sqrd_c(0, 1) self.pack_rx_bits = blocks.pack_k_bits_bb(8) self.pack_msg_bits = blocks.pack_k_bits_bb(8) self.glfsr = digital.glfsr_source_b(8, True, 0, 1) self.four_level_rrc_transmitter = four_level_rrc_transmitter( alpha=0.350, bits_per_symbol=2, rrc_taps=rrc_taps, samp_per_sym=samp_per_sym, sym_rate=symb_rate, ) self.four_level_rrc_receiver = four_level_rrc_receiver( alpha=0.350, bits_per_sym=2, rrc_taps=rrc_taps, samp_per_sym=samp_per_sym, sym_rate=symb_rate, ) self.channel_model = channels.channel_model(noise_voltage=noise, frequency_offset=0.0, epsilon=1.0, taps=(1, ), noise_seed=0, block_tags=False) self.blocks_skiphead_0_0 = blocks.skiphead(gr.sizeof_char * 1, bits_skip) self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_char * 1, bits_skip) self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, samp_rate - tcola_m) self.ber_sink = blocks.vector_sink_f(1) self.ber_measure = fec.ber_bf(True, min_errors, -7.0) ################################################## # Connections ################################################## self.connect((self.ber_measure, 0), (self.ber_sink, 0)) self.connect((self.blocks_delay_0_0, 0), (self.quadrature_demod, 0)) self.connect((self.blocks_skiphead_0, 0), (self.sample_counter, 0)) self.connect((self.blocks_skiphead_0_0, 0), (self.pack_rx_bits, 0)) self.connect((self.channel_model, 0), (self.tcola_overlap_add_0, 0)) self.connect((self.delay, 0), (self.blocks_skiphead_0, 0)) self.connect((self.four_level_rrc_receiver, 2), (self.blocks_skiphead_0_0, 0)) self.connect((self.four_level_rrc_transmitter, 1), (self.vco, 0)) self.connect((self.glfsr, 0), (self.delay, 0)) self.connect((self.glfsr, 0), (self.four_level_rrc_transmitter, 0)) self.connect((self.pack_msg_bits, 0), (self.ber_measure, 0)) self.connect((self.pack_rx_bits, 0), (self.ber_measure, 1)) self.connect((self.quadrature_demod, 0), (self.four_level_rrc_receiver, 0)) self.connect((self.sample_counter, 0), (self.pack_msg_bits, 0)) self.connect((self.tcola_overlap_add_0, 0), (self.blocks_delay_0_0, 0)) self.connect((self.tcola_time_compression_0, 0), (self.channel_model, 0)) self.connect((self.tcola_time_compression_0, 0), (self.probe_avg_power, 0)) self.connect((self.vco, 0), (self.tcola_time_compression_0, 0))
def __init__(self, squelch_rate, squelch_threshold=-100): alpha = 80.0 / squelch_rate self.rf_squelch_block = analog.simple_squelch_cc( squelch_threshold, alpha) self.rf_probe_block = analog.probe_avg_mag_sqrd_c(0, alpha=alpha)
def __init__(self): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 2e5 self.access_code = access_code = gwnutils.default_access_code ################################################## # Blocks ################################################## self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c( -140, 1) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(400000000.0, 0) self.uhd_usrp_source_0.set_gain(60, 0) self.uhd_usrp_source_0.set_antenna("TX/RX", 0) self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("", "")), uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_center_freq(400000000.0, 0) self.uhd_usrp_sink_0.set_gain(40, 0) self.uhd_usrp_sink_0.set_antenna("TX/RX", 0) self.gwn_pdu_to_ev_0 = gwn.pdu_to_ev('payload') self.gwn_l1_framer_0 = gwn.l1_framer('event', False) self.gwn_l1_deframer_0 = gwn.l1_deframer('event', False) self.gwn_hier_tx_psk_0 = gwn.hier_tx_psk( 0.35, 3, 2, ([-1 - 1j, 1 - 1j, 1 + 1j, -1 + 1j]), 7, 0.4) self.gwn_hier_rx_psk_0 = gwn.hier_rx_psk( 2 * 3.14 / 100, 3.14 / 1600, 2 * 3.14 / 100, 32, 7, digital.constellation_calcdist([-1 - 1j, 1 - 1j, 1 + 1j, -1 + 1j], [], 4, 1).base(), 3, 0.35, 2, 0.6, 0.6, 2.0, 15.0, 0.1, 0) self.gwn_event_guider_0 = gwn.event_guider('DataData', 'CtrlACK', 'EstacionBase', False, True) self.gwn_event_constructor_0 = gwn.event_constructor( 'EstacionBase', False, 1, 'Metalico', True) self.gwn_ev_to_pdu_0 = gwn.ev_to_pdu('payload') self.gwn_ack_rx_0 = gwn.ack_rx('CtrlACK', True) self.gwn_CSMA_FSM_0 = gwn.CSMA_FSM('CtrlACK', 1000, 'EventTimer', 0.5, 'TimerTOH', 0.1, 1000, 1.0, False, True) get_level = self.analog_probe_avg_mag_sqrd_x_0.level print(str(get_level)) try: self.gwn_CSMA_FSM_0.set_get_level(get_level) except AttributeError: print "Probe Medium XML, AttributeError in setting get_level function" except: print "Probe Medium XML, another error in setting get_level function" self.digital_correlate_access_code_xx_ts_0 = digital.correlate_access_code_bb_ts( access_code, 1, "correlate") self.blocks_tagged_stream_to_pdu_0 = blocks.tagged_stream_to_pdu( blocks.byte_t, "correlate") self.blocks_socket_pdu_1_0 = blocks.socket_pdu("UDP_SERVER", "127.0.0.1", "50008", 10000, False) self.blocks_socket_pdu_1 = blocks.socket_pdu("UDP_CLIENT", "127.0.0.1", "50007", 10000, False) self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream( blocks.byte_t, "packet_len") ################################################## # Connections ################################################## self.msg_connect((self.blocks_socket_pdu_1_0, 'pdus'), (self.gwn_pdu_to_ev_0, 'pdu')) self.msg_connect((self.blocks_tagged_stream_to_pdu_0, 'pdus'), (self.gwn_l1_deframer_0, 'pdu')) self.msg_connect((self.gwn_CSMA_FSM_0, 'out1'), (self.gwn_ev_to_pdu_0, 'in0')) self.msg_connect((self.gwn_CSMA_FSM_0, 'out0'), (self.gwn_l1_framer_0, 'in0')) self.msg_connect((self.gwn_ack_rx_0, 'out0'), (self.gwn_ev_to_pdu_0, 'in0')) self.msg_connect((self.gwn_ack_rx_0, 'out1'), (self.gwn_l1_framer_0, 'in0')) self.msg_connect((self.gwn_ev_to_pdu_0, 'pdu'), (self.blocks_socket_pdu_1, 'pdus')) self.msg_connect((self.gwn_event_constructor_0, 'out0'), (self.gwn_CSMA_FSM_0, 'in0')) self.msg_connect((self.gwn_event_guider_0, 'out1'), (self.gwn_CSMA_FSM_0, 'in0')) self.msg_connect((self.gwn_event_guider_0, 'out0'), (self.gwn_ack_rx_0, 'in0')) self.msg_connect((self.gwn_l1_deframer_0, 'out0'), (self.gwn_event_guider_0, 'in0')) self.msg_connect((self.gwn_l1_framer_0, 'pdu'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.gwn_pdu_to_ev_0, 'out0'), (self.gwn_event_constructor_0, 'in0')) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.gwn_hier_tx_psk_0, 0)) self.connect((self.digital_correlate_access_code_xx_ts_0, 0), (self.blocks_tagged_stream_to_pdu_0, 0)) self.connect((self.gwn_hier_rx_psk_0, 0), (self.digital_correlate_access_code_xx_ts_0, 0)) self.connect((self.gwn_hier_tx_psk_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.analog_probe_avg_mag_sqrd_x_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.gwn_hier_rx_psk_0, 0))
def __init__(self): gr.top_block.__init__(self, "Top Block") ################################################## # Variables ################################################## self.rate = rate = 2 self.polys = polys = [109, 79] self.k = k = 7 self.samp_rate = samp_rate = 48000 self.enc_cc = enc_cc = fec.cc_encoder_make(8000, k, rate, (polys), 0, fec.CC_TERMINATED, False) self.dec_cc = dec_cc = fec.cc_decoder.make(8000, k, rate, (polys), 0, -1, fec.CC_TERMINATED, False) ################################################## # Blocks ################################################## self.splash_packet_encoder_0 = splash.packet_encoder( samples_per_symbol=8, bits_per_symbol=1, preamble="", access_code="", pad_for_usrp=False, payload_length=9 ) self.splash_packet_decoder_0 = splash.packet_decoder( access_code="", threshold=-1 ) self.splash_XCEIVER_0 = splash.XCEIVER() self.digital_map_bb_0 = digital.map_bb(([-1,1])) self.dflood_dflood_0 = dflood.dflood( 2, 0, 30, False, False, 5, 65, 2, 120, 50, 2, True, None ) self.blocks_tagged_stream_to_pdu_1 = blocks.tagged_stream_to_pdu(blocks.float_t, "packet_len") self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, 1, "packet_len", True, gr.GR_MSB_FIRST) self.blocks_random_pdu_0_0 = blocks.random_pdu(1, 5, chr(0xFF), 1) self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len") self.blocks_message_strobe_2 = blocks.message_strobe(pmt.intern("TEST"), 10000) self.blocks_message_strobe_0 = blocks.message_strobe(pmt.intern("TEST"), 10000) self.blocks_message_debug_0 = blocks.message_debug() self.blocks_char_to_float_0_1 = blocks.char_to_float(1, 1) self.audio_source_0 = audio.source(48000, "", True) self.audio_sink_0 = audio.sink(48000, "", True) self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c(-70, 1) self.Async_Ecnoder = fec.async_encoder(enc_cc, True, False, False, 1500) self.Async_Decoder = fec.async_decoder(dec_cc, True, False, 1500) ################################################## # Connections ################################################## self.msg_connect((self.Async_Decoder, 'out'), (self.dflood_dflood_0, 'from_radio')) self.msg_connect((self.Async_Ecnoder, 'out'), (self.blocks_pdu_to_tagged_stream_0, 'pdus')) self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.blocks_random_pdu_0_0, 'generate')) self.msg_connect((self.blocks_message_strobe_2, 'strobe'), (self.dflood_dflood_0, 'ctrl_in')) self.msg_connect((self.blocks_random_pdu_0_0, 'pdus'), (self.dflood_dflood_0, 'from_app')) self.msg_connect((self.blocks_tagged_stream_to_pdu_1, 'pdus'), (self.Async_Decoder, 'in')) self.msg_connect((self.dflood_dflood_0, 'to_radio'), (self.Async_Ecnoder, 'in')) self.msg_connect((self.dflood_dflood_0, 'to_app'), (self.blocks_message_debug_0, 'print_pdu')) self.connect((self.audio_source_0, 0), (self.splash_XCEIVER_0, 0)) self.connect((self.blocks_char_to_float_0_1, 0), (self.blocks_tagged_stream_to_pdu_1, 0)) self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.splash_packet_encoder_0, 0)) self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_map_bb_0, 0)) self.connect((self.digital_map_bb_0, 0), (self.blocks_char_to_float_0_1, 0)) self.connect((self.splash_XCEIVER_0, 2), (self.analog_probe_avg_mag_sqrd_x_0, 0)) self.connect((self.splash_XCEIVER_0, 0), (self.audio_sink_0, 0)) self.connect((self.splash_XCEIVER_0, 1), (self.splash_packet_decoder_0, 0)) self.connect((self.splash_packet_decoder_0, 0), (self.blocks_repack_bits_bb_0, 0)) self.connect((self.splash_packet_encoder_0, 0), (self.splash_XCEIVER_0, 1))
def _setup_top_block(self): self.tb = gr.top_block() samp_rate = 96000 oversample = 10 # Radio receiver, initial downsampling args = "rtl=%d,buffers=16" % (self.device,) if self.osmosdr_args: args += ",%s" % (self.osmosdr_args,) osmosdr_source = osmosdr.source(args=args) osmosdr_source.set_sample_rate(samp_rate * oversample) osmosdr_source.set_center_freq(self.freq, 0) osmosdr_source.set_freq_corr(0, 0) osmosdr_source.set_gain_mode(1, 0) osmosdr_source.set_gain(0, 0) taps = filter.firdes.low_pass(1, samp_rate * oversample, 90e3, 8e3, filter.firdes.WIN_HAMMING, 6.76) low_pass_filter = filter.fir_filter_ccf(oversample, taps) self.tb.connect((osmosdr_source, 0), (low_pass_filter, 0)) # Squelch self.noise_probe = analog.probe_avg_mag_sqrd_c(0, 1.0 / samp_rate / 1e2) self.squelch = analog.simple_squelch_cc(self.noise_level, 1) noise_probe_thread = threading.Thread(target=self._noise_probe_thread) noise_probe_thread.start() self.threads.append(noise_probe_thread) self.tb.connect((low_pass_filter, 0), (self.noise_probe, 0)) self.tb.connect((low_pass_filter, 0), (self.squelch, 0)) # FM demodulation quadrature_demod = analog.quadrature_demod_cf(1) self.tb.connect((self.squelch, 0), (quadrature_demod, 0)) # Binary slicing, transformation into capture-compatible format add_offset = blocks.add_const_vff((-1e-3,)) binary_slicer = digital.binary_slicer_fb() char_to_float = blocks.char_to_float(1, 1) multiply_const = blocks.multiply_const_vff((255,)) float_to_uchar = blocks.float_to_uchar() pipe_sink = blocks.file_sink(gr.sizeof_char * 1, self.pipe) pipe_sink.set_unbuffered(False) self.tb.connect((quadrature_demod, 0), (add_offset, 0)) self.tb.connect((add_offset, 0), (binary_slicer, 0)) self.tb.connect((binary_slicer, 0), (char_to_float, 0)) self.tb.connect((char_to_float, 0), (multiply_const, 0)) self.tb.connect((multiply_const, 0), (float_to_uchar, 0)) self.tb.connect((float_to_uchar, 0), (pipe_sink, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Sweep10") ################################################## # Variables ################################################## self.tx_samp_rate = tx_samp_rate = 15e6 self.rx_sample_rate = rx_sample_rate = 50e3 self.frequency = frequency = 925.7e6 ################################################## # Blocks ################################################## self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=20, y_divs=10, ref_level=-10, ref_scale=2.0, sample_rate=rx_sample_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title='FFT Plot', peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '') self.osmosdr_source_0.set_sample_rate(rx_sample_rate) self.osmosdr_source_0.set_center_freq(925.7e6, 0) self.osmosdr_source_0.set_freq_corr(0, 0) self.osmosdr_source_0.set_dc_offset_mode(0, 0) self.osmosdr_source_0.set_iq_balance_mode(0, 0) self.osmosdr_source_0.set_gain_mode(False, 0) self.osmosdr_source_0.set_gain(20, 0) self.osmosdr_source_0.set_if_gain(20, 0) self.osmosdr_source_0.set_bb_gain(20, 0) self.osmosdr_source_0.set_antenna('LNAW', 0) self.osmosdr_source_0.set_bandwidth(0, 0) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + 'driver=lime') self.osmosdr_sink_0.set_sample_rate(tx_samp_rate) self.osmosdr_sink_0.set_center_freq(frequency, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(20, 0) self.osmosdr_sink_0.set_bb_gain(20, 0) self.osmosdr_sink_0.set_antenna('BAND1', 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.band_pass_filter_0 = filter.fir_filter_ccc( 1, firdes.complex_band_pass(1, rx_sample_rate, 500, 1.5e3, 200, firdes.WIN_HAMMING, 6.76)) self.analog_sig_source_x_0 = analog.sig_source_c( tx_samp_rate, analog.GR_COS_WAVE, 1e3, 1, 0) self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c(0, 1) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.analog_probe_avg_mag_sqrd_x_0, 0)) self.connect((self.band_pass_filter_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.osmosdr_source_0, 0), (self.band_pass_filter_0, 0))
def __init__(self): gr.top_block.__init__(self, "Spectrum") Qt.QWidget.__init__(self) self.setWindowTitle("Spectrum") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "spectrum") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.function_3 = function_3 = 0 self.function_2 = function_2 = 0 self.function_1 = function_1 = 0 self.variable_qtgui_label_0_1 = variable_qtgui_label_0_1 = function_3 self.variable_qtgui_label_0_0 = variable_qtgui_label_0_0 = function_1 self.variable_qtgui_label_0 = variable_qtgui_label_0 = function_2 self.samp_rate = samp_rate = 1e6 self.frequency_rx = frequency_rx = 476.0e6 ################################################## # Blocks ################################################## self.probe_signal_2 = blocks.probe_signal_f() self.probe_signal_1 = blocks.probe_signal_f() self.avg_mag_sqrd = analog.probe_avg_mag_sqrd_c(0, 1) self._variable_qtgui_label_0_1_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_1_formatter = None else: self._variable_qtgui_label_0_1_formatter = lambda x: x self._variable_qtgui_label_0_1_tool_bar.addWidget(Qt.QLabel("variable_qtgui_label_0_1"+": ")) self._variable_qtgui_label_0_1_label = Qt.QLabel(str(self._variable_qtgui_label_0_1_formatter(self.variable_qtgui_label_0_1))) self._variable_qtgui_label_0_1_tool_bar.addWidget(self._variable_qtgui_label_0_1_label) self.top_layout.addWidget(self._variable_qtgui_label_0_1_tool_bar) self._variable_qtgui_label_0_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_0_formatter = None else: self._variable_qtgui_label_0_0_formatter = lambda x: x self._variable_qtgui_label_0_0_tool_bar.addWidget(Qt.QLabel("variable_qtgui_label_0_0"+": ")) self._variable_qtgui_label_0_0_label = Qt.QLabel(str(self._variable_qtgui_label_0_0_formatter(self.variable_qtgui_label_0_0))) self._variable_qtgui_label_0_0_tool_bar.addWidget(self._variable_qtgui_label_0_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_0_tool_bar) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget(Qt.QLabel("variable_qtgui_label_0"+": ")) self._variable_qtgui_label_0_label = Qt.QLabel(str(self._variable_qtgui_label_0_formatter(self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget(self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(0.05, 1) self.qtgui_number_sink_0_0 = qtgui.number_sink( gr.sizeof_float, 0, qtgui.NUM_GRAPH_VERT, 1 ) self.qtgui_number_sink_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0.set_title("Power") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0.set_min(i, -20) self.qtgui_number_sink_0_0.set_max(i, 2) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance(self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_0_win) self.qtgui_number_sink_0 = qtgui.number_sink( gr.sizeof_float, 0.10, qtgui.NUM_GRAPH_VERT, 1 ) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("Power") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 2) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype frequency_rx, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if complex == type(float()): self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.osmosdr_source = osmosdr.source( args="numchan=" + str(1) + " " + "bladerf=0" ) self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(frequency_rx, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(2, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(3, 0) self.osmosdr_source.set_if_gain(0, 0) self.osmosdr_source.set_bb_gain(20, 0) self.osmosdr_source.set_antenna("", 0) self.osmosdr_source.set_bandwidth(6e6, 0) self.nlog10_ff = blocks.nlog10_ff(10, 1, 0) def _function_3_probe(): while True: val = self.probe_signal_2.level() try: self.set_function_3(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_3_thread = threading.Thread(target=_function_3_probe) _function_3_thread.daemon = True _function_3_thread.start() def _function_2_probe(): while True: val = self.avg_mag_sqrd.level() try: self.set_function_2(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_2_thread = threading.Thread(target=_function_2_probe) _function_2_thread.daemon = True _function_2_thread.start() def _function_1_probe(): while True: val = self.probe_signal_1.level() try: self.set_function_1(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_1_thread = threading.Thread(target=_function_1_probe) _function_1_thread.daemon = True _function_1_thread.start() self.blocks_keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_float*1, int(samp_rate / 30)) self.blocks_complex_to_mag_squared_0_0_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.probe_signal_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_keep_one_in_n, 0), (self.nlog10_ff, 0)) self.connect((self.nlog10_ff, 0), (self.probe_signal_2, 0)) self.connect((self.nlog10_ff, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.osmosdr_source, 0), (self.avg_mag_sqrd, 0)) self.connect((self.osmosdr_source, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.osmosdr_source, 0), (self.blocks_complex_to_mag_squared_0_0_0, 0)) self.connect((self.osmosdr_source, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n, 0))
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Fm Tuner") _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) ################################################## # Variables ################################################## self.tuning_frequency = tuning_frequency = 90.5e6 self.volume = volume = 1 self.transition = transition = 500000 self.samp_rate = samp_rate = 2000000 self.quadrature = quadrature = 500000 self.low_cutoff = low_cutoff = tuning_frequency-0.1e6 self.high_cutoff = high_cutoff = tuning_frequency+0.1e6 self.frequency = frequency = tuning_frequency self.cutoff = cutoff = 100000 self.center_freq_probe = center_freq_probe = 0 self.ave_mag_probe = ave_mag_probe = 0 self.audio_decimation = audio_decimation = 10 ################################################## # Blocks ################################################## self.rtlsdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) self.rtlsdr_source_0.set_sample_rate(samp_rate) self.rtlsdr_source_0.set_center_freq(tuning_frequency, 0) self.rtlsdr_source_0.set_freq_corr(0, 0) self.rtlsdr_source_0.set_dc_offset_mode(2, 0) self.rtlsdr_source_0.set_iq_balance_mode(0, 0) self.rtlsdr_source_0.set_gain_mode(1, 0) self.rtlsdr_source_0.set_gain(25, 0) self.rtlsdr_source_0.set_if_gain(20, 0) self.rtlsdr_source_0.set_bb_gain(20, 0) self.rtlsdr_source_0.set_antenna("", 0) self.rtlsdr_source_0.set_bandwidth(0, 0) self.analog_probe_avg_mag_sqrd_x_0 = analog.probe_avg_mag_sqrd_c(0, 1) self.wxgui_fftsink2_0 = fftsink2.fft_sink_c( self.GetWin(), baseband_freq=0, y_per_div=10, y_divs=10, ref_level=0, ref_scale=2.0, sample_rate=samp_rate, fft_size=1024, fft_rate=15, average=False, avg_alpha=None, title="FFT Plot", peak_hold=False, ) self.Add(self.wxgui_fftsink2_0.win) self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( interpolation=1, decimation=4, taps=None, fractional_bw=None, ) self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass( 1, samp_rate, cutoff, transition, firdes.WIN_HAMMING, 6.76)) _frequency_sizer = wx.BoxSizer(wx.VERTICAL) self._frequency_text_box = forms.text_box( parent=self.GetWin(), sizer=_frequency_sizer, value=self.frequency, callback=self.set_frequency, label='frequency', converter=forms.float_converter(), proportion=0, ) self._frequency_slider = forms.slider( parent=self.GetWin(), sizer=_frequency_sizer, value=self.frequency, callback=self.set_frequency, minimum=88e6, maximum=110e6, num_steps=100, style=wx.SL_HORIZONTAL, cast=float, proportion=1, ) self.Add(_frequency_sizer) def _center_freq_probe_probe(): while True: val = self.rtlsdr_source_0.get_center_freq() try: self.set_center_freq_probe(val) except AttributeError, e: pass time.sleep(1.0/(10)) _center_freq_probe_thread = threading.Thread(target=_center_freq_probe_probe) _center_freq_probe_thread.daemon = True _center_freq_probe_thread.start() def _ave_mag_probe_probe(): while True: val = self.analog_probe_avg_mag_sqrd_x_0.level() try: self.set_ave_mag_probe(val) except AttributeError, e: pass time.sleep(1.0/(10)) _ave_mag_probe_thread = threading.Thread(target=_ave_mag_probe_probe) _ave_mag_probe_thread.daemon = True _ave_mag_probe_thread.start() self.analog_simple_squelch_cc_0 = analog.simple_squelch_cc(-60, 1) ################################################## # Connections ################################################## self.connect((self.rtlsdr_source_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.low_pass_filter_0, 0)) self.connect((self.low_pass_filter_0, 0), (self.analog_simple_squelch_cc_0, 0)) self.connect((self.analog_simple_squelch_cc_0, 0), (self.wxgui_fftsink2_0, 0)) self.connect((self.analog_simple_squelch_cc_0, 0), (self.analog_probe_avg_mag_sqrd_x_0, 0))
def __init__(self): gr.top_block.__init__(self, "bladeRF_transceiver") ################################################## # Variables ################################################## self.symbole_rate = symbole_rate = 10e3 self.samp_rate = samp_rate = 1e6 self.rat_interop = rat_interop = 8 self.rat_decim = rat_decim = 5 self.firdes_transition_width = firdes_transition_width = 15000 self.firdes_decim = firdes_decim = 4 self.firdes_cuttoff = firdes_cuttoff = 21e3 self.tx_valve_value = tx_valve_value = False self.tx_rf_gain = tx_rf_gain = 10 self.tx_bb_gain = tx_bb_gain = -20 self.samp_per_sym_source = samp_per_sym_source = ((samp_rate/2/firdes_decim)*rat_interop/rat_decim) / symbole_rate self.samp_per_sym = samp_per_sym = int(samp_rate / symbole_rate) self.rx_valve_value = rx_valve_value = False self.rx_rf_gain = rx_rf_gain = 3 self.rx_bb_gain = rx_bb_gain = 20 self.preamble = preamble = '0101010101010101' self.msg_source_msgq_in = msg_source_msgq_in = gr.msg_queue(2) self.msg_sink_msgq_out = msg_sink_msgq_out = gr.msg_queue(2) self.frequency_tx = frequency_tx = 450e6 self.frequency_shift = frequency_shift = 520000 self.frequency_rx = frequency_rx = 450.0e6 self.firdes_filter = firdes_filter = firdes.low_pass(1,samp_rate/2, firdes_cuttoff, firdes_transition_width) self.bit_per_sym = bit_per_sym = 1 self.bandwith = bandwith = 6e6 self.access_code = access_code = '11010011100100011101001110010001' ################################################## # Blocks ################################################## self.xlating_fir_filter_1 = filter.freq_xlating_fir_filter_ccc(2, (1, ), frequency_shift, samp_rate) self.xlating_fir_filter_0 = filter.freq_xlating_fir_filter_ccc(firdes_decim, (firdes_filter), 0, samp_rate/2) self.tx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(tx_valve_value)) self.throttle = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate/2,True) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff(0.05, 1) self.rx_valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex*1, open=bool(rx_valve_value)) self.rational_resampler = filter.rational_resampler_ccc( interpolation=rat_interop, decimation=rat_decim, taps=None, fractional_bw=None, ) self.quadrature_demod = analog.quadrature_demod_cf(2) self.probe_signal_2 = blocks.probe_signal_f() self.probe_signal_1 = blocks.probe_signal_f() self.osmosdr_source = osmosdr.source( args="numchan=" + str(1) + " " + "bladerf=0" ) self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(frequency_rx-frequency_shift, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(2, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(rx_rf_gain, 0) self.osmosdr_source.set_if_gain(0, 0) self.osmosdr_source.set_bb_gain(rx_bb_gain, 0) self.osmosdr_source.set_antenna("", 0) self.osmosdr_source.set_bandwidth(bandwith, 0) self.osmosdr_sink = osmosdr.sink( args="numchan=" + str(1) + " " + "bladerf=0" ) self.osmosdr_sink.set_sample_rate(samp_rate) self.osmosdr_sink.set_center_freq(frequency_tx, 0) self.osmosdr_sink.set_freq_corr(0, 0) self.osmosdr_sink.set_gain(tx_rf_gain, 0) self.osmosdr_sink.set_if_gain(0, 0) self.osmosdr_sink.set_bb_gain(tx_bb_gain, 0) self.osmosdr_sink.set_antenna("", 0) self.osmosdr_sink.set_bandwidth(bandwith, 0) self.nlog10_ff = blocks.nlog10_ff(10, 1, 0) self.gmsk_mod = digital.gmsk_mod( samples_per_symbol=int(samp_per_sym), bt=0.5, verbose=False, log=False, ) self.correlate_access_code = digital.correlate_access_code_bb(access_code, 4) self.clock_recovery = digital.clock_recovery_mm_ff(samp_per_sym_source*(1+0.0), 0.25*0.175*0.175, 0.5, 0.175, 0.005) self.cc1111_packet_encoder = cc1111.cc1111_packet_mod_base(cc1111.cc1111_packet_encoder( samples_per_symbol=samp_per_sym, bits_per_symbol=bit_per_sym, preamble=preamble, access_code=access_code, pad_for_usrp=True, do_whitening=True, add_crc=True ), source_queue=msg_source_msgq_in ) self.cc1111_packet_decoder = cc1111.cc1111_packet_decoder(msg_sink_msgq_out,True, True, False, True) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char*1) self.blocks_keep_one_in_n = blocks.keep_one_in_n(gr.sizeof_float*1, int(samp_rate / 30)) self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1000) self.blocks_complex_to_mag_squared_0_0 = blocks.complex_to_mag_squared(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.binary_slicer = digital.binary_slicer_fb() self.avg_mag_sqrd = analog.probe_avg_mag_sqrd_c(0, 1) ################################################## # Connections ################################################## self.connect((self.binary_slicer, 0), (self.correlate_access_code, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.probe_signal_2, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_delay_0, 0), (self.osmosdr_sink, 0)) self.connect((self.blocks_keep_one_in_n, 0), (self.nlog10_ff, 0)) self.connect((self.cc1111_packet_decoder, 0), (self.blocks_null_sink_0, 0)) self.connect((self.cc1111_packet_encoder, 0), (self.gmsk_mod, 0)) self.connect((self.clock_recovery, 0), (self.binary_slicer, 0)) self.connect((self.correlate_access_code, 0), (self.cc1111_packet_decoder, 0)) self.connect((self.gmsk_mod, 0), (self.tx_valve, 0)) self.connect((self.nlog10_ff, 0), (self.probe_signal_1, 0)) self.connect((self.osmosdr_source, 0), (self.rx_valve, 0)) self.connect((self.quadrature_demod, 0), (self.clock_recovery, 0)) self.connect((self.rational_resampler, 0), (self.quadrature_demod, 0)) self.connect((self.rx_valve, 0), (self.avg_mag_sqrd, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.rx_valve, 0), (self.blocks_complex_to_mag_squared_0_0, 0)) self.connect((self.rx_valve, 0), (self.xlating_fir_filter_1, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n, 0)) self.connect((self.throttle, 0), (self.xlating_fir_filter_0, 0)) self.connect((self.tx_valve, 0), (self.blocks_delay_0, 0)) self.connect((self.xlating_fir_filter_0, 0), (self.rational_resampler, 0)) self.connect((self.xlating_fir_filter_1, 0), (self.throttle, 0))
def __init__(self): gr.top_block.__init__(self, "Tetra Rx Multi") options = self.get_options() ################################################## # Variables ################################################## self.srate_rx = srate_rx = options.sample_rate self.channels = srate_rx / 25000 self.srate_channel = 36000 self.afc_period = 5 self.afc_gain = 1. self.afc_channel = options.auto_tune or -1 self.afc_ppm_step = 100 self.debug = options.debug self.last_pwr = -100000 self.sig_det_period = 10 self.sig_det_bw = sig_det_bw = options.sig_detection_bw or srate_rx if self.sig_det_bw <= 1.: self.sig_det_bw *= srate_rx self.sig_det_threshold = options.sig_detection_threshold self.sig_det_channels = [] for ch in range(self.channels): if ch >= self.channels / 2: ch_ = (self.channels - ch - 1) else: ch_ = ch if (float(ch_) / self.channels * 2) <= (self.sig_det_bw / srate_rx): self.sig_det_channels.append(ch) ################################################## # RPC server ################################################## self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.listen_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start() ################################################## # Rx Blocks and connections ################################################## self.src = osmosdr.source( args=options.args ) self.src.set_sample_rate(srate_rx) self.src.set_center_freq(options.frequency, 0) self.src.set_freq_corr(options.ppm, 0) self.src.set_dc_offset_mode(0, 0) self.src.set_iq_balance_mode(0, 0) if options.gain is not None: self.src.set_gain_mode(False, 0) self.src.set_gain(36, 0) else: self.src.set_gain_mode(True, 0) out_type, dst_path = options.output.split("://", 1) if out_type == "udp": dst_ip, dst_port = dst_path.split(':', 1) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, srate_rx) self.channelizer = pfb.channelizer_ccf( self.channels, (firdes.root_raised_cosine(1, srate_rx, 18000, 0.35, 1024)), 36./25., 100) self.squelch = [] self.digital_mpsk_receiver_cc = [] self.diff_phasor = [] self.complex_to_arg = [] self.multiply_const = [] self.add_const = [] self.float_to_uchar = [] self.map_bits = [] self.unpack_k_bits = [] self.blocks_sink = [] for ch in range(0, self.channels): squelch = analog.pwr_squelch_cc(0, 0.001, 0, True) mpsk = digital.mpsk_receiver_cc( 4, math.pi/4, math.pi/100.0, -0.5, 0.5, 0.25, 0.001, 2, 0.001, 0.001) diff_phasor = digital.diff_phasor_cc() complex_to_arg = blocks.complex_to_arg(1) multiply_const = blocks.multiply_const_vff((2./math.pi, )) add_const = blocks.add_const_vff((1.5, )) float_to_uchar = blocks.float_to_uchar() map_bits = digital.map_bb(([3, 2, 0, 1, 3])) unpack_k_bits = blocks.unpack_k_bits_bb(2) brmchannels = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71] #brmchannels = [11,4,3,64,45,47,53,8,68,6,56,49,17,54,65,5,71,22,48,7,50] # itds kancl #brmchannels = [23,13,40,69,59,7,42,54,5,14,4,56,45,46,67,55,66,44,71,49,31,57,0,65,70] # doma - dole brmchannels = [23,13,59,40,69,7,49,60,42,70,4,50,66,67,3,14,57,33,46,22,68,32,39,24,6,12,43,58,48,17,5,56,65,29,54,30,16,52,53,41,47,2,34,44,8] # doma - strecha #brmchannels = [67, 7, 23, 70] # doma - strecha - SDS brmchannels = [67, 7, 23, 70,9,71,64,63,62,61,55,51,45,38,37,36,35,31,28,27,26,25,21,20,19,18,15,11,10,1,0] # doma - strecha - komplement if out_type == 'udp': sink = blocks.udp_sink(gr.sizeof_gr_char, dst_ip, int(dst_port)+ch, 1472, True) elif out_type == 'file': sink = blocks.file_sink(gr.sizeof_char, dst_path % ch, False) sink.set_unbuffered(True) else: raise ValueError("Invalid output URL '%s'" % options.output) if ch in brmchannels: self.connect((self.channelizer, ch), #(squelch, 0), (mpsk, 0), (diff_phasor, 0), (complex_to_arg, 0), (multiply_const, 0), (add_const, 0), (float_to_uchar, 0), (map_bits, 0), (unpack_k_bits, 0), (sink, 0)) self.squelch.append(squelch) self.digital_mpsk_receiver_cc.append(mpsk) self.diff_phasor.append(diff_phasor) self.complex_to_arg.append(complex_to_arg) self.multiply_const.append(multiply_const) self.add_const.append(add_const) self.float_to_uchar.append(float_to_uchar) self.map_bits.append(map_bits) self.unpack_k_bits.append(unpack_k_bits) self.blocks_sink.append(sink) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) ################################################## # signal strenght identification ################################################## self.pwr_probes = [] for ch in range(self.channels): pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./self.srate_channel) self.pwr_probes.append(pwr_probe) self.connect((self.channelizer, ch), (pwr_probe, 0)) def _sig_det_probe(): while True: pwr = [self.pwr_probes[ch].level() for ch in range(self.channels) if ch in self.sig_det_channels] pwr = [10 * math.log10(p) for p in pwr if p > 0.] if not pwr: continue pwr = min(pwr) + self.sig_det_threshold print "power threshold target %f"%pwr if abs(pwr - self.last_pwr) > (self.sig_det_threshold / 2): for s in self.squelch: s.set_threshold(pwr) self.last_pwr = pwr time.sleep(self.sig_det_period) if self.sig_det_threshold is not None: self._sig_det_probe_thread = threading.Thread(target=_sig_det_probe) self._sig_det_probe_thread.daemon = True self._sig_det_probe_thread.start() ################################################## # AFC blocks and connections ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex, num_inputs=self.channels, num_outputs=1, input_index=0, output_index=0, ) self.afc_demod = analog.quadrature_demod_cf(self.srate_channel/(2*math.pi)) samp_afc = self.srate_channel*self.afc_period / 2 self.afc_avg = blocks.moving_average_ff(samp_afc, 1./samp_afc*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(self.afc_period) if self.afc_channel == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_step: continue freq = self.freq_xlating.center_freq + err * self.afc_gain print "err: %f\tfreq: %f" % (err, freq, ) self.freq_xlating.set_center_freq(freq) self.afc_channel = 23 self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch in range(self.channels): self.connect((self.channelizer, ch), (self.afc_selector, ch)) self.connect( (self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) if self.afc_channel != -1: self.afc_selector.set_input_index(self.afc_channel)
def __init__(self): gr.top_block.__init__(self, "Spectrum") Qt.QWidget.__init__(self) self.setWindowTitle("Spectrum") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "spectrum") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.function_3 = function_3 = 0 self.function_2 = function_2 = 0 self.function_1 = function_1 = 0 self.variable_qtgui_label_0_1 = variable_qtgui_label_0_1 = function_3 self.variable_qtgui_label_0_0 = variable_qtgui_label_0_0 = function_1 self.variable_qtgui_label_0 = variable_qtgui_label_0 = function_2 self.samp_rate = samp_rate = 1e6 self.frequency_rx = frequency_rx = 476.0e6 ################################################## # Blocks ################################################## self.probe_signal_2 = blocks.probe_signal_f() self.probe_signal_1 = blocks.probe_signal_f() self.avg_mag_sqrd = analog.probe_avg_mag_sqrd_c(0, 1) self._variable_qtgui_label_0_1_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_1_formatter = None else: self._variable_qtgui_label_0_1_formatter = lambda x: x self._variable_qtgui_label_0_1_tool_bar.addWidget( Qt.QLabel("variable_qtgui_label_0_1" + ": ")) self._variable_qtgui_label_0_1_label = Qt.QLabel( str( self._variable_qtgui_label_0_1_formatter( self.variable_qtgui_label_0_1))) self._variable_qtgui_label_0_1_tool_bar.addWidget( self._variable_qtgui_label_0_1_label) self.top_layout.addWidget(self._variable_qtgui_label_0_1_tool_bar) self._variable_qtgui_label_0_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_0_formatter = None else: self._variable_qtgui_label_0_0_formatter = lambda x: x self._variable_qtgui_label_0_0_tool_bar.addWidget( Qt.QLabel("variable_qtgui_label_0_0" + ": ")) self._variable_qtgui_label_0_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_0_formatter( self.variable_qtgui_label_0_0))) self._variable_qtgui_label_0_0_tool_bar.addWidget( self._variable_qtgui_label_0_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_0_tool_bar) self._variable_qtgui_label_0_tool_bar = Qt.QToolBar(self) if None: self._variable_qtgui_label_0_formatter = None else: self._variable_qtgui_label_0_formatter = lambda x: x self._variable_qtgui_label_0_tool_bar.addWidget( Qt.QLabel("variable_qtgui_label_0" + ": ")) self._variable_qtgui_label_0_label = Qt.QLabel( str( self._variable_qtgui_label_0_formatter( self.variable_qtgui_label_0))) self._variable_qtgui_label_0_tool_bar.addWidget( self._variable_qtgui_label_0_label) self.top_layout.addWidget(self._variable_qtgui_label_0_tool_bar) self.single_pole_iir_filter_xx_0 = filter.single_pole_iir_filter_ff( 0.05, 1) self.qtgui_number_sink_0_0 = qtgui.number_sink(gr.sizeof_float, 0, qtgui.NUM_GRAPH_VERT, 1) self.qtgui_number_sink_0_0.set_update_time(0.10) self.qtgui_number_sink_0_0.set_title("Power") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0_0.set_min(i, -20) self.qtgui_number_sink_0_0.set_max(i, 2) self.qtgui_number_sink_0_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0_0.set_label(i, labels[i]) self.qtgui_number_sink_0_0.set_unit(i, units[i]) self.qtgui_number_sink_0_0.set_factor(i, factor[i]) self.qtgui_number_sink_0_0.enable_autoscale(False) self._qtgui_number_sink_0_0_win = sip.wrapinstance( self.qtgui_number_sink_0_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_0_win) self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 0.10, qtgui.NUM_GRAPH_VERT, 1) self.qtgui_number_sink_0.set_update_time(0.10) self.qtgui_number_sink_0.set_title("Power") labels = ["", "", "", "", "", "", "", "", "", ""] units = ["", "", "", "", "", "", "", "", "", ""] colors = [("blue", "red"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")] factor = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] for i in xrange(1): self.qtgui_number_sink_0.set_min(i, 0) self.qtgui_number_sink_0.set_max(i, 2) self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1]) if len(labels[i]) == 0: self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i)) else: self.qtgui_number_sink_0.set_label(i, labels[i]) self.qtgui_number_sink_0.set_unit(i, units[i]) self.qtgui_number_sink_0.set_factor(i, factor[i]) self.qtgui_number_sink_0.enable_autoscale(False) self._qtgui_number_sink_0_win = sip.wrapinstance( self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_number_sink_0_win) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype frequency_rx, #fc samp_rate, #bw "", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if complex == type(float()): self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.osmosdr_source = osmosdr.source(args="numchan=" + str(1) + " " + "bladerf=0") self.osmosdr_source.set_sample_rate(samp_rate) self.osmosdr_source.set_center_freq(frequency_rx, 0) self.osmosdr_source.set_freq_corr(0, 0) self.osmosdr_source.set_dc_offset_mode(0, 0) self.osmosdr_source.set_iq_balance_mode(2, 0) self.osmosdr_source.set_gain_mode(False, 0) self.osmosdr_source.set_gain(3, 0) self.osmosdr_source.set_if_gain(0, 0) self.osmosdr_source.set_bb_gain(20, 0) self.osmosdr_source.set_antenna("", 0) self.osmosdr_source.set_bandwidth(6e6, 0) self.nlog10_ff = blocks.nlog10_ff(10, 1, 0) def _function_3_probe(): while True: val = self.probe_signal_2.level() try: self.set_function_3(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_3_thread = threading.Thread(target=_function_3_probe) _function_3_thread.daemon = True _function_3_thread.start() def _function_2_probe(): while True: val = self.avg_mag_sqrd.level() try: self.set_function_2(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_2_thread = threading.Thread(target=_function_2_probe) _function_2_thread.daemon = True _function_2_thread.start() def _function_1_probe(): while True: val = self.probe_signal_1.level() try: self.set_function_1(val) except AttributeError: pass time.sleep(1.0 / (10)) _function_1_thread = threading.Thread(target=_function_1_probe) _function_1_thread.daemon = True _function_1_thread.start() self.blocks_keep_one_in_n = blocks.keep_one_in_n( gr.sizeof_float * 1, int(samp_rate / 30)) self.blocks_complex_to_mag_squared_0_0_0 = blocks.complex_to_mag_squared( 1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) ################################################## # Connections ################################################## self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.probe_signal_1, 0)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_number_sink_0, 0)) self.connect((self.blocks_complex_to_mag_squared_0_0_0, 0), (self.single_pole_iir_filter_xx_0, 0)) self.connect((self.blocks_keep_one_in_n, 0), (self.nlog10_ff, 0)) self.connect((self.nlog10_ff, 0), (self.probe_signal_2, 0)) self.connect((self.nlog10_ff, 0), (self.qtgui_number_sink_0_0, 0)) self.connect((self.osmosdr_source, 0), (self.avg_mag_sqrd, 0)) self.connect((self.osmosdr_source, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self.osmosdr_source, 0), (self.blocks_complex_to_mag_squared_0_0_0, 0)) self.connect((self.osmosdr_source, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.single_pole_iir_filter_xx_0, 0), (self.blocks_keep_one_in_n, 0))
def __init__(self, freq=394e6, gain=0, sample_rate=2400000, args="", channel_bw=12500, listen_port=60100, ppm=0, output="channel%d.bits", output_offset=None, auto_tune=-1): gr.top_block.__init__(self, "TETRAPOL multichannel reciever") ################################################## # Parameters and variables ################################################## self.freq = freq self.gain = gain self.sample_rate = sample_rate self.args = args self.channel_bw = channel_bw self.listen_port = listen_port self.ppm = ppm self.output = output self.auto_tune = auto_tune # TODO: parametrize self.debug = True self.channels = channels = int(sample_rate/channel_bw) channel_symb_rate = 8000 samples_per_symbol = 2 self.channel_samp_rate = channel_samp_rate = \ channel_symb_rate * samples_per_symbol afc_period = 6 self.afc_gain = 1 self.afc_ppm_threshold = 100 if output_offset is None: self.output_offset = 0 else: self.output_offset = output_offset - ((channels - 1) // 2) ################################################## # Blocks - RPC server ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", listen_port), allow_none=True) self.xmlrpc_server_0.register_instance(self) threading.Thread(target=self.xmlrpc_server_0.serve_forever).start() ################################################## # Blocks - RX, demod, sink ################################################## self.src = osmosdr.source( args="numchan=" + str(1) + " " + "" + self.args ) self.src.set_sample_rate(sample_rate) self.src.set_center_freq(freq, 0) self.src.set_freq_corr(ppm, 0) # TODO: manual gain control self.src.set_gain_mode(True, 0) #self.src.set_gain(gain, 0) self.freq_xlating = freq_xlating_fft_filter_ccc(1, (1, ), 0, sample_rate) bw = (9200 + self.afc_ppm_threshold)/2 self.channelizer = pfb.channelizer_ccf( channels, firdes.low_pass(1, sample_rate, bw, bw*0.15, firdes.WIN_HANN), float(channel_samp_rate)/(sample_rate/channels), 100) self.connect( (self.src, 0), (self.freq_xlating, 0), (self.channelizer, 0)) self.valves = [] self.gmsk_demods = [] self.file_sinks = [] even_no_of_chs = not (channels % 2) center_ch = channels // 2 for ch_in in range(0, channels): ch_out = (ch_in + center_ch + 1) % channels if ch_out == center_ch and even_no_of_chs: null_sink = blocks.null_sink(gr.sizeof_gr_complex) self.connect( (self.channelizer, ch_out), (null_sink, 0)) continue valve = grc_blks2.valve(item_size=gr.sizeof_gr_complex, open=True) gmsk_demod = digital.gmsk_demod( samples_per_symbol=samples_per_symbol, gain_mu=0.050, mu=0.5, omega_relative_limit=0.005, freq_error=0.0, verbose=False, log=False, ) o = output % (ch_in + self.output_offset) file_sink = blocks.file_sink(gr.sizeof_char, o, False) file_sink.set_unbuffered(True) self.connect( (self.channelizer, ch_out), (valve, 0), (gmsk_demod, 0), (file_sink, 0)) self.valves.append(valve) self.gmsk_demods.append(gmsk_demod) self.file_sinks.append(file_sink) ################################################## # Blocks - automatic fine tune ################################################## self.afc_selector = grc_blks2.selector( item_size=gr.sizeof_gr_complex*1, num_inputs=channels - even_no_of_chs, num_outputs=1, input_index=0, output_index=0, ) if auto_tune != -1: self.afc_selector.set_input_index(auto_tune) self.afc_demod = analog.quadrature_demod_cf(channel_samp_rate/(2*math.pi)) afc_samp = channel_samp_rate * afc_period / 2 self.afc_avg = blocks.moving_average_ff(afc_samp, 1./afc_samp*self.afc_gain) self.afc_probe = blocks.probe_signal_f() def _afc_probe(): while True: time.sleep(afc_period) if self.auto_tune == -1: continue err = self.afc_probe.level() if abs(err) < self.afc_ppm_threshold: continue freq = self.freq_xlating.center_freq + err * self.afc_gain if self.debug: print "freq err: % .0f\tfreq: %f" % (err, freq) self.freq_xlating.set_center_freq(freq) self._afc_err_thread = threading.Thread(target=_afc_probe) self._afc_err_thread.daemon = True self._afc_err_thread.start() for ch_in in range(0, channels - even_no_of_chs): ch_out = (ch_in + center_ch + 1) % channels self.connect((self.channelizer, ch_out), (self.afc_selector, ch_in)) self.connect((self.afc_selector, 0), (self.afc_demod, 0), (self.afc_avg, 0), (self.afc_probe, 0)) ################################################## # Blocks - signal strenght indication ################################################## self.pwr_probes = [] for ch in range(self.channels - even_no_of_chs): ch = (ch + center_ch + 1) % channels pwr_probe = analog.probe_avg_mag_sqrd_c(0, 1./channel_samp_rate) self.connect((self.channelizer, ch), (pwr_probe, 0)) self.pwr_probes.append(pwr_probe)