Skip to content

Commit

Permalink
added variable filter block
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnavaghosh04 committed Dec 17, 2023
1 parent 9fc5da4 commit eda5b6b
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 5 deletions.
3 changes: 2 additions & 1 deletion grc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion grc/UTAT_HERON_tagged_stream_fixed_length_padder.block.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions grc/UTAT_HERON_variable_filter.block.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion include/gnuradio/UTAT_HERON/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
41 changes: 41 additions & 0 deletions include/gnuradio/UTAT_HERON/variable_filter.h
Original file line number Diff line number Diff line change
@@ -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 <gnuradio/UTAT_HERON/api.h>
#include <gnuradio/block.h>

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<variable_filter> 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 */
3 changes: 2 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
62 changes: 62 additions & 0 deletions lib/variable_filter_impl.cc
Original file line number Diff line number Diff line change
@@ -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 <gnuradio/io_signature.h>
#include <functional>

namespace gr {
namespace UTAT_HERON {

variable_filter::sptr variable_filter::make(const std::string& variable_name)
{
return gnuradio::make_block_sptr<variable_filter_impl>(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 */
36 changes: 36 additions & 0 deletions lib/variable_filter_impl.h
Original file line number Diff line number Diff line change
@@ -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 <gnuradio/UTAT_HERON/variable_filter.h>

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 */
1 change: 1 addition & 0 deletions python/UTAT_HERON/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion python/UTAT_HERON/bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
../../..
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 2 additions & 0 deletions python/UTAT_HERON/bindings/python_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
}
47 changes: 47 additions & 0 deletions python/UTAT_HERON/bindings/variable_filter_python.cc
Original file line number Diff line number Diff line change
@@ -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 <pybind11/complex.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

#include <gnuradio/UTAT_HERON/variable_filter.h>
// pydoc.h is automatically generated in the build directory
#include <variable_filter_pydoc.h>

void bind_variable_filter(py::module& m)
{

using variable_filter = gr::UTAT_HERON::variable_filter;


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

.def(py::init(&variable_filter::make),
py::arg("variable_name"),
D(variable_filter, make))


;
}
39 changes: 39 additions & 0 deletions python/UTAT_HERON/qa_variable_filter.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit eda5b6b

Please sign in to comment.