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, blks2
24 from gnuradio import eng_notation
28 # /////////////////////////////////////////////////////////////////////////////
30 # /////////////////////////////////////////////////////////////////////////////
32 class receive_path(gr.hier_block2):
33 def __init__(self, demod_class, rx_callback, options):
34 gr.hier_block2.__init__(self, "receive_path",
35 gr.io_signature(1,1,gr.sizeof_gr_complex), # Input signature
36 gr.io_signature(0,0,0)) # Output signature
38 options = copy.copy(options) # make a copy so we can destructively modify
40 self._verbose = options.verbose
41 self._bitrate = options.bitrate # desired bit rate
42 self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol
44 self._rx_callback = rx_callback # this callback is fired when there's a packet available
45 self._demod_class = demod_class # the demodulator_class we're using
48 demod_kwargs = self._demod_class.extract_kwargs_from_options(options)
50 # Design filter to get actual channel we want
52 chan_coeffs = gr.firdes.low_pass (1.0, # gain
53 sw_decim * self._samples_per_symbol, # sampling rate
54 1.0, # midpoint of trans. band
55 0.5, # width of trans. band
56 gr.firdes.WIN_HANN) # filter type
59 self.packet_receiver = \
60 blks2.demod_pkts(self._demod_class(**demod_kwargs),
62 callback=self._rx_callback,
65 # Carrier Sensing Blocks
67 thresh = 30 # in dB, will have to adjust
68 self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
70 # Display some information about the setup
74 # Define the components
75 self.define_component("channel_filter", gr.fft_filter_ccc(sw_decim, chan_coeffs))
76 self.define_component("channel_probe", self.probe)
77 self.define_component("packet_receiver", self.packet_receiver)
79 # connect the channel input filter to the carrier power detector
80 self.connect("self", 0, "channel_filter", 0)
81 self.connect("channel_filter", 0, "channel_probe", 0)
83 # connect channel filter to the packet receiver
84 self.connect("channel_filter", 0, "packet_receiver", 0)
89 def samples_per_symbol(self):
90 return self._samples_per_symbol
92 def carrier_sensed(self):
94 Return True if we think carrier is present.
96 #return self.probe.level() > X
97 return self.probe.unmuted()
99 def carrier_threshold(self):
101 Return current setting in dB.
103 return self.probe.threshold()
105 def set_carrier_threshold(self, threshold_in_db):
107 Set carrier threshold.
109 @param threshold_in_db: set detection threshold
110 @type threshold_in_db: float (dB)
112 self.probe.set_threshold(threshold_in_db)
115 def add_options(normal, expert):
117 Adds receiver-specific options to the Options Parser
119 if not normal.has_option("--bitrate"):
120 normal.add_option("-r", "--bitrate", type="eng_float", default=100e3,
121 help="specify bitrate [default=%default].")
122 normal.add_option("", "--show-rx-gain-range", action="store_true", default=False,
123 help="print min and max Rx gain available on selected daughterboard")
124 normal.add_option("-v", "--verbose", action="store_true", default=False)
125 expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
126 help="set samples/symbol [default=%default]")
127 expert.add_option("", "--log", action="store_true", default=False,
128 help="Log all parts of flow graph to files (CAUTION: lots of data)")
130 # Make a static method to call before instantiation
131 add_options = staticmethod(add_options)
134 def _print_verbage(self):
136 Prints information about the receive path
138 print "modulation: %s" % (self._demod_class.__name__)
139 print "bitrate: %sb/s" % (eng_notation.num_to_str(self._bitrate))
140 print "samples/symbol: %3d" % (self._samples_per_symbol)