root/vtcross/trunk/src/cross-examples/python/gnuradio-examples/transmit_path.py @ 502

Revision 502, 4.5 KB (checked in by trnewman, 15 years ago)

Adding gnuradio files.

Line 
1#
2# Copyright 2005, 2006, 2007 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
22from gnuradio import gr, gru, blks2
23from gnuradio import eng_notation
24
25import copy
26import sys
27
28# /////////////////////////////////////////////////////////////////////////////
29#                              transmit path
30# /////////////////////////////////////////////////////////////////////////////
31
32class transmit_path(gr.hier_block2):
33    def __init__(self, modulator_class, options):
34        '''
35        See below for what options should hold
36        '''
37        gr.hier_block2.__init__(self, "transmit_path",
38                                gr.io_signature(0, 0, 0),                    # Input signature
39                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature
40       
41        options = copy.copy(options)    # make a copy so we can destructively modify
42
43        self._verbose            = options.verbose
44        self._tx_amplitude       = options.tx_amplitude    # digital amplitude sent to USRP
45        self._bitrate            = options.bitrate         # desired bit rate
46        self._samples_per_symbol = options.samples_per_symbol  # desired samples/baud
47
48        self._modulator_class = modulator_class         # the modulator_class we are using
49
50        # Get mod_kwargs
51        mod_kwargs = self._modulator_class.extract_kwargs_from_options(options)
52   
53        # transmitter
54        modulator = self._modulator_class(**mod_kwargs)
55        self.packet_transmitter = \
56            blks2.mod_pkts(modulator,
57                           access_code=None,
58                           msgq_limit=4,
59                           pad_for_usrp=True)
60
61        self.amp = gr.multiply_const_cc(1)
62        self.set_tx_amplitude(self._tx_amplitude)
63
64        # Display some information about the setup
65        if self._verbose:
66            self._print_verbage()
67
68        # Connect components in the flowgraph
69        self.connect(self.packet_transmitter, self.amp, self)
70
71    def set_tx_amplitude(self, ampl):
72        """
73        Sets the transmit amplitude sent to the USRP in volts
74        @param: ampl 0 <= ampl < 1.
75        """
76        self._tx_amplitude = max(0.0, min(ampl, 1))
77        self.amp.set_k(self._tx_amplitude)
78       
79    def send_pkt(self, payload='', eof=False):
80        """
81        Calls the transmitter method to send a packet
82        """
83        return self.packet_transmitter.send_pkt(payload, eof)
84       
85    def bitrate(self):
86        return self._bitrate
87
88    def samples_per_symbol(self):
89        return self._samples_per_symbol
90
91    def add_options(normal, expert):
92        """
93        Adds transmitter-specific options to the Options Parser
94        """
95        if not normal.has_option('--bitrate'):
96            normal.add_option("-r", "--bitrate", type="eng_float", default=100e3,
97                              help="specify bitrate [default=%default].")
98        normal.add_option("", "--tx-amplitude", type="eng_float", default=0.250, metavar="AMPL",
99                          help="set transmitter digital amplitude: 0 <= AMPL < 1 [default=%default]")
100        normal.add_option("-v", "--verbose", action="store_true", default=False)
101
102        expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
103                          help="set samples/symbol [default=%default]")
104        expert.add_option("", "--log", action="store_true", default=False,
105                          help="Log all parts of flow graph to file (CAUTION: lots of data)")
106
107    # Make a static method to call before instantiation
108    add_options = staticmethod(add_options)
109
110    def _print_verbage(self):
111        """
112        Prints information about the transmit path
113        """
114        print "Tx amplitude     %s"    % (self._tx_amplitude)
115        print "modulation:      %s"    % (self._modulator_class.__name__)
116        print "bitrate:         %sb/s" % (eng_notation.num_to_str(self._bitrate))
117        print "samples/symbol:  %3d"   % (self._samples_per_symbol)
118       
Note: See TracBrowser for help on using the browser.