new and improved simple/dual usrp blocks and wrapper classes
[debian/gnuradio] / grc / src / grc_gnuradio / usrp / simple_usrp.py
1 # Copyright 2009 Free Software Foundation, Inc.
2 #
3 # This file is part of GNU Radio
4 #
5 # GNU Radio is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
8 # any later version.
9 #
10 # GNU Radio is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Radio; see the file COPYING.  If not, write to
17 # the Free Software Foundation, Inc., 51 Franklin Street,
18 # Boston, MA 02110-1301, USA.
19 #
20
21 import common
22 from gnuradio import gr, usrp
23
24 ####################################################################
25 # Simple USRP Source
26 ####################################################################
27 class _simple_source(gr.hier_block2):
28         """A single usrp source of IO type short or complex."""
29
30         def __init__(self, number, side='A', rx_ant='RXA'):
31                 """
32                 USRP simple source contructor.
33                 @param number the unit number
34                 @param side the usrp side A or B
35                 @param rx_ant the antenna choice
36                 """
37                 #initialize hier2 block
38                 gr.hier_block2.__init__(
39                         self, 'usrp_simple_source',
40                         gr.io_signature(0, 0, 0),
41                         gr.io_signature(1, 1, self._get_io_size()),
42                 )
43                 #create usrp object
44                 self._u = self._get_usrp_constructor()(number, nchan=1)
45                 subdev_spec = common.to_spec(side, rx_ant)
46                 self._u.set_mux(usrp.determine_rx_mux_value(self._u, subdev_spec))
47                 self._subdev = usrp.selected_subdev(self._u, subdev_spec)
48                 if common.is_flex(rx_ant): self._subdev.select_rx_antenna(rx_ant)
49                 #connect
50                 self.connect(self._u, self)
51
52         def set_decim_rate(self, decim): self._u.set_decim_rate(int(decim))
53         def set_frequency(self, frequency, verbose=False):
54                 common.set_frequency(
55                         u=self._u,
56                         which=0, #ddc0
57                         subdev=self._subdev,
58                         frequency=frequency,
59                         verbose=verbose,
60                 )
61         def set_gain(self, gain): self._subdev.set_gain(gain)
62         def set_auto_tr(self, auto_tr): self._subdev.set_auto_tr(auto_tr)
63
64 class simple_source_c(_simple_source, common.usrp_source_c): pass
65 class simple_source_s(_simple_source, common.usrp_source_s): pass
66
67 ####################################################################
68 # Simple USRP Sink
69 ####################################################################
70 class _simple_sink(gr.hier_block2):
71         """A single usrp sink of IO type short or complex."""
72
73         def __init__(self, number, side='A'):
74                 """
75                 USRP simple sink contructor.
76                 @param number the unit number
77                 @param side the usrp side A or B
78                 """
79                 #initialize hier2 block
80                 gr.hier_block2.__init__(
81                         self, 'usrp_simple_sink',
82                         gr.io_signature(1, 1, self._get_io_size()),
83                         gr.io_signature(0, 0, 0),
84                 )
85                 #create usrp object
86                 self._u = self._get_usrp_constructor()(number, nchan=1)
87                 subdev_spec = common.to_spec(side)
88                 self._u.set_mux(usrp.determine_tx_mux_value(self._u, subdev_spec))
89                 self._subdev = usrp.selected_subdev(self._u, subdev_spec)
90                 #connect
91                 self.connect(self, self._u)
92
93         def set_interp_rate(self, interp): self._u.set_interp_rate(int(interp))
94         def set_frequency(self, frequency, verbose=False):
95                 common.set_frequency(
96                         u=self._u,
97                         which=self._subdev.which(),
98                         subdev=self._subdev,
99                         frequency=frequency,
100                         verbose=verbose,
101                 )
102         def set_gain(self, gain): self._subdev.set_gain(gain)
103         def set_enable(self, enable): self._subdev.set_enable(enable)
104         def set_auto_tr(self, auto_tr): self._subdev.set_auto_tr(auto_tr)
105
106 class simple_sink_c(_simple_sink, common.usrp_sink_c): pass
107 class simple_sink_s(_simple_sink, common.usrp_sink_s): pass
108