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
27 from pick_bitrate import pick_rx_bitrate
29 # /////////////////////////////////////////////////////////////////////////////
31 # /////////////////////////////////////////////////////////////////////////////
33 class receive_path(gr.hier_block):
34 def __init__(self, fg, demod_class, rx_subdev_spec,
36 rx_callback, options, demod_kwargs):
38 self.u = usrp.source_c (fusb_block_size=options.fusb_block_size,
39 fusb_nblocks=options.fusb_nblocks)
40 adc_rate = self.u.adc_rate()
42 (self._bitrate, self._spb, self._decim) = \
43 pick_rx_bitrate(bitrate, demod_class.bits_per_baud(), spb, decim, adc_rate)
45 self.u.set_decim_rate(self._decim)
48 if rx_subdev_spec is None:
49 rx_subdev_spec = usrp.pick_rx_subdevice(self.u)
50 self.subdev = usrp.selected_subdev(self.u, rx_subdev_spec)
51 print "Using RX d'board %s" % (self.subdev.side_and_name(),)
53 self.u.set_mux(usrp.determine_rx_mux_value(self.u, rx_subdev_spec))
55 # Create filter to get actual channel we want
56 chan_coeffs = gr.firdes.low_pass (1.0, # gain
57 sw_decim * self._spb, # sampling rate
58 1.0, # midpoint of trans. band
59 0.1, # width of trans. band
60 gr.firdes.WIN_HANN) # filter type
62 print "len(rx_chan_coeffs) =", len(chan_coeffs)
64 # Decimating Channel filter
65 # complex in and out, float taps
66 self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs)
67 #self.chan_filt = gr.fir_filter_ccf(sw_decim, chan_coeffs)
70 self.packet_receiver = \
72 demod_class(fg, spb=self._spb, **demod_kwargs),
77 fg.connect(self.u, self.chan_filt, self.packet_receiver)
78 gr.hier_block.__init__(self, fg, None, None)
80 g = self.subdev.gain_range()
81 #self.set_gain((g[0] + g[1])/2) # set gain to midpoint
82 self.set_gain(g[1]) # set gain to max
83 self.set_auto_tr(True) # enable Auto Transmit/Receive switching
85 # Carrier Sensing Blocks
87 thresh = 30 # in dB, will have to adjust
88 self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
89 fg.connect(self.chan_filt, self.probe)
91 def set_freq(self, target_freq):
93 Set the center frequency we're interested in.
95 @param target_freq: frequency in Hz
98 Tuning is a two step process. First we ask the front-end to
99 tune as close to the desired frequency as it can. Then we use
100 the result of that operation and our target_frequency to
101 determine the value for the digital up converter.
103 r = self.u.tune(0, self.subdev, target_freq)
109 def set_gain(self, gain):
111 r = self.subdev.gain_range()
112 gain = (r[0] + r[1])/2 # set gain to midpoint
114 return self.subdev.set_gain(gain)
116 def set_auto_tr(self, enable):
117 return self.subdev.set_auto_tr(enable)
129 def carrier_sensed(self):
131 Return True if we think carrier is present.
133 #return self.probe.level() > X
134 return self.probe.unmuted()
136 def carrier_threshold(self):
138 Return current setting in dB.
140 return self.probe.threshold()
142 def set_carrier_threshold(self, threshold_in_db):
144 Set carrier threshold.
146 @param threshold_in_db: set detection threshold
147 @type threshold_in_db: float (dB)
149 self.probe.set_threshold(threshold_in_db)