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

Switched to gnuradio-3.9 #112

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
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ add_custom_target(uninstall
########################################################################
add_subdirectory(include/gr_air_modes)
add_subdirectory(lib)
add_subdirectory(swig)
add_subdirectory(python)
add_subdirectory(grc)
add_subdirectory(apps)
Expand Down
2 changes: 1 addition & 1 deletion include/gr_air_modes/preamble.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace air_modes {
class AIR_MODES_API preamble : virtual public gr::block
{
public:
typedef boost::shared_ptr<preamble> sptr;
typedef std::shared_ptr<preamble> sptr;
static sptr make(float channel_rate, float threshold_db);

virtual void set_rate(float channel_rate) = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/gr_air_modes/slicer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace air_modes {
class AIR_MODES_API slicer : virtual public gr::sync_block
{
public:
typedef boost::shared_ptr<slicer> sptr;
typedef std::shared_ptr<slicer> sptr;
static sptr make(gr::msg_queue::sptr queue);
};

Expand Down
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ GR_PYTHON_INSTALL(
#set(GR_TEST_TARGET_DEPS gnuradio-gr-air-modes)
#set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig)
#GR_ADD_TEST(qa_gr-air-modes ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_gr-air-modes.py)

add_subdirectory(bindings)
39 changes: 39 additions & 0 deletions python/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2020 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

########################################################################
# Check if there is C++ code at all
########################################################################
if(NOT air_modes_sources)
MESSAGE(STATUS "No C++ sources... skipping python bindings")
return()
endif(NOT air_modes_sources)

########################################################################
# Check for pygccxml
########################################################################
GR_PYTHON_CHECK_MODULE_RAW(
"pygccxml"
"import pygccxml"
PYGCCXML_FOUND
)

include(GrPybind)

########################################################################
# Python Bindings
########################################################################

list(APPEND air_modes_python_files
python_bindings.cc)

GR_PYBIND_MAKE_OOT(air_modes
../..
gr::air_modes
"${air_modes_python_files}")

install(TARGETS air_modes_python DESTINATION ${GR_PYTHON_DIR}/air_modes COMPONENT pythonapi)
Empty file added python/bindings/README.md
Empty file.
57 changes: 57 additions & 0 deletions python/bindings/bind_oot_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import warnings
import argparse
import os
from gnuradio.bindtool import BindingGenerator
import pathlib
import sys

parser = argparse.ArgumentParser(description='Bind a GR Out of Tree Block')
parser.add_argument('--module', type=str,
help='Name of gr module containing file to bind (e.g. fft digital analog)')

parser.add_argument('--output_dir', default='/tmp',
help='Output directory of generated bindings')
parser.add_argument('--prefix', help='Prefix of Installed GNU Radio')
parser.add_argument('--src', help='Directory of gnuradio source tree',
default=os.path.dirname(os.path.abspath(__file__))+'/../../..')

parser.add_argument(
'--filename', help="File to be parsed")

parser.add_argument(
'--defines', help='Set additional defines for precompiler',default=(), nargs='*')
parser.add_argument(
'--include', help='Additional Include Dirs, separated', default=(), nargs='*')

parser.add_argument(
'--status', help='Location of output file for general status (used during cmake)', default=None
)
parser.add_argument(
'--flag_automatic', default='0'
)
parser.add_argument(
'--flag_pygccxml', default='0'
)

args = parser.parse_args()

prefix = args.prefix
output_dir = args.output_dir
defines = tuple(','.join(args.defines).split(','))
includes = ','.join(args.include)
name = args.module

namespace = ['gr', name]
prefix_include_root = name


with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning)

bg = BindingGenerator(prefix, namespace,
prefix_include_root, output_dir, define_symbols=defines, addl_includes=includes,
catch_exceptions=False, write_json_output=False, status_output=args.status,
flag_automatic=True if args.flag_automatic.lower() in [
'1', 'true'] else False,
flag_pygccxml=True if args.flag_pygccxml.lower() in ['1', 'true'] else False)
bg.gen_file_binding(args.filename)
1 change: 1 addition & 0 deletions python/bindings/docstrings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory stores templates for docstrings that are scraped from the include header files for each block
27 changes: 27 additions & 0 deletions python/bindings/docstrings/preamble_pydoc_template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2021 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,air-modes, __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_air-modes_preamble = R"doc()doc";


static const char *__doc_gr_air-modes_preamble_preamble = R"doc()doc";


static const char *__doc_gr_air-modes_preamble_make = R"doc()doc";


27 changes: 27 additions & 0 deletions python/bindings/docstrings/slicer_pydoc_template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2021 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,air-modes, __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_air-modes_slicer = R"doc()doc";


static const char *__doc_gr_air-modes_slicer_slicer = R"doc()doc";


static const char *__doc_gr_air-modes_slicer_make = R"doc()doc";


78 changes: 78 additions & 0 deletions python/bindings/header_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Utilities for reading values in header files

from argparse import ArgumentParser
import re


class PybindHeaderParser:
def __init__(self, pathname):
with open(pathname,'r') as f:
self.file_txt = f.read()

def get_flag_automatic(self):
# p = re.compile(r'BINDTOOL_GEN_AUTOMATIC\(([^\s])\)')
# m = p.search(self.file_txt)
m = re.search(r'BINDTOOL_GEN_AUTOMATIC\(([^\s])\)', self.file_txt)
if (m and m.group(1) == '1'):
return True
else:
return False

def get_flag_pygccxml(self):
# p = re.compile(r'BINDTOOL_USE_PYGCCXML\(([^\s])\)')
# m = p.search(self.file_txt)
m = re.search(r'BINDTOOL_USE_PYGCCXML\(([^\s])\)', self.file_txt)
if (m and m.group(1) == '1'):
return True
else:
return False

def get_header_filename(self):
# p = re.compile(r'BINDTOOL_HEADER_FILE\(([^\s]*)\)')
# m = p.search(self.file_txt)
m = re.search(r'BINDTOOL_HEADER_FILE\(([^\s]*)\)', self.file_txt)
if (m):
return m.group(1)
else:
return None

def get_header_file_hash(self):
# p = re.compile(r'BINDTOOL_HEADER_FILE_HASH\(([^\s]*)\)')
# m = p.search(self.file_txt)
m = re.search(r'BINDTOOL_HEADER_FILE_HASH\(([^\s]*)\)', self.file_txt)
if (m):
return m.group(1)
else:
return None

def get_flags(self):
return f'{self.get_flag_automatic()};{self.get_flag_pygccxml()};{self.get_header_filename()};{self.get_header_file_hash()};'



def argParse():
"""Parses commandline args."""
desc='Reads the parameters from the comment block in the pybind files'
parser = ArgumentParser(description=desc)

parser.add_argument("function", help="Operation to perform on comment block of pybind file", choices=["flag_auto","flag_pygccxml","header_filename","header_file_hash","all"])
parser.add_argument("pathname", help="Pathname of pybind c++ file to read, e.g. blockname_python.cc")

return parser.parse_args()

if __name__ == "__main__":
# Parse command line options and set up doxyxml.
args = argParse()

pbhp = PybindHeaderParser(args.pathname)

if args.function == "flag_auto":
print(pbhp.get_flag_automatic())
elif args.function == "flag_pygccxml":
print(pbhp.get_flag_pygccxml())
elif args.function == "header_filename":
print(pbhp.get_header_filename())
elif args.function == "header_file_hash":
print(pbhp.get_header_file_hash())
elif args.function == "all":
print(pbhp.get_flags())
59 changes: 59 additions & 0 deletions python/bindings/preamble_python.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021 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(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
/* BINDTOOL_HEADER_FILE(preamble.h) */
/* BINDTOOL_HEADER_FILE_HASH(99cc0f448ffd5f8da017452a42ffb8c1) */
/***********************************************************************************/

#include <pybind11/complex.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include <air-modes/preamble.h>
// pydoc.h is automatically generated in the build directory
#include <preamble_pydoc.h>

void bind_preamble(py::module& m)
{

using preamble = gr::air-modes::preamble;


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

.def(py::init(&preamble::make),
D(preamble,make)
)




;




}








57 changes: 57 additions & 0 deletions python/bindings/python_bindings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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>

namespace py = pybind11;

// Headers for binding functions
/**************************************/
/* The following comment block is used for
/* gr_modtool to insert function prototypes
/* Please do not delete
/**************************************/
// BINDING_FUNCTION_PROTOTYPES(
void bind_preamble(py::module& m);
void bind_slicer(py::module& m);
// ) END BINDING_FUNCTION_PROTOTYPES


// 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(air_modes_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");

/**************************************/
/* The following comment block is used for
/* gr_modtool to insert binding function calls
/* Please do not delete
/**************************************/
// BINDING_FUNCTION_CALLS(
bind_preamble(m);
bind_slicer(m);
// ) END BINDING_FUNCTION_CALLS
}
Loading