def __init__(self, samp_rate, carrier, TxGain, RealFileName, ImaginaryFileName,NumSeconds): gr.top_block.__init__(self, "TransmitModulationData") ################################################## # Variables ################################################## self.samp_rate = samp_rate #= 1250000 self.carrier = carrier #= 990000000 self.TxGain = TxGain #= 30 self.RxGain = RxGain = 0 #ImaginaryFileName = sys.argv[2] #RealFileName = sys.argv[1] print('Real File Name is ', RealFileName) print('Imaginary File Name is ', ImaginaryFileName) self.NumSeconds = NumSeconds ################################################## # Blocks ################################################## self.uhd_usrp_sink_0 = uhd.usrp_sink( ",".join(("addr=192.168.10.2", "")), uhd.stream_args( cpu_format="fc32", channels=range(4), ), ) self.uhd_usrp_sink_0.set_samp_rate(samp_rate) self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_sink_0.set_center_freq(carrier, 0) self.uhd_usrp_sink_0.set_gain(TxGain, 0) self.uhd_usrp_sink_0.set_antenna('TX/RX', 0) self.uhd_usrp_sink_0.set_center_freq(carrier, 1) self.uhd_usrp_sink_0.set_gain(TxGain, 1) self.uhd_usrp_sink_0.set_antenna('TX/RX', 1) self.uhd_usrp_sink_0.set_center_freq(carrier, 2) self.uhd_usrp_sink_0.set_gain(TxGain, 2) self.uhd_usrp_sink_0.set_antenna('TX/RX', 2) self.uhd_usrp_sink_0.set_center_freq(carrier, 3) self.uhd_usrp_sink_0.set_gain(TxGain, 3) self.uhd_usrp_sink_0.set_antenna('TX/RX', 3) self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex*1, NumSeconds*samp_rate) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_file_source_0_0 = blocks.file_source(gr.sizeof_float*1, ImaginaryFileName, True) self.blocks_file_source_0_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_float*1, RealFileName, True) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.blocks_null_source_0_1 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_source_0_0 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1) ################################################## # Connections ################################################## self.connect((self.blocks_file_source_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_file_source_0_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_head_0, 0)) self.connect((self.blocks_head_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.blocks_null_source_0_1, 0), (self.uhd_usrp_sink_0, 1)) self.connect((self.blocks_null_source_0_0, 0), (self.uhd_usrp_sink_0, 2)) self.connect((self.blocks_null_source_0, 0), (self.uhd_usrp_sink_0, 3))
def __init__(self): gr.top_block.__init__(self, "Channel Measurement") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 1e6 self.cent_freq = cent_freq = 2600e6 ################################################## # Blocks ################################################## self.usrp_tx = uhd.usrp_sink( ",".join(("addr=134.147.118.216", "")), uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.usrp_tx.set_subdev_spec("A:0 B:0", 0) self.usrp_tx.set_samp_rate(samp_rate) self.usrp_tx.set_center_freq(cent_freq, 0) self.usrp_tx.set_gain(15, 0) self.usrp_tx.set_antenna("TX/RX", 0) self.usrp_tx.set_center_freq(cent_freq, 1) self.usrp_tx.set_gain(15, 1) self.usrp_tx.set_antenna("TX/RX", 1) self.usrp_rx = uhd.usrp_source( ",".join(("addr=134.147.118.217", "")), uhd.stream_args( cpu_format="fc32", channels=range(2), ), ) self.usrp_rx.set_subdev_spec("A:0 B:0", 0) self.usrp_rx.set_samp_rate(samp_rate) self.usrp_rx.set_center_freq(cent_freq, 0) self.usrp_rx.set_gain(15, 0) self.usrp_rx.set_antenna("TX/RX", 0) self.usrp_rx.set_center_freq(cent_freq, 1) self.usrp_rx.set_gain(15, 1) self.usrp_rx.set_antenna("TX/RX", 1) self.blocks_null_source_1 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1) self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_gr_complex*1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.usrp_tx, 0)) self.connect((self.blocks_null_source_1, 0), (self.usrp_tx, 1)) self.connect((self.usrp_rx, 0), (self.blocks_null_sink_0, 0)) self.connect((self.usrp_rx, 1), (self.blocks_null_sink_1, 0))
def __init__(self, beta=0): gr.hier_block2.__init__( self, "Third Order Distortion", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), ) ################################################## # Parameters ################################################## self.beta = beta ################################################## # Blocks ################################################## self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float*1) self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((beta, )) self.blocks_float_to_complex_0 = blocks.float_to_complex(1) self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1) self.blocks_add_xx_0 = blocks.add_vcc(1) ################################################## # Connections ################################################## self.connect((self.blocks_float_to_complex_0, 0), (self.blocks_multiply_xx_0, 1)) self.connect((self.blocks_null_source_0, 0), (self.blocks_float_to_complex_0, 1)) self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_float_to_complex_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self, 0), (self.blocks_complex_to_mag_squared_0, 0)) self.connect((self, 0), (self.blocks_multiply_xx_0, 0)) self.connect((self, 0), (self.blocks_add_xx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self, 0))
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = blocks.null_source(gr.sizeof_float*1) f2c = blocks.float_to_complex(1) mls_correlator = channelsounder.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = blocks.head(gr.sizeof_gr_complex, 2*self.length) dest = blocks.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def test_004( self ): # insert tags and check their propagation, non-zero offset, multiple tags per copy region period = 11000 offset = 1000 packetlen = 2000 insert = [ 1.0, ] * 1000 src = blocks.null_source(gr.sizeof_float) s2ts = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, packetlen, "packet") head = blocks.head(gr.sizeof_float, 1000000) ins = blocks.vector_insert_f(insert, period, offset) dst = blocks.vector_sink_f() self.tb.connect(src, s2ts, head, ins, dst) self.tb.run() expected_result = (0, 2000, 4000, 6000, 8000, 11000, 13000, 15000, 17000, 19000, 22000, 24000, 26000) tags = dst.tags() offsets = [tag.offset for tag in tags] for i in range(len(expected_result)): self.assertTrue(expected_result[i] == offsets[i])
def __init__(self): grc_wxgui.top_block_gui.__init__(self, title="Top Block") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32e3 ################################################## # Blocks ################################################## self.blocks_vector_source_x_0 = blocks.vector_source_i((0, 1, 2, 3), True, 1, []) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_float * 1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float * 1) self.blocks_int_to_float_0 = blocks.int_to_float(1, 1) self.Mercurial_SDR_0 = Mercurial_SDR.Mercurial_SDR( 'psk', 'qpsk', 468000, 32000, 'natural_key', 'linear_key', 50, 8, 'pll_120', 'pll_120', 'pll_120', 'pll_60', 5000000, 50000, 50000) ################################################## # Connections ################################################## self.connect((self.Mercurial_SDR_0, 0), (self.blocks_null_sink_0, 0)) self.connect((self.blocks_int_to_float_0, 0), (self.Mercurial_SDR_0, 0)) self.connect((self.blocks_null_source_0, 0), (self.Mercurial_SDR_0, 1)) self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_int_to_float_0, 0))
def __init__(self): gr.top_block.__init__(self, "Nullsource To Osmocom Sink") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 10e6 self.center_freq = center_freq = 910e6 ################################################## # Blocks ################################################## self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + 'driver=lime' ) self.osmosdr_sink_0.set_sample_rate(samp_rate) self.osmosdr_sink_0.set_center_freq(center_freq, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(35, 0) self.osmosdr_sink_0.set_if_gain(0, 0) self.osmosdr_sink_0.set_bb_gain(0, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.osmosdr_sink_0, 0))
def make(self, kind='IQ'): signal_type = SignalType(kind=kind, sample_rate=1000) m = MonitorSink( context=self.context, signal_type=signal_type) self.tb.connect(blocks.null_source(signal_type.get_itemsize()), m) return m
def __init__(self, item_size, num_outputs, default_output): """ Selector constructor. Args: item_size: the size of the gr data stream in bytes num_inputs: the number of inputs (integer) num_outputs: the number of outputs (integer) input_index: the index for the source data output_index: the index for the destination data """ gr.hier_block2.__init__( self, 'selector', gr.io_signature(1, 1, item_size), gr.io_signature(num_outputs, num_outputs, item_size), ) num_inputs = 1 # Terminator blocks for unused inputs and outputs self.input_terminators = [blocks.null_sink(item_size) for i in range(num_inputs)] self.output_terminators = [blocks.head(item_size, 0) for i in range(num_outputs)] self.copy = blocks.copy(item_size) # Connections for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) for i in range(num_outputs): self.connect(blocks.null_source(item_size), self.output_terminators[i], (self, i)) # Set parameters self.num_outputs = num_outputs self.input_index = 0 self.output_index = default_output # Register the message port self.message_port_register_hier_in("selection") self.mb = message_receiver(self); # Connect message port self.msg_connect(self, "selection", self.mb,"selection") # Connect default self._connect_current()
def create_diamond(self): src = blocks.null_source(gr.sizeof_float) head = blocks.head(gr.sizeof_float, self.samples) self.connect(src, head) ends = [] for pipe in range(self.pipes): block = filter.fir_filter_fff(1, self.taps) self.connect(head, block) self.fir_blocks.append(block) for stage in range(1, self.stages): block = filter.fir_filter_fff(1, self.taps) self.connect(self.fir_blocks[-1], block) self.fir_blocks.append(block) ends.append(block) interleave = blocks.interleave(gr.sizeof_float, 1) for i, b in enumerate(ends): self.connect((b, 0), (interleave, i)) sink = blocks.null_sink(gr.sizeof_float) self.connect(interleave, sink)
def __init__(self, options): gr.top_block.__init__(self) if(options.rx_freq is not None): if options.rx_ant == 1: self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.time_source,options.verbose) else: self.source = uhd_mimo_receiver(options.args, options.bandwidth, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.time_source, options.verbose) elif(options.from_file is not None): self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) if (options.rx_ant == 1): self._setup_rx_path(options) self._setup_rpc_manager() self.dst = (self.rxpath,0) self.connect((self.source,0), self.dst) else: self._setup_rx_path(options) self._setup_rpc_manager() self.dst = (self.rxpath,0) self.dst2 = (self.rxpath,1) self.connect((self.source,0), self.dst) self.connect((self.source,1), self.dst2)
def __init__(self, callback, options): gr.top_block.__init__(self) self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "bladerf=1" ) self.osmosdr_source_0.set_sample_rate(5e6) self.osmosdr_source_0.set_center_freq(2.412e9, 0) self.osmosdr_source_0.set_freq_corr(10, 0) self.osmosdr_source_0.set_dc_offset_mode(1, 0) self.osmosdr_source_0.set_iq_balance_mode(1, 0) self.osmosdr_source_0.set_gain_mode(True, 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("", 0) self.osmosdr_source_0.set_bandwidth(5e6, 0) if(options.from_file is not None): self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.connect(self.osmosdr_source_0, self.rxpath)
def test_34b_lock_unlock(self): hblock = gr.top_block("test_block") src = blocks.null_source(gr.sizeof_float) throttle = blocks.throttle(gr.sizeof_float, 32000) sink = blocks.null_sink(gr.sizeof_float) hblock.connect(src, throttle, sink) hblock.set_processor_affinity([ 0, ]) def thread_01(hblock, cls): cls.test_34b_val = 10 hblock.lock() cls.test_34b_val = 20 hblock.unlock() cls.test_34b_val = 30 time.sleep(0.5) cls.test_34b_val = 40 hblock.stop() hblock.start() self.test_34b_val = 0 t1 = threading.Thread(target=thread_01, args=( hblock, self, )) t1.start() hblock.wait() self.assertEqual(40, self.test_34b_val)
def test_smoke(self): m = MonitorSink(context=self.context, signal_type=SignalType(kind='IQ', sample_rate=1000)) self.tb.connect(blocks.null_source(gr.sizeof_gr_complex), m) self.tb.start() self.tb.stop() self.tb.wait()
def __init__(self, callback, options): gr.top_block.__init__(self) self.samp_rate = samp_rate = 1000000 self.band_width = band_width = 20000000 if (options.rx_freq is not None): self.source = iio.pluto_source('192.168.2.1', options.rx_freq, samp_rate, long(options.bandwidth), 0x8000, True, True, True, "slow_attack", 64.0, '', True) #self.source = uhd_receiver(options.args, # options.bandwidth, options.rx_freq, # options.lo_offset, options.rx_gain, # options.spec, options.antenna, # options.clock_source, options.verbose) elif (options.from_file is not None): self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.connect(self.source, self.rxpath)
def __init__(self, callback, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.lo_offset, options.tx_gain, options.spec, options.antenna, options.clock_source, options.verbose) # elif(options.to_file is not None): # self.sink = blocks.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = blocks.null_sink(gr.sizeof_gr_complex) if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.verbose) # elif(options.from_file is not None): # self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.txpath = transmit_path(options) self.connect(self.source, self.rxpath) self.connect(self.txpath, self.sink)
def __init__(self, N, op, isizeof=gr.sizeof_gr_complex, osizeof=gr.sizeof_gr_complex, nsrcs=1, nsnks=1): gr.top_block.__init__(self, "helper") self.op = op self.srcs = [] self.snks = [] self.head = blocks.head(isizeof, N) for n in xrange(nsrcs): self.srcs.append(blocks.null_source(isizeof)) for n in xrange(nsnks): self.snks.append(blocks.null_sink(osizeof)) self.connect(self.srcs[0], self.head, (self.op, 0)) for n in xrange(1, nsrcs): self.connect(self.srcs[n], (self.op, n)) for n in xrange(nsnks): self.connect((self.op, n), self.snks[n])
def __init__(self): gr.top_block.__init__(self, "Affinity Set Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## vec_len = 1 self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*vec_len, samp_rate) self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*vec_len) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*vec_len) self.filter_filt_0 = filter.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.filter_filt_1 = filter.fir_filter_ccc(1, 40000*[0.2+0.3j,]) self.filter_filt_0.set_processor_affinity([0,]) self.filter_filt_1.set_processor_affinity([0,1]) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.filter_filt_0, 0)) self.connect((self.filter_filt_0, 0), (self.filter_filt_1, 0)) self.connect((self.filter_filt_1, 0), (self.blocks_null_sink_0, 0))
def test_001_t (self): self.degree = 5 self.length = 2**self.degree - 1 expected_result = (self.length - 1)*[-1.0/self.length]+[1] # send a maximum length sequence with period 31 src_real = digital.glfsr_source_f(self.degree, True, 0, 1) src_imag = blocks.null_source(gr.sizeof_float*1) f2c = blocks.float_to_complex(1) mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask = 0, seed = 1) # keep only the samples of the first two autocorrelation periods head = blocks.head(gr.sizeof_gr_complex, 2*self.length) dest = blocks.vector_sink_c(1) self.tb.connect( src_real, (f2c, 0)) self.tb.connect( src_imag, (f2c, 1)) self.tb.connect( f2c, mls_correlator ) self.tb.connect( mls_correlator, head, dest ) # set up fg self.tb.run () # check data result_data = dest.data() # discard the first period, since it is tainted by the zeros inserted # by set_history() result_data = result_data[self.length:] self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
def run_fir_filters_fff(self): self.blocks = [] self.tb = gr.top_block() self.blocks.append(blocks.null_source(gr.sizeof_float)) self.blocks.append(blocks.head(gr.sizeof_float, self.N)) # First filter is much larger than others taps = numpy.random.random(self.mult * self.ntaps) self.blocks.append(filter.fir_filter_fff(1, taps)) self.blocks[0].set_processor_affinity([ 0, ]) # Set up rest of mfirs filters with new taps for each filter for m in xrange(1, self.mfirs): taps = numpy.random.random(self.ntaps) self.blocks.append(filter.fir_filter_fff(1, taps)) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) # Add a null sink self.blocks.append(blocks.null_sink(gr.sizeof_float)) # Connect the blocks and run self.tb.connect(*self.blocks) self.tb.run()
def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index): """ Selector constructor. Args: item_size: the size of the gr data stream in bytes num_inputs: the number of inputs (integer) num_outputs: the number of outputs (integer) input_index: the index for the source data output_index: the index for the destination data """ gr.hier_block2.__init__( self, 'selector', gr.io_signature(num_inputs, num_inputs, item_size), gr.io_signature(num_outputs, num_outputs, item_size), ) #terminator blocks for unused inputs and outputs self.input_terminators = [blocks.null_sink(item_size) for i in range(num_inputs)] self.output_terminators = [blocks.head(item_size, 0) for i in range(num_outputs)] self.copy = blocks.copy(item_size) #connections for i in range(num_inputs): self.connect((self, i), self.input_terminators[i]) for i in range(num_outputs): self.connect(blocks.null_source(item_size), self.output_terminators[i], (self, i)) self.item_size = item_size self.input_index = input_index self.output_index = output_index self.num_inputs = num_inputs self.num_outputs = num_outputs self._connect_current()
def __init__(self, samp_rate=16E3, name="unnamed", save_dir=None, postscript=None): gr.hier_block2.__init__(self, "Recorder", gr.io_signature(1, 1, gr.sizeof_float), gr.io_signature(1, 1, gr.sizeof_float)) self.timeout = 18000 self.save_dir = save_dir self.postscript = postscript self.record_squelch = analog.pwr_squelch_ff(-200, 0.1, 0, True) self.blocks_wavfile_sink = blocks.wavfile_sink("/dev/null", 1, samp_rate, 16) self.blocks_null_source = blocks.null_source(gr.sizeof_float * 1) self.connect(self, (self.record_squelch, 0)) self.connect((self.record_squelch, 0), (self.blocks_wavfile_sink, 0)) self.connect((self.blocks_null_source, 0), self) thread = threading.Thread(target=self.timer_thread, args=(name, self.save_dir, self.blocks_wavfile_sink, \ self.record_squelch, self.postscript, self.timeout)) thread.daemon = True thread.start()
def test_null_source_real(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, probe) return top, probe
def __init__(self, demod_class, rx_callback, options): gr.top_block.__init__(self) self.rxpath = receive_path(demod_class, rx_callback, options) self.audio_tx = audio_tx(options.audio_output) if(options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bitrate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps audio_rate = self.audio_tx.sample_rate usrp_rate = self.source.get_sample_rate() rrate = audio_rate / usrp_rate self.resampler = filter.pfb.arb_resampler_ccf(rrate) self.connect(self.source, self.resampler, self.rxpath) elif(options.from_file is not None): self.thr = blocks.throttle(gr.sizeof_gr_complex, options.bitrate) self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) self.connect(self.source, self.thr, self.rxpath) else: self.thr = blocks.throttle(gr.sizeof_gr_complex, 1e6) self.source = blocks.null_source(gr.sizeof_gr_complex) self.connect(self.source, self.thr, self.rxpath) self.connect(self.audio_tx)
def test_null_source_complex(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, probe) return top, probe
def __init__(self, demodulator, rx_callback, options): gr.top_block.__init__(self) if (options.rx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = demodulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / demodulator( **args).bits_per_symbol() self.source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.verbose) options.samples_per_symbol = self.source._sps elif (options.from_file is not None): sys.stderr.write( ("Reading samples from '%s'.\n\n" % (options.from_file))) self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: sys.stderr.write( "No source defined, pulling samples from null source.\n\n") self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(demodulator, rx_callback, options) self.connect(self.source, self.rxpath) print >> sys.stderr, options
def __init__(self): gr.top_block.__init__(self) default_nsamples = 10e6 parser = ArgumentParser() parser.add_argument("-p", "--npipelines", type=intx, default=1, metavar="NPIPES", help="the number of pipelines to create (default=%(default)s)") parser.add_argument("-s", "--nstages", type=intx, default=1, metavar="NSTAGES", help="the number of stages in each pipeline (default=%(default)s)") parser.add_argument("-N", "--nsamples", type=eng_float, default=default_nsamples, help=("the number of samples to run through the graph (default=%s)" % (eng_notation.num_to_str(default_nsamples)))) parser.add_argument("-m", "--machine-readable", action="store_true", default=False, help="enable machine readable output") args = parser.parse_args() self.npipes = args.npipelines self.nstages = args.nstages self.nsamples = args.nsamples self.machine_readable = args.machine_readable ntaps = 256 # Something vaguely like floating point ops self.flop = 2 * ntaps * args.npipelines * args.nstages * args.nsamples src = blocks.null_source(gr.sizeof_float) head = blocks.head(gr.sizeof_float, int(args.nsamples)) self.connect(src, head) for n in range(args.npipelines): self.connect(head, pipeline(args.nstages, ntaps))
def __init__(self, demod_class, rx_callback, options): gr.top_block.__init__(self) self.rxpath = receive_path(demod_class, rx_callback, options) self.audio_tx = audio_tx(options.audio_output) if (options.rx_freq is not None): self.source = uhd_receiver(options.args, options.bitrate, options.samples_per_symbol, options.rx_freq, options.rx_gain, options.antenna, options.verbose) options.samples_per_symbol = self.source._sps audio_rate = self.audio_tx.sample_rate usrp_rate = self.source.get_sample_rate() rrate = audio_rate / usrp_rate self.resampler = filter.pfb.arb_resampler_ccf(rrate) self.connect(self.source, self.resampler, self.rxpath) elif (options.from_file is not None): self.thr = blocks.throttle(gr.sizeof_gr_complex, options.bitrate) self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) self.connect(self.source, self.thr, self.rxpath) else: self.thr = blocks.throttle(gr.sizeof_gr_complex, 1e6) self.source = blocks.null_source(gr.sizeof_gr_complex) self.connect(self.source, self.thr, self.rxpath) self.connect(self.audio_tx)
def __init__(self): gr.top_block.__init__(self, "Affinity Set Test") ################################################## # Variables ################################################## self.samp_rate = samp_rate = 32000 ################################################## # Blocks ################################################## vec_len = 1 self.blocks_throttle_0 = blocks.throttle( gr.sizeof_gr_complex * vec_len, samp_rate) self.blocks_null_source_0 = blocks.null_source( gr.sizeof_gr_complex * vec_len) self.blocks_null_sink_0 = blocks.null_sink( gr.sizeof_gr_complex * vec_len) self.filter_filt_0 = filter.fir_filter_ccc(1, 40000 * [0.2 + 0.3j, ]) self.filter_filt_1 = filter.fir_filter_ccc(1, 40000 * [0.2 + 0.3j, ]) self.filter_filt_0.set_processor_affinity([0, ]) self.filter_filt_1.set_processor_affinity([0, 1]) ################################################## # Connections ################################################## self.connect((self.blocks_null_source_0, 0), (self.blocks_throttle_0, 0)) self.connect((self.blocks_throttle_0, 0), (self.filter_filt_0, 0)) self.connect((self.filter_filt_0, 0), (self.filter_filt_1, 0)) self.connect((self.filter_filt_1, 0), (self.blocks_null_sink_0, 0))
def XX_test_002_tag_immediately(self): # tune message tune = pmt.dict_add(pmt.make_dict(), pmt.intern('freq'), pmt.from_double(100)) # blocks src = blocks.null_source(gr.sizeof_gr_complex * 1) throttle = blocks.throttle(gr.sizeof_gr_complex * 1, 32000, True) retuner = timing_utils.timed_tag_retuner(1e6, pmt.intern("freq"), 1, 0.1) debug = sandia_utils.sandia_tag_debug(gr.sizeof_gr_complex * 1, '', "", True) emitter = pdu_utils.message_emitter() debug.set_display(True) self.tb.connect(src, throttle) self.tb.connect(throttle, retuner) self.tb.connect(retuner, debug) self.tb.msg_connect((emitter, 'msg'), (retuner, 'command')) self.tb.start() time.sleep(.1) emitter.emit(tune) time.sleep(.1) self.tb.stop() # assert self.assertEqual(debug.num_tags(), 1) tag = debug.get_tag(0) self.assertTrue(pmt.equal(tag.key, pmt.intern('set_freq'))) freq = pmt.to_double(tag.value) self.assertAlmostEqual(-100, freq)
def __init__(self, callback, options): gr.top_block.__init__(self) if (options.freq is not None): self.source = uhd_receiver(options.args, options.bandwidth, options.freq, options.lo_offset, options.gain, options.spec, options.antenna, options.clock_source, options.verbose) elif (options.from_file is not None): self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(callback, options) self.connect(self.source, self.rxpath) # rpc server to receive remote commands self.xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer( ("localhost", options.rpc_port), allow_none=True) self.xmlrpc_server.register_instance(self) threading.Thread(target=self.xmlrpc_server.serve_forever).start()
def run_fir_filters_fff(self): self.blocks = [] self.tb = gr.top_block() self.blocks.append(blocks.null_source(gr.sizeof_float)) self.blocks.append(blocks.head(gr.sizeof_float, self.N)) # First filter is much larger than others taps = numpy.random.random(self.mult*self.ntaps) self.blocks.append(filter.fir_filter_fff(1, taps)) self.blocks[0].set_processor_affinity([0,]) # Set up rest of mfirs filters with new taps for each filter for m in xrange(1, self.mfirs): taps = numpy.random.random(self.ntaps) self.blocks.append(filter.fir_filter_fff(1, taps)) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) #self.blocks[m].set_processor_affinity([1,]) # Add a null sink self.blocks.append(blocks.null_sink(gr.sizeof_float)) # Connect the blocks and run self.tb.connect(*self.blocks) self.tb.run()
def __init__(self, demodulator, rx_callback, options): gr.top_block.__init__(self) if(options.rx_freq is not None): # Work-around to get the modulation's bits_per_symbol args = demodulator.extract_kwargs_from_options(options) symbol_rate = options.bitrate / demodulator(**args).bits_per_symbol() self.source = uhd_receiver(options.args, symbol_rate, options.samples_per_symbol, options.rx_freq, options.lo_offset, options.rx_gain, options.spec, options.antenna, options.clock_source, options.verbose) options.samples_per_symbol = self.source._sps elif(options.from_file is not None): sys.stderr.write(("Reading samples from '%s'.\n\n" % (options.from_file))) self.source = blocks.file_source(gr.sizeof_gr_complex, options.from_file) else: sys.stderr.write("No source defined, pulling samples from null source.\n\n") self.source = blocks.null_source(gr.sizeof_gr_complex) # Set up receive path # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.rxpath = receive_path(demodulator, rx_callback, options) self.connect(self.source, self.rxpath)
def __init__(self, options): gr.top_block.__init__(self) self.options = options # create a QT application self.qapp = QtGui.QApplication(sys.argv) # give Ctrl+C back to system signal.signal(signal.SIGINT, signal.SIG_DFL) # socket addresses rpc_adr_server = "tcp://localhost:6666" rpc_adr_reply = "tcp://*:6666" probe_adr_gui = "tcp://localhost:5556" probe_adr_fg = "tcp://*:5556" sink_adr = "tcp://*:5555" source_adr = "tcp://localhost:5555" # create the main window self.ui = gui.gui("Loop", rpc_adr_server, rpc_adr_server, probe_adr_gui) self.ui.show() # the strange sampling rate gives a nice movement in the plot :P self.samp_rate = samp_rate = 48200 # blocks self.gr_sig_source = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 1000, 1, 0) self.null_source = blocks.null_source(gr.sizeof_float) self.throttle = blocks.throttle(gr.sizeof_float, samp_rate) self.zmq_source = zmqblocks.source_pushpull_feedback( gr.sizeof_float, source_adr) self.mult_a = blocks.multiply_const_ff(1) self.mult_b = blocks.multiply_const_ff(0.5) self.add = blocks.add_ff(1) #self.zmq_sink = zmqblocks.sink_reqrep_nopoll(gr.sizeof_float, sink_adr) #self.zmq_sink = zmqblocks.sink_reqrep(gr.sizeof_float, sink_adr) self.zmq_sink = zmqblocks.sink_pushpull(gr.sizeof_float, sink_adr) self.zmq_probe = zmqblocks.sink_pushpull(gr.sizeof_float, probe_adr_fg) #self.null_sink = blocks.null_sink(gr.sizeof_float) # connects self.connect(self.gr_sig_source, self.mult_a) self.connect(self.zmq_source, self.mult_b, (self.add, 1)) # self.connect(self.null_source, (self.add,1)) self.connect(self.mult_a, (self.add, 0), self.throttle, self.zmq_sink) self.connect(self.throttle, self.zmq_probe) # ZeroMQ self.rpc_manager = zmqblocks.rpc_manager() self.rpc_manager.set_reply_socket(rpc_adr_reply) self.rpc_manager.add_interface("start_fg", self.start_fg) self.rpc_manager.add_interface("stop_fg", self.stop_fg) self.rpc_manager.add_interface("set_waveform", self.set_waveform) self.rpc_manager.add_interface("set_k", self.mult_a.set_k) self.rpc_manager.add_interface("get_sample_rate", self.throttle.sample_rate) self.rpc_manager.start_watcher()
def test_001(self): # Just running some data through null source/sink src = blocks.null_source(gr.sizeof_float) hed = blocks.head(gr.sizeof_float, 100) dst = blocks.null_sink(gr.sizeof_float) self.tb.connect(src, hed, dst) self.tb.run()
def test_conjugate_cc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) conj = blocks.conjugate_cc() probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, conj, probe) return top, probe
def test_complex_to_imag(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) complextoimag = blocks.complex_to_imag() probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, complextoimag, probe) return top, probe
def test_five_fft_filter(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) filters = [filter.fft_filter_ccf(1, [random.random() for j in range(256)]) for i in range(5)] probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(*([src] + filters + [probe])) return top, probe
def test_abs_ff(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) abs = blocks.abs_ff() probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, abs, probe) return top, probe
def test_fir_filter_fcc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) firfilter = filter.fir_filter_fcc(1, [complex(random.random(), random.random()) for _ in range(256)]) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, firfilter, probe) return top, probe
def test_five_fir_filter(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) filters = [filter.fir_filter_ccf(1, [random.random() for j in range(256)]) for i in range(5)] probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(*([src] + filters + [probe])) return top, probe
def test_delay(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) delay = blocks.delay(gr.sizeof_gr_complex, 3000) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, delay, probe) return top, probe
def test_smoke(self): m = MonitorSink( context=self.context, signal_type=SignalType(kind='IQ', sample_rate=1000)) self.tb.connect(blocks.null_source(gr.sizeof_gr_complex), m) self.tb.start() self.tb.stop() self.tb.wait()
def test_multiply_const_cc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) mul = blocks.multiply_const_cc(complex(random.random(), random.random())) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, mul, probe) return top, probe
def test_multiply_const_ff(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) mul = blocks.multiply_const_ff(random.random()) probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, mul, probe) return top, probe
def test_hilbert(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) hilbert = filter.hilbert_fc(257) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, hilbert, probe) return top, probe
def test_quadrature_demod_cf(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) fdisc = analog.quadrature_demod_cf(5.0) probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, fdisc, probe) return top, probe
def test_fm_deemph(): top = gr.top_block() src = blocks.null_source(gr.sizeof_float) deemph = analog.fm_deemph(30e3, 75e-6) probe = blocks.probe_rate(gr.sizeof_float) top.connect(src, deemph, probe) return top, probe
def test_rotator_cc(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) rotator = blocks.rotator_cc(2*math.pi*(200e3/1e6)) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, rotator, probe) return top, probe
def test_iir_filter_ccf(): top = gr.top_block() src = blocks.null_source(gr.sizeof_gr_complex) iirfilter = filter.iir_filter_ccf([random.random() for _ in range(5)], [random.random() for _ in range(3)]) probe = blocks.probe_rate(gr.sizeof_gr_complex) top.connect(src, iirfilter, probe) return top, probe