Imported Upstream version 3.2.2
[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 3, 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, blks2
23 from gnuradio import usrp
24 from gnuradio import eng_notation
25
26 import copy
27 import sys
28
29 # /////////////////////////////////////////////////////////////////////////////
30 #                              transmit path
31 # /////////////////////////////////////////////////////////////////////////////
32
33 class transmit_path(gr.hier_block2): 
34     def __init__(self, options):
35         '''
36         See below for what options should hold
37         '''
38
39         gr.hier_block2.__init__(self, "transmit_path",
40                                 gr.io_signature(0, 0, 0), # Input signature
41                                 gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
42
43         options = copy.copy(options)    # make a copy so we can destructively modify
44
45         self._verbose      = options.verbose         # turn verbose mode on/off
46         self._tx_amplitude = options.tx_amplitude    # digital amplitude sent to USRP
47
48         self.ofdm_tx = \
49                      blks2.ofdm_mod(options, msgq_limit=4, pad_for_usrp=False)
50
51         self.amp = gr.multiply_const_cc(1)
52         self.set_tx_amplitude(self._tx_amplitude)
53
54         # Display some information about the setup
55         if self._verbose:
56             self._print_verbage()
57
58         # Create and setup transmit path flow graph
59         self.connect(self.ofdm_tx, self.amp, self)
60
61     def set_tx_amplitude(self, ampl):
62         """
63         Sets the transmit amplitude sent to the USRP
64         @param: ampl 0 <= ampl < 32768.  Try 8000
65         """
66         self._tx_amplitude = max(0.0, min(ampl, 32767.0))
67         self.amp.set_k(self._tx_amplitude)
68         
69     def send_pkt(self, payload='', eof=False):
70         """
71         Calls the transmitter method to send a packet
72         """
73         return self.ofdm_tx.send_pkt(payload, eof)
74         
75     def add_options(normal, expert):
76         """
77         Adds transmitter-specific options to the Options Parser
78         """
79         normal.add_option("", "--tx-amplitude", type="eng_float", default=200, metavar="AMPL",
80                           help="set transmitter digital amplitude: 0 <= AMPL < 32768 [default=%default]")
81         normal.add_option("-v", "--verbose", action="store_true", default=False)
82         expert.add_option("", "--log", action="store_true", default=False,
83                           help="Log all parts of flow graph to file (CAUTION: lots of data)")
84
85     # Make a static method to call before instantiation
86     add_options = staticmethod(add_options)
87
88     def _print_verbage(self):
89         """
90         Prints information about the transmit path
91         """
92         print "Tx amplitude     %s"    % (self._tx_amplitude)
93