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, 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 build_graph (): rx_decim = 32 tb = gr.top_block () usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_COUNTING) sink = gr.check_counting_s () tb.connect (usrp_rx, sink) # file_sink = gr.file_sink (gr.sizeof_short, 'counting.dat') # tb.connect (usrp_rx, file_sink) return tb
def __init__(self): gr.flow_graph.__init__(self) parser = OptionParser (option_class=eng_option) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default='B', help="select USRP Rx side A or B (default=first one with a daughterboard)") parser.add_option ("-c", "--cordic-freq", type="eng_float", default=434845200, help="set rx cordic frequency to FREQ", metavar="FREQ") parser.add_option ("-g", "--gain", type="eng_float", default=0, help="set Rx PGA gain in dB [0,20]") (options, args) = parser.parse_args () print "cordic_freq = %s" % (eng_notation.num_to_str (options.cordic_freq)) # ---------------------------------------------------------------- self.freq = 1000 self.samples_per_symbol = 256 self.usrp_decim = int (64e6 / self.samples_per_symbol / self.freq) self.fs = self.freq * self.samples_per_symbol print "freq = ", eng_notation.num_to_str(self.freq) 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_s (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)) subdev = usrp.selected_subdev(u, options.rx_subdev_spec) print "Using RX d'board %s" % (subdev.side_and_name(),) u.tune(0, subdev, options.cordic_freq) u.set_pga(0, options.gain) u.set_pga(1, options.gain) self.u = u self.filesink = gr.file_sink(gr.sizeof_float, 'rx_sin.dat') self.stof = gr.short_to_float() filter_coeffs = gr.firdes.low_pass (1.0, # gain self.fs, # sampling rate self.freq, # low pass cutoff freq 0.1*self.freq, # width of trans. band gr.firdes.WIN_HANN) # filter type self.lowpass = gr.fir_filter_fff(1, filter_coeffs) self.connect(self.u, self.stof, self.lowpass, self.filesink)
def build_graph(): rx_decim = 32 tb = gr.top_block() usrp_rx = usrp.source_s(0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_COUNTING) sink = gr.check_counting_s() tb.connect(usrp_rx, sink) # file_sink = gr.file_sink (gr.sizeof_short, 'counting.dat') # tb.connect (usrp_rx, file_sink) return tb
def run_test (usb_throughput, verbose): # usb_throughput is in bytes/sec. # # Returns True or False nsec = 1 stream_length = int (usb_throughput/2 * nsec) # length of stream to examine adc_freq = 64e6 dac_freq = 128e6 sizeof_sample = 2 * gr.sizeof_short usb_throughput_in_samples = usb_throughput / sizeof_sample # allocate usb throughput 50/50 between Tx and Rx tx_interp = int (dac_freq) / int (usb_throughput_in_samples / 2) rx_decim = int (adc_freq) / int (usb_throughput_in_samples / 2) # print "tx_interp =", tx_interp, "rx_decim =", rx_decim assert (tx_interp == 2 * rx_decim) tb = gr.top_block () # Build the Tx pipeline data_src = gr.lfsr_32k_source_s () src_head = gr.head (gr.sizeof_short, int (stream_length * 2)) usrp_tx = usrp.sink_s (0, tx_interp) tb.connect (data_src, src_head, usrp_tx) # and the Rx pipeline usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) head = gr.head (gr.sizeof_short, stream_length) check = gr.check_lfsr_32k_s () tb.connect (usrp_rx, head, check) tb.run () ntotal = check.ntotal () nright = check.nright () runlength = check.runlength () if verbose: print "usb_throughput =", eng_notation.num_to_str (usb_throughput) print "ntotal =", ntotal print "nright =", nright print "runlength =", runlength print "delta =", ntotal - runlength return runlength >= stream_length - 80000
def build_graph (): tx_interp = 32 # tx should be twice rx rx_decim = 16 tb = gr.top_block () data_src = ramp_source (tb) # usrp_tx = usrp.sink_s (0, tx_interp, 1, 0x98) usrp_tx = usrp.sink_s (0, tx_interp) tb.connect (data_src, usrp_tx) usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK) sink = gr.check_counting_s () tb.connect (usrp_rx, sink) # file_sink = gr.file_sink (gr.sizeof_short, "loopback.dat") # tb.connect (usrp_rx, file_sink) return tb
def __init__(self): gr.top_block.__init__(self) self.frequency = 13.56e6 self.gain = 10 # USRP settings self.u_rx = usrp.source_s() #create the USRP source for RX #try and set the LF_RX for this rx_subdev_spec = usrp.pick_subdev(self.u_rx, (usrp_dbid.LF_RX, usrp_dbid.LF_TX)) #Configure the MUX for the daughterboard self.u_rx.set_mux(usrp.determine_rx_mux_value(self.u_rx, rx_subdev_spec)) #Tell it to use the LF_RX self.subdev_rx = usrp.selected_subdev(self.u_rx, rx_subdev_spec) #Make sure it worked print "Using RX dboard %s" % (self.subdev_rx.side_and_name(),) #Set gain.. duh self.subdev_rx.set_gain(self.gain) #Tune the center frequency self.u_rx.tune(0, self.subdev_rx, self.frequency) adc_rate = self.u_rx.adc_rate() #64 MS/s usrp_decim = 8 self.u_rx.set_decim_rate(usrp_decim) #BW = 64 MS/s / decim = 64,000,000 / 256 = 250 kHz #Not sure if this decim rate exceeds USRP capabilities, #if it does then some software decim may have to be done as well usrp_rx_rate = adc_rate / usrp_decim self.convert = gr.short_to_float() self.snk = gr.probe_avg_mag_sqrd_f(1,0.01) # dst = audio.sink (sample_rate, "") # stv = gr.stream_to_vector (gr.sizeof_float, fft_size) # c2m = gr.complex_to_mag_squared (fft_size) self.connect(self.u_rx, self.convert, self.snk)
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_1 = wx.Slider(self, ID_SLIDER_1, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_2 = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option( "-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ" ) parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option("-d", "--decim", type="int", default=250, help="USRP decimation") parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help="select USRP Rx side A or B (default=first one with a daughterboard)", ) (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq usb_rate = 64e6 / options.decim self.slider_range = usb_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(usb_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 / options.decim self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue((self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = usrp.source_s(decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.src) self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) self.src.tune(0, self.subdev, self.usrp_center) self.tune_offset = 0 # -self.usrp_center - self.src.rx_freq(0) else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # save radio data to a file if SAVE_RADIO_TO_FILE: file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, file) # 2nd DDC xlate_taps = gr.firdes.low_pass(1.0, usb_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING) self.xlate = gr.freq_xlating_fir_filter_ccf(fir_decim, xlate_taps, self.tune_offset, usb_rate) # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.slider_1.SetValue(0) self.slider_2.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c( self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240) ) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c( self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240), ) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc( 0.5, 0.0625, (2.0 * math.pi * 7.5e3 / self.af_sample_rate), (2.0 * math.pi * 6.5e3 / self.af_sample_rate) ) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING, ) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() # AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([0.004, 0], [0, 0.999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate)) self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display em.eventManager.Register(self.Mouse, wx.EVT_MOTION, self.fft.win) # and left click to re-tune em.eventManager.Register(self.Click, wx.EVT_LEFT_DOWN, self.fft.win) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option("-w", "--which", type="int", default=0, help="select which USRP (0, 1, ...) default is %default", metavar="NUM") # parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, # help="select USRP Rx side A or B (default=first one with a daughterboard)") parser.add_option("-A", "--antenna", default=None, help="select Rx Antenna (only on RFX-series boards)") parser.add_option("-d", "--decim", type="int", default=32, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=0.0, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") # parser.add_option( "--no-hb", action="store_true", default=False, # help="don't use halfband filter in usrp") parser.add_option("-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display (default)") parser.add_option("-F", "--fft", action="store_true", default=False, help="Enable FFT display") parser.add_option("-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option("-v", "--v-scale", type="eng_float", default=1, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option("-t", "--t-scale", type="eng_float", default=10e-6, help="set oscope initial s/div to SCALE [default=10us]") parser.add_option ("--digital", action="store_true", default=False, help="show (only) the digital wave on lsb (will be input from gpio pins with special usrp firmware)") parser.add_option ("--analog", action="store_true", default=False, help="show (only) the analog wave on msbs (will be input from analog inputs)") parser.add_option ("--file", default=None, help="input from file FILE in stead of USRP (will be input from raw file in interleaved short format)") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True self.u = usrp.source_s(which=options.which, decim_rate=options.decim, fpga_filename=gpio.fpga_filename) print "Warning: This script only supports boards on RXA, change the script if you want otherwise" #options.rx_subdev_spec=(0, 0)#force the use of RXA options.rx_subdev_spec=None #force the use of RXA if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) #This hardcoded mux setting is why this script only supports RXA #We want both I and Q active, even when using basicRX #set to 0x10 for RXA #set to 0x32 for RXB self.u.set_mux(0x10) #usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) print "format =", hex(format) r = self.u.set_format(format) print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) #if options.rx_subdev_spec==(0,0): # rx_subdev_spec2=(0,1) # self.subdev2 = usrp.selected_subdev(self.u, rx_subdev_spec2) input_rate = self.u.adc_freq() / self.u.decim_rate() if options.waterfall: self.scope = \ waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate) elif options.fft: self.scope = fftsink2.fft_sink_c (panel, fft_size=1024, sample_rate=input_rate) else: # options.oscilloscope: #self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate) self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale) self.is2c = gr.interleaved_short_to_complex() if not (options.file is None): self.filesrc=gr.file_source(gr.sizeof_short, options.file, True) thr = gr.throttle(gr.sizeof_short, input_rate) self.connect(self.filesrc,thr,self.is2c,self.scope) elif options.digital: self.select_dig=gpio.and_const_ss(0x0001) self.connect(self.u, self.select_dig,self.is2c,self.scope) elif options.analog: self.select_ana=gpio.and_const_ss(0xFFFE) self.connect(self.u, self.select_ana,self.is2c,self.scope) else: self.connect(self.u,self.is2c,self.scope) self._build_gui(vbox) self._setup_events() # 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 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0]+r[1])/2 self.set_gain(options.gain) if options.antenna is not None: print "Selecting antenna %s" % (options.antenna,) self.subdev.select_rx_antenna(options.antenna) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if not(self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.top_block.__init__(self) usage = "%prog: [options] output_filename" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Rx side A or B (default=A)") parser.add_option( "-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option("--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option( "-s", "--output-shorts", action="store_true", default=False, help="output interleaved shorts in stead of complex floats") parser.add_option("-N", "--nsamples", type="eng_float", default=None, help="number of samples to collect [default=+inf]") (options, args) = parser.parse_args() if len(args) != 1: parser.print_help() raise SystemExit, 1 filename = args[0] if options.freq is None: parser.print_help() sys.stderr.write('You must specify the frequency with -f FREQ\n') raise SystemExit, 1 # build the graph if options.no_hb or (options.decim < 8): self.fpga_filename = "std_4rx_0tx.rbf" #Min decimation of this firmware is 4. contains 4 Rx paths without halfbands and 0 tx paths. if options.output_shorts: self.u = usrp.source_s(decim_rate=options.decim, fpga_filename=self.fpga_filename) else: self.u = usrp.source_c(decim_rate=options.decim, fpga_filename=self.fpga_filename) else: #standard fpga firmware "std_2rxhb_2tx.rbf" contains 2 Rx paths with halfband filters and 2 tx paths (the default) min decimation 8 if options.output_shorts: self.u = usrp.source_s(decim_rate=options.decim) else: self.u = usrp.source_c(decim_rate=options.decim) if options.width_8: sample_width = 8 sample_shift = 8 format = self.u.make_format(sample_width, sample_shift) r = self.u.set_format(format) if options.output_shorts: self.dst = gr.file_sink(gr.sizeof_short, filename) else: self.dst = gr.file_sink(gr.sizeof_gr_complex, filename) if options.nsamples is None: self.connect(self.u, self.dst) else: if options.output_shorts: self.head = gr.head(gr.sizeof_short, int(options.nsamples) * 2) else: self.head = gr.head(gr.sizeof_gr_complex, int(options.nsamples)) self.connect(self.u, self.head, self.dst) if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u) self.u.set_mux( usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(), ) input_rate = self.u.adc_freq() / self.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 = 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 not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1
def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) # Menu Bar self.frame_1_menubar = wx.MenuBar() self.SetMenuBar(self.frame_1_menubar) wxglade_tmp_menu = wx.Menu() self.Exit = wx.MenuItem(wxglade_tmp_menu, ID_EXIT, "Exit", "Exit", wx.ITEM_NORMAL) wxglade_tmp_menu.AppendItem(self.Exit) self.frame_1_menubar.Append(wxglade_tmp_menu, "File") # Menu Bar end self.panel_1 = wx.Panel(self, -1) self.button_1 = wx.Button(self, ID_BUTTON_1, "LSB") self.button_2 = wx.Button(self, ID_BUTTON_2, "USB") self.button_3 = wx.Button(self, ID_BUTTON_3, "AM") self.button_4 = wx.Button(self, ID_BUTTON_4, "CW") self.button_5 = wx.ToggleButton(self, ID_BUTTON_5, "Upper") self.slider_1 = wx.Slider(self, ID_SLIDER_1, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.button_6 = wx.ToggleButton(self, ID_BUTTON_6, "Lower") self.slider_2 = wx.Slider(self, ID_SLIDER_2, 0, -15799, 15799, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_5 = wx.Panel(self, -1) self.label_1 = wx.StaticText(self, -1, " Band\nCenter") self.text_ctrl_1 = wx.TextCtrl(self, ID_TEXT_1, "") self.panel_6 = wx.Panel(self, -1) self.panel_7 = wx.Panel(self, -1) self.panel_2 = wx.Panel(self, -1) self.button_7 = wx.ToggleButton(self, ID_BUTTON_7, "Freq") self.slider_3 = wx.Slider(self, ID_SLIDER_3, 3000, 0, 6000) self.spin_ctrl_1 = wx.SpinCtrl(self, ID_SPIN_1, "", min=0, max=100) self.button_8 = wx.ToggleButton(self, ID_BUTTON_8, "Vol") self.slider_4 = wx.Slider(self, ID_SLIDER_4, 0, 0, 500) self.slider_5 = wx.Slider(self, ID_SLIDER_5, 0, 0, 20) self.button_9 = wx.ToggleButton(self, ID_BUTTON_9, "Time") self.button_11 = wx.Button(self, ID_BUTTON_11, "Rew") self.button_10 = wx.Button(self, ID_BUTTON_10, "Fwd") self.panel_3 = wx.Panel(self, -1) self.label_2 = wx.StaticText(self, -1, "PGA ") self.panel_4 = wx.Panel(self, -1) self.panel_8 = wx.Panel(self, -1) self.panel_9 = wx.Panel(self, -1) self.label_3 = wx.StaticText(self, -1, "AM Sync\nCarrier") self.slider_6 = wx.Slider(self, ID_SLIDER_6, 50, 0, 200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.label_4 = wx.StaticText(self, -1, "Antenna Tune") self.slider_7 = wx.Slider(self, ID_SLIDER_7, 1575, 950, 2200, style=wx.SL_HORIZONTAL | wx.SL_LABELS) self.panel_10 = wx.Panel(self, -1) self.button_12 = wx.ToggleButton(self, ID_BUTTON_12, "Auto Tune") self.button_13 = wx.Button(self, ID_BUTTON_13, "Calibrate") self.button_14 = wx.Button(self, ID_BUTTON_14, "Reset") self.panel_11 = wx.Panel(self, -1) self.panel_12 = wx.Panel(self, -1) self.__set_properties() self.__do_layout() # end wxGlade parser = OptionParser(option_class=eng_option) parser.add_option("-c", "--ddc-freq", type="eng_float", default=3.9e6, help="set Rx DDC frequency to FREQ", metavar="FREQ") parser.add_option("-a", "--audio_file", default="", help="audio output file", metavar="FILE") parser.add_option("-r", "--radio_file", default="", help="radio output file", metavar="FILE") parser.add_option("-i", "--input_file", default="", help="radio input file", metavar="FILE") parser.add_option("-d", "--decim", type="int", default=250, help="USRP decimation") parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default=None, help= "select USRP Rx side A or B (default=first one with a daughterboard)" ) (options, args) = parser.parse_args() self.usrp_center = options.ddc_freq usb_rate = 64e6 / options.decim self.slider_range = usb_rate * 0.9375 self.f_lo = self.usrp_center - (self.slider_range / 2) self.f_hi = self.usrp_center + (self.slider_range / 2) self.af_sample_rate = 32000 fir_decim = long(usb_rate / self.af_sample_rate) # data point arrays for antenna tuner self.xdata = [] self.ydata = [] self.tb = gr.top_block() # radio variables, initial conditions self.frequency = self.usrp_center # these map the frequency slider (0-6000) to the actual range self.f_slider_offset = self.f_lo self.f_slider_scale = 10000 / options.decim self.spin_ctrl_1.SetRange(self.f_lo, self.f_hi) self.text_ctrl_1.SetValue(str(int(self.usrp_center))) self.slider_5.SetValue(0) self.AM_mode = False self.slider_3.SetValue( (self.frequency - self.f_slider_offset) / self.f_slider_scale) self.spin_ctrl_1.SetValue(int(self.frequency)) POWERMATE = True try: self.pm = powermate.powermate(self) except: sys.stderr.write("Unable to find PowerMate or Contour Shuttle\n") POWERMATE = False if POWERMATE: powermate.EVT_POWERMATE_ROTATE(self, self.on_rotate) powermate.EVT_POWERMATE_BUTTON(self, self.on_pmButton) self.active_button = 7 # command line options if options.audio_file == "": SAVE_AUDIO_TO_FILE = False else: SAVE_AUDIO_TO_FILE = True if options.radio_file == "": SAVE_RADIO_TO_FILE = False else: SAVE_RADIO_TO_FILE = True if options.input_file == "": self.PLAY_FROM_USRP = True else: self.PLAY_FROM_USRP = False if self.PLAY_FROM_USRP: self.src = usrp.source_s(decim_rate=options.decim) if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.src) self.src.set_mux( usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec)) self.subdev = usrp.selected_subdev(self.src, options.rx_subdev_spec) self.src.tune(0, self.subdev, self.usrp_center) self.tune_offset = 0 # -self.usrp_center - self.src.rx_freq(0) else: self.src = gr.file_source(gr.sizeof_short, options.input_file) self.tune_offset = 2200 # 2200 works for 3.5-4Mhz band # save radio data to a file if SAVE_RADIO_TO_FILE: file = gr.file_sink(gr.sizeof_short, options.radio_file) self.tb.connect(self.src, file) # 2nd DDC xlate_taps = gr.firdes.low_pass ( \ 1.0, usb_rate, 16e3, 4e3, gr.firdes.WIN_HAMMING ) self.xlate = gr.freq_xlating_fir_filter_ccf ( \ fir_decim, xlate_taps, self.tune_offset, usb_rate ) # convert rf data in interleaved short int form to complex s2ss = gr.stream_to_streams(gr.sizeof_short, 2) s2f1 = gr.short_to_float() s2f2 = gr.short_to_float() src_f2c = gr.float_to_complex() self.tb.connect(self.src, s2ss) self.tb.connect((s2ss, 0), s2f1) self.tb.connect((s2ss, 1), s2f2) self.tb.connect(s2f1, (src_f2c, 0)) self.tb.connect(s2f2, (src_f2c, 1)) # Complex Audio filter audio_coeffs = gr.firdes.complex_band_pass( 1.0, # gain self.af_sample_rate, # sample rate -3000, # low cutoff 0, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.slider_1.SetValue(0) self.slider_2.SetValue(-3000) self.audio_filter = gr.fir_filter_ccc(1, audio_coeffs) # Main +/- 16Khz spectrum display self.fft = fftsink2.fft_sink_c(self.panel_2, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) # AM Sync carrier if AM_SYNC_DISPLAY: self.fft2 = fftsink.fft_sink_c(self.tb, self.panel_9, y_per_div=20, fft_size=512, sample_rate=self.af_sample_rate, average=True, size=(640, 240)) c2f = gr.complex_to_float() # AM branch self.sel_am = gr.multiply_const_cc(0) # the following frequencies turn out to be in radians/sample # gr.pll_refout_cc(alpha,beta,min_freq,max_freq) # suggested alpha = X, beta = .25 * X * X pll = gr.pll_refout_cc(.5, .0625, (2. * math.pi * 7.5e3 / self.af_sample_rate), (2. * math.pi * 6.5e3 / self.af_sample_rate)) self.pll_carrier_scale = gr.multiply_const_cc(complex(10, 0)) am_det = gr.multiply_cc() # these are for converting +7.5kHz to -7.5kHz # for some reason gr.conjugate_cc() adds noise ?? c2f2 = gr.complex_to_float() c2f3 = gr.complex_to_float() f2c = gr.float_to_complex() phaser1 = gr.multiply_const_ff(1) phaser2 = gr.multiply_const_ff(-1) # filter for pll generated carrier pll_carrier_coeffs = gr.firdes.complex_band_pass( 2.0, # gain self.af_sample_rate, # sample rate 7400, # low cutoff 7600, # high cutoff 100, # transition gr.firdes.WIN_HAMMING) # window self.pll_carrier_filter = gr.fir_filter_ccc(1, pll_carrier_coeffs) self.sel_sb = gr.multiply_const_ff(1) combine = gr.add_ff() #AGC sqr1 = gr.multiply_ff() intr = gr.iir_filter_ffd([.004, 0], [0, .999]) offset = gr.add_const_ff(1) agc = gr.divide_ff() self.scale = gr.multiply_const_ff(0.00001) dst = audio.sink(long(self.af_sample_rate)) self.tb.connect(src_f2c, self.xlate, self.fft) self.tb.connect(self.xlate, self.audio_filter, self.sel_am, (am_det, 0)) self.tb.connect(self.sel_am, pll, self.pll_carrier_scale, self.pll_carrier_filter, c2f3) self.tb.connect((c2f3, 0), phaser1, (f2c, 0)) self.tb.connect((c2f3, 1), phaser2, (f2c, 1)) self.tb.connect(f2c, (am_det, 1)) self.tb.connect(am_det, c2f2, (combine, 0)) self.tb.connect(self.audio_filter, c2f, self.sel_sb, (combine, 1)) if AM_SYNC_DISPLAY: self.tb.connect(self.pll_carrier_filter, self.fft2) self.tb.connect(combine, self.scale) self.tb.connect(self.scale, (sqr1, 0)) self.tb.connect(self.scale, (sqr1, 1)) self.tb.connect(sqr1, intr, offset, (agc, 1)) self.tb.connect(self.scale, (agc, 0)) self.tb.connect(agc, dst) if SAVE_AUDIO_TO_FILE: f_out = gr.file_sink(gr.sizeof_short, options.audio_file) sc1 = gr.multiply_const_ff(64000) f2s1 = gr.float_to_short() self.tb.connect(agc, sc1, f2s1, f_out) self.tb.start() # for mouse position reporting on fft display em.eventManager.Register(self.Mouse, wx.EVT_MOTION, self.fft.win) # and left click to re-tune em.eventManager.Register(self.Click, wx.EVT_LEFT_DOWN, self.fft.win) # start a timer to check for web commands if WEB_CONTROL: self.timer = UpdateTimer(self, 1000) # every 1000 mSec, 1 Sec wx.EVT_BUTTON(self, ID_BUTTON_1, self.set_lsb) wx.EVT_BUTTON(self, ID_BUTTON_2, self.set_usb) wx.EVT_BUTTON(self, ID_BUTTON_3, self.set_am) wx.EVT_BUTTON(self, ID_BUTTON_4, self.set_cw) wx.EVT_BUTTON(self, ID_BUTTON_10, self.fwd) wx.EVT_BUTTON(self, ID_BUTTON_11, self.rew) wx.EVT_BUTTON(self, ID_BUTTON_13, self.AT_calibrate) wx.EVT_BUTTON(self, ID_BUTTON_14, self.AT_reset) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_5, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_6, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_7, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_8, self.on_button) wx.EVT_TOGGLEBUTTON(self, ID_BUTTON_9, self.on_button) wx.EVT_SLIDER(self, ID_SLIDER_1, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_2, self.set_filter) wx.EVT_SLIDER(self, ID_SLIDER_3, self.slide_tune) wx.EVT_SLIDER(self, ID_SLIDER_4, self.set_volume) wx.EVT_SLIDER(self, ID_SLIDER_5, self.set_pga) wx.EVT_SLIDER(self, ID_SLIDER_6, self.am_carrier) wx.EVT_SLIDER(self, ID_SLIDER_7, self.antenna_tune) wx.EVT_SPINCTRL(self, ID_SPIN_1, self.spin_tune) wx.EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def __init__(self, fg, master_serialno, decim, nchan=2, pga_gain=0.0, cordic_freq=0.0, mux=None, align_interval=-1, fpga_filename="multi_2rxhb_2tx.rbf"): """ Align multiple sources (usrps) using samplenumbers in the first channel. Takes two ore more sources producing interleaved shorts. produces nchan * nsources gr_complex output streams. @param nchan: number of interleaved channels in source @param align_interval: number of samples to minimally skip between alignments default = -1 which means align only once per work call. @param master_serial_no: serial number of the source which must be the master. Exported sub-blocks (attributes): master_source slave_source usrp_master usrp_slave """ mode = usrp.FPGA_MODE_NORMAL mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT align = gr.align_on_samplenumbers_ss(nchan, align_interval) self.usrp_master = None self.usrp_slave = None # um is master usrp # us is slave usrp if mux is None: mux = self.get_default_mux( ) #Note that all channels have shifted left because of the added 32 bit counter channel u1 = usrp.source_s(1, decim, nchan, gru.hexint(mux), mode, fpga_filename=fpga_filename) u0 = usrp.source_s(0, decim, nchan, gru.hexint(mux), mode, fpga_filename=fpga_filename) print 'usrp[0] serial', u0.serial_number() print 'usrp[1] serial', u1.serial_number() #default, choose the second found usrp as master (which is usually the usrp which was first plugged in) um_index = 1 um = u1 us_index = 0 us = u0 if (not (master_serialno is None)): #((master_serialno>0) | (master_serialno <-2)): if (u0.serial_number() == master_serialno): um_index = 0 um = u0 us_index = 1 us = u1 elif (u1.serial_number() != master_serialno): errorstring = 'Error. requested master_serialno ' + master_serialno + ' not found\n' errorstring = errorstring + 'Available are:\n' errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number( ) + '\n' errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number( ) + '\n' print errorstring raise ValueError, errorstring else: #default, just choose the first found usrp as master um_index = 1 um = u1 us_index = 0 us = u0 self.usrp_master = um self.usrp_slave = us print 'usrp_master=usrp[%i] serial_no = %s' % ( um_index, self.usrp_master.serial_number(), ) print 'usrp_slave=usrp[%i] serial_no = %s' % ( us_index, self.usrp_slave.serial_number(), ) self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0, 0)) self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1, 0)) self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0, 0)) self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1, 0)) #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate) if not (pga_gain is None): um.set_pga(0, pga_gain) um.set_pga(1, pga_gain) us.set_pga(0, pga_gain) us.set_pga(1, pga_gain) self.input_rate = um.adc_freq() / um.decim_rate() deintm = gr.deinterleave(gr.sizeof_gr_complex) deints = gr.deinterleave(gr.sizeof_gr_complex) nullsinkm = gr.null_sink(gr.sizeof_gr_complex) nullsinks = gr.null_sink(gr.sizeof_gr_complex) tocomplexm = gr.interleaved_short_to_complex() tocomplexs = gr.interleaved_short_to_complex() fg.connect(um, (align, 0)) fg.connect(us, (align, 1)) fg.connect((align, 0), tocomplexm) fg.connect((align, 1), tocomplexs) fg.connect(tocomplexm, deintm) fg.connect(tocomplexs, deints) fg.connect( (deintm, 0), nullsinkm ) #The counters are not usefull for the user but must be connected to something fg.connect( (deints, 0), nullsinks ) #The counters are not usefull for the user but must be connected to something if 4 == nchan: nullsinkm3 = gr.null_sink(gr.sizeof_gr_complex) nullsinks3 = gr.null_sink(gr.sizeof_gr_complex) fg.connect( (deintm, 3), nullsinkm3) #channel 4 is not used but must be connected fg.connect( (deints, 3), nullsinks3) #channel 4 is not used but must be connected self.fg = fg self.master_source = deintm self.slave_source = deints if not (cordic_freq is None): um.set_rx_freq(1, cordic_freq) um.set_rx_freq(0, cordic_freq) us.set_rx_freq(1, cordic_freq) us.set_rx_freq(0, cordic_freq) self.enable_master_and_slave() # add an idle handler self.unsynced = True
def __init__(self): gr.top_block.__init__(self) usage="%prog: [options] output_filename" parser = OptionParser(option_class=eng_option, usage=usage) parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0), help="select USRP Rx side A or B (default=A)") parser.add_option("-d", "--decim", type="int", default=16, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=None, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") parser.add_option( "--no-hb", action="store_true", default=False, help="don't use halfband filter in usrp") parser.add_option( "-s","--output-shorts", action="store_true", default=False, help="output interleaved shorts in stead of complex floats") parser.add_option("-N", "--nsamples", type="eng_float", default=None, help="number of samples to collect [default=+inf]") (options, args) = parser.parse_args () if len(args) != 1: parser.print_help() raise SystemExit, 1 filename = args[0] if options.freq is None: parser.print_help() sys.stderr.write('You must specify the frequency with -f FREQ\n'); raise SystemExit, 1 # build the graph if options.no_hb or (options.decim<8): self.fpga_filename="std_4rx_0tx.rbf" #Min decimation of this firmware is 4. contains 4 Rx paths without halfbands and 0 tx paths. if options.output_shorts: self.u = usrp.source_s(decim_rate=options.decim,fpga_filename=self.fpga_filename) else: self.u = usrp.source_c(decim_rate=options.decim,fpga_filename=self.fpga_filename) else: #standard fpga firmware "std_2rxhb_2tx.rbf" contains 2 Rx paths with halfband filters and 2 tx paths (the default) min decimation 8 if options.output_shorts: self.u = usrp.source_s(decim_rate=options.decim) else: self.u = usrp.source_c(decim_rate=options.decim) if options.width_8: sample_width = 8 sample_shift = 8 format = self.u.make_format(sample_width, sample_shift) r = self.u.set_format(format) if options.output_shorts: self.dst = gr.file_sink(gr.sizeof_short, filename) else: self.dst = gr.file_sink(gr.sizeof_gr_complex, filename) if options.nsamples is None: self.connect(self.u, self.dst) else: if options.output_shorts: self.head = gr.head(gr.sizeof_short, int(options.nsamples)*2) else: self.head = gr.head(gr.sizeof_gr_complex, int(options.nsamples)) self.connect(self.u, self.head, self.dst) if options.rx_subdev_spec is None: options.rx_subdev_spec = usrp.pick_rx_subdevice(self.u) self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) print "Using RX d'board %s" % (self.subdev.side_and_name(),) input_rate = self.u.adc_freq() / self.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 = 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 not r: sys.stderr.write('Failed to set frequency\n') raise SystemExit, 1
def __init__(self, fg, master_serialno,decim,nchan=2,pga_gain=0.0,cordic_freq=0.0,mux=None,align_interval=-1): """ Align multiple sources (usrps) using samplenumbers in the first channel. Takes two ore more sources producing interleaved shorts. produces nchan * nsources gr_complex output streams. @param nchan: number of interleaved channels in source @param align_interval: number of samples to minimally skip between alignments default = -1 which means align only once per work call. @param master_serial_no: serial number of the source which must be the master. Exported sub-blocks (attributes): master_source slave_source usrp_master usrp_slave """ mode=usrp.FPGA_MODE_NORMAL mode = mode | usrp_prims.bmFR_MODE_RX_COUNTING_32BIT #(1 << 2) #usrp1.FPGA_MODE_COUNTING_32BIT align=gr.align_on_samplenumbers_ss (nchan,align_interval) self.usrp_master = None self.usrp_slave = None # um is master usrp # us is slave usrp if mux is None: mux=self.get_default_mux() #Note that all channels have shifted left because of the added 32 bit counter channel u1 = usrp.source_s (1, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" ) u0 = usrp.source_s (0, decim, nchan, gru.hexint(mux), mode,fpga_filename="multi_2rxhb_2tx.rbf" ) print 'usrp[0] serial',u0.serial_number() print 'usrp[1] serial',u1.serial_number() #default, choose the second found usrp as master (which is usually the usrp which was first plugged in) um_index=1 um=u1 us_index=0 us=u0 if (not (master_serialno is None)): #((master_serialno>0) | (master_serialno <-2)): if (u0.serial_number() == master_serialno): um_index=0 um=u0 us_index=1 us=u1 elif (u1.serial_number() != master_serialno): errorstring = 'Error. requested master_serialno ' + master_serialno +' not found\n' errorstring = errorstring + 'Available are:\n' errorstring = errorstring + 'usrp[1] serial_no = ' + u1.serial_number() +'\n' errorstring = errorstring + 'usrp[0] serial_no = ' + u0.serial_number() +'\n' print errorstring raise ValueError, errorstring else: #default, just choose the first found usrp as master um_index=0 um=u0 us_index=1 us=u1 self.usrp_master=um self.usrp_slave=us print 'usrp_master=usrp[%i] serial_no = %s' % (um_index,self.usrp_master.serial_number() ,) print 'usrp_slave=usrp[%i] serial_no = %s' % (us_index,self.usrp_slave.serial_number() ,) self.subdev_mAr = usrp.selected_subdev(self.usrp_master, (0,0)) self.subdev_mBr = usrp.selected_subdev(self.usrp_master, (1,0)) self.subdev_sAr = usrp.selected_subdev(self.usrp_slave, (0,0)) self.subdev_sBr = usrp.selected_subdev(self.usrp_slave, (1,0)) #throttle = gr.throttle(gr.sizeof_gr_complex, input_rate) if not (pga_gain is None): um.set_pga (0, pga_gain) um.set_pga (1, pga_gain) us.set_pga (0, pga_gain) us.set_pga (1, pga_gain) self.input_rate = um.adc_freq () / um.decim_rate () deintm=gr.deinterleave(gr.sizeof_gr_complex) deints=gr.deinterleave(gr.sizeof_gr_complex) nullsinkm=gr.null_sink(gr.sizeof_gr_complex) nullsinks=gr.null_sink(gr.sizeof_gr_complex) tocomplexm=gr.interleaved_short_to_complex() tocomplexs=gr.interleaved_short_to_complex() fg.connect(um,(align,0)) fg.connect(us,(align,1)) fg.connect((align,0),tocomplexm) fg.connect((align,1),tocomplexs) fg.connect(tocomplexm,deintm) fg.connect(tocomplexs,deints) fg.connect((deintm,0),nullsinkm) #The counters are not usefull for the user but must be connected to something fg.connect((deints,0),nullsinks) #The counters are not usefull for the user but must be connected to something if 4==nchan: nullsinkm3=gr.null_sink(gr.sizeof_gr_complex) nullsinks3=gr.null_sink(gr.sizeof_gr_complex) fg.connect((deintm,3), nullsinkm3) #channel 4 is not used but must be connected fg.connect((deints,3), nullsinks3) #channel 4 is not used but must be connected self.fg=fg self.master_source=deintm self.slave_source=deints if not (cordic_freq is None): um.set_rx_freq (1, cordic_freq) um.set_rx_freq (0, cordic_freq) us.set_rx_freq (1, cordic_freq) us.set_rx_freq (0, cordic_freq) self.enable_master_and_slave() # add an idle handler self.unsynced=True
def __init__(self, frame, panel, vbox, argv): stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv) self.frame = frame self.panel = panel parser = OptionParser(option_class=eng_option) parser.add_option( "-w", "--which", type="int", default=0, help="select which USRP (0, 1, ...) default is %default", metavar="NUM") # parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, # help="select USRP Rx side A or B (default=first one with a daughterboard)") parser.add_option("-A", "--antenna", default=None, help="select Rx Antenna (only on RFX-series boards)") parser.add_option( "-d", "--decim", type="int", default=32, help="set fgpa decimation rate to DECIM [default=%default]") parser.add_option("-f", "--freq", type="eng_float", default=0.0, help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=None, help="set gain in dB (default is midpoint)") parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Enable waterfall display") parser.add_option("-8", "--width-8", action="store_true", default=False, help="Enable 8-bit samples across USB") # parser.add_option( "--no-hb", action="store_true", default=False, # help="don't use halfband filter in usrp") parser.add_option("-S", "--oscilloscope", action="store_true", default=False, help="Enable oscilloscope display (default)") parser.add_option("-F", "--fft", action="store_true", default=False, help="Enable FFT display") parser.add_option( "-n", "--frame-decim", type="int", default=1, help="set oscope frame decimation factor to n [default=1]") parser.add_option( "-v", "--v-scale", type="eng_float", default=1, help="set oscope initial V/div to SCALE [default=%default]") parser.add_option( "-t", "--t-scale", type="eng_float", default=10e-6, help="set oscope initial s/div to SCALE [default=10us]") parser.add_option( "--digital", action="store_true", default=False, help= "show (only) the digital wave on lsb (will be input from gpio pins with special usrp firmware)" ) parser.add_option( "--analog", action="store_true", default=False, help= "show (only) the analog wave on msbs (will be input from analog inputs)" ) parser.add_option( "--file", default=None, help= "input from file FILE in stead of USRP (will be input from raw file in interleaved short format)" ) (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.options = options self.show_debug_info = True self.u = usrp.source_s(which=options.which, decim_rate=options.decim, fpga_filename=gpio.fpga_filename) print "Warning: This script only supports boards on RXA, change the script if you want otherwise" #options.rx_subdev_spec=(0, 0)#force the use of RXA options.rx_subdev_spec = None #force the use of RXA if options.rx_subdev_spec is None: options.rx_subdev_spec = pick_subdevice(self.u) #This hardcoded mux setting is why this script only supports RXA #We want both I and Q active, even when using basicRX #set to 0x10 for RXA #set to 0x32 for RXB self.u.set_mux( 0x10 ) #usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) if options.width_8: width = 8 shift = 8 format = self.u.make_format(width, shift) print "format =", hex(format) r = self.u.set_format(format) print "set_format =", r # determine the daughterboard subdevice we're using self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) #if options.rx_subdev_spec==(0,0): # rx_subdev_spec2=(0,1) # self.subdev2 = usrp.selected_subdev(self.u, rx_subdev_spec2) input_rate = self.u.adc_freq() / self.u.decim_rate() if options.waterfall: self.scope = \ waterfallsink2.waterfall_sink_c (panel, fft_size=1024, sample_rate=input_rate) elif options.fft: self.scope = fftsink2.fft_sink_c(panel, fft_size=1024, sample_rate=input_rate) else: # options.oscilloscope: #self.scope = scopesink2.scope_sink_c(panel, sample_rate=input_rate) self.scope = scopesink2.scope_sink_c( panel, sample_rate=input_rate, frame_decim=options.frame_decim, v_scale=options.v_scale, t_scale=options.t_scale) self.is2c = gr.interleaved_short_to_complex() if not (options.file is None): self.filesrc = gr.file_source(gr.sizeof_short, options.file, True) thr = gr.throttle(gr.sizeof_short, input_rate) self.connect(self.filesrc, thr, self.is2c, self.scope) elif options.digital: self.select_dig = gr.and_const_ss(0x0001) self.connect(self.u, self.select_dig, self.is2c, self.scope) elif options.analog: self.select_ana = gr.and_const_ss(0xFFFE) self.connect(self.u, self.select_ana, self.is2c, self.scope) else: self.connect(self.u, self.is2c, self.scope) self._build_gui(vbox) self._setup_events() # 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 if options.freq is None: # if no freq was specified, use the mid-point r = self.subdev.freq_range() options.freq = float(r[0] + r[1]) / 2 self.set_gain(options.gain) if options.antenna is not None: print "Selecting antenna %s" % (options.antenna, ) self.subdev.select_rx_antenna(options.antenna) if self.show_debug_info: self.myform['decim'].set_value(self.u.decim_rate()) self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate()) self.myform['dbname'].set_value(self.subdev.name()) self.myform['baseband'].set_value(0) self.myform['ddc'].set_value(0) if not (self.set_freq(options.freq)): self._set_status_msg("Failed to set initial frequency")
def __init__(self): gr.flow_graph.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option( "-R", "--rx-subdev-spec", type="subdev", default='B', help= "select USRP Rx side A or B (default=first one with a daughterboard)" ) parser.add_option("-c", "--cordic-freq", type="eng_float", default=434845200, help="set rx cordic frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=0, help="set Rx PGA gain in dB [0,20]") (options, args) = parser.parse_args() print "cordic_freq = %s" % (eng_notation.num_to_str( options.cordic_freq)) # ---------------------------------------------------------------- self.freq = 1000 self.samples_per_symbol = 256 self.usrp_decim = int(64e6 / self.samples_per_symbol / self.freq) self.fs = self.freq * self.samples_per_symbol print "freq = ", eng_notation.num_to_str(self.freq) 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_s(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)) subdev = usrp.selected_subdev(u, options.rx_subdev_spec) print "Using RX d'board %s" % (subdev.side_and_name(), ) u.tune(0, subdev, options.cordic_freq) u.set_pga(0, options.gain) u.set_pga(1, options.gain) self.u = u self.filesink = gr.file_sink(gr.sizeof_float, 'rx_sin.dat') self.stof = gr.short_to_float() filter_coeffs = gr.firdes.low_pass( 1.0, # gain self.fs, # sampling rate self.freq, # low pass cutoff freq 0.1 * self.freq, # width of trans. band gr.firdes.WIN_HANN) # filter type self.lowpass = gr.fir_filter_fff(1, filter_coeffs) self.connect(self.u, self.stof, self.lowpass, self.filesink)