diff options
author | trondeau <trondeau@221aa14e-8319-0410-a670-987f0aec2ac5> | 2009-06-17 02:14:59 +0000 |
---|---|---|
committer | trondeau <trondeau@221aa14e-8319-0410-a670-987f0aec2ac5> | 2009-06-17 02:14:59 +0000 |
commit | bc0a3ff98377e41fa1e31d448d45b2b377b54cea (patch) | |
tree | 2d29d50a4e68ba54c9bdb2c21902e77786ce519e /gnuradio-examples/python/digital/receive_path.py | |
parent | acd4a04cc9eec1e8d02e6cf755623df9415a575f (diff) |
Merging trondeau/digital branch r11185:11205 to improve digital example interfacing and remove redundancy.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11209 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gnuradio-examples/python/digital/receive_path.py')
-rw-r--r-- | gnuradio-examples/python/digital/receive_path.py | 126 |
1 files changed, 25 insertions, 101 deletions
diff --git a/gnuradio-examples/python/digital/receive_path.py b/gnuradio-examples/python/digital/receive_path.py index 507d05e7ba..a6bffeeac4 100644 --- a/gnuradio-examples/python/digital/receive_path.py +++ b/gnuradio-examples/python/digital/receive_path.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2005,2006,2007,2009 Free Software Foundation, Inc. +# Copyright 2005,2006,2007 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -21,55 +21,30 @@ # from gnuradio import gr, gru, blks2 -from gnuradio import usrp from gnuradio import eng_notation import copy import sys -# from current dir -from pick_bitrate import pick_rx_bitrate -import usrp_options - # ///////////////////////////////////////////////////////////////////////////// # receive path # ///////////////////////////////////////////////////////////////////////////// class receive_path(gr.hier_block2): def __init__(self, demod_class, rx_callback, options): - gr.hier_block2.__init__(self, "receive_path", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(0, 0, 0)) # Output signature + gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature + gr.io_signature(0, 0, 0)) # Output signature + options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose - self._rx_freq = options.rx_freq # receiver's center frequency self._bitrate = options.bitrate # desired bit rate - self._decim = options.decim # Decimating rate for the USRP (prelim) self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._rx_callback = rx_callback # this callback is fired when there's a packet available self._demod_class = demod_class # the demodulator_class we're using - if self._rx_freq is None: - sys.stderr.write("-f FREQ or --freq FREQ or --rx-freq FREQ must be specified\n") - raise SystemExit - - # Set up USRP source; also adjusts decim, samples_per_symbol, and bitrate - self._setup_usrp_source(options) - - # Set RF frequency - ok = self.set_freq(self._rx_freq) - if not ok: - print "Failed to set Rx frequency to %s" % (eng_notation.num_to_str(self._rx_freq)) - raise ValueError, eng_notation.num_to_str(self._rx_freq) - - # copy the final answers back into options for use by demodulator - options.samples_per_symbol = self._samples_per_symbol - options.bitrate = self._bitrate - options.decim = self._decim - # Get demod_kwargs demod_kwargs = self._demod_class.extract_kwargs_from_options(options) @@ -79,73 +54,40 @@ class receive_path(gr.hier_block2): sw_decim * self._samples_per_symbol, # sampling rate 1.0, # midpoint of trans. band 0.5, # width of trans. band - gr.firdes.WIN_HANN) # filter type - - # Decimating channel filter - # complex in and out, float taps - self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs) - #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs) - + gr.firdes.WIN_HANN) # filter type + self.channel_filter = gr.fft_filter_ccc(sw_decim, chan_coeffs) + # receiver self.packet_receiver = \ blks2.demod_pkts(self._demod_class(**demod_kwargs), access_code=None, callback=self._rx_callback, threshold=-1) - + # Carrier Sensing Blocks alpha = 0.001 thresh = 30 # in dB, will have to adjust - - if options.log_rx_power == True: - self.probe = gr.probe_avg_mag_sqrd_cf(thresh,alpha) - self.power_sink = gr.file_sink(gr.sizeof_float, "rxpower.dat") - self.connect(self.chan_filt, self.probe, self.power_sink) - else: - self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) - self.connect(self.chan_filt, self.probe) + self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha) # Display some information about the setup if self._verbose: self._print_verbage() - - self.connect(self.u, self.chan_filt, self.packet_receiver) - - def _setup_usrp_source(self, options): - - self.u = usrp_options.create_usrp_source(options) - adc_rate = self.u.adc_rate() - # derive values of bitrate, samples_per_symbol, and decim from desired info - (self._bitrate, self._samples_per_symbol, self._decim) = \ - pick_rx_bitrate(self._bitrate, self._demod_class.bits_per_symbol(), \ - self._samples_per_symbol, self._decim, adc_rate, self.u.get_decim_rates()) + # connect block input to channel filter + self.connect(self, self.channel_filter) - self.u.set_decim(self._decim) + # connect the channel input filter to the carrier power detector + self.connect(self.channel_filter, self.probe) - def set_freq(self, target_freq): - """ - Set the center frequency we're interested in. - - @param target_freq: frequency in Hz - @rypte: bool + # connect channel filter to the packet receiver + self.connect(self.channel_filter, self.packet_receiver) - Tuning is a two step process. First we ask the front-end to - tune as close to the desired frequency as it can. Then we use - the result of that operation and our target_frequency to - determine the value for the digital up converter. - """ - return self.u.set_center_freq(target_freq) - def bitrate(self): return self._bitrate def samples_per_symbol(self): return self._samples_per_symbol - def decim(self): - return self._decim - def carrier_sensed(self): """ Return True if we think carrier is present. @@ -168,49 +110,31 @@ class receive_path(gr.hier_block2): """ self.probe.set_threshold(threshold_in_db) - @staticmethod + def add_options(normal, expert): """ Adds receiver-specific options to the Options Parser """ - add_freq_option(normal) if not normal.has_option("--bitrate"): - normal.add_option("-r", "--bitrate", type="eng_float", default=None, - help="specify bitrate. samples-per-symbol and interp/decim will be derived.") - usrp_options.add_rx_options(normal) + normal.add_option("-r", "--bitrate", type="eng_float", default=100e3, + help="specify bitrate [default=%default].") + normal.add_option("", "--show-rx-gain-range", action="store_true", default=False, + help="print min and max Rx gain available on selected daughterboard") normal.add_option("-v", "--verbose", action="store_true", default=False) - expert.add_option("-S", "--samples-per-symbol", type="int", default=None, + expert.add_option("-S", "--samples-per-symbol", type="int", default=2, help="set samples/symbol [default=%default]") - expert.add_option("", "--rx-freq", type="eng_float", default=None, - help="set Rx frequency to FREQ [default=%default]", metavar="FREQ") expert.add_option("", "--log", action="store_true", default=False, help="Log all parts of flow graph to files (CAUTION: lots of data)") - expert.add_option("", "--log-rx-power", action="store_true", default=False, - help="Log receive signal power to file (CAUTION: lots of data)") + + # Make a static method to call before instantiation + add_options = staticmethod(add_options) + def _print_verbage(self): """ Prints information about the receive path """ print "\nReceive Path:" - print "USRP %s" % (self.u,) - print "Rx gain: %g" % (self.u.gain(),) print "modulation: %s" % (self._demod_class.__name__) print "bitrate: %sb/s" % (eng_notation.num_to_str(self._bitrate)) print "samples/symbol: %3d" % (self._samples_per_symbol) - print "decim: %3d" % (self._decim) - print "Rx Frequency: %s" % (eng_notation.num_to_str(self._rx_freq)) - -def add_freq_option(parser): - """ - Hackery that has the -f / --freq option set both tx_freq and rx_freq - """ - def freq_callback(option, opt_str, value, parser): - parser.values.rx_freq = value - parser.values.tx_freq = value - - if not parser.has_option('--freq'): - parser.add_option('-f', '--freq', type="eng_float", - action="callback", callback=freq_callback, - help="set Tx and/or Rx frequency to FREQ [default=%default]", - metavar="FREQ") |