11c714aafc82cf0808d75cebcf0a3a5e4afc0ef8
[debian/gnuradio] / gr-msdd6000 / src / python-examples / 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 3, 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, blks2
24 from gnuradio import usrp
25 from gnuradio import eng_notation
26 import copy
27 import sys
28
29 # /////////////////////////////////////////////////////////////////////////////
30 #                              receive path
31 # /////////////////////////////////////////////////////////////////////////////
32
33 class receive_path(gr.hier_block2):
34     def __init__(self, rx_callback, options):
35
36         gr.hier_block2.__init__(self, "receive_path",
37                                 gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
38                                 gr.io_signature(0, 0, 0)) # Output signature
39
40
41         options = copy.copy(options)    # make a copy so we can destructively modify
42
43         self._verbose     = options.verbose
44         self._log         = options.log
45         self._rx_callback = rx_callback      # this callback is fired when there's a packet available
46
47         # receiver
48         self.ofdm_rx = \
49                      blks2.ofdm_demod(options, callback=self._rx_callback)
50
51         # Carrier Sensing Blocks
52         alpha = 0.001
53         thresh = 30   # in dB, will have to adjust
54         self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
55
56         self.connect(self, self.ofdm_rx)
57         self.connect(self.ofdm_rx, self.probe)
58         
59         # Display some information about the setup
60         if self._verbose:
61             self._print_verbage()
62         
63     def carrier_sensed(self):
64         """
65         Return True if we think carrier is present.
66         """
67         #return self.probe.level() > X
68         return self.probe.unmuted()
69
70     def carrier_threshold(self):
71         """
72         Return current setting in dB.
73         """
74         return self.probe.threshold()
75
76     def set_carrier_threshold(self, threshold_in_db):
77         """
78         Set carrier threshold.
79
80         @param threshold_in_db: set detection threshold
81         @type threshold_in_db:  float (dB)
82         """
83         self.probe.set_threshold(threshold_in_db)
84     
85         
86     def add_options(normal, expert):
87         """
88         Adds receiver-specific options to the Options Parser
89         """
90         normal.add_option("-v", "--verbose", action="store_true", default=False)
91         expert.add_option("", "--log", action="store_true", default=False,
92                           help="Log all parts of flow graph to files (CAUTION: lots of data)")
93
94     # Make a static method to call before instantiation
95     add_options = staticmethod(add_options)
96
97
98     def _print_verbage(self):
99         """
100         Prints information about the receive path
101         """
102         pass