Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for GNURadio 3.10 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,16 @@ endif(ENABLE_KIWI_WS_CLIENT)
########################################################################
# Find gnuradio build dependencies
########################################################################
find_package(Doxygen REQUIRED)
find_package(Doxygen)

########################################################################
# Setup doxygen option
########################################################################
if(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" ON)
else(DOXYGEN_FOUND)
option(ENABLE_DOXYGEN "Build docs using Doxygen" OFF)
endif(DOXYGEN_FOUND)

########################################################################
# Create uninstall target
Expand All @@ -167,7 +176,6 @@ add_subdirectory(include/kiwisdr)
add_subdirectory(lib)
add_subdirectory(apps)
add_subdirectory(docs)
add_subdirectory(swig)
add_subdirectory(python)
add_subdirectory(grc)

Expand Down
2 changes: 0 additions & 2 deletions lib/kiwi_wav_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ kiwi_wav_source_impl::kiwi_wav_source_impl(std::string filename)
, _samp_rate(1)
, _id(pmt::mp(_filename))
{
GR_LOG_DECLARE_LOGPTR(d_logger);
GR_LOG_ASSIGN_LOGPTR(d_logger, "kiwi_wav_source@"+_filename);
}

kiwi_wav_source_impl::~kiwi_wav_source_impl()
Expand Down
25 changes: 13 additions & 12 deletions lib/kiwi_ws_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <regex>
#include <random>
#include <iostream>

#include <boost/asio/buffers_iterator.hpp>

Expand Down Expand Up @@ -114,9 +115,9 @@ void kiwi_ws_client::disconnect() {
_deadline_timer_read.expires_at(boost::date_time::neg_infin);
_deadline_timer_close.expires_at(boost::date_time::neg_infin);
boost::system::error_code ec_ignore{};
_ws.lowest_layer().cancel(ec_ignore);
_ws.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec_ignore);
_ws.lowest_layer().close(ec_ignore);
_ws.next_layer().cancel(ec_ignore);
_ws.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec_ignore);
_ws.next_layer().close(ec_ignore);
_resolver.cancel();
});
} else {
Expand Down Expand Up @@ -159,7 +160,7 @@ void kiwi_ws_client::on_resolve(boost::system::error_code const &ec,
return;
}
// Make the connection on the IP address we get from a lookup
boost::asio::async_connect(_ws.lowest_layer(),
boost::asio::async_connect(_ws.next_layer(),
results.begin(),
results.end(),
boost::asio::bind_executor(
Expand Down Expand Up @@ -210,9 +211,9 @@ void kiwi_ws_client::ws_async_read() {
if (_deadline_timer_read.expires_at() > boost::asio::deadline_timer::traits_type::now()) {
return;
}
if (_ws.lowest_layer().is_open()) {
if (_ws.next_layer().is_open()) {
boost::system::error_code ec_ignore{};
_ws.lowest_layer().cancel(ec_ignore);
_ws.next_layer().cancel(ec_ignore);
}
});

Expand Down Expand Up @@ -250,9 +251,9 @@ void kiwi_ws_client::on_read(boost::system::error_code const &ec,

if (ec == boost::beast::websocket::error::closed) {
_deadline_timer_read.cancel();
if (_ws.lowest_layer().is_open()) {
if (_ws.next_layer().is_open()) {
boost::system::error_code ec_ignore{};
_ws.lowest_layer().cancel(ec_ignore);
_ws.next_layer().cancel(ec_ignore);
}
_connected = false;
return;
Expand Down Expand Up @@ -410,11 +411,11 @@ void kiwi_ws_client::ws_async_close() {
if (ec == boost::asio::error::operation_aborted)
return;

if (_ws.lowest_layer().is_open()) {
if (_ws.next_layer().is_open()) {
boost::system::error_code ec_ignore{};
_ws.lowest_layer().cancel(ec_ignore);
_ws.lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec_ignore);
_ws.lowest_layer().close(ec_ignore);
_ws.next_layer().cancel(ec_ignore);
_ws.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec_ignore);
_ws.next_layer().close(ec_ignore);
}
});

Expand Down
5 changes: 2 additions & 3 deletions lib/kiwisdr_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ kiwisdr_impl::kiwisdr_impl(std::string const &host,
, _zmq_pub()
, _saved_samples()
{
GR_LOG_DECLARE_LOGPTR(d_logger);
GR_LOG_ASSIGN_LOGPTR(d_logger, "kiwisdr@"+_host+":"+_port);
_zmq_sub.bind("inproc://iq");
_zmq_pub = std::make_shared<zmq::socket_t>(_zmq_ctx, ZMQ_PAIR);
_zmq_pub->connect("inproc://iq");
Expand Down Expand Up @@ -126,7 +124,8 @@ int kiwisdr_impl::general_work(int noutput_items,
it(reinterpret_cast<std::uint8_t*>(msg.data()));

std::size_t const num_floats = (msg.size() - full_header_length) >> 1;
GR_LOG_ASSERT(d_logger, num_floats % 2 == 0, "num_floats % 2 == 0");
if (num_floats % 2 != 0)
GR_LOG_FATAL(d_logger, "num_floats % 2 == 0");
std::size_t const num_complex_samples = num_floats >> 1;

// (1) decode snd_info_header
Expand Down
13 changes: 8 additions & 5 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ if(NOT PYTHONINTERP_FOUND)
return()
endif()

add_subdirectory(bindings)

########################################################################
# Install python sources
########################################################################
GR_PYTHON_INSTALL(
FILES
list(APPEND kiwisdr_python
__init__.py
align_streams.py
coh_stream_synth.py
)

GR_PYTHON_INSTALL(
FILES
${kiwisdr_python}
DESTINATION ${GR_PYTHON_DIR}/kiwisdr
)

Expand All @@ -43,9 +49,6 @@ GR_PYTHON_INSTALL(
include(GrTest)

set(GR_TEST_TARGET_DEPS gnuradio-kiwisdr)
set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig)
set(GR_TEST_TARGET_DEPS gnuradio-kiwisdr)
set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig)
if(GR_KIWI_WS_CLIENT)
GR_ADD_TEST(qa_kiwisdr ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_kiwisdr.py)
endif()
Expand Down
8 changes: 2 additions & 6 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
'''
from __future__ import unicode_literals

# import swig generated symbols into the kiwisdr namespace
try:
# this might fail if the module is python-only
from .kiwisdr_swig import *
except ImportError:
pass
# import pybind11 generated symbols into the kiwisdr namespace
from .kiwisdr_python import *

# import any pure python here
#
Expand Down
74 changes: 74 additions & 0 deletions python/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2011-2020 Free Software Foundation, Inc.
# Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
#
# This file is part of gr-fosphor
#
# 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)

find_package(pybind11 REQUIRED)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"try:\n import numpy\n import os\n inc_path = numpy.get_include()\n if os.path.exists(os.path.join(inc_path, 'numpy', 'arrayobject.h')):\n print(inc_path, end='')\nexcept:\n pass"
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR)
# format path in CMake-style for consistency with other path variables
# (a consistent style helps conda builds by using the same path separators)
file(TO_CMAKE_PATH "${PYTHON_NUMPY_INCLUDE_DIR}" PYTHON_NUMPY_INCLUDE_DIR)

#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 kiwisdr_python_files
kiwisdr_python.cc
kiwi_wav_source_python.cc
python_bindings.cc)

GR_PYBIND_MAKE(kiwisdr
../..
gr::kiwisdr
"${kiwisdr_python_files}")

install(TARGETS kiwisdr_python DESTINATION ${GR_PYTHON_DIR}/kiwisdr COMPONENT pythonapi)
25 changes: 25 additions & 0 deletions python/bindings/kiwi_wav_source_python.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <pybind11/complex.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include <kiwisdr/kiwi_wav_source.h>

#define D(...) ""

void bind_kiwi_wav_source(py::module& m)
{
using kiwi_wav_source = gr::kiwisdr::kiwi_wav_source;

py::class_<kiwi_wav_source,
gr::sync_block,
std::shared_ptr<kiwi_wav_source>>(m, "kiwi_wav_source", D(kiwi_wav_source))

.def(py::init(&kiwi_wav_source::make),
py::arg("filename"),
D(kiwi_wav_source,make)
)

;
}
36 changes: 36 additions & 0 deletions python/bindings/kiwisdr_python.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <pybind11/complex.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include <kiwisdr/kiwisdr.h>

#define D(...) ""

void bind_kiwisdr(py::module& m)
{
using kiwisdr = gr::kiwisdr::kiwisdr;

py::class_<kiwisdr,
gr::block,
std::shared_ptr<kiwisdr>>(m, "kiwisdr", D(kiwisdr))

.def(py::init(&kiwisdr::make),
py::arg("host"),
py::arg("port"),
py::arg("freq_kHz"),
py::arg("low_cut_Hz"),
py::arg("high_cut_Hz"),
D(kiwisdr,make)
)

.def("set_rx_parameters", &kiwisdr::set_rx_parameters,
py::arg("freq_kHz"),
py::arg("low_cut_Hz"),
py::arg("high_cut_Hz"),
D(kiwisdr,set_rx_parameters)
)

;
}
34 changes: 34 additions & 0 deletions python/bindings/python_bindings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <pybind11/pybind11.h>

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include <numpy/arrayobject.h>

namespace py = pybind11;

void bind_kiwi_wav_source(py::module& m);
void bind_kiwisdr(py::module& m);
// void bind_align_streams(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(kiwisdr_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_kiwi_wav_source(m);
bind_kiwisdr(m);
// bind_align_streams(m);
}
4 changes: 2 additions & 2 deletions python/coh_stream_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#

import numpy as np
import math

from gnuradio import gr
from gnuradio import gru
from gnuradio import filter
from gnuradio import blocks
from gnuradio import analog
Expand Down Expand Up @@ -198,7 +198,7 @@ def __init__(self, num_streams, fs_in, delta_f_in):
gr.io_signature(2*num_streams, 2*num_streams, gr.sizeof_gr_complex))
assert(num_streams >= 2 and num_streams <= 6)
fsr = delta_f_in
factor = gru.gcd(fsr, fs_in)
factor = math.gcd(fsr, fs_in)
interp = fsr/factor
decim = fs_in/factor

Expand Down
2 changes: 1 addition & 1 deletion python/qa_kiwi_wav_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import kiwisdr.kiwisdr_swig as kiwisdr
from kiwisdr import kiwisdr


class qa_kiwi_wav_source(gr_unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion python/qa_kiwisdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from gnuradio import gr, gr_unittest
from gnuradio import blocks
import kiwisdr.kiwisdr_swig as kiwisdr
from kiwisdr import kiwisdr


class qa_kiwisdr(gr_unittest.TestCase):
Expand Down
Loading