def __init__(self, modulator, demodulator, rx_callback, options):
        gr.top_block.__init__(self)
		#parameters to sense channe
        #options.symbol_rate=2500000
        #options.samples_per_symbol=2
        #options.rx_freq=2500000000
        #options.rx_gain=20
        #options.chbw_factor=1
        sense_symbol_rate=2500000
        sense_samples_per_symbol=2
        sense_rx_freq=2500000000
        sense_rx_gain=20
        options.chbw_factor=1
	#options.samples_per_symbol,

 
        #args = demodulator.extract_kwargs_from_options(options)
        self.sensesource=uhd_receiver(options.args, sense_symbol_rate,
                                       sense_samples_per_symbol,
                                       sense_rx_freq, sense_rx_gain,
                                       options.spec, options.antenna,
                                       options.verbose)

        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.tx_gain,
                                        options.spec, options.antenna,
                                        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 = gr.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 = gr.null_sink(gr.sizeof_gr_complex)


        self.txgate = gr.copy(gr.sizeof_gr_complex)
        self.sensegate = gr.copy(gr.sizeof_gr_complex)
        #self.msgq             = gr.msg_queue()

        # 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)

        self.connect(self.txpath, self.txgate, self.sink)

	# do sense
        self.sensepath = sensing_path(options)

        self.tx_enabled = True
	self.sense_flag=False
	self.connect(self.sensesource, self.sensepath)
Beispiel #2
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        #self._tx_freq            = options.tx_freq         # tranmitter's center frequency
        self._tx_gain = options.tx_gain  # transmitter's gain
        self._samp_rate = options.samp_rate  # sample rate for USRP
        #self._rx_freq            = options.rx_freq         # receiver's center frequency
        self._rx_gain = options.rx_gain  # receiver's gain

        #if self._tx_freq is None:
        #    sys.stderr.write("-f FREQ or --freq FREQ or --tx-freq FREQ must be specified\n")
        #    raise SystemExit

        #if self._rx_freq is None:
        #    sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
        #    raise SystemExit

        # Set up USRP sink and source
        self._setup_usrp_sink()
        self._setup_usrp_source()

        self.txpath = transmit_path(options)
        self.rxpath = receive_path(callback, options)
        self.rx_valve = gr.copy(gr.sizeof_gr_complex)

        self.sense = sense_path(self.set_freq, options)

        # Set center frequency of USRP
        ok = self.set_freq(self.sense.channels[0])  #self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (
                eng_notation.num_to_str(self.sense.channels[0]), )
            raise ValueError

        self.sense_valve = gr.copy(gr.sizeof_gr_complex)

        self.rx_valve.set_enabled(True)
        self.sense_valve.set_enabled(False)

        self.connect(self.txpath, self.u_snk)
        self.connect(self.u_src, self.rx_valve, self.rxpath)
        self.connect(self.u_src, self.sense_valve, self.sense)

        if options.verbose:
            self._print_verbage()
        if options.show_rx_gain_range:
            print "RX gain range: ", self.u_src.get_gain_range()
        if options.show_tx_gain_range:
            print "TX gain range: ", self.u_snk.get_gain_range()
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        #self._tx_freq            = options.tx_freq         # tranmitter's center frequency
        self._tx_gain            = options.tx_gain         # transmitter's gain
        self._samp_rate          = options.samp_rate       # sample rate for USRP
        #self._rx_freq            = options.rx_freq         # receiver's center frequency
        self._rx_gain            = options.rx_gain         # receiver's gain

        #if self._tx_freq is None:
        #    sys.stderr.write("-f FREQ or --freq FREQ or --tx-freq FREQ must be specified\n")
        #    raise SystemExit

        #if self._rx_freq is None:
        #    sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
        #    raise SystemExit

        # Set up USRP sink and source
        self._setup_usrp_sink()
        self._setup_usrp_source()

        self.txpath = transmit_path(options)
        self.rxpath = receive_path(callback, options)
        self.rx_valve = gr.copy(gr.sizeof_gr_complex)
                
        self.sense = sense_path(self.set_freq, options)
        
        # Set center frequency of USRP
        ok = self.set_freq(self.sense.channels[0]) #self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(self.sense.channels[0]),)
            raise ValueError
        
        self.sense_valve = gr.copy(gr.sizeof_gr_complex)
        
        self.rx_valve.set_enabled(True)
        self.sense_valve.set_enabled(False)

        self.connect(self.txpath, self.u_snk)
        self.connect(self.u_src, self.rx_valve, self.rxpath)
        self.connect(self.u_src, self.sense_valve, self.sense)
        
        if options.verbose:
            self._print_verbage()
        if options.show_rx_gain_range:
            print "RX gain range: ", self.u_src.get_gain_range()
        if options.show_tx_gain_range:
            print "TX gain range: ", self.u_snk.get_gain_range()
 def test_copy(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = gr.vector_source_b(src_data)
     op = gr.copy(gr.sizeof_char)
     dst = gr.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Beispiel #5
0
 def test_copy (self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     src = gr.vector_source_b(src_data)
     op = gr.copy(gr.sizeof_char)
     dst = gr.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Beispiel #6
0
 def test_copy_drop (self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = ()
     src = gr.vector_source_c(src_data)
     op = gr.copy(gr.sizeof_gr_complex, False, 8)
     dst = gr.vector_sink_c()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Beispiel #7
0
 def test_copy_drop(self):
     src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     expected_result = ()
     src = blocks.vector_source_b(src_data)
     op = gr.copy(gr.sizeof_char)
     op.set_enabled(False)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, op, dst)
     self.tb.run()
     dst_data = dst.data()
     self.assertEqual(expected_result, dst_data)
Beispiel #8
0
    def test_copy_drop (self):
        src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
        expected_result = ()
        src = blocks.vector_source_b(src_data)
        op = gr.copy(gr.sizeof_char)
	op.set_enabled(False)
        dst = blocks.vector_sink_b()
        self.tb.connect(src, op, dst)
        self.tb.run()
        dst_data = dst.data()
        self.assertEqual(expected_result, dst_data)
Beispiel #9
0
	def wxgui_connect(self, *points):
		"""
		Use wxgui connect when the first point is the self source of the hb.
		The win property of this object should be set to the wx window.
		When this method tries to connect self to the next point,
		it will conditionally make this connection based on the visibility state.
		All other points will be connected normally.
		"""
		try:
			assert points[0] == self or points[0][0] == self
			copy = gr.copy(self._hb.input_signature().sizeof_stream_item(0))
			handler = self._handler_factory(copy.set_enabled)
			handler(False) #initially disable the copy block
			self._bind_to_visible_event(win=self.win, handler=handler)
			points = list(points)
			points.insert(1, copy) #insert the copy block into the chain
		except (AssertionError, IndexError): pass
		self.connect(*points) #actually connect the blocks
Beispiel #10
0
    def wxgui_connect(self, *points):
        """
		Use wxgui connect when the first point is the self source of the hb.
		The win property of this object should be set to the wx window.
		When this method tries to connect self to the next point,
		it will conditionally make this connection based on the visibility state.
		All other points will be connected normally.
		"""
        try:
            assert points[0] == self or points[0][0] == self
            copy = gr.copy(self._hb.input_signature().sizeof_stream_item(0))
            handler = self._handler_factory(copy.set_enabled)
            handler(False)  #initially disable the copy block
            self._bind_to_visible_event(win=self.win, handler=handler)
            points = list(points)
            points.insert(1, copy)  #insert the copy block into the chain
        except (AssertionError, IndexError):
            pass
        self.connect(*points)  #actually connect the blocks
Beispiel #11
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        self._tx_freq = options.tx_freq  # tranmitter's center frequency
        self._tx_gain = options.tx_gain  # transmitter's gain
        self._samp_rate = options.samp_rate  # sample rate for USRP
        self._rx_freq = options.rx_freq  # receiver's center frequency
        self._rx_gain = options.rx_gain  # receiver's gain

        if self._tx_freq is None:
            sys.stderr.write(
                "-f FREQ or --freq FREQ or --tx-freq FREQ must be specified\n")
            raise SystemExit

        if self._rx_freq is None:
            sys.stderr.write(
                "-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
            raise SystemExit

        # Set up USRP sink and source
        self._setup_usrp_sink()
        self._setup_usrp_source()

        # Set center frequency of USRP
        ok = self.set_freq(self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (
                eng_notation.num_to_str(self._tx_freq), )
            raise ValueError

        # copy the final answers back into options for use by modulator
        #options.bitrate = self._bitrate

        self.txpath = transmit_path(options)
        self.rxpath = receive_path(callback, options)
        self.rx_valve = gr.copy(gr.sizeof_gr_complex)

        self.connect(self.txpath, self.u_snk)
        self.connect(self.u_src, self.rx_valve, self.rxpath)
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        self._tx_freq            = options.tx_freq         # tranmitter's center frequency
        self._tx_gain            = options.tx_gain         # transmitter's gain
        self._samp_rate             = options.samp_rate       # sample rate for USRP
        self._rx_freq            = options.rx_freq         # receiver's center frequency
        self._rx_gain            = options.rx_gain         # receiver's gain

        if self._tx_freq is None:
            sys.stderr.write("-f FREQ or --freq FREQ or --tx-freq FREQ must be specified\n")
            raise SystemExit

        if self._rx_freq is None:
            sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n")
            raise SystemExit

        # Set up USRP sink and source
        self._setup_usrp_sink()
        self._setup_usrp_source()

        # Set center frequency of USRP
        ok = self.set_freq(self._tx_freq)
        if not ok:
            print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(self._tx_freq),)
            raise ValueError

        # copy the final answers back into options for use by modulator
        #options.bitrate = self._bitrate

        self.txpath = transmit_path(options)
        self.rxpath = receive_path(callback, options)
        self.rx_valve = gr.copy(gr.sizeof_gr_complex)

        self.connect(self.txpath, self.u_snk)
        self.connect(self.u_src, self.rx_valve, self.rxpath)
    def __init__(self, modulator, demodulator, rx_callback, options):
        gr.top_block.__init__(self)

        sense_symbol_rate=2500000
        sense_samples_per_symbol=2
        sense_rx_freq=2500000000
        sense_rx_gain=20
        options.chbw_factor=1
   
        global bandchoose


 
        #args = demodulator.extract_kwargs_from_options(options)
        self.sensesource=uhd_receiver(options.args, sense_symbol_rate,
                                       sense_samples_per_symbol,
                                       sense_rx_freq, sense_rx_gain,
                                       options.spec, options.antenna,
                                       options.verbose)

        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()
	    
            fa = samp_rate/4 #1000000

            self.sink = uhd_transmitter(options.args, symbol_rate,
                                        options.samples_per_symbol,
                                        options.tx_freq, options.tx_gain,
                                        options.spec, options.antenna,
                                        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 = gr.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 = gr.null_sink(gr.sizeof_gr_complex)


        self.txgate = gr.copy(gr.sizeof_gr_complex)
        self.sensegate = gr.copy(gr.sizeof_gr_complex)
        #self.msgq             = gr.msg_queue()

        # do this after for any adjustments to the options that may
        # occur in the sinks (specifically the UHD sink)


	# do sense
        self.sensepath = sensing_path(options)

        self.tx_enabled = True
	self.sense_flag=False

        self.connect(self.sensesource, self.sensepath)

	# do this after for any adjustments to the options that may
        # occur in the sinks (specifically the UHD sink)
        self.txpath1 = transmit_path(modulator, options)
	self.txpath2 = transmit_path(modulator, options)

	#self.connect(self.txpath, self.sink)

	# Define the math operator blocks
	

	# Generate exp(jw1t) and exp(-jw1t)
	self.gr_multiply_xx_0 = gr.multiply_vff(1)
	self.gr_float_to_complex_0_0 = gr.float_to_complex(1)
	self.gr_float_to_complex_0 = gr.float_to_complex(1)
	self.const_source_x_0 = gr.sig_source_f(0, gr.GR_CONST_WAVE, 0, 0, -1)
	self.analog_sig_source_x_0_0 = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, fa, 1, 0)
	self.analog_sig_source_x_0 = gr.sig_source_f(samp_rate, gr.GR_COS_WAVE, fa, 1, 0)


	# Combine signal from two subbands
	self.gr_multiply_xx_1 = gr.multiply_vcc(1)
	self.gr_multiply_xx_2 = gr.multiply_vcc(1)
	self.gr_c2f_1 = gr.complex_to_float(1)
	self.gr_c2f_2 = gr.complex_to_float(1)
	self.gr_add_xx_re = gr.add_vff(1)
	self.gr_add_xx_im = gr.add_vff(1)
	self.gr_f2c = gr.float_to_complex(1)
	
 	self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1)

	# output from gr_float_to_complex_0_0 is exp(-jw1t)
	# output from gr_float_to_complex_0 is exp(jw1t)
	self.connect((self.gr_multiply_xx_0, 0), (self.gr_float_to_complex_0_0, 1))
	self.connect((self.analog_sig_source_x_0, 0), (self.gr_float_to_complex_0_0, 0))
	self.connect((self.analog_sig_source_x_0_0, 0), (self.gr_float_to_complex_0, 1))
	self.connect((self.analog_sig_source_x_0, 0), (self.gr_float_to_complex_0, 0))
	self.connect((self.analog_sig_source_x_0_0, 0), (self.gr_multiply_xx_0, 0))
	self.connect((self.const_source_x_0, 0), (self.gr_multiply_xx_0, 1)) 

	# txpath1 * exp(-jw1t)
	#self.connect(self.txpath1, (self.gr_multiply_xx_1, 0))
	self.connect((self.gr_float_to_complex_0_0, 0), (self.gr_multiply_xx_1, 1))
	# txpath2 * exp(jw1t)
	#self.connect(self.txpath2, (self.gr_multiply_xx_2, 0))
	
	self.connect((self.gr_float_to_complex_0, 0), (self.gr_multiply_xx_2, 1))
	
	if bandchoose == 0:
		self.connect(self.txpath1, (self.gr_multiply_xx_1, 0))
		self.connect(self.gr_null_source_0 , (self.gr_multiply_xx_2, 0))
	elif bandchoose == 1:
		self.connect(self.gr_null_source_0 , (self.gr_multiply_xx_1, 0))
		self.connect(self.txpath2, (self.gr_multiply_xx_2, 0))
	else:
		self.connect(self.txpath1, (self.gr_multiply_xx_1, 0))
		self.connect(self.txpath2, (self.gr_multiply_xx_2, 0))

	self.connect((self.gr_multiply_xx_1, 0), self.gr_c2f_1)
	self.connect((self.gr_multiply_xx_2, 0), self.gr_c2f_2)

	self.connect((self.gr_c2f_1,0), (self.gr_add_xx_re,0))
	self.connect((self.gr_c2f_2,0), (self.gr_add_xx_re,1))

	self.connect((self.gr_c2f_1,1), (self.gr_add_xx_im,0))
	self.connect((self.gr_c2f_2,1), (self.gr_add_xx_im,1))

	self.connect(self.gr_add_xx_re, (self.gr_f2c,0))
	self.connect(self.gr_add_xx_im, (self.gr_f2c,1))
        self.connect(self.gr_f2c, self.sink)
import gnuradio
from gnuradio import gr
from gnuradio import blocks as grblocks
import sys

if __name__ == '__main__':

    duration = float(sys.argv[1])

    tb = gr.top_block()
    src = gr.null_source(8)
    b0 = gr.copy(8)
    b1 = grblocks.sub_cc()
    b2 = gr.copy(8)
    b3 = grblocks.divide_cc()
    b4 = gr.copy(8)
    sink = gr.null_sink(8)

    tb.connect(src, b0, b1, b2, b3, b4, sink)

    import time
    tb.start()
    time.sleep(duration)
    print '##RESULT##', sink.nitems_read(0)/duration
    import sys; sys.stdout.flush()
    tb.stop()
    tb.wait()
Beispiel #15
0
import gnuradio
from gnuradio import gr
from gnuradio import blocks as grblocks
import sys

if __name__ == '__main__':

    duration = float(sys.argv[1])

    tb = gr.top_block()
    src = gr.null_source(8)
    b0 = gr.copy(8)
    b1 = grblocks.sub_cc()
    b2 = gr.copy(8)
    b3 = grblocks.divide_cc()
    b4 = gr.copy(8)
    sink = gr.null_sink(8)

    tb.connect(src, b0, b1, b2, b3, b4, sink)

    import time
    tb.start()
    time.sleep(duration)
    print '##RESULT##', sink.nitems_read(0) / duration
    import sys
    sys.stdout.flush()
    tb.stop()
    tb.wait()