diff options
author | jblum | 2009-06-23 20:38:18 +0000 |
---|---|---|
committer | jblum | 2009-06-23 20:38:18 +0000 |
commit | 9988664127b367fa8fee4409f8460673d6f265e1 (patch) | |
tree | 96752c15b7f1447e5e78a7282d1de141f9e0000b /grc/grc_gnuradio/usrp | |
parent | 885e6fe1fd0e06476511c79515f34ffcef50287d (diff) | |
download | gnuradio-9988664127b367fa8fee4409f8460673d6f265e1.tar.gz gnuradio-9988664127b367fa8fee4409f8460673d6f265e1.tar.bz2 gnuradio-9988664127b367fa8fee4409f8460673d6f265e1.zip |
Merging r11186:11273 from grc branch.
Fixes, features, and reorganization for grc.
Minor fixes and features for wxgui forms.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11274 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/grc_gnuradio/usrp')
-rw-r--r-- | grc/grc_gnuradio/usrp/__init__.py | 26 | ||||
-rw-r--r-- | grc/grc_gnuradio/usrp/common.py | 75 | ||||
-rw-r--r-- | grc/grc_gnuradio/usrp/dual_usrp.py | 132 | ||||
-rw-r--r-- | grc/grc_gnuradio/usrp/simple_usrp.py | 113 |
4 files changed, 346 insertions, 0 deletions
diff --git a/grc/grc_gnuradio/usrp/__init__.py b/grc/grc_gnuradio/usrp/__init__.py new file mode 100644 index 000000000..1956bbd5b --- /dev/null +++ b/grc/grc_gnuradio/usrp/__init__.py @@ -0,0 +1,26 @@ +# Copyright 2008 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from simple_usrp import \ + simple_source_c, simple_source_s, \ + simple_sink_c, simple_sink_s +from dual_usrp import \ + dual_source_c, dual_source_s, \ + dual_sink_c, dual_sink_s diff --git a/grc/grc_gnuradio/usrp/common.py b/grc/grc_gnuradio/usrp/common.py new file mode 100644 index 000000000..65c1e7e29 --- /dev/null +++ b/grc/grc_gnuradio/usrp/common.py @@ -0,0 +1,75 @@ +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import sys +from gnuradio import usrp, gr + +################################################## +# USRP base class with common methods +################################################## +class usrp_helper(object): + def _make_usrp(self, *args, **kwargs): self._u = self._usrp_args[0](*args, **kwargs) + def _get_u(self): return self._u + def _get_io_size(self): return self._usrp_args[1] + def _set_frequency(self, chan, subdev, frequency, verbose=False): + """ + Set the carrier frequency for the given subdevice. + @param chan specifies the DDC/DUC number + @param frequency the carrier frequency in Hz + @param verbose if true, print usrp tuning information + """ + r = self._get_u().tune(chan, subdev, frequency) + if not verbose: return + print subdev.side_and_name() + if r: + print "\tr.baseband_frequency =", r.baseband_freq + print "\tr.dxc_frequency =", r.dxc_freq + print "\tr.residual_frequency =", r.residual_freq + print "\tr.inverted =", r.inverted, "\n" + else: print >> sys.stderr, 'Error calling tune on subdevice.' + def set_format(self, width, shift): self._get_u().set_format(self._get_u().make_format(width, shift)) + +################################################## +# Classes to associate usrp constructor w/ io size +################################################## +class usrp_source_c(usrp_helper): _usrp_args = (usrp.source_c, gr.sizeof_gr_complex) +class usrp_source_s(usrp_helper): _usrp_args = (usrp.source_s, gr.sizeof_short) +class usrp_sink_c(usrp_helper): _usrp_args = (usrp.sink_c, gr.sizeof_gr_complex) +class usrp_sink_s(usrp_helper): _usrp_args = (usrp.sink_s, gr.sizeof_short) + +################################################## +# Side spec and antenna spec functions +################################################## +def is_flex(rx_ant): return rx_ant.upper() in ('TX/RX', 'RX2') +def to_spec(side, rx_ant='RXA'): + """ + Convert the side to a spec number. + @param side A or B + @param rx_ant antenna type + @return the spec (0/1, 0/1/2) + """ + #determine the side spec + try: side_spec = {'A': 0, 'B': 1}[side.upper()] + except: raise ValueError, 'Side A or B expected.' + #determine the subdevice spec + if rx_ant.upper() == 'RXB': subdev_spec = 1 + elif rx_ant.upper() == 'RXAB': subdev_spec = 2 + else: subdev_spec = 0 + return (side_spec, subdev_spec) diff --git a/grc/grc_gnuradio/usrp/dual_usrp.py b/grc/grc_gnuradio/usrp/dual_usrp.py new file mode 100644 index 000000000..1ecf7c47f --- /dev/null +++ b/grc/grc_gnuradio/usrp/dual_usrp.py @@ -0,0 +1,132 @@ +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import common +from gnuradio import gr, usrp + +#################################################################### +# Dual USRP Source +#################################################################### +class _dual_source(gr.hier_block2): + """A dual usrp source of IO type short or complex.""" + + def __init__(self, which, rx_ant_a='RXA', rx_ant_b='RXA'): + """ + USRP dual source contructor. + @param which the unit number + @param rx_ant_a the antenna choice + @param rx_ant_b the antenna choice + """ + #initialize hier2 block + gr.hier_block2.__init__( + self, 'usrp_dual_source', + gr.io_signature(0, 0, 0), + gr.io_signature(2, 2, self._get_io_size()), + ) + #create usrp object + self._make_usrp(which=which, nchan=2) + subdev_spec_a = common.to_spec('A', rx_ant_a) + subdev_spec_b = common.to_spec('B', rx_ant_b) + self._get_u().set_mux(self._get_u().determine_rx_mux_value(subdev_spec_a, subdev_spec_b)) + self._subdev_a = self._get_u().selected_subdev(subdev_spec_a) + self._subdev_b = self._get_u().selected_subdev(subdev_spec_b) + #connect + deinter = gr.deinterleave(self._get_io_size()) + self.connect(self._get_u(), deinter) + for i in range(2): self.connect((deinter, i), (self, i)) + + def set_decim_rate(self, decim): self._get_u().set_decim_rate(int(decim)) + def set_frequency_a(self, frequency, verbose=False): + self._set_frequency( + chan=0, #ddc0 + subdev=self._subdev_a, + frequency=frequency, + verbose=verbose, + ) + def set_frequency_b(self, frequency, verbose=False): + self._set_frequency( + chan=1, #ddc1 + subdev=self._subdev_b, + frequency=frequency, + verbose=verbose, + ) + def set_lo_offset_a(self, lo_offset): self._subdev_a.set_lo_offset(lo_offset) + def set_lo_offset_b(self, lo_offset): self._subdev_b.set_lo_offset(lo_offset) + def set_gain_a(self, gain): self._subdev_a.set_gain(gain) + def set_gain_b(self, gain): self._subdev_b.set_gain(gain) + +class dual_source_c(_dual_source, common.usrp_source_c): pass +class dual_source_s(_dual_source, common.usrp_source_s): pass + +#################################################################### +# Dual USRP Sink +#################################################################### +class _dual_sink(gr.hier_block2): + """A dual usrp sink of IO type short or complex.""" + + def __init__(self, which): + """ + USRP simple sink contructor. + @param which the unit number + """ + #initialize hier2 block + gr.hier_block2.__init__( + self, 'usrp_dual_sink', + gr.io_signature(2, 2, self._get_io_size()), + gr.io_signature(0, 0, 0), + ) + #create usrp object + self._make_usrp(which=which, nchan=2) + subdev_spec_a = common.to_spec('A') + subdev_spec_b = common.to_spec('B') + self._get_u().set_mux(self._get_u().determine_tx_mux_value(subdev_spec_a, subdev_spec_b)) + self._subdev_a = self._get_u().selected_subdev(subdev_spec_a) + self._subdev_b = self._get_u().selected_subdev(subdev_spec_b) + #connect + inter = gr.interleave(self._get_io_size()) + self.connect(inter, self._get_u()) + for i in range(2): self.connect((self, i), (inter, i)) + + def set_interp_rate(self, interp): self._get_u().set_interp_rate(int(interp)) + def set_frequency_a(self, frequency, verbose=False): + self._set_frequency( + chan=self._subdev_a.which(), + subdev=self._subdev_a, + frequency=frequency, + verbose=verbose, + ) + def set_frequency_b(self, frequency, verbose=False): + self._set_frequency( + chan=self._subdev_b.which(), + subdev=self._subdev_b, + frequency=frequency, + verbose=verbose, + ) + def set_lo_offset_a(self, lo_offset): self._subdev_a.set_lo_offset(lo_offset) + def set_lo_offset_b(self, lo_offset): self._subdev_b.set_lo_offset(lo_offset) + def set_gain_a(self, gain): self._subdev_a.set_gain(gain) + def set_gain_b(self, gain): self._subdev_b.set_gain(gain) + def set_enable_a(self, enable): self._subdev_a.set_enable(enable) + def set_enable_b(self, enable): self._subdev_b.set_enable(enable) + def set_auto_tr_a(self, auto_tr): self._subdev_a.set_auto_tr(auto_tr) + def set_auto_tr_b(self, auto_tr): self._subdev_b.set_auto_tr(auto_tr) + +class dual_sink_c(_dual_sink, common.usrp_sink_c): pass +class dual_sink_s(_dual_sink, common.usrp_sink_s): pass diff --git a/grc/grc_gnuradio/usrp/simple_usrp.py b/grc/grc_gnuradio/usrp/simple_usrp.py new file mode 100644 index 000000000..9065c7fe9 --- /dev/null +++ b/grc/grc_gnuradio/usrp/simple_usrp.py @@ -0,0 +1,113 @@ +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import common +from gnuradio import gr, usrp + +#################################################################### +# Simple USRP Source +#################################################################### +class _simple_source(gr.hier_block2): + """A single usrp source of IO type short or complex.""" + + def __init__(self, which, side='A', rx_ant='RXA', no_hb=False): + """ + USRP simple source contructor. + @param which the unit number + @param side the usrp side A or B + @param rx_ant the antenna choice + @param no_hb disable half band filters + """ + self._no_hb = no_hb + #initialize hier2 block + gr.hier_block2.__init__( + self, 'usrp_simple_source', + gr.io_signature(0, 0, 0), + gr.io_signature(1, 1, self._get_io_size()), + ) + #create usrp object + if self._no_hb: self._make_usrp(which=which, nchan=1, fpga_filename="std_4rx_0tx.rbf") + else: self._make_usrp(which=which, nchan=1) + subdev_spec = common.to_spec(side, rx_ant) + self._get_u().set_mux(self._get_u().determine_rx_mux_value(subdev_spec)) + self._subdev = self._get_u().selected_subdev(subdev_spec) + if common.is_flex(rx_ant): self._subdev.select_rx_antenna(rx_ant) + #connect + self.connect(self._get_u(), self) + + def set_decim_rate(self, decim): + self._get_u().set_decim_rate(int(decim)) + if self._no_hb: #set the BW to half the sample rate + self._subdev.set_bw(self._get_u().converter_rate()/decim/2) + def set_lo_offset(self, lo_offset): self._subdev.set_lo_offset(lo_offset) + def set_frequency(self, frequency, verbose=False): + self._set_frequency( + chan=0, #ddc0 + subdev=self._subdev, + frequency=frequency, + verbose=verbose, + ) + def set_gain(self, gain): self._subdev.set_gain(gain) + +class simple_source_c(_simple_source, common.usrp_source_c): pass +class simple_source_s(_simple_source, common.usrp_source_s): pass + +#################################################################### +# Simple USRP Sink +#################################################################### +class _simple_sink(gr.hier_block2): + """A single usrp sink of IO type short or complex.""" + + def __init__(self, which, side='A'): + """ + USRP simple sink contructor. + @param which the unit number + @param side the usrp side A or B + """ + #initialize hier2 block + gr.hier_block2.__init__( + self, 'usrp_simple_sink', + gr.io_signature(1, 1, self._get_io_size()), + gr.io_signature(0, 0, 0), + ) + #create usrp object + self._make_usrp(which=which, nchan=1) + subdev_spec = common.to_spec(side) + self._get_u().set_mux(self._get_u().determine_tx_mux_value(subdev_spec)) + self._subdev = self._get_u().selected_subdev(subdev_spec) + #connect + self.connect(self, self._get_u()) + + def set_interp_rate(self, interp): self._get_u().set_interp_rate(int(interp)) + def set_frequency(self, frequency, verbose=False): + self._set_frequency( + chan=self._subdev.which(), + subdev=self._subdev, + frequency=frequency, + verbose=verbose, + ) + def set_lo_offset(self, lo_offset): self._subdev.set_lo_offset(lo_offset) + def set_gain(self, gain): self._subdev.set_gain(gain) + def set_enable(self, enable): self._subdev.set_enable(enable) + def set_auto_tr(self, auto_tr): self._subdev.set_auto_tr(auto_tr) + +class simple_sink_c(_simple_sink, common.usrp_sink_c): pass +class simple_sink_s(_simple_sink, common.usrp_sink_s): pass + |