1 # Copyright 2009 Free Software Foundation, Inc.
3 # This file is part of GNU Radio
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)
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.
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.
22 from gnuradio import gr, usrp
24 ####################################################################
26 ####################################################################
27 class _simple_source(gr.hier_block2):
28 """A single usrp source of IO type short or complex."""
30 def __init__(self, which, side='A', rx_ant='RXA', no_hb=False):
32 USRP simple source contructor.
33 @param which the unit number
34 @param side the usrp side A or B
35 @param rx_ant the antenna choice
36 @param no_hb disable half band filters
39 #initialize hier2 block
40 gr.hier_block2.__init__(
41 self, 'usrp_simple_source',
42 gr.io_signature(0, 0, 0),
43 gr.io_signature(1, 1, self._get_io_size()),
46 if self._no_hb: self._make_usrp(which=which, nchan=1, fpga_filename="std_4rx_0tx.rbf")
47 else: self._make_usrp(which=which, nchan=1)
48 subdev_spec = common.to_spec(side, rx_ant)
49 self._get_u().set_mux(self._get_u().determine_rx_mux_value(subdev_spec))
50 self._subdev = self._get_u().selected_subdev(subdev_spec)
51 if common.is_flex(rx_ant): self._subdev.select_rx_antenna(rx_ant)
53 self.connect(self._get_u(), self)
55 def set_decim_rate(self, decim):
56 self._get_u().set_decim_rate(int(decim))
57 if self._no_hb: #set the BW to half the sample rate
58 self._subdev.set_bw(self._get_u().converter_rate()/decim/2)
59 def set_frequency(self, frequency, verbose=False, lo_offset=None):
60 if lo_offset is not None: self._subdev.set_lo_offset(lo_offset)
67 def set_gain(self, gain): self._subdev.set_gain(gain)
69 class simple_source_c(_simple_source, common.usrp_source_c): pass
70 class simple_source_s(_simple_source, common.usrp_source_s): pass
72 ####################################################################
74 ####################################################################
75 class _simple_sink(gr.hier_block2):
76 """A single usrp sink of IO type short or complex."""
78 def __init__(self, which, side='A'):
80 USRP simple sink contructor.
81 @param which the unit number
82 @param side the usrp side A or B
84 #initialize hier2 block
85 gr.hier_block2.__init__(
86 self, 'usrp_simple_sink',
87 gr.io_signature(1, 1, self._get_io_size()),
88 gr.io_signature(0, 0, 0),
91 self._make_usrp(which=which, nchan=1)
92 subdev_spec = common.to_spec(side)
93 self._get_u().set_mux(self._get_u().determine_tx_mux_value(subdev_spec))
94 self._subdev = self._get_u().selected_subdev(subdev_spec)
96 self.connect(self, self._get_u())
98 def set_interp_rate(self, interp): self._get_u().set_interp_rate(int(interp))
99 def set_frequency(self, frequency, verbose=False, lo_offset=None):
100 if lo_offset is not None: self._subdev.set_lo_offset(lo_offset)
102 chan=self._subdev.which(),
107 def set_gain(self, gain): self._subdev.set_gain(gain)
108 def set_enable(self, enable): self._subdev.set_enable(enable)
109 def set_auto_tr(self, auto_tr): self._subdev.set_auto_tr(auto_tr)
111 class simple_sink_c(_simple_sink, common.usrp_sink_c): pass
112 class simple_sink_s(_simple_sink, common.usrp_sink_s): pass