From 98ee81f3acbba5f073c5babc507d3a7d4f9ca7ac Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 30 Sep 2024 15:34:50 +0200 Subject: [PATCH] Add Cshort_To_Gr_Complex Data Type Adapter implementation --- docs/CHANGELOG.md | 3 + .../data_type_adapter/adapters/CMakeLists.txt | 2 + .../adapters/cshort_to_grcomplex.cc | 92 +++++++++++++++++++ .../adapters/cshort_to_grcomplex.h | 83 +++++++++++++++++ .../gnuradio_blocks/CMakeLists.txt | 3 + .../gnuradio_blocks/cshort_to_gr_complex.cc | 50 ++++++++++ .../gnuradio_blocks/cshort_to_gr_complex.h | 55 +++++++++++ src/core/receiver/gnss_block_factory.cc | 7 ++ 8 files changed, 295 insertions(+) create mode 100644 src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.cc create mode 100644 src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.h create mode 100644 src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.cc create mode 100644 src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.h diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2a4db385b..290c0e976 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -50,6 +50,9 @@ All notable changes to GNSS-SDR will be documented in this file. - Add experimental decoding of Galileo's I/NAV ARAIM Integrity Support Message (ISM) as defined in the OS SIS ICD v2.1. Values, if received, are only logged but not used. +- Added new + [`Cshort_To_Gr_Complex`](https://gnss-sdr.org/docs/sp-blocks/data-type-adapter/#implementation-cshort_to_gr_complex) + Data Type Adapter implementation. ### Improvements in Portability: diff --git a/src/algorithms/data_type_adapter/adapters/CMakeLists.txt b/src/algorithms/data_type_adapter/adapters/CMakeLists.txt index 253624190..9b5935e5b 100644 --- a/src/algorithms/data_type_adapter/adapters/CMakeLists.txt +++ b/src/algorithms/data_type_adapter/adapters/CMakeLists.txt @@ -7,6 +7,7 @@ set(DATATYPE_ADAPTER_SOURCES byte_to_short.cc + cshort_to_grcomplex.cc ibyte_to_cbyte.cc ibyte_to_complex.cc ibyte_to_cshort.cc @@ -16,6 +17,7 @@ set(DATATYPE_ADAPTER_SOURCES set(DATATYPE_ADAPTER_HEADERS byte_to_short.h + cshort_to_grcomplex.h ibyte_to_cbyte.h ibyte_to_complex.h ibyte_to_cshort.h diff --git a/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.cc b/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.cc new file mode 100644 index 000000000..7eb94a519 --- /dev/null +++ b/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.cc @@ -0,0 +1,92 @@ +/*! + * \file cshort_to_grcomplex.cc + * \brief Adapts an 16-bits complex sample stream to a float complex stream + * \author Carles Fernandez Prades, 2014 cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "cshort_to_grcomplex.h" +#include "configuration_interface.h" +#include +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + + +CshortToGrComplex::CshortToGrComplex(const ConfigurationInterface* configuration, + std::string role, + unsigned int in_streams, + unsigned int out_streams) : role_(std::move(role)), + in_streams_(in_streams), + out_streams_(out_streams), + dump_(configuration->property(role_ + ".dump", false)) +{ + const std::string default_dump_filename("../data/data_type_adapter.dat"); + + DLOG(INFO) << "role " << role_; + + dump_filename_ = configuration->property(role_ + ".dump_filename", default_dump_filename); + cshort_to_gr_complex_ = make_cshort_to_gr_complex(); + + DLOG(INFO) << "data_type_adapter_(" << cshort_to_gr_complex_->unique_id() << ")"; + + if (dump_) + { + DLOG(INFO) << "Dumping output into file " << dump_filename_; + const size_t item_size = sizeof(gr_complex); + file_sink_ = gr::blocks::file_sink::make(item_size, dump_filename_.c_str()); + } + if (in_streams_ > 1) + { + LOG(ERROR) << "This implementation only supports one input stream"; + } + if (out_streams_ > 1) + { + LOG(ERROR) << "This implementation only supports one output stream"; + } +} + + +void CshortToGrComplex::connect(gr::top_block_sptr top_block) +{ + if (dump_) + { + top_block->connect(cshort_to_gr_complex_, 0, file_sink_, 0); + } + else + { + DLOG(INFO) << "Nothing to connect internally"; + } +} + + +void CshortToGrComplex::disconnect(gr::top_block_sptr top_block) +{ + if (dump_) + { + top_block->disconnect(cshort_to_gr_complex_, 0, file_sink_, 0); + } +} + + +gr::basic_block_sptr CshortToGrComplex::get_left_block() +{ + return cshort_to_gr_complex_; +} + + +gr::basic_block_sptr CshortToGrComplex::get_right_block() +{ + return cshort_to_gr_complex_; +} diff --git a/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.h b/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.h new file mode 100644 index 000000000..324211f7d --- /dev/null +++ b/src/algorithms/data_type_adapter/adapters/cshort_to_grcomplex.h @@ -0,0 +1,83 @@ +/*! + * \file cshort_to_grcomplex.h + * \brief Adapts an 16-bits complex sample stream to a float complex stream + * \author Carles Fernandez Prades, 2014 cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_CSHORT_TO_GRCOMPLEX_H +#define GNSS_SDR_CSHORT_TO_GRCOMPLEX_H + +#include "cshort_to_gr_complex.h" +#include "gnss_block_interface.h" +#include +#include +#include + +/** \addtogroup Data_Type Data Type Adapters + * Classes for data type conversion + * \{ */ +/** \addtogroup Data_type_adapters data_type_adapters + * Wrap GNU Radio data tyope adapter blocks with a GNSSBlockInterface + * \{ */ + + +class ConfigurationInterface; + +/*! + * \brief Adapts an 16-bits complex sample stream to a float complex stream + * + */ +class CshortToGrComplex : public GNSSBlockInterface +{ +public: + CshortToGrComplex(const ConfigurationInterface* configuration, + std::string role, unsigned int in_streams, + unsigned int out_streams); + + ~CshortToGrComplex() = default; + + inline std::string role() override + { + return role_; + } + + //! Returns "Cshort_To_Gr_Complex" + inline std::string implementation() override + { + return "Cshort_To_Gr_Complex"; + } + + inline size_t item_size() override + { + return 2 * sizeof(float); + } + + void connect(gr::top_block_sptr top_block) override; + void disconnect(gr::top_block_sptr top_block) override; + gr::basic_block_sptr get_left_block() override; + gr::basic_block_sptr get_right_block() override; + +private: + cshort_to_gr_complex_sptr cshort_to_gr_complex_; + gr::blocks::file_sink::sptr file_sink_; + std::string dump_filename_; + std::string role_; + unsigned int in_streams_; + unsigned int out_streams_; + bool dump_; +}; + + +/** \} */ +/** \} */ +#endif // GNSS_SDR_CSHORT_TO_GRCOMPLEX_H diff --git a/src/algorithms/data_type_adapter/gnuradio_blocks/CMakeLists.txt b/src/algorithms/data_type_adapter/gnuradio_blocks/CMakeLists.txt index 5a05385c2..79330488e 100644 --- a/src/algorithms/data_type_adapter/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/data_type_adapter/gnuradio_blocks/CMakeLists.txt @@ -6,12 +6,14 @@ set(DATA_TYPE_GR_BLOCKS_SOURCES + cshort_to_gr_complex.cc interleaved_byte_to_complex_byte.cc interleaved_short_to_complex_short.cc interleaved_byte_to_complex_short.cc ) set(DATA_TYPE_GR_BLOCKS_HEADERS + cshort_to_gr_complex.h interleaved_byte_to_complex_byte.h interleaved_short_to_complex_short.h interleaved_byte_to_complex_short.h @@ -42,6 +44,7 @@ target_link_libraries(data_type_gr_blocks Boost::headers PRIVATE Volk::volk + Volkgnsssdr::volkgnsssdr ) target_include_directories(data_type_gr_blocks diff --git a/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.cc b/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.cc new file mode 100644 index 000000000..b547d943f --- /dev/null +++ b/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.cc @@ -0,0 +1,50 @@ +/*! + * \file cshort_to_gr_complex.cc + * \brief Adapts a complex short (16 + 16 bits) sample stream into a + * std::complex stream (32 + 32 bits) + * \author Carles Fernandez Prades, 2014 cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + + +#include "cshort_to_gr_complex.h" +#include +#include +#include +#include // for max + + +cshort_to_gr_complex_sptr make_cshort_to_gr_complex() +{ + return cshort_to_gr_complex_sptr(new cshort_to_gr_complex()); +} + + +cshort_to_gr_complex::cshort_to_gr_complex() + : sync_block("cshort_to_gr_complex", + gr::io_signature::make(1, 1, sizeof(lv_16sc_t)), + gr::io_signature::make(1, 1, sizeof(gr_complex))) +{ + const auto alignment_multiple = static_cast(volk_get_alignment() / sizeof(lv_16sc_t)); + set_alignment(std::max(1, alignment_multiple)); +} + + +int cshort_to_gr_complex::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const auto *in = reinterpret_cast(input_items[0]); + auto *out = reinterpret_cast(output_items[0]); + volk_gnsssdr_16ic_convert_32fc(out, in, noutput_items); + return noutput_items; +} diff --git a/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.h b/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.h new file mode 100644 index 000000000..6605597d3 --- /dev/null +++ b/src/algorithms/data_type_adapter/gnuradio_blocks/cshort_to_gr_complex.h @@ -0,0 +1,55 @@ +/*! + * \file cshort_to_gr_complex.h + * \brief Adapts a complex short (16 + 16 bits) sample stream into a + * std::complex stream (32 + 32 bits) + * \author Carles Fernandez Prades, 2014 cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_CSHORT_TO_GR_COMPLEX_H +#define GNSS_SDR_CSHORT_TO_GR_COMPLEX_H + +#include "gnss_block_interface.h" +#include + +/** \addtogroup Data_Type + * \{ */ +/** \addtogroup data_type_gnuradio_blocks + * \{ */ + + +class cshort_to_gr_complex; + +using cshort_to_gr_complex_sptr = gnss_shared_ptr; + +cshort_to_gr_complex_sptr make_cshort_to_gr_complex(); + +/*! + * \brief This class adapts a short (16-bits) interleaved sample stream + * into a std::complex stream + */ +class cshort_to_gr_complex : public gr::sync_block +{ +public: + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + +private: + friend cshort_to_gr_complex_sptr make_cshort_to_gr_complex(); + cshort_to_gr_complex(); +}; + + +/** \} */ +/** \} */ +#endif // GNSS_SDR_CSHORT_TO_GR_COMPLEX_H \ No newline at end of file diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index fceadefb9..1635aa5f5 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -36,6 +36,7 @@ #include "byte_to_short.h" #include "channel.h" #include "configuration_interface.h" +#include "cshort_to_grcomplex.h" #include "direct_resampler_conditioner.h" #include "fifo_signal_source.h" #include "file_signal_source.h" @@ -919,6 +920,12 @@ std::unique_ptr GNSSBlockFactory::GetBlock( out_streams); block = std::move(block_); } + else if (implementation == "Cshort_To_Gr_Complex") + { + std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, + out_streams); + block = std::move(block_); + } // INPUT FILTER ------------------------------------------------------------ else if (implementation == "Fir_Filter")