aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorWade Fife <wade.fife@ettus.com>2022-01-20 17:52:44 -0600
committerAaron Rossetto <aaron.rossetto@ni.com>2022-02-01 14:53:42 -0600
commitadeeebb60a2eeb464b4bbe1140f2849a3d1656a5 (patch)
treeb494a144d7378c3d234e2da730da50f7725f8d45 /host/lib
parentf6733edc53f9c85c3b3ce67ee766181aa96b99ca (diff)
downloaduhd-adeeebb60a2eeb464b4bbe1140f2849a3d1656a5.tar.gz
uhd-adeeebb60a2eeb464b4bbe1140f2849a3d1656a5.tar.bz2
uhd-adeeebb60a2eeb464b4bbe1140f2849a3d1656a5.zip
python: rfnoc: Add get_property bindings
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/rfnoc/rfnoc_python.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/host/lib/rfnoc/rfnoc_python.hpp b/host/lib/rfnoc/rfnoc_python.hpp
index 09bd98c0a..19f408daf 100644
--- a/host/lib/rfnoc/rfnoc_python.hpp
+++ b/host/lib/rfnoc/rfnoc_python.hpp
@@ -452,6 +452,66 @@ void export_rfnoc(py::module& m)
.def("set_properties",
&node_t::set_properties,
py::arg("props"),
+ py::arg("instance") = 0)
+ .def(
+ "get_string_property",
+ [](noc_block_base& self, const std::string& id, const size_t instance) {
+ return self.get_property<std::string>(id, instance);
+ },
+ py::arg("id"),
+ py::arg("instance") = 0)
+ .def(
+ "get_bool_property",
+ [](noc_block_base& self, const std::string& id, const size_t instance) {
+ return self.get_property<bool>(id, instance);
+ },
+ py::arg("id"),
+ py::arg("instance") = 0)
+ .def(
+ "get_int_property",
+ [](noc_block_base& self, const std::string& id, const size_t instance) -> uint64_t {
+ // Try all integer types until we find the right one
+ try {
+ int value = self.get_property<int>(id, instance);
+ return (uint64_t)value;
+ } catch(const uhd::type_error&) {
+ try {
+ size_t value = self.get_property<size_t>(id, instance);
+ return (uint64_t)value;
+ } catch(const uhd::type_error&) {
+ try {
+ uint32_t value = self.get_property<uint32_t>(id, instance);
+ return (uint64_t)value;
+ } catch(const uhd::type_error&) {
+ try {
+ uint64_t value = self.get_property<uint64_t>(id, instance);
+ return (uint64_t)value;
+ } catch(...) {
+ throw;
+ }
+ }
+ }
+ }
+ },
+ py::arg("id"),
+ py::arg("instance") = 0)
+ .def(
+ "get_float_property",
+ [](noc_block_base& self, const std::string& id, const size_t instance) -> double {
+ // Try both float types
+ try {
+ int value = self.get_property<double>(id, instance);
+ return (double)value;
+ } catch(const uhd::type_error&) {
+ try {
+ size_t value = self.get_property<float>(id, instance);
+ return (double)value;
+ } catch(...) {
+ throw;
+ }
+ }
+ },
+ py::arg("id"),
py::arg("instance") = 0);
}