From dddc7cc6864d5f6c35713ca23addeeeff70d3210 Mon Sep 17 00:00:00 2001 From: Swarnava Ghosh Date: Sat, 5 Aug 2023 01:01:11 -0400 Subject: [PATCH] Created header_format_esttc in hopes of replacing heron_rx_bb. Listed heron_rx_bb as deprecated. --- CMakeLists.txt | 2 +- grc/CMakeLists.txt | 3 +- grc/UTAT_HERON_header_format_esttc.block.yml | 56 +++++++++++++ grc/UTAT_HERON_heron_rx_bb.block.yml | 1 + include/gnuradio/UTAT_HERON/CMakeLists.txt | 3 +- .../gnuradio/UTAT_HERON/header_format_esttc.h | 45 +++++++++++ lib/CMakeLists.txt | 4 +- lib/header_format_esttc.cc | 80 +++++++++++++++++++ lib/qa_header_format_esttc.cc | 22 +++++ python/UTAT_HERON/bindings/CMakeLists.txt | 3 +- .../header_format_esttc_pydoc_template.h | 33 ++++++++ .../bindings/header_format_esttc_python.cc | 75 +++++++++++++++++ python/UTAT_HERON/bindings/python_bindings.cc | 3 + 13 files changed, 325 insertions(+), 5 deletions(-) create mode 100644 grc/UTAT_HERON_header_format_esttc.block.yml create mode 100644 include/gnuradio/UTAT_HERON/header_format_esttc.h create mode 100644 lib/header_format_esttc.cc create mode 100644 lib/qa_header_format_esttc.cc create mode 100644 python/UTAT_HERON/bindings/docstrings/header_format_esttc_pydoc_template.h create mode 100644 python/UTAT_HERON/bindings/header_format_esttc_python.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eeaa54..477cb12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ endif() # Make sure our local CMake Modules path comes first list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake/Modules) # Find gnuradio to get access to the cmake modules -find_package(Gnuradio "3.10" REQUIRED) +find_package(Gnuradio "3.10" REQUIRED COMPONENTS blocks digital filter analog fft) # Set the version information here # cmake-format: off diff --git a/grc/CMakeLists.txt b/grc/CMakeLists.txt index 5a58a67..3e7f300 100644 --- a/grc/CMakeLists.txt +++ b/grc/CMakeLists.txt @@ -7,5 +7,6 @@ # install(FILES - UTAT_HERON_heron_rx_bb.block.yml DESTINATION share/gnuradio/grc/blocks + UTAT_HERON_heron_rx_bb.block.yml + UTAT_HERON_header_format_esttc.block.yml DESTINATION share/gnuradio/grc/blocks ) diff --git a/grc/UTAT_HERON_header_format_esttc.block.yml b/grc/UTAT_HERON_header_format_esttc.block.yml new file mode 100644 index 0000000..d7d161b --- /dev/null +++ b/grc/UTAT_HERON_header_format_esttc.block.yml @@ -0,0 +1,56 @@ +id: UTAT_HERON_header_format_esttc +label: ESTTC Header Format +category: '[UTAT]' +flags: [ show_id, python, cpp ] + +value: ${ UTAT_HERON.header_format_esttc() } + +templates: + imports: from gnuradio import UTAT_HERON + var_make: self.${id} = ${id} = UTAT_HERON.header_format_esttc() + +cpp_templates: + includes: ['#include '] + declarations: 'UTAT_HERON::header_format_esttc::sptr ${id};' + var_make: this->${id} = ${id} = UTAT_HERON::header_format_esttc(); + link: ['gnuradio::gnuradio-digital'] + +# 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: parametername_replace_me +# label: FIX ME: +# dtype: string +# default: You need to fill in your grc/UTAT_HERON_header_format_esttc.block.yaml +#- 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: +#- label: ... +# domain: ... +# dtype: ... +# vlen: ... +# optional: ... + +outputs: +#- label: ... +# domain: ... +# dtype: ... +# vlen: ... +# optional: ... + +# '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/grc/UTAT_HERON_heron_rx_bb.block.yml b/grc/UTAT_HERON_heron_rx_bb.block.yml index 15099cb..cd02840 100644 --- a/grc/UTAT_HERON_heron_rx_bb.block.yml +++ b/grc/UTAT_HERON_heron_rx_bb.block.yml @@ -1,6 +1,7 @@ id: UTAT_HERON_heron_rx_bb label: HERON RX BB category: '[UTAT]' +flags: '[ deprecated ]' templates: imports: from gnuradio import UTAT_HERON diff --git a/include/gnuradio/UTAT_HERON/CMakeLists.txt b/include/gnuradio/UTAT_HERON/CMakeLists.txt index 7122e54..37c61ab 100644 --- a/include/gnuradio/UTAT_HERON/CMakeLists.txt +++ b/include/gnuradio/UTAT_HERON/CMakeLists.txt @@ -11,5 +11,6 @@ ######################################################################## install(FILES api.h - heron_rx_bb.h DESTINATION include/gnuradio/UTAT_HERON + heron_rx_bb.h + header_format_esttc.h DESTINATION include/gnuradio/UTAT_HERON ) diff --git a/include/gnuradio/UTAT_HERON/header_format_esttc.h b/include/gnuradio/UTAT_HERON/header_format_esttc.h new file mode 100644 index 0000000..5dea014 --- /dev/null +++ b/include/gnuradio/UTAT_HERON/header_format_esttc.h @@ -0,0 +1,45 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef INCLUDED_UTAT_HERON_HEADER_FORMAT_ESTTC_H +#define INCLUDED_UTAT_HERON_HEADER_FORMAT_ESTTC_H + +#include +#include + +namespace gr { +namespace UTAT_HERON { + +/*! + * \brief <+description+> + * + */ +class UTAT_HERON_API header_format_esttc : public gr::digital::header_format_default +{ +public: + typedef std::shared_ptr sptr; + static sptr make(); + header_format_esttc(); + ~header_format_esttc(); + bool format( + int nbytes_in, + const unsigned char* input, + pmt::pmt_t& output, + pmt::pmt_t& info) override; + size_t header_nbits() const override; +protected: + void enter_have_sync() override; + void enter_have_header(int payload_len) override; + void enter_search() override; + bool header_ok() override; + int header_payload() override; +}; + +} // namespace UTAT_HERON +} // namespace gr + +#endif /* INCLUDED_UTAT_HERON_HEADER_FORMAT_ESTTC_H */ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 56fe4c3..36b7097 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -19,6 +19,7 @@ list(APPEND UTAT_HERON_sources heron_packet.h debug_logger.cc debug_logger.h + header_format_esttc.cc ) set(DEBUG_FILE "${CMAKE_BINARY_DIR}/debug_log.txt" CACHE FILEPATH @@ -31,7 +32,7 @@ if(NOT UTAT_HERON_sources) endif(NOT UTAT_HERON_sources) add_library(gnuradio-UTAT_HERON SHARED ${UTAT_HERON_sources}) -target_link_libraries(gnuradio-UTAT_HERON gnuradio::gnuradio-runtime) +target_link_libraries(gnuradio-UTAT_HERON gnuradio::gnuradio-runtime gnuradio::gnuradio-digital) target_include_directories(gnuradio-UTAT_HERON PUBLIC $ PUBLIC $ @@ -67,6 +68,7 @@ include(GrTest) #include_directories() # List all files that contain Boost.UTF unit tests here list(APPEND test_UTAT_HERON_sources +qa_header_format_esttc.cc ) # Anything we need to link to for the unit tests go here list(APPEND GR_TEST_TARGET_DEPS gnuradio-UTAT_HERON) diff --git a/lib/header_format_esttc.cc b/lib/header_format_esttc.cc new file mode 100644 index 0000000..5965b0d --- /dev/null +++ b/lib/header_format_esttc.cc @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include +#include + +namespace gr { +namespace UTAT_HERON { + +header_format_esttc::sptr header_format_esttc::make(){ + return header_format_esttc::sptr(new header_format_esttc()); +} + +header_format_esttc::header_format_esttc(): + header_format_default("101010101010101010101010101010101010101001111110", 3, 1) +{} + +header_format_esttc::~header_format_esttc() {} + +bool header_format_esttc::format(int nbytes_in, + const unsigned char* input, + pmt::pmt_t& output, + pmt::pmt_t& info) +{ + + if(nbytes_in > 128) + throw std::runtime_error("header_format_esttc: Packet length cannot exceed 128 bits"); + + // Creating the output pmt copies data; free our own here when done. + volk::vector bytes_out(header_nbytes()); + + gr::digital::header_buffer header(bytes_out.data()); + header.add_field64(d_access_code, d_access_code_len); + header.add_field8((uint8_t)(nbytes_in)); + + // Package output data into a PMT vector + output = pmt::init_u8vector(header_nbytes(), bytes_out.data()); + + return true; +} + + +size_t header_format_esttc::header_nbits() const{ + return d_access_code_len + 8 * 1 * sizeof(uint8_t); +} + +inline void header_format_esttc::enter_have_sync(){ + d_state = STATE_HAVE_SYNC; + d_hdr_reg.clear(); +} +inline void header_format_esttc::enter_have_header(int payload_len){ + d_state = STATE_SYNC_SEARCH; + d_pkt_len = payload_len; + d_pkt_count = 0; +} +inline void header_format_esttc::enter_search(){ + d_state = STATE_SYNC_SEARCH; +} + +bool header_format_esttc::header_ok(){ + return d_hdr_reg.length() == 8 * 1 * sizeof(uint8_t); +} + +int header_format_esttc::header_payload(){ + + uint8_t len = d_hdr_reg.extract_field16(0, 8); + + d_info = pmt::make_dict(); + d_info = pmt::dict_add( + d_info, pmt::intern("payload symbols"), pmt::from_long(8 * len / d_bps)); + return static_cast(len); +} + +} /* namespace UTAT_HERON */ +} /* namespace gr */ diff --git a/lib/qa_header_format_esttc.cc b/lib/qa_header_format_esttc.cc new file mode 100644 index 0000000..0d32ddc --- /dev/null +++ b/lib/qa_header_format_esttc.cc @@ -0,0 +1,22 @@ +/* -*- c++ -*- */ +/* + * Copyright 2023 University of Toronto Aerospace Team. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include +#include +#include + +namespace gr { +namespace UTAT_HERON { + +BOOST_AUTO_TEST_CASE(test_header_format_esttc_replace_with_specific_test_name) +{ + // Put test here + BOOST_TEST(1); +} + +} /* namespace UTAT_HERON */ +} /* namespace gr */ diff --git a/python/UTAT_HERON/bindings/CMakeLists.txt b/python/UTAT_HERON/bindings/CMakeLists.txt index 5268699..5fbba95 100644 --- a/python/UTAT_HERON/bindings/CMakeLists.txt +++ b/python/UTAT_HERON/bindings/CMakeLists.txt @@ -29,7 +29,8 @@ include(GrPybind) ######################################################################## list(APPEND UTAT_HERON_python_files - heron_rx_bb_python.cc python_bindings.cc) + heron_rx_bb_python.cc + header_format_esttc_python.cc python_bindings.cc) GR_PYBIND_MAKE_OOT(UTAT_HERON ../../.. diff --git a/python/UTAT_HERON/bindings/docstrings/header_format_esttc_pydoc_template.h b/python/UTAT_HERON/bindings/docstrings/header_format_esttc_pydoc_template.h new file mode 100644 index 0000000..05c8eb0 --- /dev/null +++ b/python/UTAT_HERON/bindings/docstrings/header_format_esttc_pydoc_template.h @@ -0,0 +1,33 @@ +/* + * 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_header_format_esttc = R"doc()doc"; + + + static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_format_esttc = R"doc()doc"; + + + static const char *__doc_gr_UTAT_HERON_header_format_esttc_make = R"doc()doc"; + + + static const char *__doc_gr_UTAT_HERON_header_format_esttc_format = R"doc()doc"; + + + static const char *__doc_gr_UTAT_HERON_header_format_esttc_header_nbits = R"doc()doc"; + + diff --git a/python/UTAT_HERON/bindings/header_format_esttc_python.cc b/python/UTAT_HERON/bindings/header_format_esttc_python.cc new file mode 100644 index 0000000..f9ee3ce --- /dev/null +++ b/python/UTAT_HERON/bindings/header_format_esttc_python.cc @@ -0,0 +1,75 @@ +/* + * 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(header_format_esttc.h) */ +/* BINDTOOL_HEADER_FILE_HASH(41bda5cf854f7a82ab2d53b92e58e7f5) */ +/***********************************************************************************/ + +#include +#include +#include + +namespace py = pybind11; + +#include +// pydoc.h is automatically generated in the build directory +#include + +void bind_header_format_esttc(py::module& m) +{ + + using header_format_esttc = gr::UTAT_HERON::header_format_esttc; + + + py::class_>(m, "header_format_esttc", D(header_format_esttc)) + + .def(py::init(&header_format_esttc::make), + D(header_format_esttc,make) + ) + .def_static( + "make", + &header_format_esttc::make, + D(header_format_esttc,make) + ) + .def( + "format", + &header_format_esttc::format, + py::arg("nbytes_in"), + py::arg("input"), + py::arg("output"), + py::arg("info"), + D(header_format_esttc, format)) + .def( + "header_nbits", + &header_format_esttc::header_nbits, + D(header_format_esttc, header_nbits)) + + + + ; + + + + +} + + + + + + + + diff --git a/python/UTAT_HERON/bindings/python_bindings.cc b/python/UTAT_HERON/bindings/python_bindings.cc index 8d05296..2d5d886 100644 --- a/python/UTAT_HERON/bindings/python_bindings.cc +++ b/python/UTAT_HERON/bindings/python_bindings.cc @@ -22,6 +22,7 @@ namespace py = pybind11; /**************************************/ // BINDING_FUNCTION_PROTOTYPES( void bind_heron_rx_bb(py::module& m); + void bind_header_format_esttc(py::module& m); // ) END BINDING_FUNCTION_PROTOTYPES @@ -43,6 +44,7 @@ PYBIND11_MODULE(UTAT_HERON_python, m) // Allow access to base block methods py::module::import("gnuradio.gr"); + py::module::import("gnuradio.digital"); /**************************************/ // The following comment block is used for @@ -51,5 +53,6 @@ PYBIND11_MODULE(UTAT_HERON_python, m) /**************************************/ // BINDING_FUNCTION_CALLS( bind_heron_rx_bb(m); + bind_header_format_esttc(m); // ) END BINDING_FUNCTION_CALLS } \ No newline at end of file