Esempio n. 1
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__(self)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        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("-d", "--decim", type="int", default=128,
                          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)")
        #align interval is default not yet enabled in gr.align_on_samplenumbers_ss
        #parser.add_option("-a", "--align_interval", type="int", default=-1,
        #                  help="Align master and slave every so much samples.")

        # width 8 does not work yet with multi_usrp because it interferes with the 32 bit samplecounter
        #parser.add_option("-8", "--width-8", action="store_true", default=False,
        #                  help="Enable 8-bit samples across USB")
        parser.add_option("-m", "--mux", type="intx", default=None,
                          help="set fpga FR_RX_MUX register to MUX")
        parser.add_option("-n", "--frame-decim", type="int", default=1,
                          help="set oscope frame decimation factor to n [default=1]")
        parser.add_option("-N", "--nchan", type="int", default=2,
                          help="set nchannels to NCHAN")
        parser.add_option("-q", "--show-q", action="store_true", default=False,
                          help="show the q value of the complex samples")
        parser.add_option("-s", "--show-counters", action="store_true", default=False,
                          help="show the counters")
        parser.add_option("-v", "--v-scale", type="eng_float", default=1000,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6,
                          help="set oscope initial s/div to SCALE [default=50us]")
        parser.add_option("-x", "--master-serialno", type="string", default=None, 
                          help="Serial_no of the usrp which should be the MASTER (default= select any)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True
        
        # build the graph

        #self.u = usrp.source_c(which=options.which_usrp,decim_rate=options.decim)
        if (options.mux is None) | (4==options.nchan):
           init_mux=None #use default mux which is 0x10321032
        else:
           init_mux=options.mux

        init_gain=0.0
        init_freq=0.0
        init_align_interval=-1

        self.multi=usrp_multi.multi_source_align( self,   options.master_serialno, options.decim,
                                                 options.nchan, init_gain, init_freq, init_mux, init_align_interval)
        self.um=self.multi.get_master_usrp()
        self.us=self.multi.get_slave_usrp()

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.um)
        if (options.mux==None) and (options.nchan!=4):
          mux=usrp.determine_rx_mux_value(self.um, options.rx_subdev_spec)
          mux= (mux<<8 & 0xffffffff) | (mux & 0xff)
          self.um.set_mux(mux)
          self.us.set_mux(mux)

        # width 8 does not work yet with multi_usrp because it interferes with the 32 bit samplecounter
        #if options.width_8:
        #    width = 8
        #    shift = 8
        #    format = self.um.make_format(width, shift)
        #    r = self.um.set_format(format)
        #    r = self.us.set_format(format)
            
        # determine the daughterboard subdevice of the first channel we're using
        self.subdevm = usrp.selected_subdev(self.um, options.rx_subdev_spec)
        self.subdevs = usrp.selected_subdev(self.us, options.rx_subdev_spec)

        input_rate = self.um.adc_freq() / self.um.decim_rate()

        self.scope = scopesink.scope_sink_f(self, panel, sample_rate=input_rate,
                                            frame_decim=options.frame_decim,
                                            v_scale=options.v_scale,
                                            t_scale=options.t_scale)
        self.sink_count=0
        self.add_to_scope((self.multi.get_master_source_c(),1),options.show_q)
        self.add_to_scope((self.multi.get_slave_source_c(),1),options.show_q)
        if 4==options.nchan:
          self.add_to_scope((self.multi.get_master_source_c(),2),options.show_q)
          self.add_to_scope((self.multi.get_slave_source_c(),2),options.show_q)

        if options.show_counters:
          self.add_to_scope((self.multi.get_master_source_c(),0),options.show_q)
          self.add_to_scope((self.multi.get_slave_source_c(),0),options.show_q)

        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdevm.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.subdevm.freq_range()
            options.freq = float(r[0]+r[1])/2

        self.set_gain(options.gain)

        if self.show_debug_info:
            self.myform['decim'].set_value(self.um.decim_rate())
            self.myform['fs@usb'].set_value(self.um.adc_freq() / self.um.decim_rate())
            self.myform['dbname'].set_value(self.subdevm.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")

        self.multi.print_db_info()
        self.unsynced=True
        frame.Bind(wx.EVT_IDLE, self.onIdle)
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__(self)

        self.frame = frame
        self.panel = panel
        
        parser = OptionParser(option_class=eng_option)
        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("-d", "--decim", type="int", default=128,
                          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)")
        #align interval is default not yet enabled in gr.align_on_samplenumbers_ss
        #parser.add_option("-a", "--align_interval", type="int", default=-1,
        #                  help="Align master and slave every so much samples.")

        # width 8 does not work yet with multi_usrp because it interferes with the 32 bit samplecounter
        #parser.add_option("-8", "--width-8", action="store_true", default=False,
        #                  help="Enable 8-bit samples across USB")
        parser.add_option("-m", "--mux", type="intx", default=None,
                          help="set fpga FR_RX_MUX register to MUX")
        parser.add_option("-n", "--frame-decim", type="int", default=1,
                          help="set oscope frame decimation factor to n [default=1]")
        parser.add_option("-N", "--nchan", type="int", default=2,
                          help="set nchannels to NCHAN")
        parser.add_option("-q", "--show-q", action="store_true", default=False,
                          help="show the q value of the complex samples")
        parser.add_option("-s", "--show-counters", action="store_true", default=False,
                          help="show the counters")
        parser.add_option("-v", "--v-scale", type="eng_float", default=1000,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=49e-6,
                          help="set oscope initial s/div to SCALE [default=50us]")
        parser.add_option("-x", "--master-serialno", type="string", default=None, 
                          help="Serial_no of the usrp which should be the MASTER (default= select any)")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True
        
        # build the graph

        #self.u = usrp.source_c(which=options.which_usrp,decim_rate=options.decim)
        if (options.mux is None) | (4==options.nchan):
           init_mux=None #use default mux which is 0x10321032
        else:
           init_mux=options.mux

        init_gain=0.0
        init_freq=0.0
        init_align_interval=-1

        self.multi=usrp_multi.multi_source_align( self,   options.master_serialno, options.decim,
                                                 options.nchan, init_gain, init_freq, init_mux, init_align_interval)
        self.um=self.multi.get_master_usrp()
        self.us=self.multi.get_slave_usrp()

        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.um)
        if (options.mux==None) and (options.nchan!=4):
          mux=usrp.determine_rx_mux_value(self.um, options.rx_subdev_spec)
          mux= (mux<<8 & 0xffffffff) | (mux & 0xff)
          self.um.set_mux(mux)
          self.us.set_mux(mux)

        # width 8 does not work yet with multi_usrp because it interferes with the 32 bit samplecounter
        #if options.width_8:
        #    width = 8
        #    shift = 8
        #    format = self.um.make_format(width, shift)
        #    r = self.um.set_format(format)
        #    r = self.us.set_format(format)
            
        # determine the daughterboard subdevice of the first channel we're using
        self.subdevm = usrp.selected_subdev(self.um, options.rx_subdev_spec)
        self.subdevs = usrp.selected_subdev(self.us, options.rx_subdev_spec)

        input_rate = self.um.adc_freq() / self.um.decim_rate()

        self.scope = scopesink.scope_sink_f(self, panel, sample_rate=input_rate,
                                            frame_decim=options.frame_decim,
                                            v_scale=options.v_scale,
                                            t_scale=options.t_scale)
        self.sink_count=0
        self.add_to_scope((self.multi.get_master_source_c(),1),options.show_q)
        self.add_to_scope((self.multi.get_slave_source_c(),1),options.show_q)
        if 4==options.nchan:
          self.add_to_scope((self.multi.get_master_source_c(),2),options.show_q)
          self.add_to_scope((self.multi.get_slave_source_c(),2),options.show_q)

        if options.show_counters:
          self.add_to_scope((self.multi.get_master_source_c(),0),options.show_q)
          self.add_to_scope((self.multi.get_slave_source_c(),0),options.show_q)

        self._build_gui(vbox)

        # set initial values

        if options.gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.subdevm.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.subdevm.freq_range()
            options.freq = float(r[0]+r[1])/2

        self.set_gain(options.gain)

        if self.show_debug_info:
            self.myform['decim'].set_value(self.um.decim_rate())
            self.myform['fs@usb'].set_value(self.um.adc_freq() / self.um.decim_rate())
            self.myform['dbname'].set_value(self.subdevm.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")

        self.multi.print_db_info()
        self.unsynced=True
        frame.Bind(wx.EVT_IDLE, self.onIdle)
    def __init__(self, frame, panel, vbox, argv):
        stdgui.gui_flow_graph.__init__(self)

        self.frame = frame
        self.panel = panel

        parser = OptionParser (option_class=eng_option)
        #parser.add_option("-S", "--subdev", type="subdev", default=(0, None),
        #                  help="select USRP Rx side A or B (default=A)")
        parser.add_option("-d", "--decim", type="int", default=128,
                          help="set fgpa decimation rate to DECIM [default=%default]")
        parser.add_option("-f", "--freq", type="eng_float", default=146.585e6,
                          help="set frequency to FREQ [default=%default])", metavar="FREQ")
        parser.add_option("-g", "--gain", type="eng_float", default=20,
                          help="set gain in dB [default=%default]")
        parser.add_option("-F", "--filter", action="store_true", default=True,
                          help="Enable channel filter")
        (options, args) = parser.parse_args()

        if len(args) != 0:
            parser.print_help()
            raise SystemExit

        nchan = 4

        if options.filter:
            sw_decim = 4
        else:
            sw_decim = 1

        self.u = usrp.source_c(0, options.decim, fpga_filename="std_4rx_0tx.rbf")
        if self.u.nddc() < nchan:
            sys.stderr.write('This code requires an FPGA build with %d DDCs.  This FPGA has only %d.\n' % (
                nchan, self.u.nddc()))
            raise SystemExit
                             
        if not self.u.set_nchannels(nchan):
            sys.stderr.write('set_nchannels(%d) failed\n' % (nchan,))
            raise SystemExit
        
        input_rate = self.u.adc_freq() / self.u.decim_rate()
        print "USB data rate   = %s" % (eng_notation.num_to_str(input_rate),)
        print "Scope data rate = %s" % (eng_notation.num_to_str(input_rate/sw_decim),)

        self.subdev = self.u.db[0] + self.u.db[1]

        if (len(self.subdev) != 4 or
            self.u.db[0][0].dbid() != usrp_dbid.BASIC_RX or
            self.u.db[1][0].dbid() != usrp_dbid.BASIC_RX):
            sys.stderr.write('This code requires a Basic Rx board on Sides A & B\n')
            sys.exit(1)

        self.u.set_mux(gru.hexint(0xf3f2f1f0))

        # deinterleave four channels from FPGA
        di = gr.deinterleave(gr.sizeof_gr_complex)

        self.connect(self.u, di)
        
        # our destination (8 float inputs)
        self.scope = scopesink.scope_sink_f(self, panel, sample_rate=input_rate/sw_decim)

        # taps for channel filter
        chan_filt_coeffs = optfir.low_pass (1,           # gain
                                            input_rate,  # sampling rate
                                            80e3,        # passband cutoff
                                            115e3,       # stopband cutoff
                                            0.1,         # passband ripple
                                            60)          # stopband attenuation
        #print len(chan_filt_coeffs)

        # bust the deinterleaved complex channels into floats
        for i in range(nchan):

            if options.filter:
                chan_filt = gr.fir_filter_ccf(sw_decim, chan_filt_coeffs)
                c2f = gr.complex_to_float()
                self.connect((di, i), chan_filt, c2f)
            else:
                c2f = gr.complex_to_float()
                self.connect((di, i), c2f)

            self.connect((c2f, 0), (self.scope, 2*i + 0))
            self.connect((c2f, 1), (self.scope, 2*i + 1))


        self._build_gui(vbox)

        self.set_gain(options.gain)
        self.set_freq(options.freq)