コード例 #1
0
ファイル: ppm_demod.py プロジェクト: FlavioFalcao/gr-air
    def __init__(self, channel_rate, threshold):
        gr.hier_block2.__init__(self, "ppm_demod",
                              gr.io_signature(1, 1, gr.sizeof_gr_complex),
                              gr.io_signature(1, 1, 512))

        chan_rate = 8000000 # Minimum sample rate

        if channel_rate < chan_rate:
            raise ValueError, "Invalid channel rate %d. Must be 8000000 sps or higher" % (channel_rate)
        
        if channel_rate >= 10000000:
            chan_rate = 10000000    # Higher Performance Receiver

        # if rate is not supported then resample
        if channel_rate != chan_rate:
            interp = gru.lcm(channel_rate, chan_rate)/channel_rate
            decim  = gru.lcm(channel_rate, chan_rate)/chan_rate
            self.RESAMP = rational_resampler_ccf(self, interp, decim)

        # Calculate the leading edge threshold per sample time
        leading_edge = risetime_threshold_db/(chan_rate/data_rate)

        # Calculate the number of following samples above threshold needed to make a sample a valid pulse position
        valid_pulse_position = 2
        if chan_rate == 10000000:
            valid_pulse_position = 3

        # Demodulate AM with classic sqrt (I*I + Q*Q)
        self.MAG = gr.complex_to_mag()
        self.DETECT = air.ms_pulse_detect(leading_edge, threshold, valid_pulse_position) # Attack, Threshold, Pulsewidth
        self.SYNC = air.ms_preamble(chan_rate)
        self.FRAME = air.ms_framer(chan_rate)
        self.BIT   = air.ms_ppm_decode(chan_rate)
        self.PARITY = air.ms_parity()
        self.EC    =  air.ms_ec_brute()

        if channel_rate != chan_rate:
            # Resample the stream first
            self.connect(self, self.RESAMP, self.MAG, self.DETECT)
        else: 
            self.connect(self, self.MAG, self.DETECT)

        self.connect((self.DETECT, 0), (self.SYNC, 0))
        self.connect((self.DETECT, 1), (self.SYNC, 1))
        self.connect((self.SYNC, 0), (self.FRAME, 0))
        self.connect((self.SYNC, 1), (self.FRAME, 1))
        self.connect((self.FRAME, 0), (self.BIT, 0))
        self.connect((self.FRAME, 1), (self.BIT, 1))
        self.connect(self.BIT, self.PARITY, self.EC, self)
コード例 #2
0
ファイル: usrp_oscope_ms.py プロジェクト: FlavioFalcao/gr-air
    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("-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=8,
                          help="set fgpa decimation rate to DECIM [default=%default]")
    	parser.add_option("-f", "--freq", type="eng_float", default=1090.0,
                          help="set receive frequency to MHz [default=%default]", 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("-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=200,
                          help="set oscope initial V/div to SCALE [default=%default]")
        parser.add_option("-t", "--t-scale", type="eng_float", default=24e-6,
                          help="set oscope initial s/div to SCALE [default=25us]")
    	parser.add_option("-T", "--thresh", type="int", default=10,
                          help="set valid pulse threshold to THRESH [default=%default]")
        (options, args) = parser.parse_args()
        if len(args) != 0:
            parser.print_help()
            sys.exit(1)

        self.show_debug_info = True

	options.freq *= 1e6

        # build the graph

	if 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.
	       	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
        	self.u = usrp.source_c(decim_rate=options.decim)
        if options.rx_subdev_spec is None:
            options.rx_subdev_spec = pick_subdevice(self.u)
        self.u.set_mux(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)
	#self.subdev.set_bw(5e6)  # only valid for dbsrx

	chan_rate = 8000000
        input_rate = self.u.adc_freq() / self.u.decim_rate()
	if input_rate < chan_rate:
            raise ValueError, "Invalid input rate %d. Must be 8000000 sps or higher" % (input_rate)
	if input_rate >= 10000000:
		chan_rate = 10000000    # Higher Performance Receiver
	# if rate is not supported then resample
	if input_rate != chan_rate:
		raise Error, "Resampling Unsupported"
		#interp = gru.lcm(input_rate, chan_rate)/input_rate
		#decim  = gru.lcm(input_rate, chan_rate)/chan_rate
		#print interp, decim
		#self.resamp = blks.rational_resampler_ccf(self, interp, decim)

	# Calculate the leading edge threshold per sample time
	leading_edge = risetime_threshold_db/(chan_rate/data_rate)
	# The number of following samples above threshold needed to make a sample a valid pulse position
	valid_pulse_position = 2
	if chan_rate == 10000000:
		valid_pulse_position = 3
	self.mag = gr.complex_to_mag()
	self.detect = air.ms_pulse_detect(leading_edge, options.thresh, valid_pulse_position)
	self.sync = air.ms_preamble(chan_rate)
	self.frame = air.ms_framer(chan_rate)
	self.cvt = air.ms_cvt_float()
        self.scope = scopesink2.scope_sink_f(self, panel, sample_rate=chan_rate,
                                            frame_decim=options.frame_decim,
                                            v_scale=options.v_scale,
                                            t_scale=options.t_scale)
	#if chan_rate == 10000000:
        #self.connect(self.u, self.resamp, self.mag, self.detect)
	#else :
        self.connect(self.u, self.mag, self.detect)
	self.connect((self.detect, 0), (self.sync, 0))
	self.connect((self.detect, 1), (self.sync, 1))
	self.connect((self.sync, 0), (self.frame, 0))
	self.connect((self.sync, 1), (self.frame, 1))
        self.connect((self.frame, 0), (self.cvt, 0))
        self.connect((self.frame, 1), (self.cvt, 1))
        self.connect((self.cvt, 0), (self.scope, 0))
        self.connect((self.cvt, 1), (self.scope,1))
        self.connect((self.cvt, 2), (self.scope,2))

        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.subdev.gain_range()
            options.gain = float(g[0]+g[1])/2


        self.set_gain(options.gain)

        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")