aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2022-03-17 11:10:57 +0100
committerAaron Rossetto <aaron.rossetto@ni.com>2022-03-30 10:28:07 -0700
commite1d98d2bcd21cae4807021564815b6d766575f73 (patch)
treeda14198dc11ddd90f16681da75cf4d83cb0dfd3e /host
parent1d2ec743170b03a1c1f9618cb48809b2d9794084 (diff)
downloaduhd-e1d98d2bcd21cae4807021564815b6d766575f73.tar.gz
uhd-e1d98d2bcd21cae4807021564815b6d766575f73.tar.bz2
uhd-e1d98d2bcd21cae4807021564815b6d766575f73.zip
python: rfnoc: Add new replay block APIs to Python API
The new API calls get_{record,play}_async_metadata() calls are now available in Python. To look more Pythonic, we change the call signature and return value to either return `None` or the value (if available). For comparison, this is the C++ code: ```cpp uhd::rx_metadata_t md; if (replay_ctrl->get_record_async_metadata(md, 0.1)) { cout << "Received metadata! Error code: " << md.strerror() << endl; } else { cout << "No metadata received!" << endl; } ``` In Python, this has the more Pythonic form: ```python md = replay_ctrl.get_record_async_metadata(0.1); if md is not None: print("Received metadata! Error code: ", md.strerror()) else: print("No metadata received!") ```
Diffstat (limited to 'host')
-rw-r--r--host/lib/rfnoc/replay_block_control_python.hpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/host/lib/rfnoc/replay_block_control_python.hpp b/host/lib/rfnoc/replay_block_control_python.hpp
index 8f8741211..d9c25f9e0 100644
--- a/host/lib/rfnoc/replay_block_control_python.hpp
+++ b/host/lib/rfnoc/replay_block_control_python.hpp
@@ -27,12 +27,36 @@ void export_replay_block_control(py::module& m)
.def("get_record_fullness", &replay_block_control::get_record_fullness)
.def("get_record_type", &replay_block_control::get_record_type)
.def("get_record_item_size", &replay_block_control::get_record_item_size)
+ // The "pass object into function to fill if available" is very un-Pythonic,
+ // and really is more of a C thing than a C++ thing. In the binding, we
+ // simply return None or the thing that we want, it it's available.
+ .def(
+ "get_record_async_metadata",
+ [](replay_block_control& self, const double timeout) -> py::object {
+ uhd::rx_metadata_t md;
+ if (self.get_record_async_metadata(md, timeout)) {
+ return py::cast(md);
+ }
+ return py::cast(nullptr);
+ },
+ py::arg("timeout") = 0.1)
.def("get_play_offset", &replay_block_control::get_play_offset)
.def("get_play_size", &replay_block_control::get_play_size)
.def("get_max_items_per_packet", &replay_block_control::get_max_items_per_packet)
.def("get_max_packet_size", &replay_block_control::get_max_packet_size)
.def("get_play_type", &replay_block_control::get_play_type)
.def("get_play_item_size", &replay_block_control::get_play_item_size)
+ // See comment on get_record_async_metadata()
+ .def(
+ "get_play_async_metadata",
+ [](replay_block_control& self, const double timeout) -> py::object {
+ uhd::async_metadata_t md;
+ if (self.get_play_async_metadata(md, timeout)) {
+ return py::cast(md);
+ }
+ return py::cast(nullptr);
+ },
+ py::arg("timeout") = 0.1)
.def("set_record_type", &replay_block_control::set_record_type)
.def("config_play", &replay_block_control::config_play)
.def("set_play_type", &replay_block_control::set_play_type)