From 172f209572c5498be7db20d7fefbbdaacea85f3d Mon Sep 17 00:00:00 2001 From: Ricardas Jonaitis Date: Sun, 8 Sep 2024 21:05:53 +0300 Subject: [PATCH] gnuradio: add pregenerated python bindings files. The gnuradio python bindings could be generated during cmake configuration step, but the process might have issues with crawling through gnuradio headers in system path. And the bindings generation process takes relatively long time, so just add the generated files for git tracking and the files are marked to be regenerated automatically if neccessary. --- plugins/gr-limesdr/python/bindings/.gitignore | 2 - .../gr-limesdr/python/bindings/CMakeLists.txt | 8 +- .../bindings/docstrings/sink_pydoc_template.h | 72 +++++++++ .../docstrings/source_pydoc_template.h | 72 +++++++++ .../gr-limesdr/python/bindings/sink_python.cc | 136 +++++++++++++++++ .../python/bindings/source_python.cc | 142 ++++++++++++++++++ 6 files changed, 427 insertions(+), 5 deletions(-) delete mode 100644 plugins/gr-limesdr/python/bindings/.gitignore create mode 100644 plugins/gr-limesdr/python/bindings/docstrings/sink_pydoc_template.h create mode 100644 plugins/gr-limesdr/python/bindings/docstrings/source_pydoc_template.h create mode 100644 plugins/gr-limesdr/python/bindings/sink_python.cc create mode 100644 plugins/gr-limesdr/python/bindings/source_python.cc diff --git a/plugins/gr-limesdr/python/bindings/.gitignore b/plugins/gr-limesdr/python/bindings/.gitignore deleted file mode 100644 index c3cf3838..00000000 --- a/plugins/gr-limesdr/python/bindings/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*_python.cc -docstrings/*_pydoc_template.h diff --git a/plugins/gr-limesdr/python/bindings/CMakeLists.txt b/plugins/gr-limesdr/python/bindings/CMakeLists.txt index a3990958..a3d7377d 100644 --- a/plugins/gr-limesdr/python/bindings/CMakeLists.txt +++ b/plugins/gr-limesdr/python/bindings/CMakeLists.txt @@ -26,9 +26,11 @@ include(GrPybind) list(APPEND limesdr_python_files sink_python.cc source_python.cc python_bindings.cc) -execute_process(COMMAND gr_modtool bind source WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) - -execute_process(COMMAND gr_modtool bind sink WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +# Generates the *_python.cc files, they could be generated with each CMake config run and not require Git tracking. +# But because the bindings rarely change and bindings generation script can have issues when crawling though system header includes, +# the generated bindings files are added to Git tracking, and marked to auto re-generate if needed. +# execute_process(COMMAND gr_modtool bind source WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) +# execute_process(COMMAND gr_modtool bind sink WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) if(ENABLE_RFE) list(APPEND limesdr_python_files rfe_python.cc) diff --git a/plugins/gr-limesdr/python/bindings/docstrings/sink_pydoc_template.h b/plugins/gr-limesdr/python/bindings/docstrings/sink_pydoc_template.h new file mode 100644 index 00000000..c1927738 --- /dev/null +++ b/plugins/gr-limesdr/python/bindings/docstrings/sink_pydoc_template.h @@ -0,0 +1,72 @@ +/* + * Copyright 2024 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, limesdr, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_limesdr_sink = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_sink_0 = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_sink_1 = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_make = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_center_freq = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_antenna = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_nco = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_bandwidth = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_digital_filter = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_gain = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_sample_rate = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_oversampling = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_calibrate = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_buffer_size = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_tcxo_dac = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_write_lms_reg = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_set_gpio_dir = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_write_gpio = R"doc()doc"; + + +static const char* __doc_gr_limesdr_sink_read_gpio = R"doc()doc"; diff --git a/plugins/gr-limesdr/python/bindings/docstrings/source_pydoc_template.h b/plugins/gr-limesdr/python/bindings/docstrings/source_pydoc_template.h new file mode 100644 index 00000000..414e3379 --- /dev/null +++ b/plugins/gr-limesdr/python/bindings/docstrings/source_pydoc_template.h @@ -0,0 +1,72 @@ +/* + * Copyright 2024 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ +#include "pydoc_macros.h" +#define D(...) DOC(gr, limesdr, __VA_ARGS__) +/* + This file contains placeholders for docstrings for the Python bindings. + Do not edit! These were automatically extracted during the binding process + and will be overwritten during the build process + */ + + +static const char* __doc_gr_limesdr_source = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_source_0 = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_source_1 = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_make = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_center_freq = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_antenna = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_nco = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_bandwidth = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_digital_filter = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_gain = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_sample_rate = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_oversampling = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_calibrate = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_buffer_size = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_tcxo_dac = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_write_lms_reg = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_set_gpio_dir = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_write_gpio = R"doc()doc"; + + +static const char* __doc_gr_limesdr_source_read_gpio = R"doc()doc"; diff --git a/plugins/gr-limesdr/python/bindings/sink_python.cc b/plugins/gr-limesdr/python/bindings/sink_python.cc new file mode 100644 index 00000000..232833fc --- /dev/null +++ b/plugins/gr-limesdr/python/bindings/sink_python.cc @@ -0,0 +1,136 @@ +/* + * Copyright 2024 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* This file is automatically generated using bindtool and can be manually edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. */ +/* BINDTOOL_GEN_AUTOMATIC(1) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(sink.h) */ +/* BINDTOOL_HEADER_FILE_HASH(f2afded25eae99fdd12ae231bd440d70) */ +/***********************************************************************************/ + +#include +#include +#include + +namespace py = pybind11; + +#include +// pydoc.h is automatically generated in the build directory +#include + +void bind_sink(py::module& m) +{ + + using sink = ::gr::limesdr::sink; + + + py::class_>( + m, "sink", D(sink)) + + .def(py::init(&sink::make), + py::arg("serial"), + py::arg("channel_mode"), + py::arg("filename"), + py::arg("length_tag_name"), + D(sink, make)) + + + .def("set_center_freq", + &sink::set_center_freq, + py::arg("freq"), + py::arg("chan") = 0, + D(sink, set_center_freq)) + + + .def("set_antenna", + &sink::set_antenna, + py::arg("antenna"), + py::arg("channel") = 0, + D(sink, set_antenna)) + + + .def("set_nco", + &sink::set_nco, + py::arg("nco_freq"), + py::arg("channel"), + D(sink, set_nco)) + + + .def("set_bandwidth", + &sink::set_bandwidth, + py::arg("analog_bandw"), + py::arg("channel") = 0, + D(sink, set_bandwidth)) + + + .def("set_digital_filter", + &sink::set_digital_filter, + py::arg("digital_bandw"), + py::arg("channel"), + D(sink, set_digital_filter)) + + + .def("set_gain", + &sink::set_gain, + py::arg("gain_dB"), + py::arg("channel") = 0, + D(sink, set_gain)) + + + .def("set_sample_rate", + &sink::set_sample_rate, + py::arg("rate"), + D(sink, set_sample_rate)) + + + .def("set_oversampling", + &sink::set_oversampling, + py::arg("oversample"), + D(sink, set_oversampling)) + + + .def("calibrate", + &sink::calibrate, + py::arg("bandw"), + py::arg("channel") = 0, + D(sink, calibrate)) + + + .def("set_buffer_size", + &sink::set_buffer_size, + py::arg("size"), + D(sink, set_buffer_size)) + + + .def("set_tcxo_dac", + &sink::set_tcxo_dac, + py::arg("dacVal") = 125, + D(sink, set_tcxo_dac)) + + + .def("write_lms_reg", + &sink::write_lms_reg, + py::arg("address"), + py::arg("val"), + D(sink, write_lms_reg)) + + + .def("set_gpio_dir", &sink::set_gpio_dir, py::arg("dir"), D(sink, set_gpio_dir)) + + + .def("write_gpio", &sink::write_gpio, py::arg("out"), D(sink, write_gpio)) + + + .def("read_gpio", &sink::read_gpio, D(sink, read_gpio)) + + ; +} diff --git a/plugins/gr-limesdr/python/bindings/source_python.cc b/plugins/gr-limesdr/python/bindings/source_python.cc new file mode 100644 index 00000000..2b4fab28 --- /dev/null +++ b/plugins/gr-limesdr/python/bindings/source_python.cc @@ -0,0 +1,142 @@ +/* + * Copyright 2024 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +/***********************************************************************************/ +/* This file is automatically generated using bindtool and can be manually edited */ +/* The following lines can be configured to regenerate this file during cmake */ +/* If manual edits are made, the following tags should be modified accordingly. */ +/* BINDTOOL_GEN_AUTOMATIC(1) */ +/* BINDTOOL_USE_PYGCCXML(0) */ +/* BINDTOOL_HEADER_FILE(source.h) */ +/* BINDTOOL_HEADER_FILE_HASH(513c2396631d13233148b0f4738adf16) */ +/***********************************************************************************/ + +#include +#include +#include + +namespace py = pybind11; + +#include +// pydoc.h is automatically generated in the build directory +#include + +void bind_source(py::module& m) +{ + + using source = ::gr::limesdr::source; + + + py::class_>(m, "source", D(source)) + + .def(py::init(&source::make), + py::arg("serial"), + py::arg("channel_mode"), + py::arg("filename"), + py::arg("align_ch_phase"), + D(source, make)) + + + .def("set_center_freq", + &source::set_center_freq, + py::arg("freq"), + py::arg("chan") = 0, + D(source, set_center_freq)) + + + .def("set_antenna", + &source::set_antenna, + py::arg("antenna"), + py::arg("channel") = 0, + D(source, set_antenna)) + + + .def("set_nco", + &source::set_nco, + py::arg("nco_freq"), + py::arg("channel"), + D(source, set_nco)) + + + .def("set_bandwidth", + &source::set_bandwidth, + py::arg("analog_bandw"), + py::arg("channel") = 0, + D(source, set_bandwidth)) + + + .def("set_digital_filter", + &source::set_digital_filter, + py::arg("digital_bandw"), + py::arg("channel"), + D(source, set_digital_filter)) + + + .def("set_gain", + &source::set_gain, + py::arg("gain_dB"), + py::arg("channel") = 0, + D(source, set_gain)) + + + .def("set_sample_rate", + &source::set_sample_rate, + py::arg("rate"), + D(source, set_sample_rate)) + + + .def("set_oversampling", + &source::set_oversampling, + py::arg("oversample"), + D(source, set_oversampling)) + + + .def("calibrate", + &source::calibrate, + py::arg("bandw"), + py::arg("channel") = 0, + D(source, calibrate)) + + + .def("set_buffer_size", + &source::set_buffer_size, + py::arg("size"), + D(source, set_buffer_size)) + + + .def("set_tcxo_dac", + &source::set_tcxo_dac, + py::arg("dacVal") = 125, + D(source, set_tcxo_dac)) + + + .def("write_lms_reg", + &source::write_lms_reg, + py::arg("address"), + py::arg("val"), + D(source, write_lms_reg)) + + + .def("set_gpio_dir", + &source::set_gpio_dir, + py::arg("dir"), + D(source, set_gpio_dir)) + + + .def("write_gpio", &source::write_gpio, py::arg("out"), D(source, write_gpio)) + + + .def("read_gpio", &source::read_gpio, D(source, read_gpio)) + + ; +}