Skip to content

Commit

Permalink
Base sink: add buffer util functions (#65)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Notou authored May 14, 2024
1 parent c728c16 commit 60cc512
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions include/bokehgui/base_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 6 additions & 1 deletion python/bindings/base_sink_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(
{m.get_buff_cols(), m.get_buff_size()}, // shape
{m.get_buff_cols(), buff_size}, // shape
m.get_plot_data() // the data pointer
);
});
Expand Down
3 changes: 3 additions & 0 deletions python/bindings/docstrings/base_sink_pydoc_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
6 changes: 0 additions & 6 deletions python/bindings/waterfall_sink_f_proc_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(
{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 */
Expand Down

0 comments on commit 60cc512

Please sign in to comment.