diff options
Diffstat (limited to 'gr-uhd/python/uhd/bindings')
-rw-r--r-- | gr-uhd/python/uhd/bindings/CMakeLists.txt | 20 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/amsg_source_python.cc | 43 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/docstrings/amsg_source_pydoc_template.h | 30 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/docstrings/usrp_block_pydoc_template.h | 234 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/docstrings/usrp_sink_pydoc_template.h | 66 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/docstrings/usrp_source_pydoc_template.h | 87 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/python_bindings.cc | 55 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/uhd_types_python.cc | 158 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/usrp_block_python.cc | 441 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/usrp_sink_python.cc | 145 | ||||
-rw-r--r-- | gr-uhd/python/uhd/bindings/usrp_source_python.cc | 191 |
11 files changed, 1470 insertions, 0 deletions
diff --git a/gr-uhd/python/uhd/bindings/CMakeLists.txt b/gr-uhd/python/uhd/bindings/CMakeLists.txt new file mode 100644 index 0000000000..8d123da16c --- /dev/null +++ b/gr-uhd/python/uhd/bindings/CMakeLists.txt @@ -0,0 +1,20 @@ +include(GrPybind) + +######################################################################## +# Python Bindings +######################################################################## + +list(APPEND uhd_python_files + uhd_types_python.cc + amsg_source_python.cc + usrp_block_python.cc + usrp_sink_python.cc + usrp_source_python.cc + python_bindings.cc) + +GR_PYBIND_MAKE(uhd + ../../.. + gr::uhd + "${uhd_python_files}") + +install(TARGETS uhd_python DESTINATION ${GR_PYTHON_DIR}/gnuradio/uhd COMPONENT pythonapi) diff --git a/gr-uhd/python/uhd/bindings/amsg_source_python.cc b/gr-uhd/python/uhd/bindings/amsg_source_python.cc new file mode 100644 index 0000000000..2e3daacf2e --- /dev/null +++ b/gr-uhd/python/uhd/bindings/amsg_source_python.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2020 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 */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/uhd/amsg_source.h> +// pydoc.h is automatically generated in the build directory +#include <amsg_source_pydoc.h> + +void bind_amsg_source(py::module& m) +{ + + using amsg_source = ::gr::uhd::amsg_source; + + + py::class_<amsg_source, std::shared_ptr<amsg_source>>( + m, "amsg_source", D(amsg_source)) + + .def(py::init(&amsg_source::make), + py::arg("device_addr"), + py::arg("msgq"), + D(amsg_source, make)) + + + .def_static("msg_to_async_metadata_t", + &amsg_source::msg_to_async_metadata_t, + py::arg("msg"), + D(amsg_source, msg_to_async_metadata_t)) + + ; +} diff --git a/gr-uhd/python/uhd/bindings/docstrings/amsg_source_pydoc_template.h b/gr-uhd/python/uhd/bindings/docstrings/amsg_source_pydoc_template.h new file mode 100644 index 0000000000..275c38042e --- /dev/null +++ b/gr-uhd/python/uhd/bindings/docstrings/amsg_source_pydoc_template.h @@ -0,0 +1,30 @@ +/* + * Copyright 2020 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, uhd, __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_uhd_amsg_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_amsg_source_amsg_source_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_amsg_source_amsg_source_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_amsg_source_make = R"doc()doc"; + + +static const char* __doc_gr_uhd_amsg_source_msg_to_async_metadata_t = R"doc()doc"; diff --git a/gr-uhd/python/uhd/bindings/docstrings/usrp_block_pydoc_template.h b/gr-uhd/python/uhd/bindings/docstrings/usrp_block_pydoc_template.h new file mode 100644 index 0000000000..3ef0dd728b --- /dev/null +++ b/gr-uhd/python/uhd/bindings/docstrings/usrp_block_pydoc_template.h @@ -0,0 +1,234 @@ +/* + * Copyright 2020 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, uhd, __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_uhd_usrp_block = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_subdev_spec = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_subdev_spec = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_num_mboards = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_samp_rate = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_samp_rate = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_samp_rates = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_center_freq_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_center_freq_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_center_freq = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_freq_range = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_gain_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_gain_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_normalized_gain = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gain_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gain_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_normalized_gain = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gain_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gain_range_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gain_range_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_antenna = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_antenna = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_antennas = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_bandwidth = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_bandwidth = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_bandwidth_range = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_sensor = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_sensor_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_dboard_sensor = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_dboard_sensor_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_mboard_sensor = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_mboard_sensor_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_time_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_time_sources = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_clock_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_clock_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_clock_sources = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_clock_rate = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_clock_rate = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_time_now = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_time_last_pps = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_time_now = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_time_next_pps = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_time_unknown_pps = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_command_time = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_clear_command_time = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_dboard_iface = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_device = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_user_register = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_time_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_stream_args = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gpio_banks = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_gpio_attr = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_gpio_attr = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_filter_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_set_filter = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_block_get_filter = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_chan_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_gain_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_freq_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_lo_offset_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_tune_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_lo_freq_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_dsp_freq_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_rate_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_bandwidth_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_time_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_mboard_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_antenna_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_direction_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_cmd_tag_key = R"doc()doc"; + + +static const char* __doc_gr_uhd_ant_direction_rx = R"doc()doc"; + + +static const char* __doc_gr_uhd_ant_direction_tx = R"doc()doc"; diff --git a/gr-uhd/python/uhd/bindings/docstrings/usrp_sink_pydoc_template.h b/gr-uhd/python/uhd/bindings/docstrings/usrp_sink_pydoc_template.h new file mode 100644 index 0000000000..233a1f4c3c --- /dev/null +++ b/gr-uhd/python/uhd/bindings/docstrings/usrp_sink_pydoc_template.h @@ -0,0 +1,66 @@ +/* + * Copyright 2020 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, uhd, __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_uhd_usrp_sink = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_usrp_sink_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_usrp_sink_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_make = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_start_time = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_usrp_info = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_lo_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_sources = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_lo_export_enabled = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_export_enabled = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_lo_freq = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_freq = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_get_lo_freq_range = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_dc_offset = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_sink_set_iq_balance = R"doc()doc"; diff --git a/gr-uhd/python/uhd/bindings/docstrings/usrp_source_pydoc_template.h b/gr-uhd/python/uhd/bindings/docstrings/usrp_source_pydoc_template.h new file mode 100644 index 0000000000..f2d93f03a0 --- /dev/null +++ b/gr-uhd/python/uhd/bindings/docstrings/usrp_source_pydoc_template.h @@ -0,0 +1,87 @@ +/* + * Copyright 2020 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, uhd, __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_uhd_usrp_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_usrp_source_0 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_usrp_source_1 = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_make = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_start_time = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_issue_stream_cmd = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_recv_timeout = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_usrp_info = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_names = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_lo_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_source = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_sources = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_lo_export_enabled = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_export_enabled = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_lo_freq = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_freq = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_get_lo_freq_range = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_auto_dc_offset = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_dc_offset = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_auto_iq_balance = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_iq_balance = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_set_rx_agc = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_finite_acquisition = R"doc()doc"; + + +static const char* __doc_gr_uhd_usrp_source_finite_acquisition_v = R"doc()doc"; diff --git a/gr-uhd/python/uhd/bindings/python_bindings.cc b/gr-uhd/python/uhd/bindings/python_bindings.cc new file mode 100644 index 0000000000..e32d1b48cc --- /dev/null +++ b/gr-uhd/python/uhd/bindings/python_bindings.cc @@ -0,0 +1,55 @@ + +/* + * Copyright 2020 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include <pybind11/pybind11.h> + +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#include <numpy/arrayobject.h> + +#include <uhd/version.hpp> + +namespace py = pybind11; + +void bind_uhd_types(py::module&); +void bind_amsg_source(py::module&); +void bind_usrp_block(py::module&); +void bind_usrp_sink(py::module&); +void bind_usrp_source(py::module&); + +// We need this hack because import_array() returns NULL +// for newer Python versions. +// This function is also necessary because it ensures access to the C API +// and removes a warning. +void* init_numpy() +{ + import_array(); + return NULL; +} + +PYBIND11_MODULE(uhd_python, m) +{ + // Initialize the numpy C API + // (otherwise we will see segmentation faults) + init_numpy(); + + // Allow access to base block methods + py::module::import("gnuradio.gr"); + + bind_uhd_types(m); + bind_amsg_source(m); + bind_usrp_block(m); + bind_usrp_sink(m); + bind_usrp_source(m); + + m.def( + "get_version_string", + []() { return ::uhd::get_version_string(); }, + "Returns UHD Version String"); +} diff --git a/gr-uhd/python/uhd/bindings/uhd_types_python.cc b/gr-uhd/python/uhd/bindings/uhd_types_python.cc new file mode 100644 index 0000000000..45202c8395 --- /dev/null +++ b/gr-uhd/python/uhd/bindings/uhd_types_python.cc @@ -0,0 +1,158 @@ +/* + * Copyright 2020 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 */ + +#include <pybind11/complex.h> +#include <pybind11/operators.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/uhd/uhd_types.h> + +void bind_uhd_types(py::module& m) +{ + // Bindings copied from UHD + + // using str_map = std::map<std::string, std::string>; + + py::class_<::uhd::device_addr_t>(m, "device_addr_t") + // Constructors + .def(py::init<>()) + .def(py::init<std::string>()) + // Not defined for UHD < 3.11 + // .def(py::init<str_map>()) + + // Methods + .def("__str__", &uhd::device_addr_t::to_pp_string) + .def("to_string", &uhd::device_addr_t::to_string) + .def("to_pp_string", &uhd::device_addr_t::to_pp_string); + + // This will allow functions in Python that take a device_addr to also take + // a string: + py::implicitly_convertible<std::string, uhd::device_addr_t>(); + + using stream_args_t = ::uhd::stream_args_t; + py::class_<stream_args_t>(m, "stream_args_t") + .def(py::init<const std::string&, const std::string&>()) + // Properties + .def_readwrite("cpu_format", &stream_args_t::cpu_format) + .def_readwrite("otw_format", &stream_args_t::otw_format) + .def_readwrite("args", &stream_args_t::args) + .def_readwrite("channels", &stream_args_t::channels); + + + // ::uhd::time_spec_t + using time_spec_t = ::uhd::time_spec_t; + + py::class_<time_spec_t>(m, "time_spec_t") + // Additional constructors + .def(py::init<double>()) + .def(py::init<int64_t, double>()) + .def(py::init<int64_t, long, double>()) + + // Methods + .def_static("from_ticks", &time_spec_t::from_ticks) + + .def("get_tick_count", &time_spec_t::get_tick_count) + .def("to_ticks", &time_spec_t::to_ticks) + .def("get_real_secs", &time_spec_t::get_real_secs) + .def("get_full_secs", &time_spec_t::get_full_secs) + .def("get_frac_secs", &time_spec_t::get_frac_secs) + + .def(py::self += time_spec_t()) + .def(py::self -= time_spec_t()) + .def(py::self + time_spec_t()) + .def(py::self - time_spec_t()) + .def(py::self += double()) + .def(py::self -= double()) + .def(py::self + double()) + .def(py::self - double()); + + // ::uhd::stream_cmd_t + using stream_cmd_t = ::uhd::stream_cmd_t; + py::class_<stream_cmd_t>(m, "stream_cmd_t") + .def(py::init<stream_cmd_t::stream_mode_t>()) + // Properties + .def_readwrite("num_samps", &stream_cmd_t::num_samps) + .def_readwrite("time_spec", &stream_cmd_t::time_spec) + .def_readwrite("stream_now", &stream_cmd_t::stream_now); + + // ::uhd::meta_range_t + using meta_range_t = ::uhd::meta_range_t; + + py::class_<meta_range_t>(m, "meta_range_t") + // Constructors + .def(py::init<>()) + .def(py::init<double, double>()) + .def(py::init<double, double, double>()) + + // Methods + .def("start", &meta_range_t::start) + .def("stop", &meta_range_t::stop) + .def("step", &meta_range_t::step) + .def("clip", &meta_range_t::clip, py::arg("value"), py::arg("clip_step") = false) + .def("__str__", &meta_range_t::to_pp_string); + + // ::uhd::tune_result_t + using tune_result_t = ::uhd::tune_result_t; + py::class_<tune_result_t>(m, "tune_result_t") + .def(py::init<>()) + .def_readwrite("clipped_rf_freq", &tune_result_t::clipped_rf_freq) + .def_readwrite("target_rf_freq", &tune_result_t::target_rf_freq) + .def_readwrite("actual_rf_freq", &tune_result_t::actual_rf_freq) + .def_readwrite("target_dsp_freq", &tune_result_t::target_dsp_freq) + .def_readwrite("actual_dsp_freq", &tune_result_t::actual_dsp_freq) + .def("__str__", &tune_result_t::to_pp_string); + + // ::uhd::tune_request_t + using tune_request_t = ::uhd::tune_request_t; + py::class_<tune_request_t>(m, "tune_request_t") + .def(py::init<double, double>()) + .def(py::init<double>(), py::arg("target_freq") = 0.0) + .def_readwrite("target_freq", &tune_request_t::target_freq) + .def_readwrite("rf_freq_policy", &tune_request_t::rf_freq_policy) + .def_readwrite("dsp_freq_policy", &tune_request_t::dsp_freq_policy) + .def_readwrite("rf_freq", &tune_request_t::rf_freq) + .def_readwrite("dsp_freq", &tune_request_t::dsp_freq) + .def_readwrite("args", &tune_request_t::args); + + + // ::uhd::sensor_value_t + using sensor_value_t = uhd::sensor_value_t; + + py::class_<sensor_value_t>(m, "sensor_value_t") + // Constructors + .def(py::init<const std::string&, bool, const std::string&, const std::string&>()) + .def(py::init<const std::string&, + signed, + const std::string&, + const std::string&>()) + .def(py::init<const std::string&, + double, + const std::string&, + const std::string&>()) + .def(py::init<const std::string&, const std::string&, const std::string&>()) + + // Methods + .def("to_bool", &sensor_value_t::to_bool) + .def("to_int", &sensor_value_t::to_int) + .def("to_real", &sensor_value_t::to_real) + .def("__str__", &sensor_value_t::to_pp_string); + + // NOTE: UHD 3.9 has these properties defined as const so they cannot be + // set in this manner. + // // Properties + // .def_readwrite("name", &sensor_value_t::name) + // .def_readwrite("value", &sensor_value_t::value) + // .def_readwrite("unit", &sensor_value_t::unit) + // .def_readwrite("type", &sensor_value_t::type); +} diff --git a/gr-uhd/python/uhd/bindings/usrp_block_python.cc b/gr-uhd/python/uhd/bindings/usrp_block_python.cc new file mode 100644 index 0000000000..7d25ce1a34 --- /dev/null +++ b/gr-uhd/python/uhd/bindings/usrp_block_python.cc @@ -0,0 +1,441 @@ +/* + * Copyright 2020 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 */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/uhd/usrp_block.h> +// pydoc.h is automatically generated in the build directory +#include <usrp_block_pydoc.h> + +void bind_usrp_block(py::module& m) +{ + + using usrp_block = ::gr::uhd::usrp_block; + + + py::class_<usrp_block, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<usrp_block>>(m, "usrp_block", D(usrp_block)) + + + .def("set_subdev_spec", + &usrp_block::set_subdev_spec, + py::arg("spec"), + py::arg("mboard") = 0, + D(usrp_block, set_subdev_spec)) + + + .def("get_subdev_spec", + &usrp_block::get_subdev_spec, + py::arg("mboard") = 0, + D(usrp_block, get_subdev_spec)) + + + .def("get_num_mboards", + &usrp_block::get_num_mboards, + D(usrp_block, get_num_mboards)) + + + .def("set_samp_rate", + &usrp_block::set_samp_rate, + py::arg("rate"), + D(usrp_block, set_samp_rate)) + + + .def("get_samp_rate", &usrp_block::get_samp_rate, D(usrp_block, get_samp_rate)) + + + .def("get_samp_rates", &usrp_block::get_samp_rates, D(usrp_block, get_samp_rates)) + + + .def("set_center_freq", + (uhd::tune_result_t(usrp_block::*)(uhd::tune_request_t const, size_t)) & + usrp_block::set_center_freq, + py::arg("tune_request"), + py::arg("chan") = 0, + D(usrp_block, set_center_freq, 0)) + + + .def("set_center_freq", + (uhd::tune_result_t(usrp_block::*)(double, size_t)) & + usrp_block::set_center_freq, + py::arg("freq"), + py::arg("chan") = 0, + D(usrp_block, set_center_freq, 1)) + + + .def("get_center_freq", + &usrp_block::get_center_freq, + py::arg("chan") = 0, + D(usrp_block, get_center_freq)) + + + .def("get_freq_range", + &usrp_block::get_freq_range, + py::arg("chan") = 0, + D(usrp_block, get_freq_range)) + + + .def("set_gain", + (void (usrp_block::*)(double, size_t)) & usrp_block::set_gain, + py::arg("gain"), + py::arg("chan") = 0, + D(usrp_block, set_gain, 0)) + + + .def("set_gain", + (void (usrp_block::*)(double, std::string const&, size_t)) & + usrp_block::set_gain, + py::arg("gain"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_block, set_gain, 1)) + + + .def("set_normalized_gain", + &usrp_block::set_normalized_gain, + py::arg("norm_gain"), + py::arg("chan") = 0, + D(usrp_block, set_normalized_gain)) + + + .def("get_gain", + (double (usrp_block::*)(size_t)) & usrp_block::get_gain, + py::arg("chan") = 0, + D(usrp_block, get_gain, 0)) + + + .def("get_gain", + (double (usrp_block::*)(std::string const&, size_t)) & usrp_block::get_gain, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_block, get_gain, 1)) + + + .def("get_normalized_gain", + &usrp_block::get_normalized_gain, + py::arg("chan") = 0, + D(usrp_block, get_normalized_gain)) + + + .def("get_gain_names", + &usrp_block::get_gain_names, + py::arg("chan") = 0, + D(usrp_block, get_gain_names)) + + + .def("get_gain_range", + (uhd::gain_range_t(usrp_block::*)(size_t)) & usrp_block::get_gain_range, + py::arg("chan") = 0, + D(usrp_block, get_gain_range, 0)) + + + .def("get_gain_range", + (uhd::gain_range_t(usrp_block::*)(std::string const&, size_t)) & + usrp_block::get_gain_range, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_block, get_gain_range, 1)) + + + .def("set_antenna", + &usrp_block::set_antenna, + py::arg("ant"), + py::arg("chan") = 0, + D(usrp_block, set_antenna)) + + + .def("get_antenna", + &usrp_block::get_antenna, + py::arg("chan") = 0, + D(usrp_block, get_antenna)) + + + .def("get_antennas", + &usrp_block::get_antennas, + py::arg("chan") = 0, + D(usrp_block, get_antennas)) + + + .def("set_bandwidth", + &usrp_block::set_bandwidth, + py::arg("bandwidth"), + py::arg("chan") = 0, + D(usrp_block, set_bandwidth)) + + + .def("get_bandwidth", + &usrp_block::get_bandwidth, + py::arg("chan") = 0, + D(usrp_block, get_bandwidth)) + + + .def("get_bandwidth_range", + &usrp_block::get_bandwidth_range, + py::arg("chan") = 0, + D(usrp_block, get_bandwidth_range)) + + + .def("get_sensor", + &usrp_block::get_sensor, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_block, get_sensor)) + + + .def("get_sensor_names", + &usrp_block::get_sensor_names, + py::arg("chan") = 0, + D(usrp_block, get_sensor_names)) + + + .def("get_dboard_sensor", + &usrp_block::get_dboard_sensor, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_block, get_dboard_sensor)) + + + .def("get_dboard_sensor_names", + &usrp_block::get_dboard_sensor_names, + py::arg("chan") = 0, + D(usrp_block, get_dboard_sensor_names)) + + + .def("get_mboard_sensor", + &usrp_block::get_mboard_sensor, + py::arg("name"), + py::arg("mboard") = 0, + D(usrp_block, get_mboard_sensor)) + + + .def("get_mboard_sensor_names", + &usrp_block::get_mboard_sensor_names, + py::arg("mboard") = 0, + D(usrp_block, get_mboard_sensor_names)) + + + .def("get_time_source", + &usrp_block::get_time_source, + py::arg("mboard"), + D(usrp_block, get_time_source)) + + + .def("get_time_sources", + &usrp_block::get_time_sources, + py::arg("mboard"), + D(usrp_block, get_time_sources)) + + + .def("set_clock_source", + &usrp_block::set_clock_source, + py::arg("source"), + py::arg("mboard") = 0, + D(usrp_block, set_clock_source)) + + + .def("get_clock_source", + &usrp_block::get_clock_source, + py::arg("mboard"), + D(usrp_block, get_clock_source)) + + + .def("get_clock_sources", + &usrp_block::get_clock_sources, + py::arg("mboard"), + D(usrp_block, get_clock_sources)) + + + .def("get_clock_rate", + &usrp_block::get_clock_rate, + py::arg("mboard") = 0, + D(usrp_block, get_clock_rate)) + + + .def("set_clock_rate", + &usrp_block::set_clock_rate, + py::arg("rate"), + py::arg("mboard") = 0, + D(usrp_block, set_clock_rate)) + + + .def("get_time_now", + &usrp_block::get_time_now, + py::arg("mboard") = 0, + D(usrp_block, get_time_now)) + + + .def("get_time_last_pps", + &usrp_block::get_time_last_pps, + py::arg("mboard") = 0, + D(usrp_block, get_time_last_pps)) + + + .def("set_time_now", + &usrp_block::set_time_now, + py::arg("time_spec"), + py::arg("mboard") = 0, + D(usrp_block, set_time_now)) + + + .def("set_time_next_pps", + &usrp_block::set_time_next_pps, + py::arg("time_spec"), + D(usrp_block, set_time_next_pps)) + + + .def("set_time_unknown_pps", + &usrp_block::set_time_unknown_pps, + py::arg("time_spec"), + D(usrp_block, set_time_unknown_pps)) + + + .def("set_command_time", + &usrp_block::set_command_time, + py::arg("time_spec"), + py::arg("mboard") = 0, + D(usrp_block, set_command_time)) + + + .def("clear_command_time", + &usrp_block::clear_command_time, + py::arg("mboard") = 0, + D(usrp_block, clear_command_time)) + + + .def("get_dboard_iface", + &usrp_block::get_dboard_iface, + py::arg("chan") = 0, + D(usrp_block, get_dboard_iface)) + + + .def("get_device", &usrp_block::get_device, D(usrp_block, get_device)) + + + .def("set_user_register", + &usrp_block::set_user_register, + py::arg("addr"), + py::arg("data"), + py::arg("mboard") = 0, + D(usrp_block, set_user_register)) + + + .def("set_time_source", + &usrp_block::set_time_source, + py::arg("source"), + py::arg("mboard") = 0, + D(usrp_block, set_time_source)) + + + .def("set_stream_args", + &usrp_block::set_stream_args, + py::arg("stream_args"), + D(usrp_block, set_stream_args)) + + + .def("get_gpio_banks", + &usrp_block::get_gpio_banks, + py::arg("mboard"), + D(usrp_block, get_gpio_banks)) + + + .def("set_gpio_attr", + &usrp_block::set_gpio_attr, + py::arg("bank"), + py::arg("attr"), + py::arg("value"), + py::arg("mask") = 4294967295U, + py::arg("mboard") = 0, + D(usrp_block, set_gpio_attr)) + + + .def("get_gpio_attr", + &usrp_block::get_gpio_attr, + py::arg("bank"), + py::arg("attr"), + py::arg("mboard") = 0, + D(usrp_block, get_gpio_attr)) + + + .def("get_filter_names", + &usrp_block::get_filter_names, + py::arg("search_mask") = "", + D(usrp_block, get_filter_names)) + + + .def("set_filter", + &usrp_block::set_filter, + py::arg("path"), + py::arg("filter"), + D(usrp_block, set_filter)) + + + .def("get_filter", + &usrp_block::get_filter, + py::arg("path"), + D(usrp_block, get_filter)) + + ; + + + m.def("cmd_chan_key", &::gr::uhd::cmd_chan_key, D(cmd_chan_key)); + + + m.def("cmd_gain_key", &::gr::uhd::cmd_gain_key, D(cmd_gain_key)); + + + m.def("cmd_freq_key", &::gr::uhd::cmd_freq_key, D(cmd_freq_key)); + + + m.def("cmd_lo_offset_key", &::gr::uhd::cmd_lo_offset_key, D(cmd_lo_offset_key)); + + + m.def("cmd_tune_key", &::gr::uhd::cmd_tune_key, D(cmd_tune_key)); + + + m.def("cmd_lo_freq_key", &::gr::uhd::cmd_lo_freq_key, D(cmd_lo_freq_key)); + + + m.def("cmd_dsp_freq_key", &::gr::uhd::cmd_dsp_freq_key, D(cmd_dsp_freq_key)); + + + m.def("cmd_rate_key", &::gr::uhd::cmd_rate_key, D(cmd_rate_key)); + + + m.def("cmd_bandwidth_key", &::gr::uhd::cmd_bandwidth_key, D(cmd_bandwidth_key)); + + + m.def("cmd_time_key", &::gr::uhd::cmd_time_key, D(cmd_time_key)); + + + m.def("cmd_mboard_key", &::gr::uhd::cmd_mboard_key, D(cmd_mboard_key)); + + + m.def("cmd_antenna_key", &::gr::uhd::cmd_antenna_key, D(cmd_antenna_key)); + + + m.def("cmd_direction_key", &::gr::uhd::cmd_direction_key, D(cmd_direction_key)); + + + m.def("cmd_tag_key", &::gr::uhd::cmd_tag_key, D(cmd_tag_key)); + + + m.def("ant_direction_rx", &::gr::uhd::ant_direction_rx, D(ant_direction_rx)); + + + m.def("ant_direction_tx", &::gr::uhd::ant_direction_tx, D(ant_direction_tx)); +} diff --git a/gr-uhd/python/uhd/bindings/usrp_sink_python.cc b/gr-uhd/python/uhd/bindings/usrp_sink_python.cc new file mode 100644 index 0000000000..d0a7dc482d --- /dev/null +++ b/gr-uhd/python/uhd/bindings/usrp_sink_python.cc @@ -0,0 +1,145 @@ +/* + * Copyright 2020 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 */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/uhd/usrp_sink.h> +// pydoc.h is automatically generated in the build directory +#include <usrp_sink_pydoc.h> + +void bind_usrp_sink(py::module& m) +{ + + using usrp_sink = ::gr::uhd::usrp_sink; + + + py::class_<usrp_sink, + gr::uhd::usrp_block, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<usrp_sink>>(m, "usrp_sink", D(usrp_sink)) + + .def(py::init((std::shared_ptr<gr::uhd::usrp_sink>(*)(const ::uhd::device_addr_t&, + const ::uhd::stream_args_t&, + const std::string&)) & + usrp_sink::make), + py::arg("device_addr"), + py::arg("stream_args"), + py::arg("tsb_tag_name") = "", + D(usrp_sink, make)) + + .def(py::init((std::shared_ptr<gr::uhd::usrp_sink>(*)(const std::string&, + const ::uhd::stream_args_t&, + const std::string&)) & + usrp_sink::make), + py::arg("device_addr"), + py::arg("stream_args"), + py::arg("tsb_tag_name") = "", + D(usrp_sink, make)) + + + .def("set_start_time", + &usrp_sink::set_start_time, + py::arg("time"), + D(usrp_sink, set_start_time)) + + + .def("get_usrp_info", + &usrp_sink::get_usrp_info, + py::arg("chan") = 0, + D(usrp_sink, get_usrp_info)) + + + .def("get_lo_names", + &usrp_sink::get_lo_names, + py::arg("chan") = 0, + D(usrp_sink, get_lo_names)) + + + .def("set_lo_source", + &usrp_sink::set_lo_source, + py::arg("src"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, set_lo_source)) + + + .def("get_lo_source", + &usrp_sink::get_lo_source, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, get_lo_source)) + + + .def("get_lo_sources", + &usrp_sink::get_lo_sources, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, get_lo_sources)) + + + .def("set_lo_export_enabled", + &usrp_sink::set_lo_export_enabled, + py::arg("enabled"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, set_lo_export_enabled)) + + + .def("get_lo_export_enabled", + &usrp_sink::get_lo_export_enabled, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, get_lo_export_enabled)) + + + .def("set_lo_freq", + &usrp_sink::set_lo_freq, + py::arg("freq"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, set_lo_freq)) + + + .def("get_lo_freq", + &usrp_sink::get_lo_freq, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, get_lo_freq)) + + + .def("get_lo_freq_range", + &usrp_sink::get_lo_freq_range, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_sink, get_lo_freq_range)) + + + .def("set_dc_offset", + &usrp_sink::set_dc_offset, + py::arg("offset"), + py::arg("chan") = 0, + D(usrp_sink, set_dc_offset)) + + + .def("set_iq_balance", + &usrp_sink::set_iq_balance, + py::arg("correction"), + py::arg("chan") = 0, + D(usrp_sink, set_iq_balance)) + + ; +} diff --git a/gr-uhd/python/uhd/bindings/usrp_source_python.cc b/gr-uhd/python/uhd/bindings/usrp_source_python.cc new file mode 100644 index 0000000000..19f3d6017d --- /dev/null +++ b/gr-uhd/python/uhd/bindings/usrp_source_python.cc @@ -0,0 +1,191 @@ +/* + * Copyright 2020 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 */ + +#include <pybind11/complex.h> +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> + +namespace py = pybind11; + +#include <gnuradio/uhd/usrp_source.h> +// pydoc.h is automatically generated in the build directory +#include <usrp_source_pydoc.h> + +void bind_usrp_source(py::module& m) +{ + + using usrp_source = ::gr::uhd::usrp_source; + + + py::class_<usrp_source, + gr::uhd::usrp_block, + gr::sync_block, + gr::block, + gr::basic_block, + std::shared_ptr<usrp_source>>(m, "usrp_source", D(usrp_source)) + + .def(py::init( + (std::shared_ptr<gr::uhd::usrp_source>(*)(const ::uhd::device_addr_t&, + const ::uhd::stream_args_t&, + const bool)) & + usrp_source::make), + py::arg("device_addr"), + py::arg("stream_args"), + py::arg("issue_stream_cmd_on_start") = true, + D(usrp_source, make)) + + .def(py::init((std::shared_ptr<gr::uhd::usrp_source>(*)( + const std::string&, const ::uhd::stream_args_t&, const bool)) & + usrp_source::make), + py::arg("device_addr"), + py::arg("stream_args"), + py::arg("issue_stream_cmd_on_start") = true, + D(usrp_source, make)) + + + .def("set_start_time", + &usrp_source::set_start_time, + py::arg("time"), + D(usrp_source, set_start_time)) + + + .def("issue_stream_cmd", + &usrp_source::issue_stream_cmd, + py::arg("cmd"), + D(usrp_source, issue_stream_cmd)) + + + .def("set_recv_timeout", + &usrp_source::set_recv_timeout, + py::arg("timeout"), + py::arg("one_packet") = true, + D(usrp_source, set_recv_timeout)) + + + .def("get_usrp_info", + &usrp_source::get_usrp_info, + py::arg("chan") = 0, + D(usrp_source, get_usrp_info)) + + + .def("get_lo_names", + &usrp_source::get_lo_names, + py::arg("chan") = 0, + D(usrp_source, get_lo_names)) + + + .def("set_lo_source", + &usrp_source::set_lo_source, + py::arg("src"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, set_lo_source)) + + + .def("get_lo_source", + &usrp_source::get_lo_source, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, get_lo_source)) + + + .def("get_lo_sources", + &usrp_source::get_lo_sources, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, get_lo_sources)) + + + .def("set_lo_export_enabled", + &usrp_source::set_lo_export_enabled, + py::arg("enabled"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, set_lo_export_enabled)) + + + .def("get_lo_export_enabled", + &usrp_source::get_lo_export_enabled, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, get_lo_export_enabled)) + + + .def("set_lo_freq", + &usrp_source::set_lo_freq, + py::arg("freq"), + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, set_lo_freq)) + + + .def("get_lo_freq", + &usrp_source::get_lo_freq, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, get_lo_freq)) + + + .def("get_lo_freq_range", + &usrp_source::get_lo_freq_range, + py::arg("name"), + py::arg("chan") = 0, + D(usrp_source, get_lo_freq_range)) + + + .def("set_auto_dc_offset", + &usrp_source::set_auto_dc_offset, + py::arg("enb"), + py::arg("chan") = 0, + D(usrp_source, set_auto_dc_offset)) + + + .def("set_dc_offset", + &usrp_source::set_dc_offset, + py::arg("offset"), + py::arg("chan") = 0, + D(usrp_source, set_dc_offset)) + + + .def("set_auto_iq_balance", + &usrp_source::set_auto_iq_balance, + py::arg("enb"), + py::arg("chan") = 0, + D(usrp_source, set_auto_iq_balance)) + + + .def("set_iq_balance", + &usrp_source::set_iq_balance, + py::arg("correction"), + py::arg("chan") = 0, + D(usrp_source, set_iq_balance)) + + + .def("set_rx_agc", + &usrp_source::set_rx_agc, + py::arg("enable"), + py::arg("chan") = 0, + D(usrp_source, set_rx_agc)) + + + .def("finite_acquisition", + &usrp_source::finite_acquisition, + py::arg("nsamps"), + D(usrp_source, finite_acquisition)) + + + .def("finite_acquisition_v", + &usrp_source::finite_acquisition_v, + py::arg("nsamps"), + D(usrp_source, finite_acquisition_v)) + + ; +} |