3 # Copyright 2005,2006 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, gru, blks
24 from gnuradio import usrp
25 from gnuradio import eng_notation
30 from pick_bitrate import pick_rx_bitrate
33 # /////////////////////////////////////////////////////////////////////////////
35 # /////////////////////////////////////////////////////////////////////////////
37 class receive_path(gr.hier_block):
38 def __init__(self, fg, rx_callback, options):
40 options = copy.copy(options) # make a copy so we can destructively modify
42 self._verbose = options.verbose
43 self._log = options.log
44 self._rx_callback = rx_callback # this callback is fired when there's a packet available
48 chan_coeffs = gr.firdes.low_pass (1.0, # gain
50 bw, # midpoint of trans. band
51 1*bw, # width of trans. band
52 gr.firdes.WIN_KAISER) # filter type
54 chan_coeffs = [ 1.0, 0.0, 0 ]
55 self.chan_filt = gr.fft_filter_ccc(1, chan_coeffs)
57 self.ofdm_demod = ofdm.ofdm_demod(fg, options)
60 self.packet_receiver = \
61 blks.demod_ofdm_pkts(fg,
64 callback=self._rx_callback,
67 # Carrier Sensing Blocks
69 thresh = 30 # in dB, will have to adjust
70 self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
71 fg.connect(self.chan_filt, self.probe)
73 # Display some information about the setup
77 fg.connect(self.chan_filt, self.packet_receiver)
78 #fg.connect(self.chan_filt, gr.file_sink(gr.sizeof_gr_complex, "ofdmrx_chflt.dat"))
79 gr.hier_block.__init__(self, fg, self.chan_filt, None)
81 def carrier_sensed(self):
83 Return True if we think carrier is present.
85 #return self.probe.level() > X
86 return self.probe.unmuted()
88 def carrier_threshold(self):
90 Return current setting in dB.
92 return self.probe.threshold()
94 def set_carrier_threshold(self, threshold_in_db):
96 Set carrier threshold.
98 @param threshold_in_db: set detection threshold
99 @type threshold_in_db: float (dB)
101 self.probe.set_threshold(threshold_in_db)
104 def add_options(normal, expert):
106 Adds receiver-specific options to the Options Parser
108 normal.add_option("-v", "--verbose", action="store_true", default=False)
109 expert.add_option("", "--log", action="store_true", default=False,
110 help="Log all parts of flow graph to files (CAUTION: lots of data)")
112 # Make a static method to call before instantiation
113 add_options = staticmethod(add_options)
116 def _print_verbage(self):
118 Prints information about the receive path
120 print "Using RX d'board %s" % (self.subdev.side_and_name(),)
121 print "Rx gain: %g" % (self.gain,)
122 print "modulation: %s" % (self._demod_class.__name__)
123 print "bitrate: %sb/s" % (eng_notation.num_to_str(self._bitrate))
124 print "samples/symbol: %3d" % (self._samples_per_symbol)
125 print "decim: %3d" % (self._decim)