0e44ffde02d3b51547bf652da124779f190cb92b
[debian/gnuradio] / gnuradio-examples / python / ofdm / receive_path.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2005,2006 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
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)
10 # any later version.
11
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.
16
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.
21
22
23 from gnuradio import gr, gru, blks
24 from gnuradio import usrp
25 from gnuradio import eng_notation
26 import copy
27 import sys
28
29 # from current dir
30 from pick_bitrate import pick_rx_bitrate
31
32 # /////////////////////////////////////////////////////////////////////////////
33 #                              receive path
34 # /////////////////////////////////////////////////////////////////////////////
35
36 class receive_path(gr.hier_block):
37     def __init__(self, fg, rx_callback, options):
38
39         options = copy.copy(options)    # make a copy so we can destructively modify
40
41         self._verbose     = options.verbose
42         self._log         = options.log
43         self._rx_callback = rx_callback      # this callback is fired when there's a packet available
44
45         # receiver
46         self.ofdm_receiver = \
47             blks.demod_ofdm_pkts(fg, options,
48                                  callback=self._rx_callback)
49
50         # Carrier Sensing Blocks
51         #alpha = 0.001
52         #thresh = 30   # in dB, will have to adjust
53         #self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
54         #fg.connect(self.chan_filt, self.probe)
55
56         # Display some information about the setup
57         if self._verbose:
58             self._print_verbage()
59         
60         gr.hier_block.__init__(self, fg, self.ofdm_receiver, None)
61
62     def carrier_sensed(self):
63         """
64         Return True if we think carrier is present.
65         """
66         #return self.probe.level() > X
67         return self.probe.unmuted()
68
69     def carrier_threshold(self):
70         """
71         Return current setting in dB.
72         """
73         return self.probe.threshold()
74
75     def set_carrier_threshold(self, threshold_in_db):
76         """
77         Set carrier threshold.
78
79         @param threshold_in_db: set detection threshold
80         @type threshold_in_db:  float (dB)
81         """
82         self.probe.set_threshold(threshold_in_db)
83     
84         
85     def add_options(normal, expert):
86         """
87         Adds receiver-specific options to the Options Parser
88         """
89         normal.add_option("-v", "--verbose", action="store_true", default=False)
90         expert.add_option("", "--log", action="store_true", default=False,
91                           help="Log all parts of flow graph to files (CAUTION: lots of data)")
92
93     # Make a static method to call before instantiation
94     add_options = staticmethod(add_options)
95
96
97     def _print_verbage(self):
98         """
99         Prints information about the receive path
100         """
101         print "Using RX d'board %s"    % (self.subdev.side_and_name(),)
102         print "Rx gain:         %g"    % (self.gain,)
103         print "modulation:      %s"    % (self._demod_class.__name__)
104         print "bitrate:         %sb/s" % (eng_notation.num_to_str(self._bitrate))
105         print "samples/symbol:  %3d"   % (self._samples_per_symbol)
106         print "decim:           %3d"   % (self._decim)