def detect_usrp1(): for i in range(3): try: u = usrp.source_c(i) print "\033[1;31mUSRP found, serial:", u.serial_number(), "\033[1;m" a = usrp.selected_subdev(u, (0,0)) if(a.dbid()!=-1): print "\033[1;33mSide A, RX:", a.name(), "(dbid: 0x%04X)" % (a.dbid()), "\033[1;m" print "freq range: (", a.freq_min()/1e6, "MHz, ", a.freq_max()/1e6, "MHz )" print "gain rainge: (", a.gain_min(), "dB, ", a.gain_max(), "dB )" b = usrp.selected_subdev(u, (1,0)) if(b.dbid()!=-1): print "\033[1;33mSide B, RX:", b.name(), "(dbid: 0x%04X)" % (b.dbid()), "\033[1;m" print "freq range: (", b.freq_min()/1e6, "MHz, ", b.freq_max()/1e6, "MHz )" print "gain rainge: (", b.gain_min(), "dB, ", b.gain_max(), "dB )" u = usrp.sink_c(i) a = usrp.selected_subdev(u, (0,0)) if(a.dbid()!=-1): print "\033[1;33mSide A, TX:", a.name(), "(dbid: 0x%04X)" % (a.dbid()), "\033[1;m" print "freq range: (", a.freq_min()/1e6, "MHz, ", a.freq_max()/1e6, "MHz )" print "gain rainge: (", a.gain_min(), "dB, ", a.gain_max(), "dB )" b = usrp.selected_subdev(u, (1,0)) if(b.dbid()!=-1): print "\033[1;33mSide B, TX:", b.name(), "(dbid: 0x%04X)" % (b.dbid()), "\033[1;m" print "freq range: (", b.freq_min()/1e6, "MHz, ", b.freq_max()/1e6, "MHz )" print "gain rainge: (", b.gain_min(), "dB, ", b.gain_max(), "dB )" except: if(i==0): print "\033[1;31mno USRPs found" break
def _setup_usrp_sink(self): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ self.u = usrp.sink_c(fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if self._tx_subdev_spec is None: self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, self._tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec) # 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 # Set the USRP for maximum transmit gain # (Note that on the RFX cards this is a nop.) self.set_gain(self.subdev.gain_range()[1]) # enable Auto Transmit/Receive switching self.set_auto_tr(True)
def __init__(self, options, usrp_rate, usrp_interp, tari_rate): gr.hier_block2.__init__(self, "downlink_usrp_sink", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) self.u = usrp.sink_c() #setup daughter boards #subdev_spec = usrp.pick_tx_subdevice(self.u) subdev_spec = (1, 0) self.subdev = usrp.selected_subdev(self.u, subdev_spec) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) print "Using TX d'board %s" % (self.subdev.side_and_name(), ) #set interp rate self.u.set_interp_rate(usrp_interp) self.subdev.set_gain(self.subdev.gain_range()[2]) #setup frequency if not self.set_freq(options.freq): freq_range = self.subdev.freq_range() print "Failed to set frequency to %s. Daughterboard supports %s to %s" % ( eng_notation.num_to_str( options.freq), eng_notation.num_to_str( freq_range[0]), eng_notation.num_to_str(freq_range[1])) raise SystemExit self.subdev.set_enable(True) self.connect(self, self.u)
def __init__(self, usrp_offset): gr.flow_graph.__init__(self) print "decim = %d, gain = %d, offset = %.2f" % (decim, gain, usrp_offset) print "filter center %.2f, filter width %.2f" % (xcf, xtw) u = usrp.source_c(decim_rate=decim) s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,)) u.set_mux(usrp.determine_rx_mux_value(u, s)) subdev = usrp.selected_subdev(u, s) if subdev.dbid() != usrp_dbid.DBS_RX: raise Exception("dbs daughterboard not detected!") subdev.set_gain(gain) sps = u.adc_freq() / u.decim_rate() if sps < 2 * gsm_rate: raise Exception("sample rate too low") u.tune(0, subdev, c0 + usrp_offset) xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING) xf = gr.fir_filter_ccf(1, xt) self.gs = gs = gssm.sink(sps) self.connect(u, xf, gs)
def __init__(self, options): gr.flow_graph.__init__(self) self.normal_gain = 8000 self.u = usrp.sink_c() dac_rate = self.u.dac_rate(); self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec) print "Using TX d'board %s" % (self.subdev.side_and_name(),) self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx) self.u.set_pga(0, options.gain) self.u.set_pga(1, options.gain) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc (self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def __set_rx_from_usrp(self, subdev_spec, decimation_rate, gain, frequency, preserve): from gnuradio import usrp # setup USRP self.usrp.set_decim_rate(decimation_rate) if subdev_spec is None: subdev_spec = usrp.pick_rx_subdevice(self.usrp) self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, subdev_spec)) subdev = usrp.selected_subdev(self.usrp, subdev_spec) capture_rate = self.usrp.adc_freq() / self.usrp.decim_rate() self.info["capture-rate"] = capture_rate if gain is None: g = subdev.gain_range() gain = float(g[0]+g[1])/2 subdev.set_gain(gain) r = self.usrp.tune(0, subdev, frequency) if not r: raise RuntimeError("failed to set USRP frequency") # capture file if preserve: try: self.capture_filename = os.tmpnam() except RuntimeWarning: ignore = True capture_file = gr.file_sink(gr.sizeof_gr_complex, self.capture_filename) self.__connect([[self.usrp, capture_file]]) else: self.capture_filename = None # everything else self.__build_graph(self.usrp, capture_rate)
def __init__(self, N, fs): gr.hier_block2.__init__(self, "usrp_source", gr.io_signature(0,0,0), gr.io_signature(1,1, gr.sizeof_gr_complex)) # Parameters. frequency = 1575.6e6 decim_rate = int(64e6/fs) fpga_filename = "std_4rx_0tx.rbf" # Sources. usrp = usrp.source_c( decim_rate=decim_rate, fpga_filename=fpga_filename ) head = gr.head( gr.sizeof_gr_complex, N*fs*1e-3 ) self.connect( usrp, head, self ) # USRP settings. rx_subdev_spec = usrp.pick_rx_subdevice(usrp) usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec)) subdev = usrp.selected_subdev( usrp, rx_subdev_spec ) print "Subdev gain range: " print subdev.gain_range() subdev.set_gain(70) r = usrp.tune( 0,_subdev, frequency ) if not r: sys.exit('Failed to set frequency')
def __init__(self, usrp_offset): gr.top_block.__init__(self) u = usrp.source_c(decim_rate = decim) s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX,)) u.set_mux(usrp.determine_rx_mux_value(u, s)) subdev = usrp.selected_subdev(u, s) if subdev.dbid() != usrp_dbid.DBS_RX: raise Exception('dbs daughterboard not detected!') subdev.set_gain(gain) sps = u.adc_freq() / u.decim_rate() if sps < 2 * gsm_rate: raise Exception('sample rate too low') u.tune(0, subdev, c0 + usrp_offset) xcf = 150e3 xtw = 50e3 xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING) xf = gr.fir_filter_ccf(1, xt) g = gssm.sink(sps) self.connect(u, xf, g)
def __init__(self): gr.top_block.__init__ (self) self.u = usrp.source_c(0, usrp_decim) print "USRP Serial: ", self.u.serial_number() usrp_rate = self.u.adc_rate() / usrp_decim # 256 kS/s rx_subdev_spec = usrp.pick_subdev(self.u, dblist) self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec) print "Using d'board", self.subdev.side_and_name() self.gain = self.subdev.gain_range()[1] self.subdev.set_gain(self.gain) r = usrp.tune(self.u, 0, self.subdev, freq) if r: print "Freq: ", freq/1e6, "MHz" else: print "Failed to set frequency, quitting!" sys.exit(1) chan_filter_coeffs = gr.firdes.low_pass( 1.0, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 35e3, # transition width gr.firdes.WIN_HAMMING) self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs) print "# channel filter:", len(chan_filter_coeffs), "taps" self.file_sink = gr.file_sink(gr.sizeof_gr_complex*1, "/home/sdr/rds_samples.dat") self.connect(self.u, self.chan_filter, self.file_sink)
def _setup_usrp_sink(self): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ self.tx_u = usrp.sink_c(fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) self.tx_u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if self._tx_subdev_spec is None: print 'tx subdev not set' self._tx_subdev_spec = usrp.pick_tx_subdevice(self.tx_u) self.tx_u.set_mux( usrp.determine_tx_mux_value(self.tx_u, self._tx_subdev_spec)) self.tx_subdev = usrp.selected_subdev(self.tx_u, self._tx_subdev_spec) # Set center frequency of USRP ok = self.tx_u.tune(1, self.tx_subdev, self._tx_freq) if not ok: print "Failed to set Tx frequency to %s" % ( eng_notation.num_to_str(self._tx_freq), ) raise ValueError # enable Auto Transmit/Receive switching self.tx_subdev.set_auto_tr(True)
def _set_source(self): options = self.options fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) self.usrp = usrp.source_c(decim_rate=options.decim, fusb_block_size=fusb_block_size, fusb_nblocks=fusb_nblocks) if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(self.usrp) self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, options.rx_subdev_spec)) # determine the daughterboard subdevice self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_spec) print "Using Rx d'board %s" % (self.subdev.side_and_name(),) input_rate = self.usrp.adc_freq() / self.usrp.decim_rate() print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 r = self.usrp.tune(0, self.subdev, options.freq) self.subdev.set_gain(options.gain) return self.usrp
def configure_cc2420(self): self.disconnect_all() gain = 0 cordic_freq = 2415000000 self.normal_gain = 8000 dac_rate = self.u.dac_rate() self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using self.u.set_mux(usrp.determine_tx_mux_value(self.u, (0, 0))) self.subdev = usrp.selected_subdev(self.u, (0, 0)) print "Using TX d'board %s" % (self.subdev.side_and_name(), ) self.u.tune(self.subdev._which, self.subdev, cordic_freq) self.u.set_pga(0, gain) self.u.set_pga(1, gain) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts( self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc(self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'rx_test.dat') #self.connect(self.gain, self.filesink) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def _setup_usrp_sink(self): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ self.tx_u = usrp.sink_c(fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) self.tx_u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if self._tx_subdev_spec is None: print 'tx subdev not set' self._tx_subdev_spec = usrp.pick_tx_subdevice(self.tx_u) self.tx_u.set_mux(usrp.determine_tx_mux_value(self.tx_u, self._tx_subdev_spec)) self.tx_subdev = usrp.selected_subdev(self.tx_u, self._tx_subdev_spec) # Set center frequency of USRP ok = self.tx_u.tune(1, self.tx_subdev, self._tx_freq) if not ok: print "Failed to set Tx frequency to %s" % (eng_notation.num_to_str(self._tx_freq),) raise ValueError # enable Auto Transmit/Receive switching self.tx_subdev.set_auto_tr(True)
def _set_source(self): options = self.options fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) self.usrp = usrp.source_c(decim_rate=options.decim, fusb_block_size=fusb_block_size, fusb_nblocks=fusb_nblocks) if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(self.usrp) self.usrp.set_mux( usrp.determine_rx_mux_value(self.usrp, options.rx_subdev_spec)) # determine the daughterboard subdevice self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_spec) print "Using Rx d'board %s" % (self.subdev.side_and_name(), ) input_rate = self.usrp.adc_freq() / self.usrp.decim_rate() print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 r = self.usrp.tune(0, self.subdev, options.freq) self.subdev.set_gain(options.gain) return self.usrp
def __init__(self): gr.top_block.__init__(self) self.frequency = 13.56e6 self.gain = 100 self.usrp_interpol = 32 # USRP settings self.u_tx = usrp.sink_c() #create the USRP sink for TX #try and set the LF_RX for this self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #set the interpolation rate to match the USRP's 128 MS/s self.u_tx.set_interp_rate(self.usrp_interpol) #Configure the MUX for the daughterboard self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec)) #Tell it to use the LF_TX self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec) #Make sure it worked print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),) #Set gain.. duh self.subdev_tx.set_gain(self.gain) #Tune the center frequency self.u_tx.tune(0, self.subdev_tx, self.frequency) self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", False) self.conv = gr.float_to_complex() self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0)) self.connect(self.src, self.conv, self.amp, self.u_tx)
def __init__( self, decim ): self.freq = -2.5e6 self.src = usrp.source_c( ) self.subdev = usrp.pick_subdev( self.src, (usrp_dbid.BASIC_RX, usrp_dbid.TV_RX, usrp_dbid.TV_RX_REV_2, usrp_dbid.TV_RX_REV_3, usrp_dbid.TV_RX_MIMO, usrp_dbid.TV_RX_REV_2_MIMO, usrp_dbid.TV_RX_REV_3_MIMO)) print self.subdev self.subdevice = usrp.selected_subdev( self.src, self.subdev ) self.mux = usrp.determine_rx_mux_value( self.src, self.subdev ) self.decim = decim self.adc_rate = self.src.adc_rate() self.usrp_rate = self.adc_rate / self.decim self.src.set_decim_rate( self.decim ) self.src.set_mux( self.mux ) usrp.tune( self.src, 0, self.subdevice, self.freq )
def configure_cc2420(self): self.disconnect_all() gain = 0 cordic_freq = 2415000000 self.normal_gain = 8000 dac_rate = self.u.dac_rate(); self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using self.u.set_mux(usrp.determine_tx_mux_value(self.u, (0, 0))) self.subdev = usrp.selected_subdev(self.u, (0, 0)) print "Using TX d'board %s" % (self.subdev.side_and_name(),) self.u.tune(self.subdev._which, self.subdev, cordic_freq) self.u.set_pga(0, gain) self.u.set_pga(1, gain) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc (self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) #self.filesink = gr.file_sink(gr.sizeof_gr_complex, 'rx_test.dat') #self.connect(self.gain, self.filesink) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def __init__(self,subdev_spec=None,gain=None,length=1,alpha=1.0,msgq=None,loopback=False,verbose=False,debug=False): self._subdev_spec = subdev_spec self._gain = gain self._length = length self._alpha = alpha self._msgq = msgq self._loopback = loopback self._verbose = verbose self._debug = debug self._fg = gr.flow_graph() self._u = usrp.source_c(fpga_filename='usrp_sounder.rbf') if not self._loopback: if self._subdev_spec == None: self._subdev_spec = pick_subdevice(self._u) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) if self._verbose: print "Using", self._subdev.name(), "for sounder receiver." self.set_gain(self._gain) self._vblen = gr.sizeof_gr_complex*self._length if self._debug: print "Generating impulse vectors of length", self._length, "byte length", self._vblen self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length) if self._verbose: print "Using smoothing alpha of", self._alpha self._lpf = gr.single_pole_iir_filter_cc(self._alpha, self._length) self._sink = gr.message_sink(self._vblen, self._msgq, True) self._fg.connect(self._u, self._s2v, self._lpf, self._sink)
def __init__(self): gr.top_block.__init__(self) self.frequency = 13.56e6 self.gain = 100 # for 4 MS/s, 32 # self.usrp_interpol = 32 # USRP settings self.u_tx = usrp.sink_c() #create the USRP sink for TX #try and set the LF_RX for this self.tx_subdev_spec = usrp.pick_subdev(self.u_tx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #set the interpolation rate to match the USRP's 128 MS/s self.u_tx.set_interp_rate(self.usrp_interpol) #Configure the MUX for the daughterboard self.u_tx.set_mux(usrp.determine_tx_mux_value(self.u_tx, self.tx_subdev_spec)) #Tell it to use the LF_TX self.subdev_tx = usrp.selected_subdev(self.u_tx, self.tx_subdev_spec) #Make sure it worked print "Using TX dboard %s" % (self.subdev_tx.side_and_name(),) #Set gain.. duh self.subdev_tx.set_gain(self.gain) #Tune the center frequency self.u_tx.tune(0, self.subdev_tx, self.frequency) # self.src = gr.wavfile_source("RFID_command_52_4M_1610.wav", True) self.src = gr.wavfile_source("wave52.wav", True) self.conv = gr.float_to_complex() self.amp = gr.multiply_const_cc(10.0 ** (self.gain / 20.0)) self.connect(self.src, self.conv, self.amp, self.u_tx)
def _setup_usrp_source(self): self.rx_u = usrp.source_c (fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) adc_rate = self.rx_u.adc_rate() self.rx_u.set_decim_rate(self._decim) # determine the daughterboard subdevice we're using if self._rx_subdev_spec is None: print 'not set rx subdev' self._rx_subdev_spec = usrp.pick_rx_subdevice(self.rx_u) print self._rx_subdev_spec self.rx_subdev = usrp.selected_subdev(self.rx_u, self._rx_subdev_spec) gains = self.rx_subdev.gain_range() self.rx_subdev.set_gain((gains[0]+gains[1])/2) self.rx_u.set_mux(usrp.determine_rx_mux_value(self.rx_u, self._rx_subdev_spec)) print 'subdev size %d' % self.rx_subdev.which() ok = self.rx_u.tune(0, self.rx_subdev, self._rx_freq) if not ok: print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(self._rx_freq),) raise ValueError self.rx_subdev.set_auto_tr(True)
def __init__(self, N, fs): gr.hier_block2.__init__(self, "usrp_source", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Parameters. frequency = 1575.6e6 decim_rate = int(64e6 / fs) fpga_filename = "std_4rx_0tx.rbf" # Sources. usrp = usrp.source_c(decim_rate=decim_rate, fpga_filename=fpga_filename) head = gr.head(gr.sizeof_gr_complex, N * fs * 1e-3) self.connect(usrp, head, self) # USRP settings. rx_subdev_spec = usrp.pick_rx_subdevice(usrp) usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec)) subdev = usrp.selected_subdev(usrp, rx_subdev_spec) print "Subdev gain range: " print subdev.gain_range() subdev.set_gain(70) r = usrp.tune(0, _subdev, frequency) if not r: sys.exit('Failed to set frequency')
def __init__(self, options): gr.flow_graph.__init__(self) self.normal_gain = 8000 self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux( usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec) print "Using TX d'board %s" % (self.subdev.side_and_name(), ) self.u.tune(self.subdev._which, self.subdev, options.cordic_freq_tx) self.u.set_pga(0, options.gain) self.u.set_pga(1, options.gain) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts( self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc(self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def _setup_usrp_source(self): self.rx_u = usrp.source_c(fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) adc_rate = self.rx_u.adc_rate() self.rx_u.set_decim_rate(self._decim) # determine the daughterboard subdevice we're using if self._rx_subdev_spec is None: print 'not set rx subdev' self._rx_subdev_spec = usrp.pick_rx_subdevice(self.rx_u) print self._rx_subdev_spec self.rx_subdev = usrp.selected_subdev(self.rx_u, self._rx_subdev_spec) gains = self.rx_subdev.gain_range() self.rx_subdev.set_gain((gains[0] + gains[1]) / 2) self.rx_u.set_mux( usrp.determine_rx_mux_value(self.rx_u, self._rx_subdev_spec)) print 'subdev size %d' % self.rx_subdev.which() ok = self.rx_u.tune(0, self.rx_subdev, self._rx_freq) if not ok: print "Failed to set Rx frequency to %s" % ( eng_notation.num_to_str(self._rx_freq), ) raise ValueError self.rx_subdev.set_auto_tr(True)
def setup_usrp(freq, gain): ######## set up usrp u = usrp.source_c(decim_rate=32) # 2M sampling freq rx_subdev_spec = usrp.pick_rx_subdevice(u) #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid() #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid() #print "rx_subdev_spec = ", options.rx_subdev_spec mux = usrp.determine_rx_mux_value(u, rx_subdev_spec) #print "mux = ", mux u.set_mux(mux) # determine the daughterboard subdevice we're using subdev = usrp.selected_subdev(u, rx_subdev_spec) #print "Using RX d'board %s" % (self.subdev.side_and_name(),) input_rate = u.adc_freq() / u.decim_rate() #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq()) #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) subdev.set_gain(gain) r = u.tune(0, subdev, freq) #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max())) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 return u
def __init__(self): gr.top_block.__init__(self) self.normal_gain = 8000 self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) self.picksubdev = pick_subdevice(self.u) #self.u.set_mux(usrp.determine_rx_mux_value(self.u, self.picksubdev)) self.subdev = usrp.selected_subdev(self.u, pick_subdevice(self.u)) print "Using TX d'board %s" % (self.subdev.side_and_name()) #self.u.tune(0, self.subdev, 2475000000) #self.u.tune(0, self.subdev, 2480000000) self.u.tune(0, self.subdev, 2425000000) self.u.set_pga(0, 0) self.u.set_pga(1, 0) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts(self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc (self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def _setup_usrp_sink(self): """ Creates a USRP sink, determines the settings for best bitrate, and attaches to the transmitter's subdevice. """ self.u = usrp.sink_c(fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if self._tx_subdev_spec is None: self._tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux( usrp.determine_tx_mux_value(self.u, self._tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, self._tx_subdev_spec) # 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 # Set the USRP for maximum transmit gain # (Note that on the RFX cards this is a nop.) self.set_gain(self.subdev.gain_range()[1]) # enable Auto Transmit/Receive switching self.set_auto_tr(True)
def __init__(self, usrp_offset): gr.top_block.__init__(self) u = usrp.source_c(decim_rate=decim) s = usrp.pick_subdev(u, (usrp_dbid.DBS_RX, )) u.set_mux(usrp.determine_rx_mux_value(u, s)) subdev = usrp.selected_subdev(u, s) if subdev.dbid() != usrp_dbid.DBS_RX: raise Exception('dbs daughterboard not detected!') subdev.set_gain(gain) sps = u.adc_freq() / u.decim_rate() if sps < 2 * gsm_rate: raise Exception('sample rate too low') u.tune(0, subdev, c0 + usrp_offset) xcf = 150e3 xtw = 50e3 xt = gr.firdes.low_pass(1.0, sps, xcf, xtw, gr.firdes.WIN_HAMMING) xf = gr.fir_filter_ccf(1, xt) g = gssm.sink(sps) self.connect(u, xf, g)
def __init__(self, options, args, queue): gr.top_block.__init__(self) self.options = options self.args = args self.u = usrp.source_c(which=0, decim_rate=self.options.decim) if self.options.rx_subdev_spec is None: self.options.rx_subdev_spec = pick_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, self.options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, self.options.rx_subdev_spec) if options.gain is None: # Select a gain in the middle of the range g = self.subdev.gain_range() options.gain = float(g[0]+g[1])/2 self.subdev.set_gain(options.gain) r = self.u.tune(0, self.subdev, options.freq) if_rate = self.u.adc_freq() / self.u.decim_rate() self.mode_s = ppm_demod(if_rate, options.thresh) pass_all = 0 if options.output_all: pass_all = 1 self.format = air.ms_fmt_log(pass_all, queue) self.connect(self.u, self.mode_s, self.format)
def __set_rx_from_usrp(self, subdev_spec, decimation_rate, gain, frequency, preserve): from gnuradio import usrp # setup USRP self.usrp.set_decim_rate(decimation_rate) if subdev_spec is None: subdev_spec = usrp.pick_rx_subdevice(self.usrp) self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, subdev_spec)) subdev = usrp.selected_subdev(self.usrp, subdev_spec) capture_rate = self.usrp.adc_freq() / self.usrp.decim_rate() self.info["capture-rate"] = capture_rate if gain is None: g = subdev.gain_range() gain = float(g[0] + g[1]) / 2 subdev.set_gain(gain) r = self.usrp.tune(0, subdev, frequency) if not r: raise RuntimeError("failed to set USRP frequency") # capture file if preserve: try: self.capture_filename = os.tmpnam() except RuntimeWarning: ignore = True capture_file = gr.file_sink(gr.sizeof_gr_complex, self.capture_filename) self.__connect([[self.usrp, capture_file]]) else: self.capture_filename = None # everything else self.__build_graph(self.usrp, capture_rate)
def _setup_usrp_source(self, options): #create USRP self._usrp = usrp.source_c(which= options.which, decim_rate = options.decim_rate) if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(self._usrp) self._subdev = usrp.selected_subdev(self._usrp, options.rx_subdev_spec) adc_rate = self._usrp.adc_rate() mux = usrp.determine_rx_mux_value(self._usrp, options.rx_subdev_spec) self._usrp.set_mux(mux) tr = self._usrp.tune(0, self._subdev, options.freq) if not (tr): print "Failed to tune to center frequency!" else: print "Center frequency:", n2s(options.freq) if options.gain is None: g = self._subdev.gain_range(); options.gain = float(g[0]+g[1])/2.0 self._subdev.set_gain(options.gain) #the bitrate option is initialised to value self.rs_rate = options.rate #Hard initialisation of bits per symbol self.bits_per_symbol = 1 if options.verbose: print "USRP source:", self._usrp print "Decimation:", options.decim_rate
def __init__(self): gr.top_block.__init__(self) self.normal_gain = 8000 self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self._data_rate = 2000000 self._spb = 2 self._interp = int(128e6 / self._spb / self._data_rate) self.fs = 128e6 / self._interp self.u.set_interp_rate(self._interp) self.picksubdev = pick_subdevice(self.u) #self.u.set_mux(usrp.determine_rx_mux_value(self.u, self.picksubdev)) self.subdev = usrp.selected_subdev(self.u, pick_subdevice(self.u)) print "Using TX d'board %s" % (self.subdev.side_and_name()) #self.u.tune(0, self.subdev, 2475000000) #self.u.tune(0, self.subdev, 2480000000) self.u.tune(0, self.subdev, 2425000000) self.u.set_pga(0, 0) self.u.set_pga(1, 0) # transmitter self.packet_transmitter = ieee802_15_4_pkt.ieee802_15_4_mod_pkts( self, spb=self._spb, msgq_limit=2) self.gain = gr.multiply_const_cc(self.normal_gain) self.connect(self.packet_transmitter, self.gain, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def setup_usrp(freq, gain): ######## set up usrp u = usrp.source_c(decim_rate=32) # 2M sampling freq rx_subdev_spec = usrp.pick_rx_subdevice(u) #print "u.db(0,0).dbid() = ", self.u.db(0,0).dbid() #print "u.db(1,0).dbid() = ", self.u.db(1,0).dbid() #print "rx_subdev_spec = ", options.rx_subdev_spec mux=usrp.determine_rx_mux_value(u, rx_subdev_spec) #print "mux = ", mux u.set_mux(mux) # determine the daughterboard subdevice we're using subdev = usrp.selected_subdev(u, rx_subdev_spec) #print "Using RX d'board %s" % (self.subdev.side_and_name(),) input_rate = u.adc_freq() / u.decim_rate() #print "ADC sampling @ ", eng_notation.num_to_str(self.u.adc_freq()) #print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) subdev.set_gain(gain) r = u.tune(0, subdev, freq) #print "freq range = [%s, %s]" % (eng_notation.num_to_str(self.subdev.freq_min()), eng_notation.num_to_str(self.subdev.freq_max())) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 return u
def __init__(self): gr.top_block.__init__(self) self.u = usrp.source_c(0, usrp_decim) print "USRP Serial: ", self.u.serial_number() usrp_rate = self.u.adc_rate() / usrp_decim # 256 kS/s rx_subdev_spec = usrp.pick_subdev(self.u, dblist) self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec) print "Using d'board", self.subdev.side_and_name() self.gain = self.subdev.gain_range()[1] self.subdev.set_gain(self.gain) r = usrp.tune(self.u, 0, self.subdev, freq) if r: print "Freq: ", freq / 1e6, "MHz" else: print "Failed to set frequency, quitting!" sys.exit(1) chan_filter_coeffs = gr.firdes.low_pass( 1.0, # gain usrp_rate, # sampling rate 80e3, # passband cutoff 35e3, # transition width gr.firdes.WIN_HAMMING) self.chan_filter = gr.fir_filter_ccf(1, chan_filter_coeffs) print "# channel filter:", len(chan_filter_coeffs), "taps" self.file_sink = gr.file_sink(gr.sizeof_gr_complex * 1, "/home/sdr/rds_samples.dat") self.connect(self.u, self.chan_filter, self.file_sink)
def __init__(self, fg, subdev_spec, interp, spb, use_barker): self.normal_gain = 28000 self.u = usrp.sink_c() dac_rate = self.u.dac_rate(); self._spb = spb self._interp=int(interp) self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "Using TX d'board %s" % (self.subdev.side_and_name(),) # transmitter self.packet_transmitter = bbn_80211b_mod_pkts(fg, spb=spb, alpha=0.5, gain=self.normal_gain, use_barker=use_barker) fg.connect(self.packet_transmitter, self.u) gr.hier_block.__init__(self, fg, None, None) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def __init__(self,options,usrp_rate,usrp_interp,tari_rate): gr.hier_block2.__init__(self,"downlink_usrp_sink", gr.io_signature(1,1,gr.sizeof_gr_complex), gr.io_signature(0,0,0)) self.u = usrp.sink_c() #setup daughter boards #subdev_spec = usrp.pick_tx_subdevice(self.u) subdev_spec = (1, 0) self.subdev = usrp.selected_subdev(self.u,subdev_spec) self.u.set_mux(usrp.determine_tx_mux_value(self.u,subdev_spec)) print "Using TX d'board %s" % (self.subdev.side_and_name(),) #set interp rate self.u.set_interp_rate(usrp_interp) self.subdev.set_gain(self.subdev.gain_range()[2]) #setup frequency if not self.set_freq(options.freq): freq_range = self.subdev.freq_range() print "Failed to set frequency to %s. Daughterboard supports %s to %s" % ( eng_notation.num_to_str(options.freq), eng_notation.num_to_str(freq_range[0]), eng_notation.num_to_str(freq_range[1])) raise SystemExit self.subdev.set_enable(True) self.connect(self,self.u)
def __init__(self,subdev_spec=None,gain=None,length=1,alpha=1.0,msgq=None,loopback=False,verbose=False,debug=False): self._subdev_spec = subdev_spec self._gain = gain self._length = length self._alpha = alpha self._msgq = msgq self._loopback = loopback self._verbose = verbose self._debug = debug self._tb = gr.top_block() self._u = usrp.source_c(fpga_filename='usrp_sounder.rbf') if not self._loopback: if self._subdev_spec == None: self._subdev_spec = pick_subdevice(self._u) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) if self._verbose: print "Using", self._subdev.name(), "for sounder receiver." self.set_gain(self._gain) self._vblen = gr.sizeof_gr_complex*self._length if self._debug: print "Generating impulse vectors of length", self._length, "byte length", self._vblen self._s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self._length) if self._verbose: print "Using smoothing alpha of", self._alpha self._lpf = gr.single_pole_iir_filter_cc(self._alpha, self._length) self._sink = gr.message_sink(self._vblen, self._msgq, True) self._tb.connect(self._u, self._s2v, self._lpf, self._sink)
def __init__(self, options): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0)) #Set up usrp block self.u = usrp.source_c() adc_rate = self.u.adc_rate() # 64 MS/s usrp_decim = 16 gain = 65 self.u.set_decim_rate(usrp_decim) usrp_rate = adc_rate / usrp_decim # 320 kS/s print usrp_rate #subdev_spec = usrp.pick_subdev(self.u) subdev_spec = (0, 0) mux_value = usrp.determine_rx_mux_value(self.u, subdev_spec) self.u.set_mux(mux_value) self.subdev = usrp.selected_subdev(self.u, subdev_spec) self.subdev.set_gain(gain) self.subdev.set_auto_tr(False) self.subdev.set_enable(True) if not (self.set_freq(915e6)): print "Failed to set initial frequency" #set up the rest of the path deci = 1 self.agc = gr.agc_cc(rate=1e-7, reference=1.0, gain=0.001, max_gain=0.5) matchtaps = [complex(-1, -1)] * 8 + [complex( 1, 1)] * 8 + [complex(-1, -1)] * 8 + [complex(1, 1)] * 8 #matchtaps = [complex(-1,-1)] * 8 + [complex(1,1)] * 8 self.matchfilter = gr.fir_filter_ccc(1, matchtaps) reverse = [complex(1, 1)] * (8 / deci) + [complex( -1, -1)] * (8 / deci) + [complex( 1, 1)] * (8 / deci) + [complex(-1, -1)] * (8 / deci) #pretaps = matchtaps * 3 + reverse * 4 + matchtaps * 4 + reverse * 8 + matchtaps * 6 + matchtaps * 62 pretaps = matchtaps * 2 + reverse * 2 + matchtaps * 2 + reverse * 4 + matchtaps * 3 + matchtaps * 31 #pretaps = matchtaps * 3 + reverse * 8 + matchtaps * 6 + matchtaps * 64 self.preamble_filter = gr.fir_filter_ccc(1, pretaps) self.c_f = gr.complex_to_real() self.c_f2 = gr.complex_to_real() self.lock = howto.lock_time(32, 5, 32) self.pd = howto.find_pre_ff(55, 200) self.dec = symbols_decoder() self.vect = gr.vector_sink_f() #self.connect(self.u, self.agc, self.matchfilter, self.c_f, (self.lock, 0), self.dec, self.vect) #self.connect(self.agc, self.preamble_filter, self.c_f2, self.pd, (self.lock, 1)) self.connect(self.u, self.agc, self.matchfilter, self.c_f, self.vect)
def main(): tb = gr.top_block() ofdm_rx = howto.ofdm_rx(); #rs = gr.vector_source_c() #rs = gr.file_source(gr.sizeof_gr_complex,'out.dat') src = usrp.source_c(0) #nchannel src.set_nchannels(1) sample_rate = 1e6 ulist = [src] print "ulist" print ulist for u in ulist: rdecim = int(u.adc_rate() / sample_rate) u.set_decim_rate(rdecim) sys.stderr.write("the decimate = %d\n"%(rdecim)) srx1 = usrp.pick_rx_subdevice(src) print "srx1=" print srx1 subdev = () """configure USRP mux and set rx/tx subdev """ ulist = [src] assert len(ulist) == 1 src = ulist[0] src.set_mux( usrp.determine_rx_mux_value(src, srx1)) subdev += (usrp.selected_subdev(src, srx1), ) for s in subdev: exec("if not hasattr(s, '_u'): s._u = src") for s in subdev: s.set_auto_tr(True) print "subdev" print subdev freq = 2400000000.0 for s in subdev: r = usrp.tune(s._u, s.which(), s, freq) if r: sys.stderr.write("setting frequency of %s :\n"%(str(s))) sys.stderr.write(" baseband frequency = %s \n" %(eng_notation.num_to_str(r.baseband_freq))) sys.stderr.write(" DUC/DDC offset = %s\n" %(eng_notation.num_to_str(r.dxc_freq))) elif not r: sys.stderr.write("Unable to set frequency of %s to %g MHz \n"%(str(s), freq/ 1.0e6)) #g = 40.0 for s in subdev: gain_range = s.gain_range() #rx_gain = max(min(g, gain_range[1]), gain_range[0]) rx_gain = 0.3 * gain_range[1] s.set_gain(rx_gain) sys.stderr.write("the rx_gain = %d \n " %(rx_gain)) tb.connect(src, ofdm_rx) print 'connect' tb.run()
def setup_usrp(freq): # Constants interp = 128 decim = 64 # Make USRP instances to TX and RX utx = usrp.sink_c(fpga_filename="local_rssi5.rbf") urx = usrp.source_c(fpga_filename="local_rssi5.rbf") # Set decim and interp rates utx.set_interp_rate(interp) urx.set_decim_rate(decim) # Pick subdevice subdev_spec_tx = usrp.pick_tx_subdevice(utx) subdev_spec_rx = usrp.pick_rx_subdevice(urx) # Set up mux mux_tx = usrp.determine_tx_mux_value(utx, subdev_spec_tx) mux_rx = usrp.determine_rx_mux_value(urx, subdev_spec_rx) utx.set_mux(mux_tx) urx.set_mux(mux_rx) # pick d'board subdev_tx = usrp.selected_subdev(utx, subdev_spec_tx) subdev_rx = usrp.selected_subdev(urx, subdev_spec_rx) print "Using TX d'board %s" %(subdev_tx.side_and_name()) print "Using RX d'board %s" %(subdev_rx.side_and_name()) # Gain subdev_tx.set_gain((subdev_tx.gain_range()[0] + subdev_tx.gain_range()[1]) / 2) subdev_rx.set_gain((subdev_rx.gain_range()[0] + subdev_rx.gain_range()[1]) / 2) # Tune if not utx.tune(subdev_tx._which, subdev_tx, freq): DEBUG( "error tuning TX") if not urx.tune(subdev_rx._which, subdev_rx, freq): DEBUG( "error tuning RX") # Power on subdev_tx.set_enable(True) subdev_rx.set_enable(True) sys.stdout.flush() return utx, urx
def __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__(self, subdev_spec, freq, subdev_gain, filename, delay): gr.top_block.__init__(self) # data sink and sink rate u = usrp.sink_c() # important vars (to be calculated from USRP when available dac_rate = u.dac_rate() usrp_rate = 320e3 usrp_interp = int(dac_rate // usrp_rate) channel_rate = 32e3 interp_factor = int(usrp_rate // channel_rate) # open the pcap source pcap = op25.pcap_source_b(filename, delay) # pcap = gr.glfsr_source_b(16) # convert octets into dibits bits_per_symbol = 2 unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST) # modulator c4fm = p25_mod_bf(output_rate=channel_rate) # setup low pass filter + interpolator low_pass = 2.88e3 interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass, low_pass * 0.1, gr.firdes.WIN_HANN) interpolator = gr.interp_fir_filter_fff(int(interp_factor), interp_taps) # frequency modulator max_dev = 12.5e3 k = 2 * math.pi * max_dev / usrp_rate adjustment = 1.5 # adjust for proper c4fm deviation level fm = gr.frequency_modulator_fc(k * adjustment) # signal gain gain = gr.multiply_const_cc(4000) # configure USRP if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(u) u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec)) self.db = usrp.selected_subdev(u, subdev_spec) print "Using TX d'board %s" % (self.db.side_and_name(), ) u.set_interp_rate(usrp_interp) if gain is None: g = self.db.gain_range() gain = float(g[0] + g[1]) / 2 self.db.set_gain(self.db.gain_range()[0]) u.tune(self.db.which(), self.db, freq) self.db.set_enable(True) self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
def __init__(self, subdev_spec, audio_input): gr.hier_block2.__init__( self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0) # Input signature ) # Output signature self.u = usrp.sink_c() dac_rate = self.u.dac_rate() self.if_rate = 320e3 # 320 kS/s self.usrp_interp = int(dac_rate // self.if_rate) self.u.set_interp_rate(self.usrp_interp) self.sw_interp = 10 self.audio_rate = self.if_rate // self.sw_interp # 32 kS/s self.audio_gain = 10 self.normal_gain = 32000 self.audio = audio.source(int(self.audio_rate), audio_input) self.audio_amp = gr.multiply_const_ff(self.audio_gain) lpf = gr.firdes.low_pass( 1, # gain self.audio_rate, # sampling rate 3800, # low pass cutoff freq 300, # width of trans. band gr.firdes.WIN_HANN, ) # filter type hpf = gr.firdes.high_pass( 1, # gain self.audio_rate, # sampling rate 325, # low pass cutoff freq 50, # width of trans. band gr.firdes.WIN_HANN, ) # filter type audio_taps = convolve(array(lpf), array(hpf)) self.audio_filt = gr.fir_filter_fff(1, audio_taps) self.pl = blks2.ctcss_gen_f(self.audio_rate, 123.0) self.add_pl = gr.add_ff() self.connect(self.pl, (self.add_pl, 1)) self.fmtx = blks2.nbfm_tx(self.audio_rate, self.if_rate) self.amp = gr.multiply_const_cc(self.normal_gain) # determine the daughterboard subdevice we're using if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux(usrp.determine_tx_mux_value(self.u, subdev_spec)) self.subdev = usrp.selected_subdev(self.u, subdev_spec) print "TX using", self.subdev.name() self.connect(self.audio, self.audio_amp, self.audio_filt, (self.add_pl, 0), self.fmtx, self.amp, self.u) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain
def __init__(self, options): gr.top_block.__init__(self) # Create a USRP source with GPIO FPGA build, then configure u = usrp.source_s(decim_rate=options.decim, fpga_filename=gpio.fpga_filename) if options.force_complex_RXA: # This is a dirty hack to force complex mode (receive both I and Q) on basicRX or LFRX # This forces the receive board in RXA (side A) to be used # FIXME: This has as a side effect that the gain for Q is not set. So only use with gain 0 (--gain 0) options.rx_subdev_spec = (0, 0) u.set_mux(0x10) if not (0 == options.gain): print "WARNING, you should set the gain to 0 with --gain 0 when using --force-complex-RXA" print "The gain for Q will now still be zero while the gain for I is not" #options.gain=0 else: if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(u) u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec)) subdev = usrp.selected_subdev(u, options.rx_subdev_spec) print "Using RX d'board %s" % (subdev.side_and_name(), ) input_rate = u.adc_freq() / u.decim_rate() print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) if options.gain is None: # if no gain was specified, use the mid-point in dB g = subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 #TODO setting gain on basicRX only sets the I channel, use a second subdev to set gain of Q channel #see gnuradio-examples/multi-antenna for possible solutions subdev.set_gain(options.gain) #TODO check if freq has same problem as gain when trying to use complex mode on basicRX r = u.tune(0, subdev, options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 # Connect pipeline src = u if options.nsamples is not None: head = gr.head(gr.sizeof_short, int(options.nsamples) * 2) self.connect(u, head) src = head ana_strip = gr.and_const_ss(0xFFFE) dig_strip = gr.and_const_ss(0x0001) ana_sink = gr.file_sink(gr.sizeof_short, options.ana_filename) dig_sink = gr.file_sink(gr.sizeof_short, options.dig_filename) self.connect(src, ana_strip, ana_sink) self.connect(src, dig_strip, dig_sink)
def __init__(self, options): gr.top_block.__init__(self) # Create a USRP source with GPIO FPGA build, then configure u = usrp.source_s(decim_rate=options.decim,fpga_filename=gpio.fpga_filename) if options.force_complex_RXA: # This is a dirty hack to force complex mode (receive both I and Q) on basicRX or LFRX # This forces the receive board in RXA (side A) to be used # FIXME: This has as a side effect that the gain for Q is not set. So only use with gain 0 (--gain 0) options.rx_subdev_spec=(0,0) u.set_mux(0x10) if not (0==options.gain): print "WARNING, you should set the gain to 0 with --gain 0 when using --force-complex-RXA" print "The gain for Q will now still be zero while the gain for I is not" #options.gain=0 else: if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(u) u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec)) subdev = usrp.selected_subdev(u, options.rx_subdev_spec) print "Using RX d'board %s" % (subdev.side_and_name(),) input_rate = u.adc_freq()/u.decim_rate() print "USB sample rate %s" % (eng_notation.num_to_str(input_rate)) if options.gain is None: # if no gain was specified, use the mid-point in dB g = subdev.gain_range() options.gain = float(g[0]+g[1])/2 #TODO setting gain on basicRX only sets the I channel, use a second subdev to set gain of Q channel #see gnuradio-examples/multi-antenna for possible solutions subdev.set_gain(options.gain) #TODO check if freq has same problem as gain when trying to use complex mode on basicRX r = u.tune(0, subdev, options.freq) if not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1 # Connect pipeline src = u if options.nsamples is not None: head = gr.head(gr.sizeof_short, int(options.nsamples)*2) self.connect(u, head) src = head ana_strip = gpio.and_const_ss(0xFFFE) dig_strip = gpio.and_const_ss(0x0001) ana_sink = gr.file_sink(gr.sizeof_short, options.ana_filename) dig_sink = gr.file_sink(gr.sizeof_short, options.dig_filename) self.connect(src, ana_strip, ana_sink) self.connect(src, dig_strip, dig_sink)
def __init__(self): gr.flow_graph.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option( "-T", "--tx-subdev-spec", type="subdev", default=None, help= "select USRP Tx side A or B (default=first one with a daughterboard)" ) parser.add_option("-c", "--cordic-freq", type="eng_float", default=434845200, help="set Tx cordic frequency to FREQ", metavar="FREQ") (options, args) = parser.parse_args() print "cordic_freq = %s" % (eng_notation.num_to_str( options.cordic_freq)) self.normal_gain = 8000 self.u = usrp.sink_s() dac_rate = self.u.dac_rate() self._freq = 1000 self._spb = 256 self._interp = int(128e6 / self._spb / self._freq) self.fs = 128e6 / self._interp print "Interpolation:", self._interp self.u.set_interp_rate(self._interp) # determine the daughterboard subdevice we're using if options.tx_subdev_spec is None: options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u) self.u.set_mux( usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec) print "Using TX d'board %s" % (self.subdev.side_and_name(), ) self.u.tune(self.subdev._which, self.subdev, options.cordic_freq) self.sin = gr.sig_source_f(self.fs, gr.GR_SIN_WAVE, self._freq, 1, 0) self.gain = gr.multiply_const_ff(self.normal_gain) self.ftos = gr.float_to_short() self.filesink = gr.file_sink(gr.sizeof_float, 'sin.dat') self.connect(self.sin, self.gain) self.connect(self.gain, self.ftos, self.u) #self.connect(self.gain, self.filesink) self.set_gain(self.subdev.gain_range()[1]) # set max Tx gain self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def _setup_usrp1(self): self._u = usrp.sink_c (self._which, fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) # determine the daughterboard subdevice we're using if self._subdev_spec is None: self._subdev_spec = usrp.pick_tx_subdevice(self._u) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) self._u.set_mux(usrp.determine_tx_mux_value(self._u, self._subdev_spec)) self._dxc = self._subdev.which()
def __init__(self, subdev_spec, freq, subdev_gain, filename, delay): gr.top_block.__init__ (self) # data sink and sink rate u = usrp.sink_c() # important vars (to be calculated from USRP when available dac_rate = u.dac_rate() usrp_rate = 320e3 usrp_interp = int(dac_rate // usrp_rate) channel_rate = 32e3 interp_factor = int(usrp_rate // channel_rate) # open the pcap source pcap = op25.pcap_source_b(filename, delay) # pcap = gr.glfsr_source_b(16) # convert octets into dibits bits_per_symbol = 2 unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST) # modulator c4fm = p25_mod_bf(output_rate=channel_rate) # setup low pass filter + interpolator low_pass = 2.88e3 interp_taps = gr.firdes.low_pass(1.0, channel_rate, low_pass, low_pass * 0.1, gr.firdes.WIN_HANN) interpolator = gr.interp_fir_filter_fff (int(interp_factor), interp_taps) # frequency modulator max_dev = 12.5e3 k = 2 * math.pi * max_dev / usrp_rate adjustment = 1.5 # adjust for proper c4fm deviation level fm = gr.frequency_modulator_fc(k * adjustment) # signal gain gain = gr.multiply_const_cc(4000) # configure USRP if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(u) u.set_mux(usrp.determine_tx_mux_value(u, subdev_spec)) self.db = usrp.selected_subdev(u, subdev_spec) print "Using TX d'board %s" % (self.db.side_and_name(),) u.set_interp_rate(usrp_interp) if gain is None: g = self.db.gain_range() gain = float(g[0] + g[1]) / 2 self.db.set_gain(self.db.gain_range()[0]) u.tune(self.db.which(), self.db, freq) self.db.set_enable(True) self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
def detect_usrp1(): for i in range(3): try: u = usrp.source_c(i) print "\033[1;31mUSRP found, serial:", u.serial_number( ), "\033[1;m" a = usrp.selected_subdev(u, (0, 0)) if (a.dbid() != -1): print "\033[1;33mSide A, RX:", a.name(), "(dbid: 0x%04X)" % ( a.dbid()), "\033[1;m" print "freq range: (", a.freq_min() / 1e6, "MHz, ", a.freq_max( ) / 1e6, "MHz )" print "gain rainge: (", a.gain_min(), "dB, ", a.gain_max( ), "dB )" b = usrp.selected_subdev(u, (1, 0)) if (b.dbid() != -1): print "\033[1;33mSide B, RX:", b.name(), "(dbid: 0x%04X)" % ( b.dbid()), "\033[1;m" print "freq range: (", b.freq_min() / 1e6, "MHz, ", b.freq_max( ) / 1e6, "MHz )" print "gain rainge: (", b.gain_min(), "dB, ", b.gain_max( ), "dB )" u = usrp.sink_c(i) a = usrp.selected_subdev(u, (0, 0)) if (a.dbid() != -1): print "\033[1;33mSide A, TX:", a.name(), "(dbid: 0x%04X)" % ( a.dbid()), "\033[1;m" print "freq range: (", a.freq_min() / 1e6, "MHz, ", a.freq_max( ) / 1e6, "MHz )" print "gain rainge: (", a.gain_min(), "dB, ", a.gain_max( ), "dB )" b = usrp.selected_subdev(u, (1, 0)) if (b.dbid() != -1): print "\033[1;33mSide B, TX:", b.name(), "(dbid: 0x%04X)" % ( b.dbid()), "\033[1;m" print "freq range: (", b.freq_min() / 1e6, "MHz, ", b.freq_max( ) / 1e6, "MHz )" print "gain rainge: (", b.gain_min(), "dB, ", b.gain_max( ), "dB )" except: if (i == 0): print "\033[1;31mno USRPs found" break
def _setup_usrp1(self): from gnuradio import usrp self._u = usrp.source_c (self._which, fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) # determine the daughterboard subdevice we're using if self._subdev_spec is None: self._subdev_spec = usrp.pick_rx_subdevice(self._u) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._dxc = 0
def __init__(self, options, queue): gr.top_block.__init__(self) self.u = usrp.source_c() self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % self.subdev.side_and_name() self.u.set_decim_rate(options.decim) self.centerfreq = options.centerfreq print "Tuning to: %fMHz" % (self.centerfreq - options.error) if not(self.tune(options.centerfreq - options.error)): print "Failed to set initial frequency" if options.gain is None: #set to halfway g = self.subdev.gain_range() options.gain = (g[0]+g[1]) / 2.0 print "Setting gain to %i" % options.gain self.subdev.set_gain(options.gain) if self.subdev.name() == "DBS Rx": self.subdev.set_bw(options.bandwidth) #only for DBSRX print "Setting DBS RX bandwidth to %fMHz" % float(options.bandwidth / 1e6) self.rate = self.u.adc_rate() / options.decim print "Samples per second is %i" % self.rate self._syms_per_sec = 3600; options.audiorate = 11025 options.rate = self.rate options.samples_per_second = self.rate #yeah i know it's on the list options.syms_per_sec = self._syms_per_sec options.gain_mu = 0.01 options.mu=0.5 options.omega_relative_limit = 0.3 options.syms_per_sec = self._syms_per_sec options.offset = options.centerfreq - options.freq print "Control channel offset: %f" % options.offset self.demod = fsk_demod(options) self.start_correlator = gr.correlate_access_code_bb("10101100",0) #should mark start of packet self.smartnet_sync = smartnet.sync() self.smartnet_deinterleave = smartnet.deinterleave() self.smartnet_parity = smartnet.parity() self.smartnet_crc = smartnet.crc() self.smartnet_packetize = smartnet.packetize() self.parse = smartnet.parse(queue) #packet-based. this simply posts lightly-formatted messages to the queue. self.connect(self.u, self.demod) self.connect(self.demod, self.start_correlator, self.smartnet_sync, self.smartnet_deinterleave, self.smartnet_parity, self.smartnet_crc, self.smartnet_packetize, self.parse)
def _setup_usrp1(self): self._u = usrp.sink_c(self._which, fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) # determine the daughterboard subdevice we're using if self._subdev_spec is None: self._subdev_spec = usrp.pick_tx_subdevice(self._u) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) self._u.set_mux(usrp.determine_tx_mux_value(self._u, self._subdev_spec)) self._dxc = self._subdev.which()
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option, usage="%prog: [options] input-filename") parser.add_option("-T", "--tx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Tx side A or B [default=A]") parser.add_option("-f", "--freq", type="eng_float", default=227.36e6, help="set frequency to FREQ [default=%default]") parser.add_option("-g", "--tx-gain", type="eng_float", default=None, help="set transmit gain in dB (default is midpoint)") parser.add_option('-v', '--verbose', action="store_true", default=False, help="verbose output") (options, args) = parser.parse_args () if len(args)!=1: parser.print_help() sys.exit(1) else: self.filename = args[0] # if gr.enable_realtime_scheduling() != gr.RT_OK: # print "-> failed to enable realtime scheduling" interp = 64 self.dab_params = dab.parameters.dab_parameters(mode=1, sample_rate=2000000, verbose=options.verbose) self.src = gr.file_source(gr.sizeof_char, self.filename) self.trigsrc = gr.vector_source_b([1]+[0]*(self.dab_params.symbols_per_frame-1),True) self.s2v = gr.stream_to_vector(gr.sizeof_char, 384) self.mod = dab.ofdm_mod(self.dab_params, verbose=options.verbose) self.sink = usrp.sink_c(interp_rate = interp) self.sink.set_mux(usrp.determine_tx_mux_value(self.sink, options.tx_subdev_spec)) self.subdev = usrp.selected_subdev(self.sink, options.tx_subdev_spec) self.sample_rate = self.sink.dac_rate()/interp print "--> using sample rate: " + str(self.sample_rate) self.connect(self.src, self.s2v, self.mod, self.sink) self.connect(self.trigsrc, (self.mod,1)) # tune frequency self.sink.tune(0, self.subdev, options.freq) # set gain if options.tx_gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.tx_gain = float(g[0]+g[1])/2 self.subdev.set_gain(options.tx_gain)
def _setup_usrp1(self): from gnuradio import usrp self._u = usrp.source_c(self._which, fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) # determine the daughterboard subdevice we're using if self._subdev_spec is None: self._subdev_spec = usrp.pick_rx_subdevice(self._u) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._dxc = 0
def __init__(self): gr.top_block.__init__(self) #build graph now #usrp_source self.usrp = usrp.source_c() adc_rate = self.usrp.adc_rate() #64MHz hw_decim = 16 #so Sample rate into host is 4MHz self.usrp.set_decim_rate(hw_decim) self.subdev = usrp.selected_subdev(self.usrp, usrp.pick_rx_subdevice(self.usrp)) self.usrp.set_mux( usrp.determine_rx_mux_value(self.usrp, usrp.pick_rx_subdevice(self.usrp))) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) self.subdev.set_gain(30) rf_freq = 106800000 # 106.8MHz self.set_freq(rf_freq) print "Freq: ", rf_freq self.subdev.select_rx_antenna("TX/RX") #low pass filter self.sample_rate = adc_rate / hw_decim self.lpf_decim = 20 # so after channel filter, the sample rate is 200KHz self.lp_filter = gr.fir_filter_ccf( self.lpf_decim, gr.firdes.low_pass( 1, self.sample_rate, 100e3, # cut off freq 10e3, # transition band gr.firdes.WIN_BLACKMAN, # Window function 6.76 # not used )) # WBFM receiver quad_rate = self.sample_rate #input rate of demodulator max_dev = 75e3 #max deviation of FM Broadcast fm_demod_gain = quad_rate / (2 * math.pi * max_dev) self.fm_decoder = gr.quadrature_demod_cf(fm_demod_gain) # Rational Resampler self.audio_sample_rate = 96000 self.rational_resampler = blks2.rational_resampler_fff( interpolation=int(self.audio_sample_rate / 1000), decimation=int(self.sample_rate / self.lpf_decim / 1000), taps=None, fractional_bw=None, ) self.audio_sink = audio.sink(int(self.audio_sample_rate), "", True) #connections self.connect(self.usrp, self.lp_filter, self.fm_decoder, self.rational_resampler, self.audio_sink)
def _setup_usrp(self): self._u = usrp.source_c(fpga_filename='usrp_radar_mono.rbf') if self._subdev_spec == None: self._subdev_spec = usrp.pick_rx_subdevice(self._u) self._u.set_mux(usrp.determine_rx_mux_value(self._u, self._subdev_spec)) self._subdev = usrp.selected_subdev(self._u, self._subdev_spec) if self._verbose: print "Using", self._subdev.side_and_name(), "for radar receiver." print "Setting receiver gain to", self._gain self.set_gain(self._gain) self.tune(self._frequency)
def _setup_usrp_source(self): self.u = usrp.source_c (fusb_block_size=self._fusb_block_size, fusb_nblocks=self._fusb_nblocks) adc_rate = self.u.adc_rate() self.u.set_decim_rate(self._decim) # determine the daughterboard subdevice we're using if self._rx_subdev_spec is None: self._rx_subdev_spec = usrp.pick_rx_subdevice(self.u) self.subdev = usrp.selected_subdev(self.u, self._rx_subdev_spec) self.u.set_mux(usrp.determine_rx_mux_value(self.u, self._rx_subdev_spec))
def __init__(self, options, queue): gr.top_block.__init__(self, "usrp_flex_all") if options.from_file is not None: src = gr.file_source(gr.sizeof_gr_complex, options.from_file) if options.verbose: print "Reading samples from file", options.from_file else: src = usrp.source_c() if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(src) subdev = usrp.selected_subdev(src, options.rx_subdev_spec) src.set_mux( usrp.determine_rx_mux_value(src, options.rx_subdev_spec)) src.set_decim_rate(20) result = usrp.tune(src, 0, subdev, 930.5125e6 + options.calibration) if options.verbose: print "Using", subdev.name(), " for receiving." print "Tuned USRP to", 930.5125e6 + options.calibration taps = gr.firdes.low_pass(1.0, 1.0, 1.0 / 128.0 * 0.4, 1.0 / 128.0 * 0.1, gr.firdes.WIN_HANN) if options.verbose: print "Channel filter has", len(taps), "taps" bank = blks2.analysis_filterbank(128, taps) self.connect(src, bank) if options.log and options.from_file == None: src_sink = gr.file_sink(gr.sizeof_gr_complex, 'usrp.dat') self.connect(src, src_sink) for i in range(128): if i < 64: freq = 930.5e6 + i * 25e3 else: freq = 928.9e6 + (i - 64) * 25e3 if (freq < 929.0e6 or freq > 932.0e6): self.connect((bank, i), gr.null_sink(gr.sizeof_gr_complex)) else: self.connect((bank, i), pager.flex_demod(queue, freq, options.verbose, options.log)) if options.log: self.connect( (bank, i), gr.file_sink(gr.sizeof_gr_complex, 'chan_' + '%3.3f' % (freq / 1e6) + '.dat'))
def setup_usrp(self): options = self.options #set resonable defaults if no user prefs set if options.realtime: if options.fusb_block_size == 0: options.fusb_block_size = gr.prefs().get_long( 'fusb', 'rt_block_size', 1024) if options.fusb_nblocks == 0: options.fusb_nblocks = gr.prefs().get_long( 'fusb', 'rt_nblocks', 16) else: if options.fusb_block_size == 0: options.fusb_block_size = gr.prefs().get_long( 'fusb', 'block_size', 4096) if options.fusb_nblocks == 0: options.fusb_nblocks = gr.prefs().get_long( 'fusb', 'nblocks', 16) print >> sys.stderr, "fusb_block_size =", options.fusb_block_size print >> sys.stderr, "fusb_nblocks =", options.fusb_nblocks self.ursp = usrp.source_c(decim_rate=options.decim, fusb_block_size=options.fusb_block_size, fusb_nblocks=options.fusb_nblocks) self.ursp.set_fpga_master_clock_freq(options.clock_frequency) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.ursp) self.ursp.set_mux( usrp.determine_rx_mux_value(self.ursp, options.rx_subdev_spec)) # determine the daughterboard subdevice self.subdev = usrp.selected_subdev(self.ursp, options.rx_subdev_spec) input_rate = self.ursp.adc_freq() / self.ursp.decim_rate() if options.antenna is not None: print >> sys.stderr, "USRP antenna %s" % (options.antenna, ) self.subdev.select_rx_antenna(options.antenna) # set initial values if options.gain is None: # if no gain was specified, use the mid-point in dB g = self.subdev.gain_range() options.gain = float(g[0] + g[1]) / 2 self.set_gain(options.gain) self.source = self.ursp
def __init__(self, options, rx_callback): """ @param options Optparse option field for command line arguments. @param rx_callback Callback function for the event when a packet is received. """ gr.flow_graph.__init__(self) print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq_rx)) # ---------------------------------------------------------------- self.data_rate = options.data_rate self.samples_per_symbol = 2 self.usrp_decim = int (64e6 / self.samples_per_symbol / self.data_rate) self.fs = self.data_rate * self.samples_per_symbol payload_size = 128 # bytes print "data_rate = ", eng_notation.num_to_str(self.data_rate) print "samples_per_symbol = ", self.samples_per_symbol print "usrp_decim = ", self.usrp_decim print "fs = ", eng_notation.num_to_str(self.fs) u = usrp.source_c (0, self.usrp_decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(u) u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) #self.subdev.select_rx_antenna('RX2') u.tune(0, self.subdev, options.cordic_freq_rx) u.set_pga(0, options.gain) u.set_pga(1, options.gain) self.u = u self.packet_receiver = ieee802_15_4_pkt.ieee802_15_4_demod_pkts(self, callback=rx_callback, sps=self.samples_per_symbol, symbol_rate=self.data_rate, threshold=-1) self.squelch = gr.pwr_squelch_cc(50, 1, 0, True) #self.file_sink = gr.file_sink(gr.sizeof_gr_complex, "/dev/null") self.connect(self.u, self.squelch, self.packet_receiver) #self.connect(self.u, self.file_sink) self.set_auto_tr(True) # enable Auto Transmit/Receive switching
def _setup_usrp(self, which, interp, subdev_spec, freq): self._usrp = usrp.sink_c(which=which, interp_rate=interp) if subdev_spec is None: subdev_spec = usrp.pick_tx_subdevice(self._usrp) self._usrp.set_mux(usrp.determine_tx_mux_value(self._usrp, subdev_spec)) self._subdev = usrp.selected_subdev(self._usrp, subdev_spec) tr = usrp.tune(self._usrp, self._subdev.which(), self._subdev, freq) if not (tr): print "Failed to tune to center frequency!" else: print "Center frequency:", n2s(freq) gain = float(self._subdev.gain_range()[1]) # Max TX gain self._subdev.set_gain(gain) self._subdev.set_enable(True) print "TX d'board:", self._subdev.side_and_name()