mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-07-26 04:35:39 +03:00
173 lines
5.7 KiB
Diff
173 lines
5.7 KiB
Diff
From 1f724162e1e0afd1636658c2e8fed60320f0809a Mon Sep 17 00:00:00 2001
|
|
From: Clayton Smith <argilo@gmail.com>
|
|
Date: Wed, 30 Dec 2020 10:05:36 -0500
|
|
Subject: Add Python bindings
|
|
|
|
Signed-off-by: Eric Wild <ewild@sysmocom.de>
|
|
---
|
|
python/bindings/CMakeLists.txt | 3 +++
|
|
python/bindings/device_python.cc | 27 +++++++++++++++++++++++++++
|
|
python/bindings/python_bindings.cc | 8 ++++++++
|
|
python/bindings/ranges_python.cc | 35 +++++++++++++++++++++++++++++++++++
|
|
python/bindings/time_spec_python.cc | 33 +++++++++++++++++++++++++++++++++
|
|
5 files changed, 106 insertions(+)
|
|
create mode 100644 python/bindings/device_python.cc
|
|
create mode 100644 python/bindings/ranges_python.cc
|
|
create mode 100644 python/bindings/time_spec_python.cc
|
|
|
|
diff --git a/python/bindings/CMakeLists.txt b/python/bindings/CMakeLists.txt
|
|
index ed50d7e..f2233cf 100644
|
|
--- a/python/bindings/CMakeLists.txt
|
|
+++ b/python/bindings/CMakeLists.txt
|
|
@@ -18,8 +18,11 @@ include(GrPybind)
|
|
########################################################################
|
|
|
|
list(APPEND osmosdr_python_files
|
|
+ device_python.cc
|
|
sink_python.cc
|
|
source_python.cc
|
|
+ ranges_python.cc
|
|
+ time_spec_python.cc
|
|
python_bindings.cc)
|
|
|
|
GR_PYBIND_MAKE_OOT(osmosdr
|
|
diff --git a/python/bindings/device_python.cc b/python/bindings/device_python.cc
|
|
new file mode 100644
|
|
index 0000000..f82a48f
|
|
--- /dev/null
|
|
+++ b/python/bindings/device_python.cc
|
|
@@ -0,0 +1,27 @@
|
|
+#include <pybind11/pybind11.h>
|
|
+#include <pybind11/stl.h>
|
|
+
|
|
+namespace py = pybind11;
|
|
+
|
|
+#include <osmosdr/device.h>
|
|
+
|
|
+void bind_device(py::module& m)
|
|
+{
|
|
+ using device_t = ::osmosdr::device_t;
|
|
+
|
|
+ py::class_<device_t>(m, "device_t")
|
|
+ .def(py::init<std::string&>(), py::arg("args") = "")
|
|
+ .def("to_pp_string", &device_t::to_pp_string)
|
|
+ .def("to_string", &device_t::to_string);
|
|
+
|
|
+
|
|
+ using devices_t = ::osmosdr::devices_t;
|
|
+
|
|
+ py::class_<devices_t>(m, "devices_t");
|
|
+
|
|
+
|
|
+ using device = ::osmosdr::device;
|
|
+
|
|
+ py::class_<device>(m, "device")
|
|
+ .def_static("find", &device::find, py::arg("hint") = device_t());
|
|
+}
|
|
diff --git a/python/bindings/python_bindings.cc b/python/bindings/python_bindings.cc
|
|
index fc11ee0..7204b2b 100644
|
|
--- a/python/bindings/python_bindings.cc
|
|
+++ b/python/bindings/python_bindings.cc
|
|
@@ -25,6 +25,10 @@ namespace py = pybind11;
|
|
void bind_source(py::module& m);
|
|
// ) END BINDING_FUNCTION_PROTOTYPES
|
|
|
|
+void bind_device(py::module& m);
|
|
+void bind_ranges(py::module& m);
|
|
+void bind_time_spec(py::module& m);
|
|
+
|
|
|
|
// We need this hack because import_array() returns NULL
|
|
// for newer Python versions.
|
|
@@ -54,4 +58,8 @@ PYBIND11_MODULE(osmosdr_python, m)
|
|
bind_sink(m);
|
|
bind_source(m);
|
|
// ) END BINDING_FUNCTION_CALLS
|
|
+
|
|
+ bind_device(m);
|
|
+ bind_ranges(m);
|
|
+ bind_time_spec(m);
|
|
}
|
|
diff --git a/python/bindings/ranges_python.cc b/python/bindings/ranges_python.cc
|
|
new file mode 100644
|
|
index 0000000..fce957c
|
|
--- /dev/null
|
|
+++ b/python/bindings/ranges_python.cc
|
|
@@ -0,0 +1,35 @@
|
|
+#include <pybind11/pybind11.h>
|
|
+
|
|
+namespace py = pybind11;
|
|
+
|
|
+#include <osmosdr/ranges.h>
|
|
+
|
|
+void bind_ranges(py::module& m)
|
|
+{
|
|
+ m.attr("ALL_MBOARDS") = ::osmosdr::ALL_MBOARDS;
|
|
+ m.attr("ALL_CHANS") = ::osmosdr::ALL_CHANS;
|
|
+
|
|
+
|
|
+ using range_t = ::osmosdr::range_t;
|
|
+
|
|
+ py::class_<range_t>(m, "range_t")
|
|
+ .def(py::init<double>(), py::arg("value") = 0)
|
|
+ .def(py::init<double, double, double>(), py::arg("start"), py::arg("stop"), py::arg("step") = 0)
|
|
+ .def("start", &range_t::start)
|
|
+ .def("stop", &range_t::stop)
|
|
+ .def("step", &range_t::step)
|
|
+ .def("to_pp_string", &range_t::to_pp_string);
|
|
+
|
|
+
|
|
+ using meta_range_t = ::osmosdr::meta_range_t;
|
|
+
|
|
+ py::class_<meta_range_t>(m, "meta_range_t")
|
|
+ .def(py::init())
|
|
+ .def(py::init<double, double, double>(), py::arg("start"), py::arg("stop"), py::arg("step") = 0)
|
|
+ .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("values", &meta_range_t::values)
|
|
+ .def("to_pp_string", &meta_range_t::to_pp_string);
|
|
+}
|
|
diff --git a/python/bindings/time_spec_python.cc b/python/bindings/time_spec_python.cc
|
|
new file mode 100644
|
|
index 0000000..d12a3c7
|
|
--- /dev/null
|
|
+++ b/python/bindings/time_spec_python.cc
|
|
@@ -0,0 +1,33 @@
|
|
+#include <pybind11/pybind11.h>
|
|
+#include <pybind11/operators.h>
|
|
+
|
|
+namespace py = pybind11;
|
|
+
|
|
+#include <osmosdr/time_spec.h>
|
|
+
|
|
+void bind_time_spec(py::module& m)
|
|
+{
|
|
+ using time_spec_t = ::osmosdr::time_spec_t;
|
|
+
|
|
+ py::class_<time_spec_t>(m, "time_spec_t")
|
|
+ .def_static("get_system_time", &time_spec_t::get_system_time)
|
|
+ .def(py::init<double>(), py::arg("secs") = 0)
|
|
+ .def(py::init<time_t, double>(), py::arg("full_secs"), py::arg("frac_secs") = 0)
|
|
+ .def(py::init<time_t, long, double>(), py::arg("full_secs"), py::arg("tick_count"), py::arg("tick_rate"))
|
|
+ .def_static("from_ticks", &time_spec_t::from_ticks, py::arg("ticks"), py::arg("tick_rate"))
|
|
+ .def("get_tick_count", &time_spec_t::get_tick_count, py::arg("tick_rate"))
|
|
+ .def("to_ticks", &time_spec_t::to_ticks, py::arg("tick_rate"))
|
|
+ .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 + py::self)
|
|
+ .def(py::self += py::self)
|
|
+ .def(py::self - py::self)
|
|
+ .def(py::self -= py::self)
|
|
+ .def(py::self == py::self)
|
|
+ .def(py::self != py::self)
|
|
+ .def(py::self < py::self)
|
|
+ .def(py::self > py::self)
|
|
+ .def(py::self <= py::self)
|
|
+ .def(py::self >= py::self);
|
|
+}
|
|
--
|
|
cgit v1.2.3
|
|
|