Beispiel #1
0
    def freq(self, value):
        # Check the input value is usable
        try:
            cen_freq, lo_off = value
        except ValueError:
            raise ValueError("Pass an iterable with two items")
        if cen_freq is None:
            raise TypeError("You must specify -f FREQ or --freq FREQ")
        if type(cen_freq) is list:
            if len(cen_freq) > 1 and not self.mimo:
                raise AssertionError('freq must be a one item list or a float (SISO mode)')
            elif self.mimo and len(cen_freq) != 2:
                raise AssertionError('freq must be a two-item list (MIMO mode)')
            elif self.mimo:
                tmp_freq = cen_freq
            else:
                tmp_freq = cen_freq[0]
        elif type(cen_freq) is not float:
            raise AssertionError('freq must be a list or a float')
        else:
            # cen_freq is a float
            tmp_freq = [cen_freq]

        if lo_off is not None:
            response = self.u.set_center_freq(uhd.tune_request_t(tmp_freq[0], lo_off), 0)
            if self.mimo:
                response1 = self.u.set_center_freq(uhd.tune_request_t(tmp_freq[1], lo_off), 1)
            RT_LOGGER.i_logging("Setting freq to %s and LO-offset to %f" % (tmp_freq, lo_off), self.block_name)
        else:
            response = self.u.set_center_freq(tmp_freq[0], 0)
            if self.mimo:
                response1 = self.u.set_center_freq(tmp_freq[1], 1)
            RT_LOGGER.i_logging("Setting freq to %s and no LO-offset" % tmp_freq, self.block_name)

        if response is not None:
            actual_freq = []
            actual_freq.append(self.u.get_center_freq(0))
            if actual_freq[0] != tmp_freq[0]:
                RT_LOGGER.w_logging("actual freq %s does not match the expected freq %s" % (actual_freq, tmp_freq),
                                    self.block_name)
            if self.mimo:
                if response1 is not None:
                    actual_freq.append(self.u.get_center_freq(1))
                    if actual_freq[1] != tmp_freq[1]:
                        RT_LOGGER.w_logging("actual freq %s does not match the expected freq %s" % (actual_freq, tmp_freq),
                                            self.block_name)
                else:
                    f_range = self.u.get_freq_range(1)
                    raise ValueError("expected frequency %f is out-of-range [%f, %f] in 2nd path" %
                                     (tmp_freq[1], f_range.start(), f_range.stop()))
            self._freq = actual_freq
            self._lo_offset = lo_off
        else:
            f_range = self.u.get_freq_range()
            raise ValueError("expected frequency %f is out-of-range [%f, %f]" %
                             (tmp_freq, f_range.start(), f_range.stop()))
Beispiel #2
0
	def work(self,ins,outs):
		n=min(len(ins[0]),len(outs[0]))
		outs[0][:n]=ins[0][:n]
		self.consume(0,n)
		self.produce(0,n)
		if(time.time()>self.start):
			print "hoping"
			self.uhd_control.set("tx_freq",uhd.tune_request_t(self.freq_ls[self.hop_index]))
			self.hop_index=(self.hop_index+1)%len(self.freq_ls)
			self.start=time.time()+5
Beispiel #3
0
 def set_rfFreqMhz(self, rfFreqMhz):
     self.rfFreqMhz = rfFreqMhz
     self.uhd_usrp_sink_1.set_center_freq(uhd.tune_request_t((self.rfFreqMhz+1)*1e6, 2*self.samp_rate), 0)
     self._cfg_rfFreqMhz_config = ConfigParser.ConfigParser()
     self._cfg_rfFreqMhz_config.read(self.configFilePath)
     if not self._cfg_rfFreqMhz_config.has_section('tuner'):
     	self._cfg_rfFreqMhz_config.add_section('tuner')
     self._cfg_rfFreqMhz_config.set('tuner', 'freq', str(self.rfFreqMhz))
     self._cfg_rfFreqMhz_config.write(open(self.configFilePath, 'w'))
     self.CyberRadio_freq_msg_strobe_0.set_fManual(self.rfFreqMhz)
	def __init__(self, u, center_freq, hw_dec_rate, downsample_rate, pulse_width, tari, debug_on, output_data):
		gr.top_block.__init__(self)

		# sample_rate = 100e6 / hw_dec_rate
		sample_rate = 2e6

		self.u = u
		# self.u.set_decim(hw_dec_rate)
		g = u.get_gain_range()
		print "-----------"

		self.u.set_gain(float(g.start() + g.stop()) / 4)
		print "Using gain of", float(g.start() + g.stop()) / 4 , "(", g.stop(), "-", g.start(), ")"
		tune_req = uhd.tune_request_t(center_freq,sample_rate)
		# r = rx.set_center_freq(tune_req)
		x = self.u.set_center_freq(tune_req)
		if not x:
			print "Couldn't set rx freq"
            
		self.u.set_samp_rate(sample_rate)
		us_per_sample = 1e6 / sample_rate * downsample_rate
		print "USRP Sample Rate: "+ str(sample_rate) + " us Per Sample: " + str(us_per_sample)

		# 25 Msps is too much to process. But we don't want to decimate at the USRP because we want the full band.
		# We can downsample, because we don't care about aliasing. 
		self.downsample = gr.keep_one_in_n(gr.sizeof_gr_complex, int(downsample_rate))
		self.to_mag = gr.complex_to_mag()
		
		# For TARI = 24, PW == DELIM. So we can't do a matched filter, or everything becomes a delimiter and a zero.
		# PW / 2 smooths reasonably well.
		# self.smooth = gr.moving_average_ff(int(pulse_width / us_per_sample) /2  , int(pulse_width / us_per_sample) /2 ) 
		self.smooth = gr.moving_average_ff(int(1), 1.0) 
		self.rd = rfid.reader_decoder(us_per_sample, tari)

		if(debug_on):
			# fileInfo = "_smooth1_b"
        	# time = strftime("%H_%M_%S", localtime())
        	# threshFileName = "rm_thresh_" + time + fileInfo + ".out"
        	# signalFileName = "rm_signal_" + time + fileInfo + ".out"

			signalFileName = "rm_signal.out"
			threshFileName = "rm_thresh.out"
			self.sink = gr.file_sink(gr.sizeof_float, threshFileName)
			# self.signal_sink = gr.file_sink(gr.sizeof_float, signalFileName)
			# self.connect(self.smooth, self.signal_sink)
		else:
			self.sink = gr.null_sink(gr.sizeof_float)

		self.connect(self.u, self.downsample, self.to_mag, self.smooth, self.rd, self.sink)

		# Change to "gr.sizeof_gr_complex" if "block_x" is "rx" 
		file_rx_sink = gr.file_sink(gr.sizeof_gr_complex, output_data) 
		self.connect(self.u, file_rx_sink)
Beispiel #5
0
    def set_center_freq(self, fc, lo_off):
        '''
        set the center frequency
        '''
        tune_request = uhd.tune_request_t(fc, lo_off)
        tune_res = self.rx.set_center_freq(tune_request)
        rf_freq = tune_res.actual_rf_freq
        dxc_freq = 0
        print("i: actual_rf_freq = " + str(rf_freq) + 
              "\ni: actual_dsp_freq = " + str(tune_res.actual_dsp_freq) + 
              "\ni: target_rf_freq = " + str(tune_res.target_rf_freq) +
              "\ni: target_dsp_freq = " + str(tune_res.target_dsp_freq))
        
#        return (rf_sink, rf_freq, dxc_freq)

        
Beispiel #6
0
    def __init__(self, p, c, pw, ff, sr, br):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = sr
        self.channel_select = channel_select = c
        self.bit_rate = bit_rate = br

        ##################################################
        # Blocks
        ##################################################
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(
            uhd.tune_request_t(161975000 + 50000 * c, ff), 0)
        self.uhd_usrp_sink_0.set_gain(-10, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
            samples_per_symbol=int(samp_rate / bit_rate),
            bt=0.4,
            verbose=False,
            log=False,
        )
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.9, ))
        self.AISTX_Build_Frame_0 = AISTX.Build_Frame(p, False, True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.AISTX_Build_Frame_0, 0),
                     (self.digital_gmsk_mod_0, 0))
        self.connect((self.digital_gmsk_mod_0, 0),
                     (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0),
                     (self.uhd_usrp_sink_0, 0))
Beispiel #7
0
	def __init__(self, p, c, pw, ff, sr, br):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = sr
		self.channel_select = channel_select = c
		self.bit_rate = bit_rate = br

		##################################################
		# Blocks
		##################################################
		self.uhd_usrp_sink_0 = uhd.usrp_sink(
			device_addr="",
			stream_args=uhd.stream_args(
				cpu_format="fc32",
				channels=range(1),
			),
		)
		self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
		self.uhd_usrp_sink_0.set_center_freq(uhd.tune_request_t(161975000+50000*c,ff), 0)
		self.uhd_usrp_sink_0.set_gain(-10, 0)
		self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
		self.digital_gmsk_mod_0 = digital.gmsk_mod(
			samples_per_symbol=int(samp_rate/bit_rate),
			bt=0.4,
			verbose=False,
			log=False,
		)
		self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((0.9, ))
		self.AISTX_Build_Frame_0 = AISTX.Build_Frame(p, False, True)

		##################################################
		# Connections
		##################################################
		self.connect((self.AISTX_Build_Frame_0, 0), (self.digital_gmsk_mod_0, 0))
		self.connect((self.digital_gmsk_mod_0, 0), (self.blocks_multiply_const_vxx_0, 0))
		self.connect((self.blocks_multiply_const_vxx_0, 0), (self.uhd_usrp_sink_0, 0))
    	def __init__(self):
       		gr.top_block.__init__(self)
		

           
		amplitude = 30000   # 1  2150 10000
		
		rx_out = gr.file_sink(gr.sizeof_gr_complex, "./rx.out")
		

		interp_rate = 128  # tx_samprate = 1M
#		dec_rate = 8       # rx_samprate = 8M

		dec_rate = 16     #16 # rx_samprate = 4M
		sw_dec = 4       #2

#		num_taps = int(64000 / ( (dec_rate * 4) * 40 )) #Filter matched to 1/4 of the 40 kHz tag cycle
		num_taps = int(64000 / ( (dec_rate * 4) * 256 )) #Filter matched to 1/4 of the 256 kHz tag cycle

		taps = [complex(1,1)] * num_taps
		
		matched_filt = gr.fir_filter_ccc(sw_dec, taps);
		  
		to_mag = gr.complex_to_mag()
		center = rfid.center_ff(4)

		mm = rfid.clock_recovery_zc_ff(4,1);
		self.reader = rfid.reader_f(int(128e6/interp_rate)); 
		
		tag_decoder = rfid.tag_decoder_f()

		command_gate = rfid.command_gate_cc(12, 60, 64000000 / dec_rate / sw_dec)
		

	       
	       
		to_complex = gr.float_to_complex()
		amp = gr.multiply_const_ff(amplitude)
		
		##################################################
		# Blocks
		##################################################
		freq = 915e6 #915e6 
		rx_gain = 24 #xjtu

		tx = uhd.usrp_sink(
			device_addr="",
			io_type=uhd.io_type.COMPLEX_FLOAT32,
			num_channels=1,
		)
		
		tx.set_samp_rate(128e6/interp_rate)
		
		p = tx.get_gain_range()
		tx.set_gain(float(p.start() + p.stop()) / 4)

		#r = tx.set_center_freq(freq, 0)	
		t = tx.set_samp_rate(64e6/dec_rate)
		tune_req_tx = uhd.tune_request_t(freq,128e6/interp_rate/2)
		tt = tx.set_center_freq(tune_req_tx)

		rx = uhd.usrp_source(
			options.args,
			io_type=uhd.io_type.COMPLEX_FLOAT32,
			num_channels=1,
		)
		r = rx.set_samp_rate(64e6/dec_rate)
		tune_req = uhd.tune_request_t(freq,64e6/dec_rate)
		x = rx.set_center_freq(tune_req)
		if not x:
            	    print "Couldn't set rx freq"
		#g = rx.get_gain_range()
		rx.set_gain(rx_gain)
		
		print "***************Info******************"
		print "-----tx: get sample rate:"
		print (tx.get_samp_rate())
		print "tx: get freq:"
		print (tx.get_center_freq())	

		print "-----rx.detail"
		print rx.detail()
		print "rx: get samp rate"
		print (rx.get_samp_rate())		
		print "rx: get freq "
		print (rx.get_center_freq())
		print "rx: get gain "
		print (rx.get_gain())		
		print "***************END******************"

		command_gate.set_ctrl_out(self.reader.ctrl_q())
		tag_decoder.set_ctrl_out(self.reader.ctrl_q())

	#########Build Graph
		self.connect(rx, matched_filt)		
		self.connect(matched_filt, command_gate)


		self.connect(command_gate, to_mag)
		#self.connect(command_gate, agc)
		#self.connect(agc, to_mag) 

		self.connect(to_mag, center, mm, tag_decoder)
		#self.connect(to_mag, center, matched_filt_tag_decode, tag_decoder)
		self.connect(tag_decoder, self.reader)
		self.connect(self.reader, amp)	
		self.connect(amp, to_complex)
		self.connect(to_complex, tx)

	#################
		#self.connect(command_gate, commandGate_out)	
		self.connect(rx, rx_out)
Beispiel #9
0
        channels=list(range(0, 2)),
    ),
)

#streamer restart/align
stop_cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_STOP_CONTINUOUS)
stop_cmd.stream_now = True

self.uhd_usrp_source_0.issue_stream_cmd(stop_cmd)

stream_cmd = uhd.stream_cmd_t(uhd.stream_cmd_t.STREAM_MODE_START_CONTINUOUS)
stream_cmd.stream_now = False
#delay by 5s
stream_cmd.time_spec = self.uhd_usrp_source_0.get_time_now() + uhd.time_spec_t(
    5.0)
self.uhd_usrp_source_0.issue_stream_cmd(stream_cmd)

#freq align - potential phase sync
retune_time = self.uhd_usrp_source_0.get_time_now() + uhd.time_spec_t(5.0)
self.uhd_usrp_source_0.set_command_time(retune_time)

center_freq_tmp = 2.4501e9
tune_req = uhd.tune_request_t(center_freq_tmp)
self.uhd_usrp_source_0.set_center_freq(tune_req, 0)
self.uhd_usrp_source_0.set_center_freq(tune_req, 1)

self.uhd_usrp_source_0.clear_command_time()

print("Finished!")
# %%
Beispiel #10
0
def getUhdUSRPSink(fc, lo_off, inter, gain, addr, sync):
    """
    Tx
    def getUhdUSRPSink(fc, inter, gain, addr, sync)
    
    in: 
    - fc = center frequency
    - lo_off = LO off
    - inter = interpolation factor
    - gain = gain in the tx, only with 2450
    - addr = ip address, format = "addr=ip, mimo_mode="
    - sync = if True them sync with external clock
    
    out:
    (usrp2, baseband_freq, dxc_freq)
    - usrp2 sink object
    - baseband_freq
    - dxc_freq
    """
    
    rf_sink = uhd.usrp_sink(addr, uhd.io_type_t.COMPLEX_FLOAT32, 1)
    
    # gain
    gRange = rf_sink.get_gain_range()
    
    if gRange.start() <> gRange.stop():
        rf_sink.set_gain(gain)
        print("i: set_gain = " + str(rf_sink.set_gain()))
    else:
        print("i: this daughterboard not support the set gain behavior")
    
    # samo freq
    rf_sink.set_samp_rate(rf_sink.get_clock_rate()/inter)
    print("i: samp_freq = " + str(rf_sink.get_samp_rate()))
    
    # center freq
    freqRange = rf_sink.get_freq_range()
    
    if float(freqRange.start()) > fc and float(freqRange.stop()) < fc:
        fc = float(freqRange.start()+freqRange.stop())/2
        print("e: fc have to be between [" + str(freqRange.start()) + ", " + str(freqRange.stop()) + "]")
        
        
    tune_request = uhd.tune_request_t(fc, lo_off)
    tune_res = rf_sink.set_center_freq(tune_request)
#    tune_res = rf_sink.set_center_freq(fc)
        
    rf_freq = tune_res.actual_rf_freq
    dxc_freq = 0
    print("i: actual_rf_freq = " + str(rf_freq) + 
          "\ni: actual_dsp_freq = " + str(tune_res.actual_dsp_freq) + 
          "\ni: target_rf_freq = " + str(tune_res.target_rf_freq) +
          "\ni: target_dsp_freq = " + str(tune_res.target_dsp_freq))
    
    # sync
    if type(sync) == type(False) and bool(sync):
#        print "i: sync to pps = " + str(rf_sink.set_time_unknown_pps(uhd.time_spec_t()))
#        print "i: sync to pps = " + str(rf_sink.set_time_next_pps(uhd.time_spec_t()))
       
        # Common references signals
        ccfg = uhd.clock_config_t()
        ccfg.ref_source = uhd.clock_config_t.REF_SMA
        ccfg.pps_source = uhd.clock_config_t.PPS_SMA
        ccfg.pps_polarity = uhd.clock_config_t.PPS_NEG
        
        rf_sink.set_clock_config(ccfg)
        #EO CRS
        
        # sync the device time
#        last_pps_time = rf_sink.get_time_last_pps()
#        while (last_pps_time != rf_sink.get_time_last_pps()):
#            time.sleep(0.1)
            
        rf_sink.set_time_next_pps(uhd.time_spec_t(0.0))
        print("i: sync == True")
        
    else:
        print("i: sync == False")
        
#    time.sleep(2)
    
    return (rf_sink, rf_freq, dxc_freq)
Beispiel #11
0
def getUhdUSRP2Source(fc, lo_off, dec, gain, addr, sync):
    """
    Rx
    def getUhdUSRP2Source(fc, dec, gain, addr, sync):
    
    in: 
    - fc = center frequency
    - dec = decimation factor
    - gain = gain in the tx, only with 2450
    - addr = ip address, format = "addr=ip, mimo_mode="
    - sync = if True them sync with external clock
    
    out:
    (usrp2, baseband_freq, dxc_freq)
    - usrp2 source object
    - baseband_freq
    - dxc_freq
    """
    
    rf_src = uhd.usrp_source(addr, uhd.io_type_t.COMPLEX_FLOAT32, 1)
    
    # gain
    gRange = rf_src.get_gain_range()
    
    if gRange.start() <> gRange.stop():
        rf_src.set_gain(gain)
        print("i: set_gain = " + str(rf_src.get_gain()))
    else:
        print("i: this daughterboard not support the set gain behavior")
    
    # samo freq
    rf_src.set_samp_rate(rf_src.get_clock_rate()/dec)
    print("i: samp_freq = " + str(rf_src.get_samp_rate()))
    
    # center freq
    freqRange = rf_src.get_freq_range()
    
    if float(freqRange.start()) > fc and float(freqRange.stop()) < fc:
        fc = float(freqRange.start()+freqRange.stop())/2
        print("e: fc have to be between [" + str(freqRange.start()) + ", " + str(freqRange.stop()) + "]")
    
    tune_request = uhd.tune_request_t(fc, lo_off)
    tune_res = rf_src.set_center_freq(tune_request)
        
    rf_freq = tune_res.actual_rf_freq
    dxc_freq = 0
    print("i: actual_rf_freq = " + str(rf_freq) + 
          "\ni: actual_dsp_freq = " + str(tune_res.actual_dsp_freq) + 
          "\ni: target_rf_freq = " + str(tune_res.target_rf_freq) +
          "\ni: target_dsp_freq = " + str(tune_res.target_dsp_freq))
    
    # sync
    if type(sync) == type(False) and bool(sync):
##        print "i: sync to pps = " + str(rf_src.set_time_unknown_pps(uhd.time_spec_t()))
##        print "i: sync to pps = " + str(rf_src.set_time_next_pps(uhd.time_spec_t()))
#        print "i: sync to pps = " + str(rf_src.set)
#        rf_src.set_time_next_pps(uhd.time_spec_t(uhd.time_spec_t.get_system_time().get_real_secs()+1))
        
        # Common references signals
        ccfg = uhd.clock_config_t()
        ccfg.ref_source = uhd.clock_config_t.REF_SMA
        ccfg.pps_source = uhd.clock_config_t.PPS_SMA
        ccfg.pps_polarity = uhd.clock_config_t.PPS_NEG
        
        rf_src.set_clock_config(ccfg)
        #EO CRS
        
        # sync the device time
#        last_pps_time = rf_src.get_time_last_pps()
#        while (last_pps_time != rf_src.get_time_last_pps()):
#            time.sleep(0.1)
#        rf_src.set_time_unknown_pps(uhd.time_spec_t(0.0))
        
        rf_src.set_time_next_pps(uhd.time_spec_t(0.0))
        print("i: sync == True")
        
        # EO SDT
    else:
        print("i: sync == False")   
        
#    time.sleep(1)
        
    return (rf_src, rf_freq, dxc_freq)
    
    
#def getUSRP2Sink(fc, inter, gain, eth, sync):
#    """
#    Tx
#    def getUSRP2Sink(fc, inter, gain, eth, sync):
#    
#    in: 
#    - fc = center frequency
#    - inter = interpolation factor
#    - gain = gain in the tx, only with 2450
#    - eth = ethernet interface name(String)
#    - sync = if True them sync with external clock
#    
#    out:
#    (usrp2, baseband_freq, dxc_freq)
#    - usrp2 sink object
#    - baseband_freq
#    - dxc_freq
#    """
#    rf_sink = usrp2.sink_32fc(eth)
#    
#    if rf_sink.gain_max() <> rf_sink.gain_min():
#        print("i: set_gain = " + str(rf_sink.set_gain(gain)))
#    else:
#        print("i: this daughterboard not support the set gain behavior")
#    
#    print("i: set inter = " +str(rf_sink.set_interp(inter)))
#    tune_res = rf_sink.set_center_freq(fc)
#    
#    baseband_freq = tune_res.baseband_freq
#    dxc_freq = tune_res.dxc_freq
#    print("i: set center freq = " + str(baseband_freq) + 
#          "\ni: residual freq = " + str(tune_res.residual_freq) + 
#          "\ni: dxc freq = " + str(dxc_freq))
#    
#    if type(sync) == type(False) and bool(sync):
##        print "i: sync to mimo = " + str(rf_sink.config_mimo(usrp2.MC_WE_LOCK_TO_MIMO))
#        print "i: sync to pps = " + str(rf_sink.sync_to_pps())
#        print "i: sync to ref clock = " + str(rf_sink.config_mimo(usrp2.MC_WE_LOCK_TO_SMA))
#    else:
#        print "i: ref clock don't lock = " + str(rf_sink.config_mimo(usrp2.MC_WE_DONT_LOCK))
#    
#    print("i: samp_freq = " + str(float(rf_sink.dac_rate())/inter))
#    
#    return (rf_sink, baseband_freq, dxc_freq)

#def getUSRP2Source(fc, dec, gain, eth, sync):
#    """
#    Rx
#    def getUSRP2Source(fc, dec, gain, eth, sync):
#    
#    in: 
#    - fc = center frequency
#    - dec = decimation factor
#    - gain = gain in the tx, only with 2450
#    - eth = ethernet interface name(String)
#    - sync = if True them sync with external clock
#    
#    out:
#    (usrp2, baseband_freq, dxc_freq)
#    - usrp2 source object
#    - baseband_freq
#    - dxc_freq
#    """
#    
#    rf_src = usrp2.source_32fc(eth)
#    
#    print("i: set_gain = " + str(rf_src.set_gain(gain)))
#    print("i: set int = " +str(rf_src.set_decim(dec)))
#    tune_res = rf_src.set_center_freq(fc)
#    
#    baseband_freq = tune_res.baseband_freq
#    dxc_freq = tune_res.dxc_freq
#    print("i: set center freq = " + str(baseband_freq) + 
#          "\ni: residual freq = " + str(tune_res.residual_freq) + 
#          "\ni: dxc freq = " + str(dxc_freq))
#    
#    if type(sync) == type(False) and bool(sync):
##        print "i: sync to mimo = " + str(rf_src.config_mimo(usrp2.MC_PROVIDE_CLK_TO_MIMO))
#        print "i: sync to pps = " + str(rf_src.sync_to_pps())
#        print "i: sync to ref clock = " + str(rf_src.config_mimo(usrp2.MC_WE_LOCK_TO_SMA))
#    else:
#        print "i: ref clock don't lock = " + str(rf_src.config_mimo(usrp2.MC_WE_DONT_LOCK))
#    
#    print("i: samp_freq = " + str(float(rf_src.adc_rate())/dec))
#    
#    return (rf_src, baseband_freq, dxc_freq)
        
Beispiel #12
0
            average=False,
            avg_alpha=None,
            title="Frequency Waterfall",
            size=(400, 400),
        )
        self.Add(self.wxgui_waterfallsink2_0_0.win)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            device_addr="",
            stream_args=uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(
            uhd.tune_request_t(161900000, 19000000), 0)
        self.uhd_usrp_sink_0.set_gain(20 if (func_burst_out > 0) else 0, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.source_txtimer_0 = analog.sig_source_i(samp_rate,
                                                    analog.GR_SQR_WAVE,
                                                    doppler_control_freq1, 1,
                                                    0)
        self.source_txtimer = analog.sig_source_i(samp_rate,
                                                  analog.GR_SQR_WAVE,
                                                  doppler_control_freq1 / 4, 1,
                                                  0)

        def _func_burst_out_0_probe():
            while True:
                val = self.probe_burst_0.level()
                try:
Beispiel #13
0
 def set_samp_rate(self, samp_rate):
     self.samp_rate = samp_rate
     self.uhd_usrp_sink_1.set_samp_rate(self.samp_rate)
     self.uhd_usrp_sink_1.set_center_freq(uhd.tune_request_t((self.rfFreqMhz+1)*1e6, 2*self.samp_rate), 0)
     self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate)
Beispiel #14
0
    def __init__(self, radioHostname='192.168.0.20', radioType='ndr364'):
        gr.top_block.__init__(self, "Freq Msg Strobe Test")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Freq Msg Strobe Test")
        qtgui.util.check_set_qss()
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "frq_strobe_test")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Parameters
        ##################################################
        self.radioHostname = radioHostname
        self.radioType = radioType

        ##################################################
        # Variables
        ##################################################
        self.radioObj = radioObj = crd.getRadioObject(radioType, verbose=bool(False), host=radioHostname)
        self.wbddcRateSet = wbddcRateSet = dict( [(k,v) for k,v in radioObj.getWbddcRateSet().iteritems() if radioObj.getDdcDataFormat(True).get(k,"iq")!="real"] )
        self.configFilePath = configFilePath = os.path.expanduser( os.path.join("~",".%s_demo.cfg"%(radioObj.name.lower(),)) )
        self._cfg_wbddcRateIndex_config = ConfigParser.ConfigParser()
        self._cfg_wbddcRateIndex_config.read(configFilePath)
        try: cfg_wbddcRateIndex = self._cfg_wbddcRateIndex_config.getint('wbddc', 'rate_index')
        except: cfg_wbddcRateIndex = sorted(wbddcRateSet.keys())[0]
        self.cfg_wbddcRateIndex = cfg_wbddcRateIndex
        self._cfg_iirAvgExp_config = ConfigParser.ConfigParser()
        self._cfg_iirAvgExp_config.read(configFilePath)
        try: cfg_iirAvgExp = self._cfg_iirAvgExp_config.getint('gui', 'iirAvgExp')
        except: cfg_iirAvgExp = int(3)
        self.cfg_iirAvgExp = cfg_iirAvgExp
        self.wbddcRateIndex = wbddcRateIndex = cfg_wbddcRateIndex
        self.wbddcBwSet = wbddcBwSet = dict( [(k,v) for k,v in radioObj.getWbddcBwSet().iteritems() if radioObj.getDdcDataFormat(True).get(k,"iq")!="real"] )
        self.iirAvgExp = iirAvgExp = cfg_iirAvgExp
        self._cfg_tunerIndex_config = ConfigParser.ConfigParser()
        self._cfg_tunerIndex_config.read(configFilePath)
        try: cfg_tunerIndex = self._cfg_tunerIndex_config.getint('tuner', 'index')
        except: cfg_tunerIndex = radioObj.getTunerIndexRange()[0]
        self.cfg_tunerIndex = cfg_tunerIndex
        self._cfg_tunerAtten_config = ConfigParser.ConfigParser()
        self._cfg_tunerAtten_config.read(configFilePath)
        try: cfg_tunerAtten = self._cfg_tunerAtten_config.getint('tuner', 'atten')
        except: cfg_tunerAtten = int(radioObj.getTunerAttenuationRange()[0])
        self.cfg_tunerAtten = cfg_tunerAtten
        self._cfg_rfFreqMhz_config = ConfigParser.ConfigParser()
        self._cfg_rfFreqMhz_config.read(configFilePath)
        try: cfg_rfFreqMhz = self._cfg_rfFreqMhz_config.getint('tuner', 'freq')
        except: cfg_rfFreqMhz = int(radioObj.getTunerFrequencyRange()[0]/1e6)
        self.cfg_rfFreqMhz = cfg_rfFreqMhz
        self._cfg_refLevel_config = ConfigParser.ConfigParser()
        self._cfg_refLevel_config.read(configFilePath)
        try: cfg_refLevel = self._cfg_refLevel_config.getint('display', 'ref_level')
        except: cfg_refLevel = 0
        self.cfg_refLevel = cfg_refLevel
        self._cfg_dynRange_config = ConfigParser.ConfigParser()
        self._cfg_dynRange_config.read(configFilePath)
        try: cfg_dynRange = self._cfg_dynRange_config.getint('display', 'dyn_range')
        except: cfg_dynRange = 120
        self.cfg_dynRange = cfg_dynRange
        self.wbSampleRate = wbSampleRate = wbddcRateSet[wbddcRateIndex]
        self.wbBw = wbBw = wbddcBwSet[wbddcRateIndex]
        self.udpBasePort = udpBasePort = 0xcafe
        self.tunerIndex = tunerIndex = cfg_tunerIndex
        self.tunerAtten = tunerAtten = cfg_tunerAtten
        self.samp_rate = samp_rate = 10e6
        self.rfFreqMhz = rfFreqMhz = cfg_rfFreqMhz
        self.refLevel = refLevel = cfg_refLevel
        self.pauseScan = pauseScan = False
        self.iirAlpha = iirAlpha = 2.0**(float(-iirAvgExp))
        self.fStep = fStep = 100
        self.f2 = f2 = int(radioObj.getTunerFrequencyRange()[1]/1e6)
        self.f1 = f1 = 100
        self.dynRange = dynRange = cfg_dynRange
        self.dwell = dwell = 0.5

        ##################################################
        # Blocks
        ##################################################
        self.wbTabs = Qt.QTabWidget()
        self.wbTabs_widget_0 = Qt.QWidget()
        self.wbTabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.wbTabs_widget_0)
        self.wbTabs_grid_layout_0 = Qt.QGridLayout()
        self.wbTabs_layout_0.addLayout(self.wbTabs_grid_layout_0)
        self.wbTabs.addTab(self.wbTabs_widget_0, 'Spectrum')
        self.top_grid_layout.addWidget(self.wbTabs, 1,0,1,3)
        self.controlTabs = Qt.QTabWidget()
        self.controlTabs_widget_0 = Qt.QWidget()
        self.controlTabs_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controlTabs_widget_0)
        self.controlTabs_grid_layout_0 = Qt.QGridLayout()
        self.controlTabs_layout_0.addLayout(self.controlTabs_grid_layout_0)
        self.controlTabs.addTab(self.controlTabs_widget_0, 'control')
        self.top_grid_layout.addWidget(self.controlTabs, 0,0,1,1)
        self._wbddcRateIndex_options = sorted(wbddcRateSet.keys())
        self._wbddcRateIndex_labels = ["%d: %ssps"%(k,num_to_str(wbddcRateSet[k])) for k in sorted(wbddcRateSet.keys())]
        self._wbddcRateIndex_tool_bar = Qt.QToolBar(self)
        self._wbddcRateIndex_tool_bar.addWidget(Qt.QLabel('WBDDC Sample Rate'+": "))
        self._wbddcRateIndex_combo_box = Qt.QComboBox()
        self._wbddcRateIndex_tool_bar.addWidget(self._wbddcRateIndex_combo_box)
        for label in self._wbddcRateIndex_labels: self._wbddcRateIndex_combo_box.addItem(label)
        self._wbddcRateIndex_callback = lambda i: Qt.QMetaObject.invokeMethod(self._wbddcRateIndex_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._wbddcRateIndex_options.index(i)))
        self._wbddcRateIndex_callback(self.wbddcRateIndex)
        self._wbddcRateIndex_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_wbddcRateIndex(self._wbddcRateIndex_options[i]))
        self.controlTabs_grid_layout_0.addWidget(self._wbddcRateIndex_tool_bar, 0,1,1,1)
        self._tunerIndex_options = radioObj.getTunerIndexRange()
        self._tunerIndex_labels = map(str, self._tunerIndex_options)
        self._tunerIndex_tool_bar = Qt.QToolBar(self)
        self._tunerIndex_tool_bar.addWidget(Qt.QLabel('Tuner Index'+": "))
        self._tunerIndex_combo_box = Qt.QComboBox()
        self._tunerIndex_tool_bar.addWidget(self._tunerIndex_combo_box)
        for label in self._tunerIndex_labels: self._tunerIndex_combo_box.addItem(label)
        self._tunerIndex_callback = lambda i: Qt.QMetaObject.invokeMethod(self._tunerIndex_combo_box, "setCurrentIndex", Qt.Q_ARG("int", self._tunerIndex_options.index(i)))
        self._tunerIndex_callback(self.tunerIndex)
        self._tunerIndex_combo_box.currentIndexChanged.connect(
        	lambda i: self.set_tunerIndex(self._tunerIndex_options[i]))
        self.controlTabs_grid_layout_0.addWidget(self._tunerIndex_tool_bar, 0,0,1,1)
        self._tunerAtten_range = Range(int(radioObj.getTunerAttenuationRange()[0]), int(radioObj.getTunerAttenuationRange()[1]), int(radioObj.getTunerAttenuationRes()), cfg_tunerAtten, 200)
        self._tunerAtten_win = RangeWidget(self._tunerAtten_range, self.set_tunerAtten, 'Tuner Atten (dB)', "counter", int)
        self.controlTabs_grid_layout_0.addWidget(self._tunerAtten_win, 0,2,1,1)
        self._rfFreqMhz_range = Range(int(radioObj.getTunerFrequencyRange()[0]/1e6), int(radioObj.getTunerFrequencyRange()[1]/1e6), 10, cfg_rfFreqMhz, 200)
        self._rfFreqMhz_win = RangeWidget(self._rfFreqMhz_range, self.set_rfFreqMhz, 'Tuner Freq (MHz)', "counter_slider", int)
        self.controlTabs_grid_layout_0.addWidget(self._rfFreqMhz_win, 0,3,1,2)
        self._refLevel_range = Range(-120, +10, 5, cfg_refLevel, (130/5)+1)
        self._refLevel_win = RangeWidget(self._refLevel_range, self.set_refLevel, "Ref.\nLevel\n(dB)", "dial", int)
        self.wbTabs_grid_layout_0.addWidget(self._refLevel_win, 0,1,1,1)
        self._pauseScan_options = (False, True, )
        self._pauseScan_labels = ('Run', 'Pause', )
        self._pauseScan_group_box = Qt.QGroupBox('Scan')
        self._pauseScan_box = Qt.QHBoxLayout()
        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)
            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)
        self._pauseScan_button_group = variable_chooser_button_group()
        self._pauseScan_group_box.setLayout(self._pauseScan_box)
        for i, label in enumerate(self._pauseScan_labels):
        	radio_button = Qt.QRadioButton(label)
        	self._pauseScan_box.addWidget(radio_button)
        	self._pauseScan_button_group.addButton(radio_button, i)
        self._pauseScan_callback = lambda i: Qt.QMetaObject.invokeMethod(self._pauseScan_button_group, "updateButtonChecked", Qt.Q_ARG("int", self._pauseScan_options.index(i)))
        self._pauseScan_callback(self.pauseScan)
        self._pauseScan_button_group.buttonClicked[int].connect(
        	lambda i: self.set_pauseScan(self._pauseScan_options[i]))
        self.controlTabs_grid_layout_0.addWidget(self._pauseScan_group_box, 1,0,1,1)
        self._fStep_range = Range(1, 1000, 10, 100, 200)
        self._fStep_win = RangeWidget(self._fStep_range, self.set_fStep, 'Step (MHz)', "counter", float)
        self.controlTabs_grid_layout_0.addWidget(self._fStep_win, 1,3,1,1)
        self._f2_range = Range(int(radioObj.getTunerFrequencyRange()[0]/1e6), int(radioObj.getTunerFrequencyRange()[1]/1e6), 10, int(radioObj.getTunerFrequencyRange()[1]/1e6), 200)
        self._f2_win = RangeWidget(self._f2_range, self.set_f2, 'f2 (MHz)', "counter", float)
        self.controlTabs_grid_layout_0.addWidget(self._f2_win, 1,2,1,1)
        self._f1_range = Range(int(radioObj.getTunerFrequencyRange()[0]/1e6), int(radioObj.getTunerFrequencyRange()[1]/1e6), 10, 100, 200)
        self._f1_win = RangeWidget(self._f1_range, self.set_f1, 'f1 (MHz)', "counter", float)
        self.controlTabs_grid_layout_0.addWidget(self._f1_win, 1,1,1,1)
        self._dynRange_range = Range(5, 200, 5, cfg_dynRange, (195/5)+1)
        self._dynRange_win = RangeWidget(self._dynRange_range, self.set_dynRange, "Dyn.\nRange\n(dB)", "dial", int)
        self.wbTabs_grid_layout_0.addWidget(self._dynRange_win, 1,1,1,1)
        self._dwell_range = Range(0.001, 10.0, 0.1, 0.5, 200)
        self._dwell_win = RangeWidget(self._dwell_range, self.set_dwell, 'dwell', "counter", float)
        self.controlTabs_grid_layout_0.addWidget(self._dwell_win, 1,4,1,1)
        self.z_tunerControl = CyberRadio.generic_tuner_control_block(
                    radioObj,
                    tunerIndex,
                    True,
                    1000,
                    tunerAtten,
                    1,
                    None,
                    {},
                    False
                     )
        self.y_ddcControl = CyberRadio.generic_ddc_control_block(
                    radioObj,
                    tunerIndex,
                    True,
                    True,
                    wbddcRateIndex,
                    0,
                    0,
                    tunerIndex,
                    0,
                    -1,
                    -1,
                    '',
                    udpBasePort,
                    {},
                    True
                     )
        self.uhd_usrp_sink_1 = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		otw_format='sc8',
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_1.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_1.set_center_freq(uhd.tune_request_t((rfFreqMhz+1)*1e6, 2*samp_rate), 0)
        self.uhd_usrp_sink_1.set_gain(20, 0)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	4096, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	wbSampleRate, #bw
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(1.0/32)
        self.qtgui_freq_sink_x_0.set_y_axis(refLevel-dynRange, refLevel)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.2)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)

        if not False:
          self.qtgui_freq_sink_x_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)

        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.wbTabs_grid_layout_0.addWidget(self._qtgui_freq_sink_x_0_win, 0,0,3,1)
        self._iirAvgExp_range = Range(0, 8, 1, cfg_iirAvgExp, 200)
        self._iirAvgExp_win = RangeWidget(self._iirAvgExp_range, self.set_iirAvgExp, 'Avg.', "dial", int)
        self.wbTabs_grid_layout_0.addWidget(self._iirAvgExp_win, 2,1,1,1)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, radioObj.getVitaPayloadSize()/4)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((0.7, ))
        self.blocks_message_debug_1 = blocks.message_debug()
        self.analog_sig_source_x_0 = analog.sig_source_f(samp_rate, analog.GR_SIN_WAVE, 0.1, 1, 0)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(1)
        self.CyberRadio_zero_copy_source_0 = CyberRadio.zero_copy_source(
              '255.255.255.255', udpBasePort,
              1, radioObj.getVitaHeaderSize(), radioObj.getVitaPayloadSize()/4,
              radioObj.isByteswapped(), radioObj.isIqSwapped(),
              "ip proto 17 and ip dst 255.255.255.255 and udp dst port %d"%(udpBasePort,), True,
               )
        self.CyberRadio_generic_group_control_block_0 = CyberRadio.generic_group_control_block(
                  radioObj,
                  0,
                  False,
                  True,
                  ([0,1,2,3,]),
                  {},
                  False,
                   )
        self.CyberRadio_freq_msg_strobe_0 = CyberRadio.freq_msg_strobe(
              pause = bool(pauseScan),
              f1 = f1,
              f2 = f2,
              step = fStep,
              dwell = dwell,
              wrap = True,
              fManual = rfFreqMhz,
              msgUnits = 1.0,
              msgRes = 1.0e6,
              debug = False,
               )

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.CyberRadio_freq_msg_strobe_0, 'freq'), (self.uhd_usrp_sink_1, 'command'))
        self.msg_connect((self.CyberRadio_freq_msg_strobe_0, 'freq'), (self.z_tunerControl, 'freq'))
        self.msg_connect((self.y_ddcControl, 'status'), (self.blocks_message_debug_1, 'print'))
        self.msg_connect((self.z_tunerControl, 'freq'), (self.qtgui_freq_sink_x_0, 'freq'))
        self.connect((self.CyberRadio_zero_copy_source_0, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.uhd_usrp_sink_1, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.qtgui_freq_sink_x_0, 0))