From 60cc512803e51a69b74b34570ea416a8ab40d8cc Mon Sep 17 00:00:00 2001 From: Cyrille Morin Date: Tue, 14 May 2024 11:17:37 +0200 Subject: [PATCH] Base sink: add buffer util functions (#65) * Pull waterfall get_plot_data binding to base_sink And make is so returned array has proper length * Add function to poll number of items in buffer of base_sinks --- include/bokehgui/base_sink.h | 5 +++++ python/bindings/base_sink_python.cc | 7 ++++++- python/bindings/docstrings/base_sink_pydoc_template.h | 3 +++ python/bindings/waterfall_sink_f_proc_python.cc | 6 ------ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/bokehgui/base_sink.h b/include/bokehgui/base_sink.h index 6d2c796..2ed0816 100644 --- a/include/bokehgui/base_sink.h +++ b/include/bokehgui/base_sink.h @@ -123,11 +123,16 @@ namespace gr { int get_buff_size(){ if (!d_buffers.size()) { + // printf("The buffer is empty, returning 0\n"); return 0; } return d_buffers.front()[0].size(); } + int get_buff_num_items(){ + return d_buffers.size(); + } + int get_buff_cols(){ return (sizeof(T)/sizeof(float))*d_nconnections; } diff --git a/python/bindings/base_sink_python.cc b/python/bindings/base_sink_python.cc index bc641a5..e917c13 100644 --- a/python/bindings/base_sink_python.cc +++ b/python/bindings/base_sink_python.cc @@ -51,9 +51,14 @@ void bind_base_sink_template(py::module& m, const char* classname) D(base_sink,get_nconnections) ) + .def("get_buff_num_items",&base_sink::get_buff_num_items, + D(base_sink,get_buff_num_items) + ) + .def("get_plot_data", [](base_sink &m){ + int buff_size = m.get_buff_size(); return py::array_t( - {m.get_buff_cols(), m.get_buff_size()}, // shape + {m.get_buff_cols(), buff_size}, // shape m.get_plot_data() // the data pointer ); }); diff --git a/python/bindings/docstrings/base_sink_pydoc_template.h b/python/bindings/docstrings/base_sink_pydoc_template.h index a7087a9..0598cbe 100644 --- a/python/bindings/docstrings/base_sink_pydoc_template.h +++ b/python/bindings/docstrings/base_sink_pydoc_template.h @@ -40,4 +40,7 @@ static const char *__doc_gr_bokehgui_base_sink_get_nconnections = R"doc()doc"; + static const char *__doc_gr_bokehgui_base_sink_get_buff_num_items = R"doc()doc"; + + static const char *__doc_gr_bokehgui_base_sink_get_plot_data = R"doc()doc"; diff --git a/python/bindings/waterfall_sink_f_proc_python.cc b/python/bindings/waterfall_sink_f_proc_python.cc index 449e533..c487bde 100755 --- a/python/bindings/waterfall_sink_f_proc_python.cc +++ b/python/bindings/waterfall_sink_f_proc_python.cc @@ -105,12 +105,6 @@ void bind_waterfall_sink_f_proc(py::module& m) ) - .def("get_plot_data", [](waterfall_sink_f_proc &m){ - return py::array_t( - {m.get_buff_cols(), m.get_buff_size()}, // shape - m.get_plot_data() // the data pointer - ); - }); // .def_buffer([] (waterfall_sink_f_proc &m) -> py::buffer_info { // return py::buffer_info( // m.get_plot_data(), /* Pointer to buffer */