aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-12-04 13:53:34 +0100
committermichael-west <michael.west@ettus.com>2020-12-07 11:53:35 -0800
commit60fb5d5f1377f5a4af7e1e55b1ec83fed864153f (patch)
treea9e12d953cad5de20be2270fb9504a9b0c6c83fe
parenteaf006225425e146657a09c7360aca1f9615886d (diff)
downloaduhd-60fb5d5f1377f5a4af7e1e55b1ec83fed864153f.tar.gz
uhd-60fb5d5f1377f5a4af7e1e55b1ec83fed864153f.tar.bz2
uhd-60fb5d5f1377f5a4af7e1e55b1ec83fed864153f.zip
python: Add find() to the Python API
This a mapping of uhd::device::find() into uhd.find() on the Python side. The uhd::device is intentionally not mapped into Python (prefer MultiUSRP or RfnocGraph instead), so the namespace is moved up one level. Example: >>> import uhd >>> # Now print the device args for all found B200s: >>> for dev_args in uhd.find("type=b200")): print(dev_args.to_string())
-rw-r--r--host/lib/device_python.cpp19
-rw-r--r--host/lib/device_python.hpp9
-rw-r--r--host/python/CMakeLists.txt1
-rw-r--r--host/python/pyuhd.cpp4
-rw-r--r--host/python/uhd/__init__.py1
5 files changed, 34 insertions, 0 deletions
diff --git a/host/lib/device_python.cpp b/host/lib/device_python.cpp
new file mode 100644
index 000000000..43147a09c
--- /dev/null
+++ b/host/lib/device_python.cpp
@@ -0,0 +1,19 @@
+//
+// Copyright 2020 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <pybind11/complex.h>
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+
+namespace py = pybind11;
+
+#include "device_python.hpp"
+#include <uhd/device.hpp>
+
+void export_device(py::module& m)
+{
+ m.def("find", [](const uhd::device_addr_t& hint) { return uhd::device::find(hint); });
+}
diff --git a/host/lib/device_python.hpp b/host/lib/device_python.hpp
new file mode 100644
index 000000000..1cc0445cd
--- /dev/null
+++ b/host/lib/device_python.hpp
@@ -0,0 +1,9 @@
+//
+// Copyright 2020 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#pragma once
+
+void export_device(py::module& m);
diff --git a/host/python/CMakeLists.txt b/host/python/CMakeLists.txt
index 1e9fefa43..234870c5f 100644
--- a/host/python/CMakeLists.txt
+++ b/host/python/CMakeLists.txt
@@ -32,6 +32,7 @@ execute_process(
add_library(pyuhd SHARED
pyuhd.cpp
${CMAKE_SOURCE_DIR}/lib/property_tree_python.cpp
+ ${CMAKE_SOURCE_DIR}/lib/device_python.cpp
${CMAKE_SOURCE_DIR}/lib/usrp/multi_usrp_python.cpp
)
# python expects extension modules with a particular suffix
diff --git a/host/python/pyuhd.cpp b/host/python/pyuhd.cpp
index eadb88d40..ca06f2d97 100644
--- a/host/python/pyuhd.cpp
+++ b/host/python/pyuhd.cpp
@@ -14,6 +14,7 @@
namespace py = pybind11;
#include "cal/cal_python.hpp"
+#include "device_python.hpp"
#include "property_tree_python.hpp"
#include "rfnoc/ddc_block_control_python.hpp"
#include "rfnoc/duc_block_control_python.hpp"
@@ -61,6 +62,9 @@ PYBIND11_MODULE(libpyuhd, m)
// (otherwise we will see segmentation faults)
init_numpy();
+ // Register uhd::device::find
+ export_device(m);
+
// Register paths submodule
auto paths_module = m.def_submodule("paths", "Path Utilities");
export_paths(paths_module);
diff --git a/host/python/uhd/__init__.py b/host/python/uhd/__init__.py
index bf11ac513..bfbe9a57f 100644
--- a/host/python/uhd/__init__.py
+++ b/host/python/uhd/__init__.py
@@ -14,6 +14,7 @@ from . import rfnoc
from . import dsp
from . import chdr
from .libpyuhd.paths import *
+from .libpyuhd import find
from .property_tree import PropertyTree