aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/rfnoc
diff options
context:
space:
mode:
authorAaron Rossetto <aaron.rossetto@ni.com>2020-06-04 09:04:24 -0500
committerAaron Rossetto <aaron.rossetto@ni.com>2020-06-09 07:12:15 -0500
commitdac56ff0dcf35c4bf8ecb1e127465f6f726de737 (patch)
tree092c168788d8770844896a9e4ed5d2c4012b09e3 /host/lib/rfnoc
parent65578ebd055c65f8e3ddf68f97cf1e0a4afdffa7 (diff)
downloaduhd-dac56ff0dcf35c4bf8ecb1e127465f6f726de737.tar.gz
uhd-dac56ff0dcf35c4bf8ecb1e127465f6f726de737.tar.bz2
uhd-dac56ff0dcf35c4bf8ecb1e127465f6f726de737.zip
python: Add __repr__, property bindings to NocBlockBase
This commit adds a __repr__ function to the noc_block_base bindings, which helpfully displays the block's unique ID, e.g.: >>> block = g.get_block('0/VectorIIR#0') >>> block <NocBlock for block ID '0/VectorIIR#0'> Also added are get_property_ids and set_properties functions, so Python clients can set block properties by string if desired, e.g.: >>> block.get_property_ids() ['alpha', 'beta', 'delay', 'max_delay'] >>> block.set_properties('alpha=0.45,beta=0.77,delay=41') >>> viir = uhd.rfnoc.VectorIirBlockControl(block) >>> viir.get_alpha(0) 0.45 >>> viir.get_beta(0) 0.77
Diffstat (limited to 'host/lib/rfnoc')
-rw-r--r--host/lib/rfnoc/rfnoc_python.hpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/host/lib/rfnoc/rfnoc_python.hpp b/host/lib/rfnoc/rfnoc_python.hpp
index 061fb8a9a..b0809a8b6 100644
--- a/host/lib/rfnoc/rfnoc_python.hpp
+++ b/host/lib/rfnoc/rfnoc_python.hpp
@@ -266,11 +266,23 @@ void export_rfnoc(py::module& m)
.def("get_tick_rate", &noc_block_base::get_tick_rate)
.def("get_mtu", &noc_block_base::get_mtu)
.def("get_block_args", &noc_block_base::get_block_args)
- .def("get_tree", [](noc_block_base::sptr& self) {
- // Force the non-const `get_tree`
- uhd::property_tree::sptr tree = self->get_tree();
- return tree;
- });
+ .def("get_tree",
+ [](noc_block_base::sptr& self) {
+ // Force the non-const `get_tree`
+ uhd::property_tree::sptr tree = self->get_tree();
+ return tree;
+ })
+ .def("__repr__",
+ [](noc_block_base::sptr& self) {
+ return "<NocBlock for block ID '" + self->get_unique_id() + "'>";
+ })
+ // node_t superclass methods--not worth having a separate Py class
+ // for them
+ .def("get_property_ids", &node_t::get_property_ids)
+ .def("set_properties",
+ &node_t::set_properties,
+ py::arg("props"),
+ py::arg("instance") = 0);
}
#endif /* INCLUDED_UHD_RFNOC_PYTHON_HPP */