2 # Copyright 2005,2006 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
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)
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.
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.
22 from gnuradio import gr, gru, blks2
23 from gnuradio import eng_notation
28 # /////////////////////////////////////////////////////////////////////////////
30 # /////////////////////////////////////////////////////////////////////////////
32 class transmit_path(gr.hier_block2):
33 def __init__(self, modulator_class, options):
35 See below for what options should hold
38 gr.hier_block2.__init__(self, "transmit_path",
39 gr.io_signature(0,0,0), # Input signature
40 gr.io_signature(1,1,gr.sizeof_gr_complex)) # Output signature
42 options = copy.copy(options) # make a copy so we can destructively modify
44 self._verbose = options.verbose
45 self._tx_amplitude = options.tx_amplitude # digital amplitude sent to USRP
46 self._bitrate = options.bitrate # desired bit rate
47 self._samples_per_symbol = options.samples_per_symbol # desired samples/baud
49 self._modulator_class = modulator_class # the modulator_class we are using
52 mod_kwargs = self._modulator_class.extract_kwargs_from_options(options)
55 self.packet_transmitter = \
56 blks2.mod_pkts(self._modulator_class(**mod_kwargs),
61 self.amp = gr.multiply_const_cc(1)
62 self.set_tx_amplitude(self._tx_amplitude)
64 # Display some information about the setup
68 # Define the components
69 self.define_component("packet_transmitter", self.packet_transmitter)
70 self.define_component("amp", self.amp)
72 # Connect components in the flowgraph; set amp component to the output of this block
73 self.connect("packet_transmitter", 0, "amp", 0)
74 self.connect("amp", 0, "self", 0)
76 def set_tx_amplitude(self, ampl):
78 Sets the transmit amplitude sent to the USRP
79 @param: ampl 0 <= ampl < 32768. Try 8000
81 self._tx_amplitude = max(0.0, min(ampl, 32767.0))
82 self.amp.set_k(self._tx_amplitude)
84 def send_pkt(self, payload='', eof=False):
86 Calls the transmitter method to send a packet
88 return self.packet_transmitter.send_pkt(payload, eof)
93 def samples_per_symbol(self):
94 return self._samples_per_symbol
96 def add_options(normal, expert):
98 Adds transmitter-specific options to the Options Parser
100 if not normal.has_option('--bitrate'):
101 normal.add_option("-r", "--bitrate", type="eng_float", default=100e3,
102 help="specify bitrate [default=%default].")
103 normal.add_option("", "--tx-amplitude", type="eng_float", default=12000, metavar="AMPL",
104 help="set transmitter digital amplitude: 0 <= AMPL < 32768 [default=%default]")
105 normal.add_option("-v", "--verbose", action="store_true", default=False)
107 expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
108 help="set samples/symbol [default=%default]")
109 expert.add_option("", "--log", action="store_true", default=False,
110 help="Log all parts of flow graph to file (CAUTION: lots of data)")
112 # Make a static method to call before instantiation
113 add_options = staticmethod(add_options)
115 def _print_verbage(self):
117 Prints information about the transmit path
119 print "Tx amplitude %s" % (self._tx_amplitude)
120 print "modulation: %s" % (self._modulator_class.__name__)
121 print "bitrate: %sb/s" % (eng_notation.num_to_str(self._bitrate))
122 print "samples/symbol: %3d" % (self._samples_per_symbol)