summaryrefslogtreecommitdiff
path: root/gr-uhd/swig
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/swig')
-rw-r--r--gr-uhd/swig/CMakeLists.txt53
-rw-r--r--gr-uhd/swig/Makefile.swig.gen2
-rw-r--r--gr-uhd/swig/__init__.py15
-rw-r--r--gr-uhd/swig/uhd_swig.i11
4 files changed, 80 insertions, 1 deletions
diff --git a/gr-uhd/swig/CMakeLists.txt b/gr-uhd/swig/CMakeLists.txt
new file mode 100644
index 000000000..4c778b05c
--- /dev/null
+++ b/gr-uhd/swig/CMakeLists.txt
@@ -0,0 +1,53 @@
+# Copyright 2011 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.
+
+########################################################################
+# Setup swig generation
+########################################################################
+include(GrPython)
+include(GrSwig)
+
+set(GR_SWIG_FLAGS -DGR_HAVE_UHD) #needed to parse uhd_swig.i
+
+set(GR_SWIG_INCLUDE_DIRS
+ ${GR_UHD_INCLUDE_DIRS}
+ ${GNURADIO_CORE_SWIG_INCLUDE_DIRS}
+)
+link_directories(${UHD_LIBRARY_DIRS})
+set(GR_SWIG_LIBRARIES gnuradio-uhd ${UHD_LIBRARIES})
+
+GR_SWIG_MAKE(uhd_swig uhd_swig.i)
+
+GR_SWIG_INSTALL(
+ TARGETS uhd_swig
+ DESTINATION ${GR_PYTHON_DIR}/gnuradio/uhd
+ COMPONENT "uhd_python"
+)
+
+install(
+ FILES uhd_swig.i
+ DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
+ COMPONENT "uhd_swig"
+)
+
+GR_PYTHON_INSTALL(
+ FILES __init__.py
+ DESTINATION ${GR_PYTHON_DIR}/gnuradio/uhd
+ COMPONENT "uhd_python"
+)
diff --git a/gr-uhd/swig/Makefile.swig.gen b/gr-uhd/swig/Makefile.swig.gen
index b73ccd3c4..62adf8958 100644
--- a/gr-uhd/swig/Makefile.swig.gen
+++ b/gr-uhd/swig/Makefile.swig.gen
@@ -105,7 +105,7 @@ _uhd_swig_la_CXXFLAGS = \
$(uhd_swig_la_swig_cxxflags)
python/uhd_swig.cc: uhd_swig.py
-uhd_swig.py: uhd_swig.i
+uhd_swig.py: uhd_swig.i
# Include the python dependencies for this file
-include python/uhd_swig.d
diff --git a/gr-uhd/swig/__init__.py b/gr-uhd/swig/__init__.py
index 1f82b4a26..7745b4b79 100644
--- a/gr-uhd/swig/__init__.py
+++ b/gr-uhd/swig/__init__.py
@@ -19,6 +19,12 @@
# Boston, MA 02110-1301, USA.
#
+'''
+This is the GNU Radio UHD package. It is the interface to the UHD
+library to connect to and send and receive data between the Ettus
+Research, LLC product line.
+'''
+
########################################################################
# Prepare uhd swig module to make it more pythonic
########################################################################
@@ -63,6 +69,15 @@ def _prepare_uhd_swig():
if hasattr(myobj, 'to_real'): myobj.__float__ = lambda o: o.to_real()
if attr.endswith('_t'): setattr(uhd_swig, attr[:-2], myobj)
+ #make a new find devices that casts everything with the pythonized device_addr_t which has __str__
+ def find_devices(*args, **kwargs):
+ def to_pythonized_dev_addr(dev_addr):
+ new_dev_addr = uhd_swig.device_addr_t()
+ for key in dev_addr.keys(): new_dev_addr[key] = dev_addr.get(key)
+ return new_dev_addr
+ return map(to_pythonized_dev_addr, uhd_swig.find_devices_raw(*args, **kwargs))
+ setattr(uhd_swig, 'find_devices', find_devices)
+
#Cast constructor args (FIXME swig handle overloads?)
for attr in ('usrp_source', 'usrp_sink', 'amsg_source'):
def constructor_factory(old_constructor):
diff --git a/gr-uhd/swig/uhd_swig.i b/gr-uhd/swig/uhd_swig.i
index f8381ae64..7e612907c 100644
--- a/gr-uhd/swig/uhd_swig.i
+++ b/gr-uhd/swig/uhd_swig.i
@@ -102,6 +102,17 @@ GR_SWIG_BLOCK_MAGIC(uhd,amsg_source)
%include <gr_uhd_amsg_source.h>
////////////////////////////////////////////////////////////////////////
+// device discovery (no need to %include device.hpp)
+////////////////////////////////////////////////////////////////////////
+%{
+static uhd::device_addrs_t find_devices_raw(const uhd::device_addr_t &dev_addr = uhd::device_addr_t()){
+ return uhd::device::find(dev_addr);
+}
+%}
+
+static uhd::device_addrs_t find_devices_raw(const uhd::device_addr_t &dev_addr = uhd::device_addr_t());
+
+////////////////////////////////////////////////////////////////////////
// helpful constants
////////////////////////////////////////////////////////////////////////
%{