Esempio n. 1
0
    def __init__(self):
        search_criteria = uhd.device_addr_t()
        search_criteria['type'] = 'b200'  # ensure we don't find networked usrp
        available_devices = list(uhd.find_devices(search_criteria))
        ndevices_found = len(available_devices)

        if ndevices_found != 1:
            err = "Found {} devices that matches USRP identification\n"
            err += "information in sysinfo:\n"
            err += search_criteria.to_pp_string()
            err += "\nPlease add/correct identifying information."
            err = err.format(ndevices_found)

            for device in available_devices:
                err += "    {}\n".format(device.to_pp_string())

            raise RuntimeError(err)

        device = available_devices[0]
        logger.debug("Using the following USRP:")
        logger.debug(device.to_pp_string())

        stream_args = uhd.stream_args('fc32')
        self.usrp = uhd.usrp_source(device_addr=device,
                                    stream_args=stream_args)

        self.usrp.set_auto_dc_offset(True)
Esempio n. 2
0
    def __init__(self, cfg):
        self.logger = logging.getLogger('gr-analyzer.usrp')

        self.stream_args = uhd.stream_args(cpu_format=cfg.cpu_format,
                                           otw_format=cfg.wire_format,
                                           args=cfg.stream_args)

        found_devices = uhd.find_devices(uhd.device_addr_t(cfg.device_addr))
        len_found_devices = len(found_devices)

        if len_found_devices is 1:
            self.device_addr = found_devices[0]
            self.logger.debug("Found device {!s}".format(self.device_addr))
        else:
            if len_found_devices > 1:
                err = "\n\nFound more than 1 USRP:\n\n"
                err += str(found_devices)
                err += "\n\n"
                err += "Use --device-addr to select desired device.\n"
                err += "  example: --device-addr='serial=*****,addr=192.168.*.*'"
                err += "\n\n"
            else:
                err = "No devices found."
            raise RuntimeError(err)

        self.uhd = uhd.usrp_source(device_addr=self.device_addr,
                                   stream_args=self.stream_args)

        self.clock_rate = int(self.uhd.get_clock_rate())
        self.sample_rate = int(self.uhd.get_samp_rate())
        self.apply_cfg(cfg)
Esempio n. 3
0
def get_usrps_with_device_info():
    devs = uhd.find_devices()
    devs_infos = []
    eths_ids = get_eths_with_ids()
    for dev in devs:
        if dev['addr']:
            ridx = dev['addr'].rfind('.')
            net = dev['addr'][0:ridx + 1]
            for eth in eths_ids:
                if eth['addr'].startswith(net):
                    dev_info = {'type': dev['type'], 'addr': dev['addr'], 'name': dev['name'], 'serial': dev['serial'],
                                'host': eth}
                    devs_infos.append(dev_info)

    return devs_infos
Esempio n. 4
0
    def __init__(self, profile):
        self.profile = profile

        search_criteria = uhd.device_addr_t()
        if profile.usrp_device_name is not None:
            search_criteria['name'] = profile.usrp_device_name
        if profile.usrp_device_type is not None:
            search_criteria['type'] = profile.usrp_device_type
        if profile.usrp_serial is not None:
            search_criteria['serial'] = profile.usrp_serial
        if profile.usrp_ip_address is not None:
            search_criteria['addr'] = profile.usrp_ip_address

        found_devices = uhd.find_devices(search_criteria)

        if len(found_devices) != 1:
            err = "Found {} devices that matches USRP identification\n"
            err += "information in the test profile:\n"
            err += search_criteria.to_pp_string()
            err += "Please add/correct identifying information.\n"
            print(err, file=sys.stderr)
            for device in found_devices:
                print()
                print(device.to_pp_string())
                print()
            raise RuntimeError()
        else:
            device = found_devices[0]
            print("Found the following USRP matching test profile criteria:\n")
            print(device.to_pp_string())

        stream_args = uhd.stream_args(profile.usrp_stream_args)
        self.usrp = uhd.usrp_source(device_addr=device,
                                    stream_args=stream_args)

        self.usrp.set_auto_dc_offset(True)
        self.usrp.set_clock_rate(profile.usrp_clock_rate)
        self.usrp.set_samp_rate(profile.usrp_sample_rate)
        self.sample_rate = self.usrp.get_samp_rate()
        print("USRP actual sample rate: {} MS/s".format(self.sample_rate /
                                                        1e6))

        for gain_type, value in profile.usrp_gain.items():
            self.usrp.set_gain(value, gain_type)
        print("USRP gain: {} dB".format(self.usrp.get_gain()))

        if hasattr(profile, 'usrp_center_freq'):
            self.set_frequency(profile.usrp_center_freq)
Esempio n. 5
0
def get_usrps_with_device_info():
    devs = uhd.find_devices()
    devs_infos = []
    eths_ids = get_eths_with_ids()
    for dev in devs:
        if dev['addr']:
            ridx = dev['addr'].rfind('.')
            net = dev['addr'][0:ridx + 1]
            for eth in eths_ids:
                if eth['addr'].startswith(net):
                    dev_info = {
                        'type': dev['type'],
                        'addr': dev['addr'],
                        'name': dev['name'],
                        'serial': dev['serial'],
                        'host': eth
                    }
                    devs_infos.append(dev_info)

    return devs_infos
Esempio n. 6
0
	def __init__(self):
		gr.top_block.__init__(self)
		
		usage = "usage: %prog [options]"
		parser = OptionParser(option_class=eng_option, usage=usage)
		parser.add_option("-f", "--tx-freq", type="eng_float", default=None,
						  metavar="Hz", help="Transmit frequency [default=center_frequency]")

		(options, args) = parser.parse_args()

		args = "" #only supporting USB USRPs for now

		#find uhd devices

		d = uhd.find_devices(uhd.device_addr(args))

		if d:
			uhd_type = d[0].get('type')
			print "\nFound '%s'" % uhd_type
		else:
			print "\nNo device found"
			self.u_tx = None
			return

		#check version of USRP and set num_channels

		if uhd_type == "usrp":
			tx_nchan = 2
			rx_nchan = 2
		else:
			tx_nchan = 1
			rx_nchan = 1

		#setup transmit chain (usrp sink, signal source)
		
		#usrp sink
		stream_args = uhd.stream_args('fc32', channels = range(tx_nchan))
		self.u_tx = uhd.usrp_sink(device_addr=args, stream_args=stream_args)
		self.u_tx.set_samp_rate(MAX_RATE)

		#analog signal source - sig_source_c(sampling_freq,waveform, wave_freq, ampl, offset=0)
		self.tx_src0 = analog.sig_source_c(self.u_tx.get_samp_rate(), analog.GR_CONST_WAVE, 0, 1.0, 0)

		#check and output freq range, gain range, num_channels

		#gain range and max
		tx_gain_range = self.u_tx.get_gain_range()
		tx_gain_min = tx_gain_range.start()
		tx_gain_max = tx_gain_range.stop()

		#freq range
		tx_freq_range = self.u_tx.get_freq_range()
		tx_freq_low = tx_freq_range.start()
		tx_freq_high = tx_freq_range.stop()
		tx_freq_mid = (tx_freq_low + tx_freq_high) / 2.0

		if options.tx_freq is None:
			self.tx_freq = tx_freq_mid
		else:
			if options.tx_freq < 1e6:
				options.tx_freq *= 1e6
			self.tx_freq = options.tx_freq

		#output info
		print "\nDevice Info -\tType: %s\tFreq(MHz): (%d,%d,%d)\tGain(dB): (%f,%f)\n" % (uhd_type, (tx_freq_low/1e6), (tx_freq_mid/1e6), (tx_freq_high/1e6), tx_gain_min, tx_gain_max)		

		#set initial parameters 
		self.u_tx.set_center_freq(self.tx_freq)
		self.u_tx.set_gain(tx_gain_max)

		#connect blocks

		self.connect(self.tx_src0, self.u_tx)
Esempio n. 7
0
    def __init__(self, args, tx_enable, rx_enable):
        gr.top_block.__init__(self)

        d = uhd.find_devices(uhd.device_addr(args))
        uhd_type = d[0].get('type')

        print "\nFound '%s' at args '%s'" % \
            (uhd_type, args)

        # Test the type of USRP; if it's a USRP (v1), it has
        # 2 channels; otherwise, it has 1 channel
        if uhd_type == "usrp":
            tx_nchan = 2
            rx_nchan = 2
        else:
            tx_nchan = 1
            rx_nchan = 1
        
        if tx_enable:
            print "\nTRANSMIT CHAIN"
            self.u_tx = uhd.usrp_sink(device_addr=args,
                                      io_type=uhd.io_type.COMPLEX_FLOAT32,
                                      num_channels=tx_nchan)
            self.u_tx.set_samp_rate(MAX_RATE)

            self.tx_src0 = gr.sig_source_c(self.u_tx.get_samp_rate(),
                                           gr.GR_CONST_WAVE,
                                           0, 1.0, 0)

            # Get dboard gain range and select maximum
            tx_gain_range = self.u_tx.get_gain_range()
            tx_gain = tx_gain_range.stop()

            # Get dboard freq range and select midpoint
            tx_freq_range = self.u_tx.get_freq_range()
            tx_freq_mid = (tx_freq_range.start() + tx_freq_range.stop())/2.0

            for i in xrange(tx_nchan):
                self.u_tx.set_center_freq (tx_freq_mid + i*1e6, i)
                self.u_tx.set_gain(tx_gain, i)

            print "\nTx Sample Rate: %ssps" % (n2s(self.u_tx.get_samp_rate()))
            for i in xrange(tx_nchan):
                print "Tx Channel %d: " % (i)
                print "\tFrequency = %sHz" % \
                    (n2s(self.u_tx.get_center_freq(i)))
                print "\tGain = %f dB" % (self.u_tx.get_gain(i))
            print ""

            self.connect (self.tx_src0, self.u_tx)

        if rx_enable:
            print "\nRECEIVE CHAIN"
            self.u_rx = uhd.usrp_source(device_addr=args,
                                        io_type=uhd.io_type.COMPLEX_FLOAT32,
                                        num_channels=rx_nchan)
            self.rx_dst0 = gr.null_sink (gr.sizeof_gr_complex)

            self.u_rx.set_samp_rate(MAX_RATE)

            # Get dboard gain range and select maximum
            rx_gain_range = self.u_rx.get_gain_range()
            rx_gain = rx_gain_range.stop()

            # Get dboard freq range and select midpoint
            rx_freq_range = self.u_rx.get_freq_range()
            rx_freq_mid = (rx_freq_range.start() + rx_freq_range.stop())/2.0

            for i in xrange(tx_nchan):
                self.u_rx.set_center_freq (rx_freq_mid + i*1e6, i)
                self.u_rx.set_gain(rx_gain, i)

            print "\nRx Sample Rate: %ssps" % (n2s(self.u_rx.get_samp_rate()))
            for i in xrange(rx_nchan):
                print "Rx Channel %d: " % (i)
                print "\tFrequency = %sHz" % \
                    (n2s(self.u_rx.get_center_freq(i)))
                print "\tGain = %f dB" % (self.u_rx.get_gain(i))
            print ""

            self.connect (self.u_rx, self.rx_dst0)
Esempio n. 8
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] tx-freq0 tx-freq1"
        parser = OptionParser (option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=320e3,
                          help="set sample rate [default=%default]")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        (options, args) = parser.parse_args ()

        if len(args) != 2:
            parser.print_help()
            raise SystemExit
        else:
            freq0 = str_to_num(args[0])
            freq1 = str_to_num(args[1])

        # ----------------------------------------------------------------
        # Set up USRP to transmit on both daughterboards

        d = uhd.find_devices(uhd.device_addr(options.args))
        uhd_type = d[0].get('type')

        stream_args = uhd.stream_args('fc32', channels=range(2))
        self.u = uhd.usrp_sink(device_addr=options.args, stream_args=stream_args)

        # Set up USRP system based on type
        if(uhd_type == "usrp"):
            self.u.set_subdev_spec("A:0 B:0")
            tr0 = uhd.tune_request(freq0)
            tr1 = uhd.tune_request(freq1)

        else:
            if abs(freq0 - freq1) > 5.5e6:
                sys.stderr.write("\nError: When not using two separate d'boards, frequencies must bewithin 5.5MHz of each other.\n")
                raise SystemExit

            self.u.set_subdev_spec("A:0 A:0")

            mid_freq = (freq0 + freq1)/2.0
            tr0 = uhd.tune_request(freq0, rf_freq=mid_freq,
                                   rf_freq_policy=uhd.tune_request.POLICY_MANUAL)

            tr1 = uhd.tune_request(freq1, rf_freq=mid_freq,
                                   rf_freq_policy=uhd.tune_request.POLICY_MANUAL)

        # Use the tune requests to tune each channel
        self.set_freq(tr0, 0)
        self.set_freq(tr1, 1)

        self.usrp_rate  = options.samp_rate

        self.u.set_samp_rate(self.usrp_rate)
        dev_rate = self.u.get_samp_rate()

        # ----------------------------------------------------------------
        # build two signal sources, interleave them, amplify and
        # connect them to usrp

        sig0 = example_signal_0(self.usrp_rate)
        sig1 = example_signal_1(self.usrp_rate)

        intl = blocks.interleave(gr.sizeof_gr_complex)
        self.connect(sig0, (intl, 0))
        self.connect(sig1, (intl, 1))

        # Correct for any difference in requested and actual rates
        rrate = self.usrp_rate / dev_rate
        resamp = filter.pfb.arb_resampler_ccf(rrate)

        # and wire them up
        self.connect(intl, resamp, self.u)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            options.gain = float(g.start()+g.stop())/2.0

        self.set_gain(options.gain, 0)
        self.set_gain(options.gain, 1)

        # Set the subdevice spec
        if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

        # Set the antenna
        if(options.antenna):
            self.u.set_antenna(options.antenna, 0)
            self.u.set_antenna(options.antenna, 1)
Esempio n. 9
0
    def __init__(self):
        gr.top_block.__init__(self)

        args = ""  #only supporting USB USRPs for now

        #find uhd devices

        d = uhd.find_devices(uhd.device_addr(args))
        if d:

            uhd_type = d[0].get('type')
            print "\nFound '%s'" % uhd_type
        else:
            print "\nNo device found"
            self.u_tx = None
            return

        #check version of USRP and set num_channels

        if uhd_type == "usrp":
            tx_nchan = 2
            rx_nchan = 2
        else:
            tx_nchan = 1
            rx_nchan = 1

        #setup transmit chain (usrp sink, signal source)

        #usrp sink
        stream_args = uhd.stream_args('fc32', channels=range(tx_nchan))
        self.u_tx = uhd.usrp_sink(device_addr=args, stream_args=stream_args)
        self.u_tx.set_samp_rate(MAX_RATE)

        #analog signal source - sig_source_c(sampling_freq,waveform, wave_freq, ampl, offset=0)
        self.tx_src0 = analog.sig_source_c(self.u_tx.get_samp_rate(),
                                           analog.GR_CONST_WAVE, 0, 1.0, 0)

        #check and output freq range, gain range, num_channels

        #gain range and max
        tx_gain_range = self.u_tx.get_gain_range()
        tx_gain_min = tx_gain_range.start()
        tx_gain_max = tx_gain_range.stop()

        #freq range
        tx_freq_range = self.u_tx.get_freq_range()
        tx_freq_low = tx_freq_range.start()
        tx_freq_high = tx_freq_range.stop()
        tx_freq_mid = (tx_freq_low + tx_freq_high) / 2.0

        #output info
        print "\nDevice Info"
        print "\n\tType: %s" % uhd_type

        print "\n\tMin Freq: %d MHz" % (tx_freq_low / 1e6)
        print "\tMax Freq: %d MHz" % (tx_freq_high / 1e6)
        print "\tMid Freq: %d MHz" % (tx_freq_mid / 1e6)

        print "\n\tMin Gain: %d dB" % tx_gain_min
        print "\tMax Gain: %d dB" % tx_gain_max

        #set initial parameters

        for i in xrange(tx_nchan):
            self.u_tx.set_center_freq(tx_freq_mid + i * 1e6, i)
            self.u_tx.set_gain(tx_gain_max, i)

        #connect blocks

        self.connect(self.tx_src0, self.u_tx)
Esempio n. 10
0
    def __init__(self, args1, args2):
        gr.top_block.__init__(self)

        ##############################
        # TRANSMIT CHAIN
        ##############################
        print "\nTRANSMIT CHAIN"

        ##USRP transmits repeating file generated in MATLAB
        #self.tx_src = blocks.file_source(gr.sizeof_gr_complex, "iq_in.dat", True)

        #USRP transmits a repeating vector generated here...
        tx_list = [
            0.2363 + 0.0741j, 0.0733 - 0.2865j, -0.1035 - 0.2663j,
            -0.0853 + 0.1909j, -0.0736 + 0.2699j, 0.0773 + 0.1481j,
            -0.0336 + 0.2079j, -0.0644 - 0.2244j, 0.0396 + 0.2822j,
            -0.0595 - 0.2416j, 0.1379 + 0.2658j, -0.0449 - 0.2539j,
            0.0593 + 0.2946j, 0.0221 - 0.0113j, -0.1303 + 0.2762j,
            -0.1351 - 0.2598j, -0.0275 - 0.2617j, 0.2157 + 0.1021j,
            0.0332 - 0.0383j, -0.1369 - 0.2680j
        ]
        self.vec_tx_src = blocks.vector_source_c(tuple(tx_list), True,
                                                 SIGNAL_LEN, [])
        self.tx_src = blocks.vector_to_stream(gr.sizeof_gr_complex, SIGNAL_LEN)

        #Find USRP with device characteristics specified by args1
        d1 = uhd.find_devices(uhd.device_addr(args1))
        uhd_type1 = d1[0].get('type')
        print "\nFound '%s' at args '%s'" % \
            (uhd_type1, args1)

        stream_args = uhd.stream_args('fc32')
        self.u_tx = uhd.usrp_sink(device_addr=args1, stream_args=stream_args)
        self.u_tx.set_samp_rate(SAMPLE_RATE)
        self.u_tx.set_clock_source("external")
        self.center_freq = END_FREQ - STEP_FREQ
        self.tr = uhd.tune_request(self.center_freq)
        self.tr.args = uhd.device_addr_t("mode_n=integer")
        self.u_tx.set_center_freq(self.tr)
        self.u_tx.set_bandwidth(SAMPLE_RATE * 1.5)

        # Get dboard gain range and select maximum
        tx_gain_range = self.u_tx.get_gain_range()
        tx_gain = tx_gain_range.stop()
        self.u_tx.set_gain(tx_gain - 9)

        self.connect(self.vec_tx_src, self.tx_src, self.u_tx)

        ##############################
        # RECEIVE CHAIN
        ##############################
        print "\nRECEIVE CHAIN"

        #USRP logs IQ data to file
        #This PMT dictionary stuff is stupid, however it's required otherwise the header will become corrupted...
        key = pmt.intern("rx_freq")
        val = pmt.from_double(0)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, key, val)
        extras = pmt.serialize_str(extras)

        self.tag_debug = None
        self.u_rxs = []

        for usrp_addr in args2.split(","):
            kv = usrp_addr.split("=")
            rx_dst = blocks.file_meta_sink(
                gr.sizeof_gr_complex * SIGNAL_LEN,
                "iq_out_{}.dat".format(kv[1]),
                SAMPLE_RATE,
                extra_dict=extras)  #, detached_header=True)
            #rx_dst = blocks.file_sink(gr.sizeof_gr_complex*SIGNAL_LEN, "iq_out.dat")

            # Accumulate repeating sequences using custom block
            rx_accum = slocalization.accumulator_vcvc(SIGNAL_LEN, int(1e3))

            #Find USRP with device characteristics specified by args1
            d2 = uhd.find_devices(uhd.device_addr(usrp_addr))
            uhd_type2 = d2[0].get('type')
            print "\nFound '%s' at args '%s'" % \
                (uhd_type2, usrp_addr)

            u_rx = uhd.usrp_source(device_addr=usrp_addr,
                                   io_type=uhd.io_type.COMPLEX_FLOAT32,
                                   num_channels=1)
            u_rx.set_samp_rate(SAMPLE_RATE)
            u_rx.set_bandwidth(SAMPLE_RATE * 1.5)
            u_rx.set_clock_source("external")
            u_rx.set_center_freq(self.tr)
            self.u_rxs.append(u_rx)

            # Get dboard gain range and select maximum
            rx_gain_range = u_rx.get_gain_range()
            rx_gain = rx_gain_range.stop()
            u_rx.set_gain(rx_gain, 0)

            # Convert stream to vector
            s_to_v = blocks.stream_to_vector(gr.sizeof_gr_complex, SIGNAL_LEN)

            self.connect(u_rx, s_to_v, rx_accum, rx_dst)
            #self.connect (u_rx, s_to_v, rx_dst)

            if not self.tag_debug:
                # DEBUG: Monitor incoming tags...
                self.tag_debug = blocks.tag_debug(
                    gr.sizeof_gr_complex * SIGNAL_LEN, "tag_debugger", "")
                self.connect(rx_accum, self.tag_debug)

            # Synchronize both USRPs' timebases
            u_rx.set_time_now(uhd.time_spec(0.0))

        # Synchronize both USRPs' timebases
        self.u_tx.set_time_now(uhd.time_spec(0.0))
Esempio n. 11
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] tx-freq0 tx-freq1"
        parser = OptionParser (option_class=eng_option, usage=usage)
        parser.add_option("-a", "--args", type="string", default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("", "--spec", type="string", default=None,
	                  help="Subdevice of UHD device where appropriate")
        parser.add_option("-A", "--antenna", type="string", default=None,
                          help="select Rx Antenna where appropriate")
        parser.add_option("-s", "--samp-rate", type="eng_float", default=320e3,
                          help="set sample rate [default=%default]")
        parser.add_option("-g", "--gain", type="eng_float", default=None,
                          help="set gain in dB (default is midpoint)")
        (options, args) = parser.parse_args ()

        if len(args) != 2:
            parser.print_help()
            raise SystemExit
        else:
            freq0 = str_to_num(args[0])
            freq1 = str_to_num(args[1])

        # ----------------------------------------------------------------
        # Set up USRP to transmit on both daughterboards

        d = uhd.find_devices(uhd.device_addr(options.args))
        uhd_type = d[0].get('type')

        stream_args = uhd.stream_args('fc32', channels=range(2))
        self.u = uhd.usrp_sink(device_addr=options.args, stream_args=stream_args)

        # Set up USRP system based on type
        if(uhd_type == "usrp"):
            self.u.set_subdev_spec("A:0 B:0")
            tr0 = uhd.tune_request(freq0)
            tr1 = uhd.tune_request(freq1)

        else:
            if abs(freq0 - freq1) > 5.5e6:
                sys.stderr.write("\nError: When not using two separate d'boards, frequencies must bewithin 5.5MHz of each other.\n")
                raise SystemExit

            self.u.set_subdev_spec("A:0 A:0")

            mid_freq = (freq0 + freq1)/2.0
            tr0 = uhd.tune_request(freq0, rf_freq=mid_freq,
                                   rf_freq_policy=uhd.tune_request.POLICY_MANUAL)

            tr1 = uhd.tune_request(freq1, rf_freq=mid_freq,
                                   rf_freq_policy=uhd.tune_request.POLICY_MANUAL)

        # Use the tune requests to tune each channel
        self.set_freq(tr0, 0)
        self.set_freq(tr1, 1)

        self.usrp_rate  = options.samp_rate

        self.u.set_samp_rate(self.usrp_rate)
        dev_rate = self.u.get_samp_rate()

        # ----------------------------------------------------------------
        # build two signal sources, interleave them, amplify and
        # connect them to usrp

        sig0 = example_signal_0(self.usrp_rate)
        sig1 = example_signal_1(self.usrp_rate)

        intl = gr.interleave(gr.sizeof_gr_complex)
        self.connect(sig0, (intl, 0))
        self.connect(sig1, (intl, 1))

        # Correct for any difference in requested and actual rates
        rrate = self.usrp_rate / dev_rate
        resamp = blks2.pfb_arb_resampler_ccf(rrate)

        # and wire them up
        self.connect(intl, resamp, self.u)

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.u.get_gain_range()
            options.gain = float(g.start()+g.stop())/2.0

        self.set_gain(options.gain, 0)
        self.set_gain(options.gain, 1)

        # Set the subdevice spec
        if(options.spec):
            self.u.set_subdev_spec(options.spec, 0)

        # Set the antenna
        if(options.antenna):
            self.u.set_antenna(options.antenna, 0)
            self.u.set_antenna(options.antenna, 1)
Esempio n. 12
0
    def __init__(self, args, tx_enable, rx_enable):
        gr.top_block.__init__(self)

        d = uhd.find_devices(uhd.device_addr(args))
        print(d)
        uhd_type = d[0].get('type')

        print "\nFound '%s' at args '%s'" % \
            (uhd_type, args)

        # Test the type of USRP; if it's a USRP (v1), it has
        # 2 channels; otherwise, it has 1 channel
        if uhd_type == "usrp":
            tx_nchan = 2
            rx_nchan = 2
        else:
            tx_nchan = 1
            rx_nchan = 1

        if tx_enable:
            print "\nTRANSMIT CHAIN"
            stream_args = uhd.stream_args('fc32', channels=range(tx_nchan))
            self.u_tx = uhd.usrp_sink(device_addr=args,
                                      stream_args=stream_args)
            self.u_tx.set_samp_rate(MAX_RATE)

            self.tx_src0 = analog.sig_source_c(self.u_tx.get_samp_rate(),
                                               analog.GR_CONST_WAVE, 0, 1.0, 0)

            # Get dboard gain range and select maximum
            tx_gain_range = self.u_tx.get_gain_range()
            tx_gain = tx_gain_range.stop()

            # Get dboard freq range and select midpoint
            tx_freq_range = self.u_tx.get_freq_range()
            tx_freq_mid = (tx_freq_range.start() + tx_freq_range.stop()) / 2.0

            for i in xrange(tx_nchan):
                self.u_tx.set_center_freq(tx_freq_mid + i * 1e6, i)
                self.u_tx.set_gain(tx_gain, i)

            print "\nTx Sample Rate: %ssps" % (n2s(self.u_tx.get_samp_rate()))
            for i in xrange(tx_nchan):
                print "Tx Channel %d: " % (i)
                print "\tFrequency = %sHz" % \
                    (n2s(self.u_tx.get_center_freq(i)))
                print "\tGain = %f dB" % (self.u_tx.get_gain(i))
            print ""

            self.connect(self.tx_src0, self.u_tx)

        if rx_enable:
            print "\nRECEIVE CHAIN"
            self.u_rx = uhd.usrp_source(device_addr=args,
                                        io_type=uhd.io_type.COMPLEX_FLOAT32,
                                        num_channels=rx_nchan)
            self.rx_dst0 = blocks.null_sink(gr.sizeof_gr_complex)

            self.u_rx.set_samp_rate(MAX_RATE)

            # Get dboard gain range and select maximum
            rx_gain_range = self.u_rx.get_gain_range()
            rx_gain = rx_gain_range.stop()

            # Get dboard freq range and select midpoint
            rx_freq_range = self.u_rx.get_freq_range()
            rx_freq_mid = (rx_freq_range.start() + rx_freq_range.stop()) / 2.0

            for i in xrange(tx_nchan):
                self.u_rx.set_center_freq(rx_freq_mid + i * 1e6, i)
                self.u_rx.set_gain(rx_gain, i)

            print "\nRx Sample Rate: %ssps" % (n2s(self.u_rx.get_samp_rate()))
            for i in xrange(rx_nchan):
                print "Rx Channel %d: " % (i)
                print "\tFrequency = %sHz" % \
                    (n2s(self.u_rx.get_center_freq(i)))
                print "\tGain = %f dB" % (self.u_rx.get_gain(i))
            print ""

            self.connect(self.u_rx, self.rx_dst0)
Esempio n. 13
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "usage: %prog [options] min_freq max_freq"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-a",
                          "--args",
                          type="string",
                          default="",
                          help="UHD device address args [default=%default]")
        parser.add_option("",
                          "--spec",
                          type="string",
                          default=None,
                          help="Subdevice of UHD device where appropriate")
        parser.add_option("-R",
                          "--rx-antenna",
                          type="string",
                          default="RX2",
                          help="select RX antenna where appropriate")
        parser.add_option("-T",
                          "--tx-antenna",
                          type="string",
                          default="TX/RX",
                          help="select TX antenna where appropriate")
        parser.add_option("-s",
                          "--samp-rate",
                          type="eng_float",
                          default=1e6,
                          help="set sample rate [default=%default]")
        parser.add_option("-g",
                          "--gain",
                          type="eng_float",
                          default=None,
                          help="set gain in dB (default is midpoint)")
        parser.add_option(
            "",
            "--tune-delay",
            type="eng_float",
            default=0.25,
            metavar="SECS",
            help=
            "time to delay (in seconds) after changing frequency [default=%default]"
        )
        parser.add_option(
            "",
            "--dwell-delay",
            type="eng_float",
            default=0.25,
            metavar="SECS",
            help=
            "time to delay (in seconds) at a given frequency [default=%default]"
        )
        parser.add_option(
            "-b",
            "--channel-bandwidth",
            type="eng_float",
            default=6.25e3,
            metavar="Hz",
            help="channel bandwidth of fft bins in Hz [default=%default]")
        parser.add_option("-l",
                          "--lo-offset",
                          type="eng_float",
                          default=0,
                          metavar="Hz",
                          help="lo_offset in Hz [default=%default]")
        parser.add_option("-q",
                          "--squelch-threshold",
                          type="eng_float",
                          default=None,
                          metavar="dB",
                          help="squelch threshold in dB [default=%default]")
        parser.add_option(
            "-F",
            "--fft-size",
            type="int",
            default=None,
            help="specify the number of FFT bins [default=samp_rate/channel_bw]"
        )
        parser.add_option("",
                          "--real-time",
                          action="store_true",
                          default=False,
                          help="Attempt to enable real-time scheduling")
        parser.add_option(
            "-w",
            "--tx-bandwidth",
            type="eng_float",
            default=6e6,
            metavar="Hz",
            help="transmit frequency bandwidth [default=%default]")

        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.print_help()
            sys.exit(1)

        self.channel_bandwidth = options.channel_bandwidth  #fft channel bandwidth
        self.tx_bandwidth = options.tx_bandwidth

        self.min_freq = eng_notation.str_to_num(args[0])
        self.max_freq = eng_notation.str_to_num(args[1])

        if self.min_freq < 1e6: self.min_freq *= 1e6
        if self.max_freq < 1e6: self.max_freq *= 1e6

        self.n_channel_grps = 5  #number of channel groups
        self.curr_channel_grp = 0
        self.n_channels = 5  #number of channels / channel group
        self.curr_channel = 0

        self.tx_guard_band = 4e6

        if self.min_freq > self.max_freq:
            #swap them
            self.min_freq, self.max_freq = self.max_freq, self.min_freq

        self.channel_grp_bw = (self.max_freq -
                               self.min_freq) / self.n_channel_grps
        self.tx_channel_bw = self.channel_grp_bw / self.n_channels  # tx channel bw

        if not options.real_time:
            real_time = False
        else:
            #Attempt to enable realtime scheduling
            r = gr.enable_realtime_scheduling()
            if r == gr.RT_OK:
                realtime = True
            else:
                realtime = False
                print "Note: failed to enable realtime scheduling"

        #build graph
        self.u_rx = uhd.usrp_source(device_addr=options.args,
                                    stream_args=uhd.stream_args('fc32'))

        #Set the subdevice spec
        if options.spec:
            self.u_rx.set_subdev_spec(options.spec, 0)

        #Set the antenna
        if options.rx_antenna:
            self.u_rx.set_antenna(options.rx_antenna, 0)

        self.u_rx.set_samp_rate(options.samp_rate)
        self.usrp_rate = usrp_rate = self.u_rx.get_samp_rate()

        self.lo_offset = options.lo_offset

        if options.fft_size is None:
            self.fft_size = int(self.usrp_rate / self.channel_bandwidth)
        else:
            self.fft_size = options.fft_size

        print "FFT Size: %d, USRP Samp Rate: %d, Channel Bandwidth: %d" % (
            self.fft_size, self.usrp_rate, self.channel_bandwidth)

        self.squelch_threshold = options.squelch_threshold

        s2v = blocks.stream_to_vector(gr.sizeof_gr_complex, self.fft_size)

        mywindow = filter.window.blackmanharris(self.fft_size)
        ffter = fft.fft_vcc(self.fft_size, True, mywindow, True)

        c2mag = blocks.complex_to_mag_squared(self.fft_size)

        tune_delay = max(0,
                         int(
                             round(options.tune_delay * usrp_rate /
                                   self.fft_size)))  # in fft_frames
        dwell_delay = max(1,
                          int(
                              round(options.dwell_delay * usrp_rate /
                                    self.fft_size)))  # in fft frames

        self.msgq = gr.msg_queue(1)
        self._tune_callback = tune(
            self)  #hang on to this to keep it from being GC'd

        stats = blocks.bin_statistics_f(self.fft_size, self.msgq,
                                        self._tune_callback, tune_delay,
                                        dwell_delay)

        self.connect(self.u_rx, s2v, ffter, c2mag, stats)

        #transmit chain

        d = uhd.find_devices(uhd.device_addr(options.args))
        if d:

            uhd_type = d[0].get('type')
            print "\nFound '%s'" % uhd_type
        else:
            print "\nNo device found"
            self.u_tx = None
            return

        #check version of USRP and set num_channels

        if uhd_type == "usrp":
            tx_nchan = 2
            rx_nchan = 2
        else:
            tx_nchan = 1
            rx_nchan = 1

        #setup transmit chain (usrp sink, signal source)

        #usrp sink
        stream_args = uhd.stream_args('fc32', channels=range(tx_nchan))
        self.u_tx = uhd.usrp_sink(device_addr=options.args,
                                  stream_args=stream_args)
        self.u_tx.set_samp_rate(self.usrp_rate)

        if options.tx_antenna:
            self.u_tx.set_antenna(options.tx_antenna, 0)

#analog signal source - sig_source_c(sampling_freq,waveform, wave_freq, ampl, offset=0)
        self.tx_src0 = analog.sig_source_c(self.u_tx.get_samp_rate(),
                                           analog.GR_CONST_WAVE, 0, 1.0, 0)

        #connect blocks

        self.connect(self.tx_src0, self.u_tx)

        if options.gain is None:
            # if no gain was specified use the midpoint in dB
            g = self.u_rx.get_gain_range()
            options.gain = float(g.start() + g.stop()) / 2.0

        self.set_gain(options.gain)
        print "gain =", options.gain

        #initialize transmission parameters
        self.set_channel_group(3)
        self.step_count = 0