Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gnuradio-examples / python / gmsk2 / 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
25 # from current dir
26 from pick_bitrate import pick_tx_bitrate
27
28 # /////////////////////////////////////////////////////////////////////////////
29 #                              transmit path
30 # /////////////////////////////////////////////////////////////////////////////
31
32 class transmit_path(gr.hier_block): 
33     def __init__(self, fg, mod_class, tx_subdev_spec,
34                  bitrate, interp, spb, gain,
35                  options, mod_kwargs):
36
37         self.normal_gain = gain
38
39         self.u = usrp.sink_c (fusb_block_size=options.fusb_block_size,
40                               fusb_nblocks=options.fusb_nblocks)
41         dac_rate = self.u.dac_rate();
42
43         print mod_class
44         print mod_class.bits_per_baud()
45         (self._bitrate, self._spb, self._interp) = \
46             pick_tx_bitrate(bitrate, mod_class.bits_per_baud(), spb, interp, dac_rate)
47
48         self.u.set_interp_rate(self._interp)
49
50         # determine the daughterboard subdevice we're using
51         if tx_subdev_spec is None:
52             tx_subdev_spec = usrp.pick_tx_subdevice(self.u)
53         self.u.set_mux(usrp.determine_tx_mux_value(self.u, tx_subdev_spec))
54         self.subdev = usrp.selected_subdev(self.u, tx_subdev_spec)
55         print "Using TX d'board %s" % (self.subdev.side_and_name(),)
56
57         # transmitter
58         self.packet_transmitter = \
59             blks.mod_pkts(fg,
60                           mod_class(fg, spb=self._spb, **mod_kwargs),
61                           access_code=None,
62                           msgq_limit=4,
63                           pad_for_usrp=True)
64
65         self.amp = gr.multiply_const_cc (self.normal_gain)
66
67         fg.connect(self.packet_transmitter, self.amp, self.u)
68         gr.hier_block.__init__(self, fg, None, None)
69
70         self.set_gain(self.subdev.gain_range()[1])  # set max Tx gain
71         self.set_auto_tr(True)                      # enable Auto Transmit/Receive switching
72
73     def set_freq(self, target_freq):
74         """
75         Set the center frequency we're interested in.
76
77         @param target_freq: frequency in Hz
78         @rypte: bool
79
80         Tuning is a two step process.  First we ask the front-end to
81         tune as close to the desired frequency as it can.  Then we use
82         the result of that operation and our target_frequency to
83         determine the value for the digital up converter.
84         """
85         r = self.u.tune(self.subdev._which, self.subdev, target_freq)
86         if r:
87             return True
88
89         return False
90
91     def set_gain(self, gain):
92         self.gain = gain
93         self.subdev.set_gain(gain)
94
95     def set_auto_tr(self, enable):
96         return self.subdev.set_auto_tr(enable)
97         
98     def send_pkt(self, payload='', eof=False):
99         return self.packet_transmitter.send_pkt(payload, eof)
100         
101     def bitrate(self):
102         return self._bitrate
103
104     def spb(self):
105         return self._spb
106
107     def interp(self):
108         return self._interp