From eda5b6b3449e1285e6630385f1c1337dde5ace19 Mon Sep 17 00:00:00 2001 From: Swarnava Ghosh Date: Sat, 16 Dec 2023 19:04:27 -0500 Subject: [PATCH] added variable filter block --- grc/CMakeLists.txt | 3 +- ...agged_stream_fixed_length_padder.block.yml | 2 +- grc/UTAT_HERON_variable_filter.block.yml | 45 ++++++++++++++ include/gnuradio/UTAT_HERON/CMakeLists.txt | 3 +- include/gnuradio/UTAT_HERON/variable_filter.h | 41 ++++++++++++ lib/CMakeLists.txt | 3 +- lib/variable_filter_impl.cc | 62 +++++++++++++++++++ lib/variable_filter_impl.h | 36 +++++++++++ python/UTAT_HERON/CMakeLists.txt | 1 + python/UTAT_HERON/bindings/CMakeLists.txt | 3 +- .../variable_filter_pydoc_template.h | 21 +++++++ python/UTAT_HERON/bindings/python_bindings.cc | 2 + .../bindings/variable_filter_python.cc | 47 ++++++++++++++ python/UTAT_HERON/qa_variable_filter.py | 39 ++++++++++++ 14 files changed, 303 insertions(+), 5 deletions(-) create mode 100644 grc/UTAT_HERON_variable_filter.block.yml create mode 100644 include/gnuradio/UTAT_HERON/variable_filter.h create mode 100644 lib/variable_filter_impl.cc create mode 100644 lib/variable_filter_impl.h create mode 100644 python/UTAT_HERON/bindings/docstrings/variable_filter_pydoc_template.h create mode 100644 python/UTAT_HERON/bindings/variable_filter_python.cc create mode 100755 python/UTAT_HERON/qa_variable_filter.py diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 7619ad0..55f59ab 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -10,5 +10,6 @@ install(FILES UTAT_HERON_header_format_esttc.block.yml UTAT_HERON_esttc_framer.block.yml UTAT_HERON_esttc_deframer.block.yml - UTAT_HERON_tagged_stream_fixed_length_padder.block.yml DESTINATION share/gnuradio/grc/blocks + UTAT_HERON_tagged_stream_fixed_length_padder.block.yml + UTAT_HERON_variable_filter.block.yml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml b/grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml index 9c455d4..a55f3f7 100644 --- a/grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml +++ b/grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml @@ -1,6 +1,6 @@ id: UTAT_HERON_tagged_stream_fixed_length_padder label: Tagged Stream Fixed Length Padder -category: '[UTAT]/Fixes' +category: '[UTAT]/Utilities' templates: imports: from gnuradio import UTAT_HERON diff --git a/grc/UTAT_HERON_variable_filter.block.yml b/grc/UTAT_HERON_variable_filter.block.yml new file mode 100644 index 0000000..911e57b --- /dev/null +++ b/grc/UTAT_HERON_variable_filter.block.yml @@ -0,0 +1,45 @@ +id: UTAT_HERON_variable_filter +label: Variable Filter +category: '[UTAT]/Utilities' + +templates: + imports: from gnuradio import UTAT_HERON + make: UTAT_HERON.variable_filter(${variable_name}) + +# Make one 'parameters' list entry for every parameter you want settable from the GUI. +# Keys include: +# * id (makes the value accessible as keyname, e.g. in the make entry) +# * label (label shown in the GUI) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +# * default +parameters: +- id: variable_name + label: Variable Name + dtype: string + default: freq +#- id: ... +# label: ... +# dtype: ... + +# Make one 'inputs' list entry per input and one 'outputs' list entry per output. +# Keys include: +# * label (an identifier for the GUI) +# * domain (optional - stream or message. Default is stream) +# * dtype (e.g. int, float, complex, byte, short, xxx_vector, ...) +# * vlen (optional - data stream vector length. Default is 1) +# * optional (optional - set to 1 for optional inputs. Default is 0) +inputs: +- id: in + label: in + domain: message + dtype: message + +outputs: +- id: out + label: out + domain: message + dtype: message + +# 'file_format' specifies the version of the GRC yml format used in the file +# and should usually not be changed. +file_format: 1 diff --git a/include/gnuradio/UTAT_HERON/CMakeLists.txt b/include/gnuradio/UTAT_HERON/CMakeLists.txt index 94a38af..67a833d 100644 --- a/include/gnuradio/UTAT_HERON/CMakeLists.txt +++ b/include/gnuradio/UTAT_HERON/CMakeLists.txt @@ -15,5 +15,6 @@ install(FILES header_format_esttc.h esttc_framer.h esttc_deframer.h - tagged_stream_fixed_length_padder.h DESTINATION include/gnuradio/UTAT_HERON + tagged_stream_fixed_length_padder.h + variable_filter.h DESTINATION include/gnuradio/UTAT_HERON ) diff --git a/include/gnuradio/UTAT_HERON/variable_filter.h b/include/gnuradio/UTAT_HERON/variable_filter.h new file mode 100644 index 0000000..5d37aaa --- /dev/null +++ b/include/gnuradio/UTAT_HERON/variable_filter.h @@ -0,0 +1,41 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef INCLUDED_UTAT_HERON_VARIABLE_FILTER_H +#define INCLUDED_UTAT_HERON_VARIABLE_FILTER_H + +#include +#include + +namespace gr { +namespace UTAT_HERON { + +/*! + * \brief <+description of block+> + * \ingroup UTAT_HERON + * + */ +class UTAT_HERON_API variable_filter : virtual public gr::block +{ +public: + typedef std::shared_ptr sptr; + + /*! + * \brief Return a shared_ptr to a new instance of UTAT_HERON::variable_filter. + * + * To avoid accidental use of raw pointers, UTAT_HERON::variable_filter's + * constructor is in a private implementation + * class. UTAT_HERON::variable_filter::make is the public interface for + * creating new instances. + */ + static sptr make(const std::string& variable_name); +}; + +} // namespace UTAT_HERON +} // namespace gr + +#endif /* INCLUDED_UTAT_HERON_VARIABLE_FILTER_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 07f6f04..6ee09e5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -25,7 +25,8 @@ list(APPEND UTAT_HERON_sources header_format_esttc.cc esttc_framer_impl.cc esttc_deframer_impl.cc - tagged_stream_fixed_length_padder_impl.cc ) + tagged_stream_fixed_length_padder_impl.cc + variable_filter_impl.cc ) set(DEBUG_FILE "${CMAKE_BINARY_DIR}/debug_log.txt" CACHE FILEPATH "Log debug to this file when CMAKE_BULD_TYPE is Debug or RelWithDebInfo") diff --git a/lib/variable_filter_impl.cc b/lib/variable_filter_impl.cc new file mode 100644 index 0000000..731efaa --- /dev/null +++ b/lib/variable_filter_impl.cc @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "variable_filter_impl.h" +#include +#include + +namespace gr { +namespace UTAT_HERON { + +variable_filter::sptr variable_filter::make(const std::string& variable_name) +{ + return gnuradio::make_block_sptr(variable_name); +} + + +/* + * The private constructor + */ +variable_filter_impl::variable_filter_impl(const std::string& variable_name) + : gr::block("variable_filter", + gr::io_signature::make(0,0,0), + gr::io_signature::make(0,0,0)) +{ + auto var_name = pmt::intern(variable_name); + auto in_port = pmt::intern("in"); + auto out_port = pmt::intern("out"); + message_port_register_in(in_port); + message_port_register_out(out_port); + set_msg_handler(in_port, [=](const pmt::pmt_t& msg){ + try{ + if(pmt::eqv(var_name, pmt::car(msg))) + message_port_pub(out_port, msg); + }catch(pmt::wrong_type&){ + d_logger->alert("bad variable message"); + } + }); +} + +/* + * Our virtual destructor. + */ +variable_filter_impl::~variable_filter_impl() {} + +void variable_filter_impl::forecast(int noutput_items, + gr_vector_int& ninput_items_required) +{} + +int variable_filter_impl::general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + return 0; +} + +} /* namespace UTAT_HERON */ +} /* namespace gr */ diff --git a/lib/variable_filter_impl.h b/lib/variable_filter_impl.h new file mode 100644 index 0000000..9d449ec --- /dev/null +++ b/lib/variable_filter_impl.h @@ -0,0 +1,36 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef INCLUDED_UTAT_HERON_VARIABLE_FILTER_IMPL_H +#define INCLUDED_UTAT_HERON_VARIABLE_FILTER_IMPL_H + +#include + +namespace gr { +namespace UTAT_HERON { + +class variable_filter_impl : public variable_filter +{ +private: + +public: + variable_filter_impl(const std::string& variable_name); + ~variable_filter_impl(); + + // Where all the action really happens + void forecast(int noutput_items, gr_vector_int& ninput_items_required); + + int general_work(int noutput_items, + gr_vector_int& ninput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items); +}; + +} // namespace UTAT_HERON +} // namespace gr + +#endif /* INCLUDED_UTAT_HERON_VARIABLE_FILTER_IMPL_H */ diff --git a/python/UTAT_HERON/CMakeLists.txt b/python/UTAT_HERON/CMakeLists.txt index a481549..edd67b3 100644 --- a/python/UTAT_HERON/CMakeLists.txt +++ b/python/UTAT_HERON/CMakeLists.txt @@ -43,3 +43,4 @@ GR_ADD_TEST(qa_heron_rx_bb ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_h GR_ADD_TEST(qa_esttc_framer ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_esttc_framer.py) GR_ADD_TEST(qa_esttc_deframer ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_esttc_deframer.py) GR_ADD_TEST(qa_tagged_stream_fixed_length_padder ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_tagged_stream_fixed_length_padder.py) +GR_ADD_TEST(qa_variable_filter ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_variable_filter.py) diff --git a/python/UTAT_HERON/bindings/CMakeLists.txt b/python/UTAT_HERON/bindings/CMakeLists.txt index f744b75..717f259 100644 --- a/python/UTAT_HERON/bindings/CMakeLists.txt +++ b/python/UTAT_HERON/bindings/CMakeLists.txt @@ -32,7 +32,8 @@ list(APPEND UTAT_HERON_python_files header_format_esttc_python.cc esttc_framer_python.cc esttc_deframer_python.cc - tagged_stream_fixed_length_padder_python.cc python_bindings.cc) + tagged_stream_fixed_length_padder_python.cc + variable_filter_python.cc python_bindings.cc) GR_PYBIND_MAKE_OOT(UTAT_HERON ../../.. diff --git a/python/UTAT_HERON/bindings/docstrings/variable_filter_pydoc_template.h b/python/UTAT_HERON/bindings/docstrings/variable_filter_pydoc_template.h new file mode 100644 index 0000000..2c3f0a6 --- /dev/null +++ b/python/UTAT_HERON/bindings/docstrings/variable_filter_pydoc_template.h @@ -0,0 +1,21 @@ +/* + * Copyright 2023 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, UTAT_HERON, __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_UTAT_HERON_variable_filter = R"doc()doc"; + + +static const char* __doc_gr_UTAT_HERON_variable_filter_make = R"doc()doc"; diff --git a/python/UTAT_HERON/bindings/python_bindings.cc b/python/UTAT_HERON/bindings/python_bindings.cc index 46e171e..3f78a66 100644 --- a/python/UTAT_HERON/bindings/python_bindings.cc +++ b/python/UTAT_HERON/bindings/python_bindings.cc @@ -26,6 +26,7 @@ namespace py = pybind11; void bind_esttc_framer(py::module& m); void bind_esttc_deframer(py::module& m); void bind_tagged_stream_fixed_length_padder(py::module& m); + void bind_variable_filter(py::module& m); // ) END BINDING_FUNCTION_PROTOTYPES @@ -60,5 +61,6 @@ PYBIND11_MODULE(UTAT_HERON_python, m) bind_esttc_framer(m); bind_esttc_deframer(m); bind_tagged_stream_fixed_length_padder(m); + bind_variable_filter(m); // ) END BINDING_FUNCTION_CALLS } \ No newline at end of file diff --git a/python/UTAT_HERON/bindings/variable_filter_python.cc b/python/UTAT_HERON/bindings/variable_filter_python.cc new file mode 100644 index 0000000..a07afc6 --- /dev/null +++ b/python/UTAT_HERON/bindings/variable_filter_python.cc @@ -0,0 +1,47 @@ +/* + * Copyright 2023 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(variable_filter.h) */ +/* BINDTOOL_HEADER_FILE_HASH(766845e61a49b7b901968168b8cc740f) */ +/***********************************************************************************/ + +#include +#include +#include + +namespace py = pybind11; + +#include +// pydoc.h is automatically generated in the build directory +#include + +void bind_variable_filter(py::module& m) +{ + + using variable_filter = gr::UTAT_HERON::variable_filter; + + + py::class_>(m, "variable_filter", D(variable_filter)) + + .def(py::init(&variable_filter::make), + py::arg("variable_name"), + D(variable_filter, make)) + + + ; +} diff --git a/python/UTAT_HERON/qa_variable_filter.py b/python/UTAT_HERON/qa_variable_filter.py new file mode 100755 index 0000000..b2ef3e1 --- /dev/null +++ b/python/UTAT_HERON/qa_variable_filter.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright 2023 University of Toronto Aerospace Team. +# +# SPDX-License-Identifier: GPL-3.0-or-later +# + +from gnuradio import gr, gr_unittest +# from gnuradio import blocks +try: + from gnuradio.UTAT_HERON import variable_filter +except ImportError: + import os + import sys + dirname, filename = os.path.split(os.path.abspath(__file__)) + sys.path.append(os.path.join(dirname, "bindings")) + from gnuradio.UTAT_HERON import variable_filter + +class qa_variable_filter(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_instance(self): + # FIXME: Test will fail until you pass sensible arguments to the constructor + instance = variable_filter() + + def test_001_descriptive_test_name(self): + # set up fg + self.tb.run() + # check data + + +if __name__ == '__main__': + gr_unittest.run(qa_variable_filter)