Merged r4518:5130 from developer branch n4hy/ofdm into trunk, passes distcheck.
[debian/gnuradio] / gnuradio-examples / python / ofdm / transmit_path.py
1 #
2 # Copyright 2005,2006 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
20
21
22 from gnuradio import gr, gru, blks
23 from gnuradio import usrp
24 from gnuradio import eng_notation
25
26 import copy
27 import sys
28
29 # from current dir
30 import ofdm
31
32 # /////////////////////////////////////////////////////////////////////////////
33 #                              transmit path
34 # /////////////////////////////////////////////////////////////////////////////
35
36 class transmit_path(gr.hier_block): 
37     def __init__(self, fg, options):
38         '''
39         See below for what options should hold
40         '''
41
42         options = copy.copy(options)    # make a copy so we can destructively modify
43
44         self._verbose      = options.verbose
45         self._tx_amplitude = options.tx_amplitude    # digital amplitude sent to USRP
46
47         self.ofdm_mod = ofdm.ofdm_mod(fg, options)
48         self.packet_transmitter = \
49             blks.mod_ofdm_pkts(fg,
50                                self.ofdm_mod,
51                                access_code=None,
52                                msgq_limit=4,
53                                pad_for_usrp=True)
54
55         self.amp = gr.multiply_const_cc(1)
56         self.set_tx_amplitude(self._tx_amplitude)
57
58         # Display some information about the setup
59         if self._verbose:
60             self._print_verbage()
61
62         # Create and setup transmit path flow graph
63         fg.connect(self.packet_transmitter, self.amp)
64         gr.hier_block.__init__(self, fg, None, self.amp)
65
66     def set_tx_amplitude(self, ampl):
67         """
68         Sets the transmit amplitude sent to the USRP
69         @param: ampl 0 <= ampl < 32768.  Try 8000
70         """
71         self._tx_amplitude = max(0.0, min(ampl, 32767.0))
72         self.amp.set_k(self._tx_amplitude)
73         
74     def send_pkt(self, payload='', eof=False):
75         """
76         Calls the transmitter method to send a packet
77         """
78         return self.packet_transmitter.send_pkt(payload, eof)
79         
80     def bitrate(self):
81         return self._bitrate
82
83     def samples_per_symbol(self):
84         return self._samples_per_symbol
85
86     def add_options(normal, expert):
87         """
88         Adds transmitter-specific options to the Options Parser
89         """
90         normal.add_option("", "--tx-amplitude", type="eng_float", default=12000, metavar="AMPL",
91                           help="set transmitter digital amplitude: 0 <= AMPL < 32768 [default=%default]")
92         normal.add_option("-v", "--verbose", action="store_true", default=False)
93         expert.add_option("", "--log", action="store_true", default=False,
94                           help="Log all parts of flow graph to file (CAUTION: lots of data)")
95
96     # Make a static method to call before instantiation
97     add_options = staticmethod(add_options)
98
99     def _print_verbage(self):
100         """
101         Prints information about the transmit path
102         """
103         print "Tx amplitude     %s"    % (self._tx_amplitude)
104