7 changed files with 240 additions and 2 deletions
@ -0,0 +1,65 @@
|
||||
# Copyright 2011-2020 Free Software Foundation, Inc. |
||||
# Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com> |
||||
# |
||||
# This file is part of gr-iqbalance |
||||
# |
||||
# SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
||||
######################################################################## |
||||
# Check for pygccxml |
||||
######################################################################## |
||||
GR_PYTHON_CHECK_MODULE_RAW( |
||||
"pygccxml" |
||||
"import pygccxml" |
||||
PYGCCXML_FOUND |
||||
) |
||||
|
||||
# Official module is broken, makes too many assumptions that are not true |
||||
#include(GrPybind) |
||||
|
||||
include(GrPython) |
||||
|
||||
macro(GR_PYBIND_MAKE name updir filter files) |
||||
|
||||
configure_file(${CMAKE_SOURCE_DIR}/docs/doxygen/pydoc_macros.h ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) |
||||
|
||||
pybind11_add_module(${name}_python ${files}) |
||||
|
||||
SET(MODULE_NAME ${name}) |
||||
if (${name} STREQUAL gr) |
||||
SET(MODULE_NAME "runtime") |
||||
endif() |
||||
|
||||
target_include_directories(${name}_python PUBLIC |
||||
${CMAKE_CURRENT_BINARY_DIR} |
||||
${PYTHON_NUMPY_INCLUDE_DIR} |
||||
${CMAKE_CURRENT_SOURCE_DIR}/${updir}/lib |
||||
${CMAKE_CURRENT_SOURCE_DIR}/${updir}/include |
||||
${PYBIND11_INCLUDE_DIR} |
||||
) |
||||
target_link_libraries(${name}_python PUBLIC ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} gnuradio-${MODULE_NAME}) |
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR |
||||
CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
||||
target_compile_options(${name}_python PRIVATE -Wno-unused-variable) # disable warnings for docstring templates |
||||
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR |
||||
CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
||||
|
||||
endmacro(GR_PYBIND_MAKE) |
||||
|
||||
|
||||
|
||||
######################################################################## |
||||
# Python Bindings |
||||
######################################################################## |
||||
|
||||
list(APPEND iqbalance_python_files |
||||
fix_cc_python.cc |
||||
optimize_c_python.cc |
||||
python_bindings.cc) |
||||
|
||||
GR_PYBIND_MAKE(iqbalance |
||||
../.. |
||||
gr::iqbalance |
||||
"${iqbalance_python_files}") |
||||
|
||||
install(TARGETS iqbalance_python DESTINATION ${GR_PYTHON_DIR}/gnuradio/iqbalance COMPONENT pythonapi) |
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com> |
||||
* |
||||
* This file is part of gr-iqbalance |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-or-later |
||||
*/ |
||||
|
||||
#include <pybind11/complex.h> |
||||
#include <pybind11/pybind11.h> |
||||
#include <pybind11/stl.h> |
||||
|
||||
namespace py = pybind11; |
||||
|
||||
#include <gnuradio/iqbalance/fix_cc.h> |
||||
|
||||
#define D(...) "" |
||||
|
||||
void bind_fix_cc(py::module& m) |
||||
{ |
||||
using fix_cc = gr::iqbalance::fix_cc; |
||||
|
||||
py::class_<fix_cc, |
||||
gr::sync_block, |
||||
gr::block, |
||||
gr::basic_block, |
||||
std::shared_ptr<fix_cc>>(m, "fix_cc", D(fix_cc)) |
||||
|
||||
.def(py::init(&fix_cc::make), |
||||
py::arg("mag") = 0.0f, |
||||
py::arg("phase") = 0.0f, |
||||
D(fix_cc,make) |
||||
) |
||||
|
||||
.def("set_mag", |
||||
&fix_cc::set_mag, |
||||
py::arg("mag"), |
||||
D(fix_cc,set_mag) |
||||
) |
||||
|
||||
.def("mag", |
||||
&fix_cc::mag, |
||||
D(fix_cc,mag) |
||||
) |
||||
|
||||
.def("set_phase", |
||||
&fix_cc::set_phase, |
||||
py::arg("phase"), |
||||
D(fix_cc,set_phase) |
||||
) |
||||
|
||||
.def("phase", |
||||
&fix_cc::phase, |
||||
D(fix_cc,phase) |
||||
) |
||||
|
||||
; |
||||
} |
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com> |
||||
* |
||||
* This file is part of gr-iqbalance |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-or-later |
||||
*/ |
||||
|
||||
#include <pybind11/complex.h> |
||||
#include <pybind11/pybind11.h> |
||||
#include <pybind11/stl.h> |
||||
|
||||
namespace py = pybind11; |
||||
|
||||
#include <gnuradio/iqbalance/optimize_c.h> |
||||
|
||||
#define D(...) "" |
||||
|
||||
void bind_optimize_c(py::module& m) |
||||
{ |
||||
using optimize_c = gr::iqbalance::optimize_c; |
||||
|
||||
py::class_<optimize_c, |
||||
gr::sync_block, |
||||
gr::block, |
||||
gr::basic_block, |
||||
std::shared_ptr<optimize_c>>(m, "optimize_c", D(optimize_c)) |
||||
|
||||
.def(py::init(&optimize_c::make), |
||||
py::arg("period") = 0, |
||||
D(optimize_c,make) |
||||
) |
||||
|
||||
.def("set_period", |
||||
&optimize_c::set_period, |
||||
py::arg("period"), |
||||
D(optimize_c,set_period) |
||||
) |
||||
|
||||
.def("period", |
||||
&optimize_c::period, |
||||
D(optimize_c,period) |
||||
) |
||||
|
||||
.def("mag", |
||||
&optimize_c::mag, |
||||
D(optimize_c,mag) |
||||
) |
||||
|
||||
.def("phase", |
||||
&optimize_c::phase, |
||||
D(optimize_c,phase) |
||||
) |
||||
|
||||
.def("reset", |
||||
&optimize_c::reset, |
||||
D(optimize_c,reset) |
||||
) |
||||
|
||||
; |
||||
} |
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2020-2021 Free Software Foundation, Inc. |
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com> |
||||
* |
||||
* This file is part of gr-iqbalance |
||||
* |
||||
* 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> |
||||
|
||||
namespace py = pybind11; |
||||
|
||||
void bind_fix_cc(py::module& m); |
||||
void bind_optimize_c(py::module& m); |
||||
|
||||
// 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(iqbalance_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_fix_cc(m); |
||||
bind_optimize_c(m); |
||||
} |
Loading…
Reference in new issue