From 9b393098a6e79c3c9ab2eaf431ebb80939cb062f Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 16 Aug 2024 13:27:36 +0200 Subject: [PATCH 01/66] Bump version of google benchmark to 1.9.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffa66cf5b..3696eede2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,7 +361,7 @@ set(GNSSSDR_PUGIXML_LOCAL_VERSION "1.14") set(GNSSSDR_GTEST_LOCAL_VERSION "1.15.2") set(GNSSSDR_GNSS_SIM_LOCAL_VERSION "origin/master") set(GNSSSDR_GNSSTK_LOCAL_VERSION "14.3.0") -set(GNSSSDR_BENCHMARK_LOCAL_VERSION "1.8.5") +set(GNSSSDR_BENCHMARK_LOCAL_VERSION "1.9.0") set(GNSSSDR_MATHJAX_EXTERNAL_VERSION "2.7.7") set(GNSSSDR_ABSL_LOCAL_VERSION "origin/master") # live at head (see https://abseil.io/about/releases) From dbd94e005d5b0352874b5918a16772dfc54e54b1 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 04:15:33 +0200 Subject: [PATCH 02/66] Fix CMakeLists header file list in signal source libs Header file paths were being appended to the source files list. This is not that important since, in general, you don't need to add the header files to the cmake target. --- src/algorithms/signal_source/libs/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 3506dc4f7..fd5c664d5 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -9,7 +9,7 @@ set(OPT_SIGNAL_SOURCE_LIB_SOURCES "") set(OPT_SIGNAL_SOURCE_LIB_HEADERS "") if(ENABLE_FMCOMMS2 OR ENABLE_AD9361) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad9361_manager.h) endif() if(ENABLE_MAX2771) @@ -36,12 +36,12 @@ endif() if(ENABLE_PLUTOSDR) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_samples.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.h) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} pps_samplestamp.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} pps_samplestamp.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ppstcprx.h) endif() From 1f3047c67acd926146746b6e80b8580066f4c23e Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 04:17:40 +0200 Subject: [PATCH 03/66] Added ION GNSS SDR Metadata Standard signal source --- CMakeLists.txt | 15 + .../signal_source/adapters/CMakeLists.txt | 2 + .../adapters/ion_gnss_ms_signal_source.cc | 119 +++++++ .../adapters/ion_gnss_ms_signal_source.h | 78 +++++ .../signal_source/libs/CMakeLists.txt | 11 + .../libs/ion_gnss_sdr_metadata_standard.cc | 304 +++++++++++++++++ .../libs/ion_gnss_sdr_metadata_standard.h | 319 ++++++++++++++++++ src/core/receiver/gnss_block_factory.cc | 7 + 8 files changed, 855 insertions(+) create mode 100644 src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc create mode 100644 src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h create mode 100644 src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc create mode 100644 src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ffa66cf5b..0bb716ad9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ option(ENABLE_ARRAY "Enable the use of CTTC's antenna array front-end as signal option(ENABLE_ZMQ "Enable GNU Radio ZeroMQ Messaging, requires gr-zeromq" ON) +option(ENABLE_ION "Enable ION GNSS-SDR Metadata Standard signal source" ON) + # Performance analysis tools option(ENABLE_GPERFTOOLS "Enable linking to Gperftools libraries (tcmalloc and profiler)" OFF) @@ -1422,6 +1424,19 @@ else() endif() +################################################################################ +# ION GNSS-SDR Metadata Standard +################################################################################ +include(FetchContent) +FetchContent_Declare( + gnss_metadata_standard + GIT_REPOSITORY https://github.com/IonMetadataWorkingGroup/GNSS-Metadata-Standard + GIT_TAG master + SOURCE_DIR ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard + CMAKE_ARGS -DABSL_PROPAGATE_CXX_STD=ON -ABSL_BUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${GNSSSDR_BINARY_DIR}/gnss-metadata-standard ${ABSEIL_TOOLCHAIN_FILE} + BINARY_DIR ${GNSSSDR_BINARY_DIR}/gnss-metadata-standard +) +FetchContent_MakeAvailable(gnss_metadata_standard) ################################################################################ # Abseil C++ - https://abseil.io/docs/cpp/ diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 0aa745101..54d577c53 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -119,6 +119,7 @@ set(SIGNAL_SOURCE_ADAPTER_SOURCES two_bit_packed_file_signal_source.cc four_bit_cpx_file_signal_source.cc file_timestamp_signal_source.cc + ion_gnss_ms_signal_source.cc ${OPT_DRIVER_SOURCES} ) @@ -138,6 +139,7 @@ set(SIGNAL_SOURCE_ADAPTER_HEADERS two_bit_packed_file_signal_source.h four_bit_cpx_file_signal_source.h file_timestamp_signal_source.h + ion_gnss_ms_signal_source.h ${OPT_DRIVER_HEADERS} ) diff --git a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc new file mode 100644 index 000000000..fe81e4556 --- /dev/null +++ b/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc @@ -0,0 +1,119 @@ +/*! + * \file file_timestamp_signal_source.cc + * \brief This class reads samples stored in a file and generate stream tags + * with its timestamp information stored in separated file + * \author Javier Arribas, jarribas(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "ion_gnss_ms_signal_source.h" +#include "gnss_sdr_flags.h" +#include "gnss_sdr_string_literals.h" +#include +#include +#include + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +using namespace std::string_literals; + +std::vector parse_comma_list(const std::string& str) +{ + std::vector list{}; + std::size_t prev_comma_at{0}; + + while (prev_comma_at < str.size()) + { + std::size_t comma_at = str.find_first_of(',', prev_comma_at); + if (comma_at == std::string::npos) + { + comma_at = str.size(); + } + list.emplace_back(str.substr(prev_comma_at, (comma_at - prev_comma_at))); + prev_comma_at = comma_at + 1; + } + + return list; +} + +IONMetadataStandardSignalSource::IONMetadataStandardSignalSource(const ConfigurationInterface* configuration, + const std::string& role, + unsigned int in_streams, + unsigned int out_streams, + Concurrent_Queue* queue) + : SignalSourceBase(configuration, role, "ION_Metadata_Standard_Signal_Source"s), + metadata_file_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), + stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), + metadata_(metadata_file_), + timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)) +{ + if (in_streams > 0) + { + LOG(ERROR) << "A signal source does not have an input stream"; + } + + sources_ = metadata_.make_stream_sources(stream_ids_); + + for (const auto& source : sources_) + { + for (int i = 0; i < source->output_stream_count(); ++i) + { + copy_blocks_.push_back(gr::blocks::copy::make(source->output_stream_item_size(i))); + } + } +} + + +void IONMetadataStandardSignalSource::connect(gr::top_block_sptr top_block) +{ + std::size_t cumulative_index = 0; + for (const auto& source : sources_) + { + for (int i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) + { + top_block->connect(source, i, copy_blocks_[cumulative_index], 0); + } + } +} + +void IONMetadataStandardSignalSource::disconnect(gr::top_block_sptr top_block) +{ + std::size_t cumulative_index = 0; + for (const auto& source : sources_) + { + for (int i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) + { + top_block->disconnect(source, i, copy_blocks_[cumulative_index], 0); + } + } +} + +gr::basic_block_sptr IONMetadataStandardSignalSource::get_left_block() +{ + LOG(WARNING) << "Trying to get signal source left block."; + // return gr_basic_block_sptr(); + return IONMetadataStdFileSource::sptr(); +} + +gr::basic_block_sptr IONMetadataStandardSignalSource::get_right_block() +{ + return get_right_block(0); +} + +gr::basic_block_sptr IONMetadataStandardSignalSource::get_right_block(int RF_channel) +{ + return copy_blocks_[RF_channel]; +} diff --git a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h new file mode 100644 index 000000000..ed84cab5c --- /dev/null +++ b/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h @@ -0,0 +1,78 @@ +/*! + * \file file_timestamp_signal_source.h + * \brief This class reads samples stored in a file and generate stream tags + * with its timestamp information stored in separated file + * \author Javier Arribas, jarribas(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + + +#ifndef GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H +#define GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H + +#include "configuration_interface.h" +#include "file_source_base.h" +#include "gnss_sdr_timestamp.h" +#include "ion_gnss_sdr_metadata_standard.h" +#include + +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_adapters + * \{ */ + +/*! + * \brief Class that reads signals samples from a file + * and adapts it to a SignalSourceInterface + */ +class IONMetadataStandardSignalSource : public SignalSourceBase +{ +public: + IONMetadataStandardSignalSource(const ConfigurationInterface* configuration, const std::string& role, + unsigned int in_streams, unsigned int out_streams, + Concurrent_Queue* queue); + + ~IONMetadataStandardSignalSource() override = default; + +protected: + // std::tuple itemTypeToSize() override; + // double packetsPerSample() const override; + 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; + gr::basic_block_sptr get_right_block(int RF_channel) override; + + inline size_t item_size() override + { + return (*sources_.begin())->output_stream_item_size(0); + } +private: + std::string metadata_file_; + std::vector stream_ids_; + std::vector sources_; + std::vector> copy_blocks_; + GnssMetadataHandler metadata_; + + gnss_shared_ptr timestamp_block_; + std::string timestamp_file_; + double timestamp_clock_offset_ms_; + + uint32_t in_streams_; + uint32_t out_streams_; +}; + + +/** \} */ +/** \} */ +#endif // GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index fd5c664d5..f0b2c09fd 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -7,6 +7,7 @@ set(OPT_SIGNAL_SOURCE_LIB_SOURCES "") set(OPT_SIGNAL_SOURCE_LIB_HEADERS "") + if(ENABLE_FMCOMMS2 OR ENABLE_AD9361) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad9361_manager.h) @@ -44,6 +45,11 @@ if(ENABLE_PLUTOSDR) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ppstcprx.h) endif() +if(ENABLE_ION) + set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gnss_sdr_metadata_standard.cc) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gnss_sdr_metadata_standard.h) +endif() + set(SIGNAL_SOURCE_LIB_SOURCES rtl_tcp_commands.cc @@ -139,6 +145,11 @@ if(ENABLE_CLANG_TIDY) endif() endif() +if(ENABLE_ION) + target_include_directories(signal_source_libs PUBLIC ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard/source/api/inc) + target_link_libraries(signal_source_libs PUBLIC api xml) +endif() + set_property(TARGET signal_source_libs APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ ) diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc new file mode 100644 index 000000000..c31ec3d1d --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc @@ -0,0 +1,304 @@ +// +// Created by castle on 6/24/24. +// + +#include "ion_gnss_sdr_metadata_standard.h" + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +GnssMetadataHandler::GnssMetadataHandler(const std::string& metadata_filepath) + : metadata_filepath_(metadata_filepath) +{ + load_metadata(); +} + +const std::string& GnssMetadataHandler::metadata_filepath() const +{ + return metadata_filepath_; +} + +void GnssMetadataHandler::load_metadata() +{ + try + { + GnssMetadata::XmlProcessor xml_proc; + if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) + { + LOG(ERROR) << "Could not load XML metadata file:"; + } + } + catch (GnssMetadata::ApiException& e) + { + LOG(ERROR) << "API Exception while loadind XML metadata file: " << e.what(); + } + catch (std::exception& e) + { + LOG(ERROR) << "Exception while loading XML metadata file: " << e.what(); + } +} + +std::vector GnssMetadataHandler::make_stream_sources(const std::vector& stream_ids) const +{ + std::vector sources{}; + for (const auto& file : metadata_.Files()) + { + for (const auto& block : file.Lane().Blocks()) + { + for (const auto& chunk : block.Chunks()) + { + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + auto source = gnss_make_shared( + file, + block, + stream_ids); + + sources.push_back(source); + + // This file source will take care of any other matching streams in this block + // We can skip the rest of this block + goto next_block; + } + } + } + } + next_block: + } + } + + return sources; +} + + +IONMetadataStdFileSource::IONMetadataStdFileSource( + const GnssMetadata::File& file, + const GnssMetadata::Block& block, + const std::vector& stream_ids) + : gr::sync_block( + "ion_metadata_standard_source", + gr::io_signature::make(0, 0, 0), + make_output_signature(block)), + file_metadata_(file), + block_metadata_(block) +{ + fd_ = std::fopen(file.Url().Value().c_str(), "rb"); + std::size_t block_offset = file.Offset(); + std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); + + std::size_t output_stream_offset = 0; + for (const auto& chunk : block.Chunks()) + { + chunk_data_.emplace_back(std::make_shared(chunk, stream_ids, output_stream_offset)); + const std::size_t out_count = chunk_data_.back()->output_stream_count(); + output_stream_offset += out_count; + for (std::size_t i = 0; i < out_count; ++i) + { + output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); + } + } + output_stream_count_ = output_stream_offset; +} + +IONMetadataStdFileSource::~IONMetadataStdFileSource() +{ + std::fclose(fd_); +} + +int IONMetadataStdFileSource::work( + int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + for (int i = 0; i < noutput_items; ++i) + { + read_chunk_pattern(output_items); + } + return WORK_CALLED_PRODUCE; +} + +std::size_t IONMetadataStdFileSource::output_stream_count() const +{ + return output_stream_count_; +} + +std::size_t IONMetadataStdFileSource::output_stream_item_size(std::size_t stream_index) const +{ + return output_stream_item_sizes_[stream_index]; +} + + +void IONMetadataStdFileSource::read_chunk_pattern(gr_vector_void_star& output_items) +{ + gr_vector_void_star chunk_outputs = output_items; + for (auto& c : chunk_data_) + { + c->read_from_file(fd_); + c->write_to_output(output_items, [this](int output, int nitems) { + produce(output, nitems); + }); + } +} + +gr::io_signature::sptr IONMetadataStdFileSource::make_output_signature(const GnssMetadata::Block& block) +{ + int nstreams = 0; + std::vector item_sizes{}; + + for (const auto& chunk : block.Chunks()) + { + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + ++nstreams; + item_sizes.emplace_back(stream.RateFactor() * stream.Quantization()); + } + } + } + + return gr::io_signature::make( + nstreams, + nstreams, + item_sizes); +} + + +chunk_data_t::chunk_data_t(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset) + : chunk_(chunk), + sizeword_(chunk_.SizeWord()), + countwords_(chunk_.CountWords()) +{ + switch (sizeword_) + { + case 1: + buffer_ = new uint8_t[countwords_]; + break; + case 2: + buffer_ = new uint16_t[countwords_]; + break; + case 4: + buffer_ = new uint32_t[countwords_]; + break; + case 8: + buffer_ = new uint64_t[countwords_]; + break; + default: + LOG(ERROR) << "Unknown word size: " << std::to_string(sizeword_); + break; + } + + + const std::size_t total_bitsize = sizeword_ * countwords_ * 8; + std::size_t used_bitsize = 0; + std::size_t output_streams = 0; + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + used_bitsize += stream.Packedbits(); + + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + streams_.emplace_back(lump, stream, output_streams + output_stream_offset); + ++output_streams; + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + if (sample_bitsize <= 8) + { + output_stream_item_size_.push_back(1); + } + else if (sample_bitsize <= 16) + { + output_stream_item_size_.push_back(2); + } + else if (sample_bitsize <= 32) + { + output_stream_item_size_.push_back(4); + } + else if (sample_bitsize <= 64) + { + output_stream_item_size_.push_back(8); + } + else + { + // This shouldn't happen + output_stream_item_size_.push_back(1); + } + } + else + { + streams_.emplace_back(lump, stream, -1); + } + } + } + + output_stream_count_ = output_streams; + padding_bitsize_ = total_bitsize - used_bitsize; +} +chunk_data_t::~chunk_data_t() +{ + switch (sizeword_) + { + case 1: + delete[] static_cast(buffer_); + break; + case 2: + delete[] static_cast(buffer_); + break; + case 4: + delete[] static_cast(buffer_); + break; + case 8: + delete[] static_cast(buffer_); + break; + default: + break; + } +} + +void chunk_data_t::read_from_file(FILE* fd) +{ + std::fread(buffer_, sizeword_, countwords_, fd); +} + +void chunk_data_t::write_to_output(gr_vector_void_star& outputs, const std::function& produce) +{ + switch (sizeword_) + { + case 1: + unpack_words(outputs, produce); + break; + case 2: + unpack_words(outputs, produce); + break; + case 4: + unpack_words(outputs, produce); + break; + case 8: + unpack_words(outputs, produce); + break; + default: + break; + } +} + +std::size_t chunk_data_t::output_stream_count() const +{ + return output_stream_count_; +} + +std::size_t chunk_data_t::output_stream_item_size(std::size_t stream_index) const +{ + return output_stream_item_size_[stream_index]; +} diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h new file mode 100644 index 000000000..badf834c1 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h @@ -0,0 +1,319 @@ +// +// Created by castle on 6/24/24. +// + +#ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H + +#include "GnssMetadata.h" +#include "gnss_block_interface.h" +#include +#include + +class chunk_data_t +{ +public: + chunk_data_t(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset); + + ~chunk_data_t(); + + chunk_data_t(const chunk_data_t& rhl) = delete; + chunk_data_t& operator=(const chunk_data_t& rhl) = delete; + + chunk_data_t(chunk_data_t&& rhl) = delete; + chunk_data_t& operator=(chunk_data_t&& rhl) = delete; + + void read_from_file(FILE* fd); + + void write_to_output(gr_vector_void_star& outputs, const std::function& produce); + + std::size_t output_stream_count() const; + std::size_t output_stream_item_size(std::size_t stream_index) const; + +private: + template + struct unpacking_context_t + { + WT* iterator_; + WT current_word_; + uint8_t bitshift_ = 0; + }; + + template + void unpack_words(gr_vector_void_star& outputs, const std::function& produce) + { + WT* data = static_cast(buffer_); + // TODO - Swap endiannes if needed + + unpacking_context_t ctx{}; + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.iterator_ = data; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.iterator_ = &data[countwords_]; + } + advance_word(ctx); // Initializes ctx.current_word_ + + // Head padding + if (padding_bitsize_ > 0 && chunk_.Padding() == GnssMetadata::Chunk::Head) + { + shift_padding(ctx, padding_bitsize_); + } + + // Samples + for (const auto& [lump, stream, output_index] : streams_) + { + if (output_index == -1) + { + skip_stream(ctx, lump, stream); + } + else + { + produce(output_index, write_stream_samples(ctx, lump, stream, outputs[output_index])); + } + } + } + + template + void skip_stream( + unpacking_context_t& ctx, + const GnssMetadata::Lump& lump, + const GnssMetadata::IonStream& stream) + { + shift_padding(ctx, stream.Packedbits()); + } + + template + std::size_t write_stream_samples( + unpacking_context_t& ctx, + const GnssMetadata::Lump& lump, + const GnssMetadata::IonStream& stream, + void*& out) + { + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_count = stream.RateFactor(); + if (sample_bitsize <= 8) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); + } + else if (sample_bitsize <= 16) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); + } + else if (sample_bitsize <= 32) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); + } + else if (sample_bitsize <= 64) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); + } + + return sample_count; + } + + template + void write_n_samples( + unpacking_context_t& ctx, + GnssMetadata::Lump::LumpShift lump_shift, + uint8_t sample_bitsize, + std::size_t sample_count, + void*& out) + { + if (lump_shift == GnssMetadata::Lump::shiftLeft) + { + auto* sample = static_cast(out); + for (int i = 0; i < sample_count; ++i) + { + shift_sample(ctx, sample_bitsize, sample); + ++sample; + } + } + else if (lump_shift == GnssMetadata::Lump::shiftRight) + { + auto* sample = static_cast(out); + sample += sample_count; + for (int i = 0; i < sample_count; ++i) + { + shift_sample(ctx, sample_bitsize, sample); + --sample; + } + } + } + + template + void shift_sample(unpacking_context_t& ctx, uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) + { + const uint8_t word_bitsize = sizeword_ * 8; + + if ((sample_bitsize + (ctx.bitshift_ % word_bitsize)) > word_bitsize) + { + uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); + + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize - bits_shifted)) - 1); + *output |= ((ctx.current_word_ & mask) >> output_bit_offset); + ctx.current_word_ <<= bits_shifted; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (bits_shifted)) - 1); + *output |= (ctx.current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + ctx.current_word_ >>= bits_shifted; + } + + advance_word(ctx); + ctx.bitshift_ += bits_shifted; + shift_sample(ctx, sample_bitsize - bits_shifted, output, bits_shifted); + } + else + { + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize - sample_bitsize)) - 1); + *output |= (ctx.current_word_ & mask) >> output_bit_offset; + ctx.current_word_ <<= sample_bitsize; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (sample_bitsize)) - 1); + *output |= (ctx.current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + ctx.current_word_ >>= sample_bitsize; + } + + ctx.bitshift_ += sample_bitsize; + } + } + + template + void shift_padding(unpacking_context_t& ctx, uint8_t n_bits) + { + const uint8_t word_bitsize = sizeword_ * 8; + + if ((n_bits + (ctx.bitshift_ % word_bitsize)) > word_bitsize) + { + uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); + + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.current_word_ <<= bits_shifted; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.current_word_ >>= bits_shifted; + } + + advance_word(ctx); + ctx.bitshift_ += bits_shifted; + shift_padding(ctx, n_bits - bits_shifted); + } + else + { + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.current_word_ <<= n_bits; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.current_word_ >>= n_bits; + } + + ctx.bitshift_ += n_bits; + } + } + + template + void advance_word(unpacking_context_t& ctx) + { + WT word = *ctx.iterator_; + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ++ctx.iterator_; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + --ctx.iterator_; + } + + ctx.current_word_ = word; + } + +private: + const GnssMetadata::Chunk& chunk_; + uint8_t sizeword_; + uint8_t countwords_; + uint8_t padding_bitsize_; + std::size_t output_stream_count_; + std::vector output_stream_item_size_; + + struct stream_metadata_t + { + const GnssMetadata::Lump& lump; + const GnssMetadata::IonStream& stream; + int output_index = -1; + }; + std::vector streams_; + + void* buffer_; +}; + +class IONMetadataStdFileSource : public gr::sync_block +{ +public: + using sptr = gnss_shared_ptr; + + IONMetadataStdFileSource( + const GnssMetadata::File& file, + const GnssMetadata::Block& block, + const std::vector& stream_ids); + + ~IONMetadataStdFileSource() override; + + int work( + int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) override; + + std::size_t output_stream_count() const; + std::size_t output_stream_item_size(std::size_t stream_index) const; + +private: + void read_chunk_pattern(gr_vector_void_star& output_items); + +private: + static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block); + +private: + const GnssMetadata::File& file_metadata_; + const GnssMetadata::Block& block_metadata_; + FILE* fd_; + std::size_t output_stream_count_; + std::vector output_stream_item_sizes_; + std::vector> chunk_data_; +}; + +class GnssMetadataHandler +{ +public: + explicit GnssMetadataHandler(const std::string& metadata_filepath); + + std::vector make_stream_sources(const std::vector& stream_ids) const; + +public: // Getters + const std::string& metadata_filepath() const; + +private: + void load_metadata(); + +private: + std::string metadata_filepath_; + GnssMetadata::Metadata metadata_; +}; + + +#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index ce77442ee..69406a711 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -113,6 +113,7 @@ #include "tracking_interface.h" #include "two_bit_cpx_file_signal_source.h" #include "two_bit_packed_file_signal_source.h" +#include "ion_gnss_ms_signal_source.h" #include // for exit #include // for exception #include // for cerr @@ -759,6 +760,12 @@ std::unique_ptr GNSSBlockFactory::GetBlock( block = std::move(block_); } #endif + else if (implementation == "ION_Metadata_Standard_Signal_Source") + { + std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, + out_streams, queue); + block = std::move(block_); + } #if RAW_ARRAY_DRIVER else if (implementation == "Raw_Array_Signal_Source") From 38d548ba5090b193bb0681fccd7edd526e30a92e Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 18:03:36 +0200 Subject: [PATCH 04/66] Only specify outputs for the requested streams --- .../libs/ion_gnss_sdr_metadata_standard.cc | 34 ++++++++++++++++--- .../libs/ion_gnss_sdr_metadata_standard.h | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc index c31ec3d1d..9466e798f 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc @@ -87,7 +87,7 @@ IONMetadataStdFileSource::IONMetadataStdFileSource( : gr::sync_block( "ion_metadata_standard_source", gr::io_signature::make(0, 0, 0), - make_output_signature(block)), + make_output_signature(block, stream_ids)), file_metadata_(file), block_metadata_(block) { @@ -149,7 +149,7 @@ void IONMetadataStdFileSource::read_chunk_pattern(gr_vector_void_star& output_it } } -gr::io_signature::sptr IONMetadataStdFileSource::make_output_signature(const GnssMetadata::Block& block) +gr::io_signature::sptr IONMetadataStdFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) { int nstreams = 0; std::vector item_sizes{}; @@ -160,8 +160,34 @@ gr::io_signature::sptr IONMetadataStdFileSource::make_output_signature(const Gns { for (const auto& stream : lump.Streams()) { - ++nstreams; - item_sizes.emplace_back(stream.RateFactor() * stream.Quantization()); + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + ++nstreams; + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + if (sample_bitsize <= 8) + { + item_sizes.push_back(1); + } + else if (sample_bitsize <= 16) + { + item_sizes.push_back(2); + } + else if (sample_bitsize <= 32) + { + item_sizes.push_back(4); + } + else if (sample_bitsize <= 64) + { + item_sizes.push_back(8); + } + else + { + // This shouldn't happen + item_sizes.push_back(1); + } + } } } } diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h index badf834c1..b97a84576 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h @@ -286,7 +286,7 @@ private: void read_chunk_pattern(gr_vector_void_star& output_items); private: - static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block); + static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); private: const GnssMetadata::File& file_metadata_; From 5c442c8aae637510d05276890dfb7f08106f35bd Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 18:06:01 +0200 Subject: [PATCH 05/66] Fixed block iteration withing a file The `File` object only holds a shallow reference to its `Lane` (without the list of blocks). So we must retrieve the full reference manually. --- .../libs/ion_gnss_sdr_metadata_standard.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc index 9466e798f..45e3eebbe 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc @@ -46,10 +46,14 @@ std::vector GnssMetadataHandler::make_stream_sou std::vector sources{}; for (const auto& file : metadata_.Files()) { - for (const auto& block : file.Lane().Blocks()) + for (const auto& lane : metadata_.Lanes()) { - for (const auto& chunk : block.Chunks()) + if (lane.Id() == file.Lane().Id()) { + for (const auto& block : lane.Blocks()) + { + for (const auto& chunk : block.Chunks()) + { for (const auto& lump : chunk.Lumps()) { for (const auto& stream : lump.Streams()) @@ -71,8 +75,11 @@ std::vector GnssMetadataHandler::make_stream_sou } } } + } + next_block: + } + break; } - next_block: } } From 598fa283b80ca5873d7eb0e78195442548c1aa6f Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 24 Jun 2024 18:08:40 +0200 Subject: [PATCH 06/66] Treat data file paths as relative to the metadata file The data file paths are actually not native paths but URLs, this covers most cases but not all of them. --- .../libs/ion_gnss_sdr_metadata_standard.cc | 39 ++++++++++--------- .../libs/ion_gnss_sdr_metadata_standard.h | 2 + 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc index 45e3eebbe..3c8f1809d 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc @@ -54,28 +54,29 @@ std::vector GnssMetadataHandler::make_stream_sou { for (const auto& chunk : block.Chunks()) { - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) + for (const auto& lump : chunk.Lumps()) { - auto source = gnss_make_shared( - file, - block, - stream_ids); + for (const auto& stream : lump.Streams()) + { + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + auto source = gnss_make_shared( + metadata_filepath_, + file, + block, + stream_ids); - sources.push_back(source); + sources.push_back(source); - // This file source will take care of any other matching streams in this block - // We can skip the rest of this block - goto next_block; + // This file source will take care of any other matching streams in this block + // We can skip the rest of this block + goto next_block; + } + } } } - } - } next_block: } break; @@ -88,6 +89,7 @@ std::vector GnssMetadataHandler::make_stream_sou IONMetadataStdFileSource::IONMetadataStdFileSource( + const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids) @@ -98,7 +100,8 @@ IONMetadataStdFileSource::IONMetadataStdFileSource( file_metadata_(file), block_metadata_(block) { - fd_ = std::fopen(file.Url().Value().c_str(), "rb"); + std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); + fd_ = std::fopen(data_filepath.c_str(), "rb"); std::size_t block_offset = file.Offset(); std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h index b97a84576..0543de71d 100644 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h +++ b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h @@ -9,6 +9,7 @@ #include "gnss_block_interface.h" #include #include +#include class chunk_data_t { @@ -268,6 +269,7 @@ public: using sptr = gnss_shared_ptr; IONMetadataStdFileSource( + const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids); From 469eaf76e5cc241e1f0c452e1a1665292c3ff6b8 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Tue, 23 Jul 2024 01:13:34 +0200 Subject: [PATCH 07/66] Fixed decoding errors and refactored each class into its own file --- .../signal_source/adapters/CMakeLists.txt | 4 +- ...al_source.cc => ion_gsms_signal_source.cc} | 27 +- ...gnal_source.h => ion_gsms_signal_source.h} | 19 +- .../signal_source/libs/CMakeLists.txt | 8 +- .../libs/ion_gnss_sdr_metadata_standard.cc | 340 ------------ .../libs/ion_gnss_sdr_metadata_standard.h | 321 ----------- src/algorithms/signal_source/libs/ion_gsms.cc | 123 +++++ src/algorithms/signal_source/libs/ion_gsms.h | 64 +++ .../signal_source/libs/ion_gsms_chunk_data.cc | 108 ++++ .../signal_source/libs/ion_gsms_chunk_data.h | 510 ++++++++++++++++++ .../libs/ion_gsms_metadata_handler.cc | 101 ++++ .../libs/ion_gsms_metadata_handler.h | 47 ++ src/core/receiver/gnss_block_factory.cc | 6 +- 13 files changed, 987 insertions(+), 691 deletions(-) rename src/algorithms/signal_source/adapters/{ion_gnss_ms_signal_source.cc => ion_gsms_signal_source.cc} (78%) rename src/algorithms/signal_source/adapters/{ion_gnss_ms_signal_source.h => ion_gsms_signal_source.h} (76%) delete mode 100644 src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc delete mode 100644 src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h create mode 100644 src/algorithms/signal_source/libs/ion_gsms.cc create mode 100644 src/algorithms/signal_source/libs/ion_gsms.h create mode 100644 src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc create mode 100644 src/algorithms/signal_source/libs/ion_gsms_chunk_data.h create mode 100644 src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc create mode 100644 src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 54d577c53..9ff0ab434 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -119,7 +119,7 @@ set(SIGNAL_SOURCE_ADAPTER_SOURCES two_bit_packed_file_signal_source.cc four_bit_cpx_file_signal_source.cc file_timestamp_signal_source.cc - ion_gnss_ms_signal_source.cc + ion_gsms_signal_source.cc ${OPT_DRIVER_SOURCES} ) @@ -139,7 +139,7 @@ set(SIGNAL_SOURCE_ADAPTER_HEADERS two_bit_packed_file_signal_source.h four_bit_cpx_file_signal_source.h file_timestamp_signal_source.h - ion_gnss_ms_signal_source.h + ion_gsms_signal_source.h ${OPT_DRIVER_HEADERS} ) diff --git a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc similarity index 78% rename from src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc rename to src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index fe81e4556..e4becf5e3 100644 --- a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -1,8 +1,7 @@ /*! - * \file file_timestamp_signal_source.cc - * \brief This class reads samples stored in a file and generate stream tags - * with its timestamp information stored in separated file - * \author Javier Arribas, jarribas(at)cttc.es + * \file ion_gsms_signal_source.h + * \brief GNSS-SDR Signal Source that reads sample streams following ION's GNSS-SDR metadata standard + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com * * ----------------------------------------------------------------------------- * @@ -15,9 +14,9 @@ * ----------------------------------------------------------------------------- */ -#include "ion_gnss_ms_signal_source.h" #include "gnss_sdr_flags.h" #include "gnss_sdr_string_literals.h" +#include "ion_gsms_signal_source.h" #include #include #include @@ -49,7 +48,7 @@ std::vector parse_comma_list(const std::string& str) return list; } -IONMetadataStandardSignalSource::IONMetadataStandardSignalSource(const ConfigurationInterface* configuration, +IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configuration, const std::string& role, unsigned int in_streams, unsigned int out_streams, @@ -58,7 +57,9 @@ IONMetadataStandardSignalSource::IONMetadataStandardSignalSource(const Configura metadata_file_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), metadata_(metadata_file_), - timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)) + timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)), + in_streams_(in_streams), + out_streams_(out_streams) { if (in_streams > 0) { @@ -77,7 +78,7 @@ IONMetadataStandardSignalSource::IONMetadataStandardSignalSource(const Configura } -void IONMetadataStandardSignalSource::connect(gr::top_block_sptr top_block) +void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) { std::size_t cumulative_index = 0; for (const auto& source : sources_) @@ -89,7 +90,7 @@ void IONMetadataStandardSignalSource::connect(gr::top_block_sptr top_block) } } -void IONMetadataStandardSignalSource::disconnect(gr::top_block_sptr top_block) +void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) { std::size_t cumulative_index = 0; for (const auto& source : sources_) @@ -101,19 +102,19 @@ void IONMetadataStandardSignalSource::disconnect(gr::top_block_sptr top_block) } } -gr::basic_block_sptr IONMetadataStandardSignalSource::get_left_block() +gr::basic_block_sptr IONGSMSSignalSource::get_left_block() { LOG(WARNING) << "Trying to get signal source left block."; // return gr_basic_block_sptr(); - return IONMetadataStdFileSource::sptr(); + return IONGSMSFileSource::sptr(); } -gr::basic_block_sptr IONMetadataStandardSignalSource::get_right_block() +gr::basic_block_sptr IONGSMSSignalSource::get_right_block() { return get_right_block(0); } -gr::basic_block_sptr IONMetadataStandardSignalSource::get_right_block(int RF_channel) +gr::basic_block_sptr IONGSMSSignalSource::get_right_block(int RF_channel) { return copy_blocks_[RF_channel]; } diff --git a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h similarity index 76% rename from src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h rename to src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index ed84cab5c..9d959279f 100644 --- a/src/algorithms/signal_source/adapters/ion_gnss_ms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -1,8 +1,7 @@ /*! - * \file file_timestamp_signal_source.h - * \brief This class reads samples stored in a file and generate stream tags - * with its timestamp information stored in separated file - * \author Javier Arribas, jarribas(at)cttc.es + * \file ion_gsms_signal_source.h + * \brief GNSS-SDR Signal Source that reads sample streams following ION's GNSS-SDR metadata standard + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com * * ----------------------------------------------------------------------------- * @@ -22,7 +21,7 @@ #include "configuration_interface.h" #include "file_source_base.h" #include "gnss_sdr_timestamp.h" -#include "ion_gnss_sdr_metadata_standard.h" +#include "ion_gsms.h" #include /** \addtogroup Signal_Source @@ -34,14 +33,14 @@ * \brief Class that reads signals samples from a file * and adapts it to a SignalSourceInterface */ -class IONMetadataStandardSignalSource : public SignalSourceBase +class IONGSMSSignalSource : public SignalSourceBase { public: - IONMetadataStandardSignalSource(const ConfigurationInterface* configuration, const std::string& role, + IONGSMSSignalSource(const ConfigurationInterface* configuration, const std::string& role, unsigned int in_streams, unsigned int out_streams, Concurrent_Queue* queue); - ~IONMetadataStandardSignalSource() override = default; + ~IONGSMSSignalSource() override = default; protected: // std::tuple itemTypeToSize() override; @@ -60,9 +59,9 @@ protected: private: std::string metadata_file_; std::vector stream_ids_; - std::vector sources_; + std::vector sources_; std::vector> copy_blocks_; - GnssMetadataHandler metadata_; + IONGSMSMetadataHandler metadata_; gnss_shared_ptr timestamp_block_; std::string timestamp_file_; diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index f0b2c09fd..fb7faf9ee 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -46,8 +46,12 @@ if(ENABLE_PLUTOSDR) endif() if(ENABLE_ION) - set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gnss_sdr_metadata_standard.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gnss_sdr_metadata_standard.h) + set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms.cc) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms.h) + set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_chunk_data.cc) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_data.h) + set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_metadata_handler.cc) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_metadata_handler.h) endif() diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc deleted file mode 100644 index 3c8f1809d..000000000 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.cc +++ /dev/null @@ -1,340 +0,0 @@ -// -// Created by castle on 6/24/24. -// - -#include "ion_gnss_sdr_metadata_standard.h" - -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif - -GnssMetadataHandler::GnssMetadataHandler(const std::string& metadata_filepath) - : metadata_filepath_(metadata_filepath) -{ - load_metadata(); -} - -const std::string& GnssMetadataHandler::metadata_filepath() const -{ - return metadata_filepath_; -} - -void GnssMetadataHandler::load_metadata() -{ - try - { - GnssMetadata::XmlProcessor xml_proc; - if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) - { - LOG(ERROR) << "Could not load XML metadata file:"; - } - } - catch (GnssMetadata::ApiException& e) - { - LOG(ERROR) << "API Exception while loadind XML metadata file: " << e.what(); - } - catch (std::exception& e) - { - LOG(ERROR) << "Exception while loading XML metadata file: " << e.what(); - } -} - -std::vector GnssMetadataHandler::make_stream_sources(const std::vector& stream_ids) const -{ - std::vector sources{}; - for (const auto& file : metadata_.Files()) - { - for (const auto& lane : metadata_.Lanes()) - { - if (lane.Id() == file.Lane().Id()) - { - for (const auto& block : lane.Blocks()) - { - for (const auto& chunk : block.Chunks()) - { - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) - { - auto source = gnss_make_shared( - metadata_filepath_, - file, - block, - stream_ids); - - sources.push_back(source); - - // This file source will take care of any other matching streams in this block - // We can skip the rest of this block - goto next_block; - } - } - } - } - next_block: - } - break; - } - } - } - - return sources; -} - - -IONMetadataStdFileSource::IONMetadataStdFileSource( - const std::filesystem::path& metadata_filepath, - const GnssMetadata::File& file, - const GnssMetadata::Block& block, - const std::vector& stream_ids) - : gr::sync_block( - "ion_metadata_standard_source", - gr::io_signature::make(0, 0, 0), - make_output_signature(block, stream_ids)), - file_metadata_(file), - block_metadata_(block) -{ - std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); - fd_ = std::fopen(data_filepath.c_str(), "rb"); - std::size_t block_offset = file.Offset(); - std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); - - std::size_t output_stream_offset = 0; - for (const auto& chunk : block.Chunks()) - { - chunk_data_.emplace_back(std::make_shared(chunk, stream_ids, output_stream_offset)); - const std::size_t out_count = chunk_data_.back()->output_stream_count(); - output_stream_offset += out_count; - for (std::size_t i = 0; i < out_count; ++i) - { - output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); - } - } - output_stream_count_ = output_stream_offset; -} - -IONMetadataStdFileSource::~IONMetadataStdFileSource() -{ - std::fclose(fd_); -} - -int IONMetadataStdFileSource::work( - int noutput_items, - gr_vector_const_void_star& input_items, - gr_vector_void_star& output_items) -{ - for (int i = 0; i < noutput_items; ++i) - { - read_chunk_pattern(output_items); - } - return WORK_CALLED_PRODUCE; -} - -std::size_t IONMetadataStdFileSource::output_stream_count() const -{ - return output_stream_count_; -} - -std::size_t IONMetadataStdFileSource::output_stream_item_size(std::size_t stream_index) const -{ - return output_stream_item_sizes_[stream_index]; -} - - -void IONMetadataStdFileSource::read_chunk_pattern(gr_vector_void_star& output_items) -{ - gr_vector_void_star chunk_outputs = output_items; - for (auto& c : chunk_data_) - { - c->read_from_file(fd_); - c->write_to_output(output_items, [this](int output, int nitems) { - produce(output, nitems); - }); - } -} - -gr::io_signature::sptr IONMetadataStdFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) -{ - int nstreams = 0; - std::vector item_sizes{}; - - for (const auto& chunk : block.Chunks()) - { - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) - { - ++nstreams; - std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); - if (sample_bitsize <= 8) - { - item_sizes.push_back(1); - } - else if (sample_bitsize <= 16) - { - item_sizes.push_back(2); - } - else if (sample_bitsize <= 32) - { - item_sizes.push_back(4); - } - else if (sample_bitsize <= 64) - { - item_sizes.push_back(8); - } - else - { - // This shouldn't happen - item_sizes.push_back(1); - } - } - } - } - } - - return gr::io_signature::make( - nstreams, - nstreams, - item_sizes); -} - - -chunk_data_t::chunk_data_t(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset) - : chunk_(chunk), - sizeword_(chunk_.SizeWord()), - countwords_(chunk_.CountWords()) -{ - switch (sizeword_) - { - case 1: - buffer_ = new uint8_t[countwords_]; - break; - case 2: - buffer_ = new uint16_t[countwords_]; - break; - case 4: - buffer_ = new uint32_t[countwords_]; - break; - case 8: - buffer_ = new uint64_t[countwords_]; - break; - default: - LOG(ERROR) << "Unknown word size: " << std::to_string(sizeword_); - break; - } - - - const std::size_t total_bitsize = sizeword_ * countwords_ * 8; - std::size_t used_bitsize = 0; - std::size_t output_streams = 0; - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - used_bitsize += stream.Packedbits(); - - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) - { - streams_.emplace_back(lump, stream, output_streams + output_stream_offset); - ++output_streams; - std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); - if (sample_bitsize <= 8) - { - output_stream_item_size_.push_back(1); - } - else if (sample_bitsize <= 16) - { - output_stream_item_size_.push_back(2); - } - else if (sample_bitsize <= 32) - { - output_stream_item_size_.push_back(4); - } - else if (sample_bitsize <= 64) - { - output_stream_item_size_.push_back(8); - } - else - { - // This shouldn't happen - output_stream_item_size_.push_back(1); - } - } - else - { - streams_.emplace_back(lump, stream, -1); - } - } - } - - output_stream_count_ = output_streams; - padding_bitsize_ = total_bitsize - used_bitsize; -} -chunk_data_t::~chunk_data_t() -{ - switch (sizeword_) - { - case 1: - delete[] static_cast(buffer_); - break; - case 2: - delete[] static_cast(buffer_); - break; - case 4: - delete[] static_cast(buffer_); - break; - case 8: - delete[] static_cast(buffer_); - break; - default: - break; - } -} - -void chunk_data_t::read_from_file(FILE* fd) -{ - std::fread(buffer_, sizeword_, countwords_, fd); -} - -void chunk_data_t::write_to_output(gr_vector_void_star& outputs, const std::function& produce) -{ - switch (sizeword_) - { - case 1: - unpack_words(outputs, produce); - break; - case 2: - unpack_words(outputs, produce); - break; - case 4: - unpack_words(outputs, produce); - break; - case 8: - unpack_words(outputs, produce); - break; - default: - break; - } -} - -std::size_t chunk_data_t::output_stream_count() const -{ - return output_stream_count_; -} - -std::size_t chunk_data_t::output_stream_item_size(std::size_t stream_index) const -{ - return output_stream_item_size_[stream_index]; -} diff --git a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h b/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h deleted file mode 100644 index 0543de71d..000000000 --- a/src/algorithms/signal_source/libs/ion_gnss_sdr_metadata_standard.h +++ /dev/null @@ -1,321 +0,0 @@ -// -// Created by castle on 6/24/24. -// - -#ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H -#define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H - -#include "GnssMetadata.h" -#include "gnss_block_interface.h" -#include -#include -#include - -class chunk_data_t -{ -public: - chunk_data_t(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset); - - ~chunk_data_t(); - - chunk_data_t(const chunk_data_t& rhl) = delete; - chunk_data_t& operator=(const chunk_data_t& rhl) = delete; - - chunk_data_t(chunk_data_t&& rhl) = delete; - chunk_data_t& operator=(chunk_data_t&& rhl) = delete; - - void read_from_file(FILE* fd); - - void write_to_output(gr_vector_void_star& outputs, const std::function& produce); - - std::size_t output_stream_count() const; - std::size_t output_stream_item_size(std::size_t stream_index) const; - -private: - template - struct unpacking_context_t - { - WT* iterator_; - WT current_word_; - uint8_t bitshift_ = 0; - }; - - template - void unpack_words(gr_vector_void_star& outputs, const std::function& produce) - { - WT* data = static_cast(buffer_); - // TODO - Swap endiannes if needed - - unpacking_context_t ctx{}; - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.iterator_ = data; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.iterator_ = &data[countwords_]; - } - advance_word(ctx); // Initializes ctx.current_word_ - - // Head padding - if (padding_bitsize_ > 0 && chunk_.Padding() == GnssMetadata::Chunk::Head) - { - shift_padding(ctx, padding_bitsize_); - } - - // Samples - for (const auto& [lump, stream, output_index] : streams_) - { - if (output_index == -1) - { - skip_stream(ctx, lump, stream); - } - else - { - produce(output_index, write_stream_samples(ctx, lump, stream, outputs[output_index])); - } - } - } - - template - void skip_stream( - unpacking_context_t& ctx, - const GnssMetadata::Lump& lump, - const GnssMetadata::IonStream& stream) - { - shift_padding(ctx, stream.Packedbits()); - } - - template - std::size_t write_stream_samples( - unpacking_context_t& ctx, - const GnssMetadata::Lump& lump, - const GnssMetadata::IonStream& stream, - void*& out) - { - std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); - std::size_t sample_count = stream.RateFactor(); - if (sample_bitsize <= 8) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); - } - else if (sample_bitsize <= 16) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); - } - else if (sample_bitsize <= 32) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); - } - else if (sample_bitsize <= 64) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, out); - } - - return sample_count; - } - - template - void write_n_samples( - unpacking_context_t& ctx, - GnssMetadata::Lump::LumpShift lump_shift, - uint8_t sample_bitsize, - std::size_t sample_count, - void*& out) - { - if (lump_shift == GnssMetadata::Lump::shiftLeft) - { - auto* sample = static_cast(out); - for (int i = 0; i < sample_count; ++i) - { - shift_sample(ctx, sample_bitsize, sample); - ++sample; - } - } - else if (lump_shift == GnssMetadata::Lump::shiftRight) - { - auto* sample = static_cast(out); - sample += sample_count; - for (int i = 0; i < sample_count; ++i) - { - shift_sample(ctx, sample_bitsize, sample); - --sample; - } - } - } - - template - void shift_sample(unpacking_context_t& ctx, uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) - { - const uint8_t word_bitsize = sizeword_ * 8; - - if ((sample_bitsize + (ctx.bitshift_ % word_bitsize)) > word_bitsize) - { - uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); - - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - WT mask = ~((1 << (word_bitsize - bits_shifted)) - 1); - *output |= ((ctx.current_word_ & mask) >> output_bit_offset); - ctx.current_word_ <<= bits_shifted; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - WT mask = ((1 << (bits_shifted)) - 1); - *output |= (ctx.current_word_ & mask) << output_bit_offset; - // TODO - reverse bit order of sample? maybe? - ctx.current_word_ >>= bits_shifted; - } - - advance_word(ctx); - ctx.bitshift_ += bits_shifted; - shift_sample(ctx, sample_bitsize - bits_shifted, output, bits_shifted); - } - else - { - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - WT mask = ~((1 << (word_bitsize - sample_bitsize)) - 1); - *output |= (ctx.current_word_ & mask) >> output_bit_offset; - ctx.current_word_ <<= sample_bitsize; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - WT mask = ((1 << (sample_bitsize)) - 1); - *output |= (ctx.current_word_ & mask) << output_bit_offset; - // TODO - reverse bit order of sample? maybe? - ctx.current_word_ >>= sample_bitsize; - } - - ctx.bitshift_ += sample_bitsize; - } - } - - template - void shift_padding(unpacking_context_t& ctx, uint8_t n_bits) - { - const uint8_t word_bitsize = sizeword_ * 8; - - if ((n_bits + (ctx.bitshift_ % word_bitsize)) > word_bitsize) - { - uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); - - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.current_word_ <<= bits_shifted; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.current_word_ >>= bits_shifted; - } - - advance_word(ctx); - ctx.bitshift_ += bits_shifted; - shift_padding(ctx, n_bits - bits_shifted); - } - else - { - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.current_word_ <<= n_bits; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.current_word_ >>= n_bits; - } - - ctx.bitshift_ += n_bits; - } - } - - template - void advance_word(unpacking_context_t& ctx) - { - WT word = *ctx.iterator_; - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ++ctx.iterator_; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - --ctx.iterator_; - } - - ctx.current_word_ = word; - } - -private: - const GnssMetadata::Chunk& chunk_; - uint8_t sizeword_; - uint8_t countwords_; - uint8_t padding_bitsize_; - std::size_t output_stream_count_; - std::vector output_stream_item_size_; - - struct stream_metadata_t - { - const GnssMetadata::Lump& lump; - const GnssMetadata::IonStream& stream; - int output_index = -1; - }; - std::vector streams_; - - void* buffer_; -}; - -class IONMetadataStdFileSource : public gr::sync_block -{ -public: - using sptr = gnss_shared_ptr; - - IONMetadataStdFileSource( - const std::filesystem::path& metadata_filepath, - const GnssMetadata::File& file, - const GnssMetadata::Block& block, - const std::vector& stream_ids); - - ~IONMetadataStdFileSource() override; - - int work( - int noutput_items, - gr_vector_const_void_star& input_items, - gr_vector_void_star& output_items) override; - - std::size_t output_stream_count() const; - std::size_t output_stream_item_size(std::size_t stream_index) const; - -private: - void read_chunk_pattern(gr_vector_void_star& output_items); - -private: - static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); - -private: - const GnssMetadata::File& file_metadata_; - const GnssMetadata::Block& block_metadata_; - FILE* fd_; - std::size_t output_stream_count_; - std::vector output_stream_item_sizes_; - std::vector> chunk_data_; -}; - -class GnssMetadataHandler -{ -public: - explicit GnssMetadataHandler(const std::string& metadata_filepath); - - std::vector make_stream_sources(const std::vector& stream_ids) const; - -public: // Getters - const std::string& metadata_filepath() const; - -private: - void load_metadata(); - -private: - std::string metadata_filepath_; - GnssMetadata::Metadata metadata_; -}; - - -#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc new file mode 100644 index 000000000..8110b3af1 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -0,0 +1,123 @@ +/*! + * \file ion_gsms.cc + * \brief GNU Radio block that reads a Block from a file following ION's GNSS-SDR metadata standard + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "gnuradio/block.h" +#include "ion_gsms.h" + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include + +#include +#endif + + +IONGSMSFileSource::IONGSMSFileSource( + const std::filesystem::path& metadata_filepath, + const GnssMetadata::File& file, + const GnssMetadata::Block& block, + const std::vector& stream_ids) + : gr::sync_block( + "ion_metadata_standard_source", + gr::io_signature::make(0, 0, 0), + make_output_signature(block, stream_ids)), + file_metadata_(file), + block_metadata_(block) +{ + std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); + fd_ = std::fopen(data_filepath.c_str(), "rb"); + std::size_t block_offset = file.Offset(); + std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); + + std::size_t output_stream_offset = 0; + for (const auto& chunk : block.Chunks()) + { + chunk_data_.emplace_back(std::make_shared(chunk, stream_ids, output_stream_offset)); + const std::size_t out_count = chunk_data_.back()->output_stream_count(); + output_stream_offset += out_count; + for (std::size_t i = 0; i < out_count; ++i) + { + output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); + } + } + output_stream_count_ = output_stream_offset; +} + +IONGSMSFileSource::~IONGSMSFileSource() +{ + std::fclose(fd_); +} + +int IONGSMSFileSource::work( + int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) +{ + // for (int i = 0; i < noutput_items; ++i) + // { + for (auto& c : chunk_data_) + { + c->read_from_file(fd_); + c->write_to_output(output_items, [&](int output, int nitems) { + produce(output, nitems); + }); + } + // } + return WORK_CALLED_PRODUCE; +} + +std::size_t IONGSMSFileSource::output_stream_count() const +{ + return output_stream_count_; +} + +std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) const +{ + return output_stream_item_sizes_[stream_index]; +} + + +gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) +{ + int nstreams = 0; + std::vector item_sizes{}; + + for (const auto& chunk : block.Chunks()) + { + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + ++nstreams; + const std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + item_sizes.push_back(bits_to_item_size(sample_bitsize)); + } + } + } + } + + return gr::io_signature::make( + nstreams, + nstreams, + item_sizes); +} + + diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h new file mode 100644 index 000000000..a15206b84 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -0,0 +1,64 @@ +/*! + * \file ion_gsms.h + * \brief GNU Radio block that reads a Block from a file following ION's GNSS-SDR metadata standard + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H + +#include "gnss_block_interface.h" +#include "ion_gsms_chunk_data.h" +#include +#include +#include +#include + + +class IONGSMSFileSource : public gr::sync_block +{ +public: + using sptr = gnss_shared_ptr; + + IONGSMSFileSource( + const std::filesystem::path& metadata_filepath, + const GnssMetadata::File& file, + const GnssMetadata::Block& block, + const std::vector& stream_ids); + + ~IONGSMSFileSource() override; + + int work( + int noutput_items, + gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) override; + + std::size_t output_stream_count() const; + std::size_t output_stream_item_size(std::size_t stream_index) const; + +private: + static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); + +private: + const GnssMetadata::File& file_metadata_; + const GnssMetadata::Block& block_metadata_; + FILE* fd_; + std::size_t output_stream_count_; + std::vector output_stream_item_sizes_; + std::vector> chunk_data_; +}; + +#include "ion_gsms_metadata_handler.h" + + +#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc new file mode 100644 index 000000000..f961772a0 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -0,0 +1,108 @@ +/*! + * \file ion_gsms_chunk_data.cc + * \brief Holds logic for reading and decoding samples from a chunk + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "ion_gsms_chunk_data.h" +#include + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset) + : chunk_(chunk), + sizeword_(chunk_.SizeWord()), + countwords_(chunk_.CountWords()) +{ + with_word_type(sizeword_, [&] + { + buffer_ = new WordType[countwords_]; + }); + + const std::size_t total_bitsize = sizeword_ * countwords_ * 8; + std::size_t used_bitsize = 0; + std::size_t output_streams = 0; + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + used_bitsize += stream.Packedbits(); + + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()),output_streams + output_stream_offset); + ++output_streams; + const std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + output_stream_item_size_.push_back(bits_to_item_size(sample_bitsize)); + } + else + { + streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()), -1); + } + } + } + + output_stream_count_ = output_streams; + padding_bitsize_ = total_bitsize - used_bitsize; +} + + +IONGSMSChunkData::~IONGSMSChunkData() +{ + with_word_type(sizeword_, [&] + { + delete[] static_cast(buffer_); + }); +} + +void IONGSMSChunkData::read_from_file(FILE* fd) +{ + std::fread(buffer_, sizeword_, countwords_, fd); +} + +void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, const std::function& produce) +{ + with_word_type(sizeword_, [&] + { + unpack_words(outputs, produce); + }); +} + +std::size_t IONGSMSChunkData::output_stream_count() const +{ + return output_stream_count_; +} + +std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) const +{ + return output_stream_item_size_[stream_index]; +} + + + +void IONGSMSChunkData::dump_sample(auto value) +{ + static int count = 100; + if (count > 0) + { + --count; + std::cout << "SAMPLE: " << std::bitset<32>(value) << std::endl; + } +} + diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h new file mode 100644 index 000000000..f87a03aef --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -0,0 +1,510 @@ +/*! + * \file ion_gsms_chunk_data.h + * \brief Holds logic for reading and decoding samples from a chunk + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef ION_GSM_CHUNK_DATA_H +#define ION_GSM_CHUNK_DATA_H + +#include "GnssMetadata.h" +#include + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +inline std::size_t bits_to_item_size(const std::size_t bit_count) +{ + if (bit_count <= 8) + { + return 1; + } + if (bit_count <= 16) + { + return 2; + } + if (bit_count <= 32) + { + return 4; + } + if (bit_count <= 64) + { + return 8; + } + + // You are asking too much of this humble processor + LOG(ERROR) << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense."; + return 1; +} + +void with_word_type(const uint8_t word_size, auto&& callback) +{ + switch (word_size) + { + case 1: + callback.template operator()(); + break; + case 2: + callback.template operator()(); + break; + case 4: + callback.template operator()(); + break; + case 8: + callback.template operator()(); + break; + default: + LOG(ERROR) << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense."; + break; + } +} + +namespace GnssMetadata +{ + using StreamEncoding = unsigned char; + + namespace StreamEncodings + { + constexpr unsigned char SIGN = 0; + constexpr unsigned char OB = 1; + constexpr unsigned char SM = 2; + constexpr unsigned char MS = 3; + constexpr unsigned char TC = 4; + constexpr unsigned char OG = 5; + constexpr unsigned char OBA = 6; + constexpr unsigned char SMA = 7; + constexpr unsigned char MSA = 8; + constexpr unsigned char TCA = 9; + constexpr unsigned char OGA = 10; + constexpr unsigned char FP = 11; + } + + inline StreamEncoding encoding_from_string(const std::string& str) + { + if (str == "SIGN") + { + return StreamEncodings::SIGN; + } + if (str == "OB") + { + return StreamEncodings::OB; + } + if (str == "SM") + { + return StreamEncodings::SM; + } + if (str == "MS") + { + return StreamEncodings::MS; + } + if (str == "TC") + { + return StreamEncodings::TC; + } + if (str == "OG") + { + return StreamEncodings::OG; + } + if (str == "OBA") + { + return StreamEncodings::OBA; + } + if (str == "SMA") + { + return StreamEncodings::SMA; + } + if (str == "MSA") + { + return StreamEncodings::MSA; + } + if (str == "TCA") + { + return StreamEncodings::TCA; + } + if (str == "OGA") + { + return StreamEncodings::OGA; + } + if (str == "FP") + { + return StreamEncodings::FP; + } + return 0; + } + + template + inline T two_bit_look_up[11][4] + { + [0] = {}, + [1 /*OB*/] = {-2, -1, 0, 1}, + [2 /*SM*/] = {0, 1, 0, -1}, + [3 /*MS*/] = {0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, -2, -1}, + [5 /*OG*/] = {-2, -1, 1, 0}, + [6 /*OBA*/] = {-3, -1, 1, 3}, + [7 /*SMA*/] = {1, 3, -1, -3}, + [8 /*MSA*/] = {1, -1, 3, -3}, + [9 /*TCA*/] = {1, 3, -3, -1}, + [10 /*OGA*/] = {-3, -1, 3, 1}, + }; + + template + inline T three_bit_look_up[11][8] + { + [0] = {}, + [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, + [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, + [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, + [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, + [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, + [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, + [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, + }; + + template + inline T four_bit_look_up[11][16] + { + [0] = {}, + [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, + [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, + }; + + template + inline T five_bit_look_up[11][32] + { + [0] = {}, + [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, + [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, + }; +} + +class IONGSMSChunkData +{ +public: + IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset); + + ~IONGSMSChunkData(); + + IONGSMSChunkData(const IONGSMSChunkData& rhl) = delete; + IONGSMSChunkData& operator=(const IONGSMSChunkData& rhl) = delete; + + IONGSMSChunkData(IONGSMSChunkData&& rhl) = delete; + IONGSMSChunkData& operator=(IONGSMSChunkData&& rhl) = delete; + + void read_from_file(FILE* fd); + + void write_to_output(gr_vector_void_star& outputs, const std::function& produce); + + std::size_t output_stream_count() const; + std::size_t output_stream_item_size(std::size_t stream_index) const; + +private: + template + struct unpacking_context_t + { + WT* iterator_; + WT current_word_; + uint8_t bitshift_ = 0; + }; + + template + void unpack_words(gr_vector_void_star& outputs, const std::function& produce) + { + WT* data = static_cast(buffer_); + // TODO - Swap endiannes if needed + + unpacking_context_t ctx{}; + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.iterator_ = data; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.iterator_ = &data[countwords_]; + } + advance_word(ctx); // Initializes ctx.current_word_ + + // Head padding + if (padding_bitsize_ > 0 && chunk_.Padding() == GnssMetadata::Chunk::Head) + { + shift_padding(ctx, padding_bitsize_); + } + + // Samples + for (const auto& [lump, stream, encoding, output_index] : streams_) + { + if (output_index == -1) + { + skip_stream(ctx, lump, stream); + } + else + { + produce(output_index, write_stream_samples(ctx, lump, stream, encoding, outputs[output_index])); + } + } + } + + template + void skip_stream( + unpacking_context_t& ctx, + const GnssMetadata::Lump& lump, + const GnssMetadata::IonStream& stream) + { + shift_padding(ctx, stream.Packedbits()); + } + + template + std::size_t write_stream_samples( + unpacking_context_t& ctx, + const GnssMetadata::Lump& lump, + const GnssMetadata::IonStream& stream, + const GnssMetadata::StreamEncoding stream_encoding, + void*& out) + { + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_count = stream.RateFactor(); + + if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) + { + // Samples have 'Complex' format + sample_bitsize /= 2; + sample_count *= 2; + } + + if (sample_bitsize <= 8) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 16) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 32) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 64) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + + return sample_count; + } + + template + void write_n_samples( + unpacking_context_t& ctx, + GnssMetadata::Lump::LumpShift lump_shift, + uint8_t sample_bitsize, + std::size_t sample_count, + GnssMetadata::StreamEncoding stream_encoding, + void*& out) + { + if (lump_shift == GnssMetadata::Lump::shiftRight) + { + auto* sample = static_cast(out); + sample += sample_count; + for (std::size_t i = 0; i < sample_count; ++i) + { + shift_sample(ctx, sample_bitsize, sample); + decode_sample(sample_bitsize, sample, stream_encoding); + --sample; + } + } + else // if (lump_shift == GnssMetadata::Lump::shiftLeft || lump_shift == GnssMetadata::Lump::shiftUndefined) + { + auto* sample = static_cast(out); + for (std::size_t i = 0; i < sample_count; ++i) + { + shift_sample(ctx, sample_bitsize, sample); + decode_sample(sample_bitsize, sample, stream_encoding); + ++sample; + } + } + } + + template + void shift_sample(unpacking_context_t& ctx, uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) + { + const uint8_t word_bitsize = sizeword_ * 8; + + if ((sample_bitsize + (ctx.bitshift_ % word_bitsize)) > word_bitsize) + { + uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); + + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize - bits_shifted)) - 1); + dump_sample(ctx.current_word_ & mask); + *output |= ((ctx.current_word_ & mask) >> output_bit_offset); + ctx.current_word_ <<= bits_shifted; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (bits_shifted)) - 1); + dump_sample(ctx.current_word_ & mask); + *output |= (ctx.current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + ctx.current_word_ >>= bits_shifted; + } + + advance_word(ctx); + ctx.bitshift_ += bits_shifted; + shift_sample(ctx, sample_bitsize - bits_shifted, output, bits_shifted); + } + else + { + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize - sample_bitsize)) - 1); + OT sample = (ctx.current_word_ & mask) >> (word_bitsize - sample_bitsize); + dump_sample(sample); + *output |= (sample) >> output_bit_offset; + ctx.current_word_ <<= sample_bitsize; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (sample_bitsize)) - 1); + dump_sample(ctx.current_word_ & mask); + *output |= (ctx.current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + ctx.current_word_ >>= sample_bitsize; + } + + ctx.bitshift_ += sample_bitsize; + } + } + + template + void shift_padding(unpacking_context_t& ctx, uint8_t n_bits) + { + if(n_bits == 0) return; + + const uint8_t word_bitsize = sizeword_ * 8; + + if ((n_bits + (ctx.bitshift_ % word_bitsize)) >= word_bitsize) + { + uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); + + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.current_word_ <<= bits_shifted; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.current_word_ >>= bits_shifted; + } + + advance_word(ctx); + ctx.bitshift_ += bits_shifted; + shift_padding(ctx, n_bits - bits_shifted); + } + else + { + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ctx.current_word_ <<= n_bits; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + ctx.current_word_ >>= n_bits; + } + + ctx.bitshift_ += n_bits; + } + } + + template + void advance_word(unpacking_context_t& ctx) + { + WT word = *ctx.iterator_; + if (chunk_.Shift() == GnssMetadata::Chunk::Left) + { + ++ctx.iterator_; + } + else if (chunk_.Shift() == GnssMetadata::Chunk::Right) + { + --ctx.iterator_; + } + + ctx.current_word_ = word; + } + + template + static void decode_sample(const uint8_t sample_bitsize, ST* sample, const GnssMetadata::StreamEncoding encoding) + { + switch (sample_bitsize) + { + case 2: + *sample = GnssMetadata::two_bit_look_up[encoding][*sample]; + break; + case 3: + *sample = GnssMetadata::three_bit_look_up[encoding][*sample]; + break; + case 4: + *sample = GnssMetadata::four_bit_look_up[encoding][*sample]; + break; + case 5: + *sample = GnssMetadata::five_bit_look_up[encoding][*sample]; + break; + default: + // TODO - Is this an error that can happen? + break; + } + } + + static void dump_sample(auto value); + +private: + const GnssMetadata::Chunk& chunk_; + uint8_t sizeword_; + uint8_t countwords_; + uint8_t padding_bitsize_; + std::size_t output_stream_count_; + std::vector output_stream_item_size_; + + struct stream_metadata_t + { + const GnssMetadata::Lump& lump; + const GnssMetadata::IonStream& stream; + GnssMetadata::StreamEncoding stream_encoding; + int output_index = -1; + }; + std::vector streams_; + + void* buffer_; +}; + +#endif //ION_GSM_CHUNK_DATA_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc new file mode 100644 index 000000000..48aced035 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -0,0 +1,101 @@ +/*! + * \file ion_gsms_metadata_handler.cc + * \brief Build instances of IONGSMSFileSource as needed given a list of stream ids + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "ion_gsms.h" + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +IONGSMSMetadataHandler::IONGSMSMetadataHandler(const std::string& metadata_filepath) + : metadata_filepath_(metadata_filepath) +{ + load_metadata(); +} + +const std::string& IONGSMSMetadataHandler::metadata_filepath() const +{ + return metadata_filepath_; +} + +void IONGSMSMetadataHandler::load_metadata() +{ + try + { + GnssMetadata::XmlProcessor xml_proc; + if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) + { + LOG(ERROR) << "Could not load XML metadata file:"; + } + } + catch (GnssMetadata::ApiException& e) + { + LOG(ERROR) << "API Exception while loadind XML metadata file: " << e.what(); + } + catch (std::exception& e) + { + LOG(ERROR) << "Exception while loading XML metadata file: " << e.what(); + } +} + +std::vector IONGSMSMetadataHandler::make_stream_sources(const std::vector& stream_ids) const +{ + std::vector sources{}; + for (const auto& file : metadata_.Files()) + { + for (const auto& lane : metadata_.Lanes()) + { + if (lane.Id() == file.Lane().Id()) + { + for (const auto& block : lane.Blocks()) + { + for (const auto& chunk : block.Chunks()) + { + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { + return stream.Id() == it; + })) + { + auto source = gnss_make_shared( + metadata_filepath_, + file, + block, + stream_ids); + + sources.push_back(source); + + // This file source will take care of any other matching streams in this block + // We can skip the rest of this block + goto next_block; + } + } + } + } + next_block: + } + break; + } + } + } + + return sources; +} + diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h new file mode 100644 index 000000000..0cbf634f6 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -0,0 +1,47 @@ +/*! + * \file ion_gsms_metadata_handler.h + * \brief Build instances of IONGSMSFileSource as needed given a list of stream ids + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef ION_GSMS_METADATA_HANDLER_H +#define ION_GSMS_METADATA_HANDLER_H + +#include "GnssMetadata.h" +#include + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +class IONGSMSMetadataHandler +{ +public: + explicit IONGSMSMetadataHandler(const std::string& metadata_filepath); + + std::vector make_stream_sources(const std::vector& stream_ids) const; + +public: // Getters + const std::string& metadata_filepath() const; + +private: // Private methods + void load_metadata(); + +private: // State + std::string metadata_filepath_; + GnssMetadata::Metadata metadata_; +}; + +#endif //ION_GSMS_METADATA_HANDLER_H diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 69406a711..99a05e95c 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -93,6 +93,7 @@ #include "ibyte_to_complex.h" #include "ibyte_to_cshort.h" #include "in_memory_configuration.h" +#include "ion_gsms_signal_source.h" #include "ishort_to_complex.h" #include "ishort_to_cshort.h" #include "labsat_signal_source.h" @@ -113,7 +114,6 @@ #include "tracking_interface.h" #include "two_bit_cpx_file_signal_source.h" #include "two_bit_packed_file_signal_source.h" -#include "ion_gnss_ms_signal_source.h" #include // for exit #include // for exception #include // for cerr @@ -760,9 +760,9 @@ std::unique_ptr GNSSBlockFactory::GetBlock( block = std::move(block_); } #endif - else if (implementation == "ION_Metadata_Standard_Signal_Source") + else if (implementation == "ION_GSMS_Signal_Source") { - std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, + std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, out_streams, queue); block = std::move(block_); } From 00fd1821b17f0512b13dc556d6478989c7271c95 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Tue, 23 Jul 2024 15:24:28 +0200 Subject: [PATCH 08/66] Fixed sample count error & refactored --- .../adapters/ion_gsms_signal_source.cc | 2 +- .../signal_source/libs/CMakeLists.txt | 2 + src/algorithms/signal_source/libs/ion_gsms.cc | 9 +- .../signal_source/libs/ion_gsms_chunk_data.cc | 140 ++++++- .../signal_source/libs/ion_gsms_chunk_data.h | 386 +----------------- .../libs/ion_gsms_chunk_unpacking_ctx.h | 153 +++++++ .../libs/ion_gsms_stream_encodings.h | 164 ++++++++ 7 files changed, 474 insertions(+), 382 deletions(-) create mode 100644 src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h create mode 100644 src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index e4becf5e3..d01268d67 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -53,7 +53,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura unsigned int in_streams, unsigned int out_streams, Concurrent_Queue* queue) - : SignalSourceBase(configuration, role, "ION_Metadata_Standard_Signal_Source"s), + : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), metadata_file_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), metadata_(metadata_file_), diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index fb7faf9ee..36f327931 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -52,6 +52,8 @@ if(ENABLE_ION) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_data.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_metadata_handler.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_metadata_handler.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_stream_encodings.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_unpacking_ctx.h) endif() diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 8110b3af1..2034f12d1 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -32,7 +32,7 @@ IONGSMSFileSource::IONGSMSFileSource( const GnssMetadata::Block& block, const std::vector& stream_ids) : gr::sync_block( - "ion_metadata_standard_source", + "ion_gsms_file_source", gr::io_signature::make(0, 0, 0), make_output_signature(block, stream_ids)), file_metadata_(file), @@ -107,7 +107,12 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada })) { ++nstreams; - const std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) + { + // Samples have 'Complex' format + sample_bitsize /= 2; + } item_sizes.push_back(bits_to_item_size(sample_bitsize)); } } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index f961772a0..8a0d1a7b4 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -48,7 +48,12 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: { streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()),output_streams + output_stream_offset); ++output_streams; - const std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) + { + // Samples have 'Complex' format + sample_bitsize /= 2; + } output_stream_item_size_.push_back(bits_to_item_size(sample_bitsize)); } else @@ -95,6 +100,137 @@ std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) } +template +void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::function& produce) +{ + WT* data = static_cast(buffer_); + // TODO - Swap endiannes if needed + + IONGSMSChunkUnpackingCtx ctx{ + chunk_.Shift(), + data, + countwords_, + }; + + // Head padding + if (padding_bitsize_ > 0 && chunk_.Padding() == GnssMetadata::Chunk::Head) + { + ctx.shift_padding(padding_bitsize_); + } + + // Samples + for (const auto& [lump, stream, encoding, output_index] : streams_) + { + if (output_index == -1) + { + // skip stream + ctx.shift_padding(stream.Packedbits()); + } + else + { + produce(output_index, write_stream_samples(ctx, lump, stream, encoding, outputs[output_index])); + } + } +} + +template +std::size_t IONGSMSChunkData::write_stream_samples( + IONGSMSChunkUnpackingCtx& ctx, + const GnssMetadata::Lump& lump, + const GnssMetadata::IonStream& stream, + const GnssMetadata::StreamEncoding stream_encoding, + void*& out) +{ + std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_count = stream.RateFactor(); + + if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) + { + // Samples have 'Complex' format + sample_bitsize /= 2; + sample_count *= 2; + } + + if (sample_bitsize <= 8) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 16) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 32) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + else if (sample_bitsize <= 64) + { + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + } + + return sample_count; +} + +template +void IONGSMSChunkData::write_n_samples( + IONGSMSChunkUnpackingCtx& ctx, + GnssMetadata::Lump::LumpShift lump_shift, + uint8_t sample_bitsize, + std::size_t sample_count, + GnssMetadata::StreamEncoding stream_encoding, + void*& out) +{ + if (lump_shift == GnssMetadata::Lump::shiftRight) + { + auto* sample = static_cast(out); + sample += sample_count; + for (std::size_t i = 0; i < sample_count; ++i) + { + ctx.shift_sample(sample_bitsize, sample); + dump_sample(*sample); + decode_sample(sample_bitsize, sample, stream_encoding); + --sample; + } + } + else // if (lump_shift == GnssMetadata::Lump::shiftLeft || lump_shift == GnssMetadata::Lump::shiftUndefined) + { + auto* sample = static_cast(out); + for (std::size_t i = 0; i < sample_count; ++i) + { + ctx.shift_sample(sample_bitsize, sample); + dump_sample(*sample); + decode_sample(sample_bitsize, sample, stream_encoding); + ++sample; + } + } +} + + + +// Static utilities +void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, auto* sample, const GnssMetadata::StreamEncoding encoding) +{ + using SampleType = std::remove_pointer_t; + switch (sample_bitsize) + { + case 2: + *sample = GnssMetadata::two_bit_look_up[encoding][*sample]; + break; + case 3: + *sample = GnssMetadata::three_bit_look_up[encoding][*sample]; + break; + case 4: + *sample = GnssMetadata::four_bit_look_up[encoding][*sample]; + break; + case 5: + *sample = GnssMetadata::five_bit_look_up[encoding][*sample]; + break; + default: + // TODO - Is this an error that can happen? + // for now we'll just do nothing, if the sample is this wide it may need no decoding + break; + } +} void IONGSMSChunkData::dump_sample(auto value) { @@ -102,7 +238,7 @@ void IONGSMSChunkData::dump_sample(auto value) if (count > 0) { --count; - std::cout << "SAMPLE: " << std::bitset<32>(value) << std::endl; + // std::cout << "SAMPLE: [0x" << std::hex << value << "] " << std::bitset<32>(value) << std::endl; } } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index f87a03aef..c5fc3e6f7 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -18,6 +18,8 @@ #define ION_GSM_CHUNK_DATA_H #include "GnssMetadata.h" +#include "ion_gsms_stream_encodings.h" +#include "ion_gsms_chunk_unpacking_ctx.h" #include #if USE_GLOG_AND_GFLAGS @@ -72,144 +74,6 @@ void with_word_type(const uint8_t word_size, auto&& callback) } } -namespace GnssMetadata -{ - using StreamEncoding = unsigned char; - - namespace StreamEncodings - { - constexpr unsigned char SIGN = 0; - constexpr unsigned char OB = 1; - constexpr unsigned char SM = 2; - constexpr unsigned char MS = 3; - constexpr unsigned char TC = 4; - constexpr unsigned char OG = 5; - constexpr unsigned char OBA = 6; - constexpr unsigned char SMA = 7; - constexpr unsigned char MSA = 8; - constexpr unsigned char TCA = 9; - constexpr unsigned char OGA = 10; - constexpr unsigned char FP = 11; - } - - inline StreamEncoding encoding_from_string(const std::string& str) - { - if (str == "SIGN") - { - return StreamEncodings::SIGN; - } - if (str == "OB") - { - return StreamEncodings::OB; - } - if (str == "SM") - { - return StreamEncodings::SM; - } - if (str == "MS") - { - return StreamEncodings::MS; - } - if (str == "TC") - { - return StreamEncodings::TC; - } - if (str == "OG") - { - return StreamEncodings::OG; - } - if (str == "OBA") - { - return StreamEncodings::OBA; - } - if (str == "SMA") - { - return StreamEncodings::SMA; - } - if (str == "MSA") - { - return StreamEncodings::MSA; - } - if (str == "TCA") - { - return StreamEncodings::TCA; - } - if (str == "OGA") - { - return StreamEncodings::OGA; - } - if (str == "FP") - { - return StreamEncodings::FP; - } - return 0; - } - - template - inline T two_bit_look_up[11][4] - { - [0] = {}, - [1 /*OB*/] = {-2, -1, 0, 1}, - [2 /*SM*/] = {0, 1, 0, -1}, - [3 /*MS*/] = {0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, -2, -1}, - [5 /*OG*/] = {-2, -1, 1, 0}, - [6 /*OBA*/] = {-3, -1, 1, 3}, - [7 /*SMA*/] = {1, 3, -1, -3}, - [8 /*MSA*/] = {1, -1, 3, -3}, - [9 /*TCA*/] = {1, 3, -3, -1}, - [10 /*OGA*/] = {-3, -1, 3, 1}, - }; - - template - inline T three_bit_look_up[11][8] - { - [0] = {}, - [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, - [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, - [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, - [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, - [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, - [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, - [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, - }; - - template - inline T four_bit_look_up[11][16] - { - [0] = {}, - [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, - [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, - }; - - template - inline T five_bit_look_up[11][32] - { - [0] = {}, - [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, - [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, - }; -} - class IONGSMSChunkData { public: @@ -232,258 +96,26 @@ public: private: template - struct unpacking_context_t - { - WT* iterator_; - WT current_word_; - uint8_t bitshift_ = 0; - }; - - template - void unpack_words(gr_vector_void_star& outputs, const std::function& produce) - { - WT* data = static_cast(buffer_); - // TODO - Swap endiannes if needed - - unpacking_context_t ctx{}; - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.iterator_ = data; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.iterator_ = &data[countwords_]; - } - advance_word(ctx); // Initializes ctx.current_word_ - - // Head padding - if (padding_bitsize_ > 0 && chunk_.Padding() == GnssMetadata::Chunk::Head) - { - shift_padding(ctx, padding_bitsize_); - } - - // Samples - for (const auto& [lump, stream, encoding, output_index] : streams_) - { - if (output_index == -1) - { - skip_stream(ctx, lump, stream); - } - else - { - produce(output_index, write_stream_samples(ctx, lump, stream, encoding, outputs[output_index])); - } - } - } - - template - void skip_stream( - unpacking_context_t& ctx, - const GnssMetadata::Lump& lump, - const GnssMetadata::IonStream& stream) - { - shift_padding(ctx, stream.Packedbits()); - } + void unpack_words(gr_vector_void_star& outputs, const std::function& produce); template std::size_t write_stream_samples( - unpacking_context_t& ctx, + IONGSMSChunkUnpackingCtx& ctx, const GnssMetadata::Lump& lump, const GnssMetadata::IonStream& stream, - const GnssMetadata::StreamEncoding stream_encoding, - void*& out) - { - std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); - std::size_t sample_count = stream.RateFactor(); - - if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) - { - // Samples have 'Complex' format - sample_bitsize /= 2; - sample_count *= 2; - } - - if (sample_bitsize <= 8) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); - } - else if (sample_bitsize <= 16) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); - } - else if (sample_bitsize <= 32) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); - } - else if (sample_bitsize <= 64) - { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); - } - - return sample_count; - } + GnssMetadata::StreamEncoding stream_encoding, + void*& out); template void write_n_samples( - unpacking_context_t& ctx, + IONGSMSChunkUnpackingCtx& ctx, GnssMetadata::Lump::LumpShift lump_shift, uint8_t sample_bitsize, std::size_t sample_count, GnssMetadata::StreamEncoding stream_encoding, - void*& out) - { - if (lump_shift == GnssMetadata::Lump::shiftRight) - { - auto* sample = static_cast(out); - sample += sample_count; - for (std::size_t i = 0; i < sample_count; ++i) - { - shift_sample(ctx, sample_bitsize, sample); - decode_sample(sample_bitsize, sample, stream_encoding); - --sample; - } - } - else // if (lump_shift == GnssMetadata::Lump::shiftLeft || lump_shift == GnssMetadata::Lump::shiftUndefined) - { - auto* sample = static_cast(out); - for (std::size_t i = 0; i < sample_count; ++i) - { - shift_sample(ctx, sample_bitsize, sample); - decode_sample(sample_bitsize, sample, stream_encoding); - ++sample; - } - } - } + void*& out); - template - void shift_sample(unpacking_context_t& ctx, uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) - { - const uint8_t word_bitsize = sizeword_ * 8; - - if ((sample_bitsize + (ctx.bitshift_ % word_bitsize)) > word_bitsize) - { - uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); - - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - WT mask = ~((1 << (word_bitsize - bits_shifted)) - 1); - dump_sample(ctx.current_word_ & mask); - *output |= ((ctx.current_word_ & mask) >> output_bit_offset); - ctx.current_word_ <<= bits_shifted; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - WT mask = ((1 << (bits_shifted)) - 1); - dump_sample(ctx.current_word_ & mask); - *output |= (ctx.current_word_ & mask) << output_bit_offset; - // TODO - reverse bit order of sample? maybe? - ctx.current_word_ >>= bits_shifted; - } - - advance_word(ctx); - ctx.bitshift_ += bits_shifted; - shift_sample(ctx, sample_bitsize - bits_shifted, output, bits_shifted); - } - else - { - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - WT mask = ~((1 << (word_bitsize - sample_bitsize)) - 1); - OT sample = (ctx.current_word_ & mask) >> (word_bitsize - sample_bitsize); - dump_sample(sample); - *output |= (sample) >> output_bit_offset; - ctx.current_word_ <<= sample_bitsize; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - WT mask = ((1 << (sample_bitsize)) - 1); - dump_sample(ctx.current_word_ & mask); - *output |= (ctx.current_word_ & mask) << output_bit_offset; - // TODO - reverse bit order of sample? maybe? - ctx.current_word_ >>= sample_bitsize; - } - - ctx.bitshift_ += sample_bitsize; - } - } - - template - void shift_padding(unpacking_context_t& ctx, uint8_t n_bits) - { - if(n_bits == 0) return; - - const uint8_t word_bitsize = sizeword_ * 8; - - if ((n_bits + (ctx.bitshift_ % word_bitsize)) >= word_bitsize) - { - uint8_t bits_shifted = word_bitsize - (ctx.bitshift_ % word_bitsize); - - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.current_word_ <<= bits_shifted; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.current_word_ >>= bits_shifted; - } - - advance_word(ctx); - ctx.bitshift_ += bits_shifted; - shift_padding(ctx, n_bits - bits_shifted); - } - else - { - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ctx.current_word_ <<= n_bits; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - ctx.current_word_ >>= n_bits; - } - - ctx.bitshift_ += n_bits; - } - } - - template - void advance_word(unpacking_context_t& ctx) - { - WT word = *ctx.iterator_; - if (chunk_.Shift() == GnssMetadata::Chunk::Left) - { - ++ctx.iterator_; - } - else if (chunk_.Shift() == GnssMetadata::Chunk::Right) - { - --ctx.iterator_; - } - - ctx.current_word_ = word; - } - - template - static void decode_sample(const uint8_t sample_bitsize, ST* sample, const GnssMetadata::StreamEncoding encoding) - { - switch (sample_bitsize) - { - case 2: - *sample = GnssMetadata::two_bit_look_up[encoding][*sample]; - break; - case 3: - *sample = GnssMetadata::three_bit_look_up[encoding][*sample]; - break; - case 4: - *sample = GnssMetadata::four_bit_look_up[encoding][*sample]; - break; - case 5: - *sample = GnssMetadata::five_bit_look_up[encoding][*sample]; - break; - default: - // TODO - Is this an error that can happen? - break; - } - } + static void decode_sample(uint8_t sample_bitsize, auto* sample, GnssMetadata::StreamEncoding encoding); static void dump_sample(auto value); diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h new file mode 100644 index 000000000..249063e4d --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -0,0 +1,153 @@ +/*! + * \file ion_gsms_chunk_unpacking_ctx.h + * \brief Holds state and provides utilities for unpacking samples from a chunk + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * This is a template class, and thus, its member functions must be defined in the header file. + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef ION_GSM_CHUNK_UNPACKING_CTX_H +#define ION_GSM_CHUNK_UNPACKING_CTX_H + +#include "GnssMetadata.h" +#include + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +template +struct IONGSMSChunkUnpackingCtx +{ + static constexpr uint8_t word_bitsize_ = sizeof(WT) * 8; + + const GnssMetadata::Chunk::WordShift word_shift_direction_; + WT* iterator_; // Not owned by this class, must not destroy + WT current_word_; + uint8_t bitshift_ = 0; + + IONGSMSChunkUnpackingCtx( + const GnssMetadata::Chunk::WordShift word_shift, + WT* data_buffer, + uint8_t data_buffer_word_count) : word_shift_direction_(word_shift) + { + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + iterator_ = data_buffer; + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + iterator_ = &data_buffer[data_buffer_word_count]; + } + advance_word(); // Initializes current_word_ + } + + void advance_word() + { + WT word = *iterator_; + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + ++iterator_; + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + --iterator_; + } + + current_word_ = word; + } + + void shift_current_word(uint8_t n) + { + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + current_word_ <<= n; + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + current_word_ >>= n; + } + + bitshift_ += n; + if (bitshift_ >= word_bitsize_) + { + advance_word(); + bitshift_ -= word_bitsize_; + } + } + + void shift_padding(uint8_t n_bits) + { + if (n_bits == 0) + { + return; + } + + if ((n_bits + (bitshift_ % word_bitsize_)) >= word_bitsize_) + { + const uint8_t bits_shifted = word_bitsize_ - (bitshift_ % word_bitsize_); + + shift_current_word(bits_shifted); + shift_padding(n_bits - bits_shifted); + } + else + { + shift_current_word(n_bits); + } + } + + template + void shift_sample(const uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) + { + if ((sample_bitsize + (bitshift_ % word_bitsize_)) > word_bitsize_) + { + const uint8_t bits_shifted = word_bitsize_ - (bitshift_ % word_bitsize_); + + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize_ - bits_shifted)) - 1); + *output |= ((current_word_ & mask) >> output_bit_offset); + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (bits_shifted)) - 1); + *output |= (current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + } + + shift_current_word(bits_shifted); + shift_sample(sample_bitsize - bits_shifted, output, bits_shifted); + } + else + { + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + WT mask = ~((1 << (word_bitsize_ - sample_bitsize)) - 1); + OT sample = (current_word_ & mask) >> (word_bitsize_ - sample_bitsize); + *output |= (sample) >> output_bit_offset; + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + WT mask = ((1 << (sample_bitsize)) - 1); + *output |= (current_word_ & mask) << output_bit_offset; + // TODO - reverse bit order of sample? maybe? + } + + shift_current_word(sample_bitsize); + } + } +}; + +#endif //ION_GSM_CHUNK_UNPACKING_CTX_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h new file mode 100644 index 000000000..8f965ad99 --- /dev/null +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -0,0 +1,164 @@ +/*! + * \file ion_gsms_stream_encodings.h + * \brief Implements look up tables for all encodings in the standard + * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef ION_GSM_STREAM_ENCODINGS_H +#define ION_GSM_STREAM_ENCODINGS_H + +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + +namespace GnssMetadata +{ + using StreamEncoding = unsigned char; + + namespace StreamEncodings + { + constexpr unsigned char SIGN = 0; + constexpr unsigned char OB = 1; + constexpr unsigned char SM = 2; + constexpr unsigned char MS = 3; + constexpr unsigned char TC = 4; + constexpr unsigned char OG = 5; + constexpr unsigned char OBA = 6; + constexpr unsigned char SMA = 7; + constexpr unsigned char MSA = 8; + constexpr unsigned char TCA = 9; + constexpr unsigned char OGA = 10; + constexpr unsigned char FP = 11; + } + + inline StreamEncoding encoding_from_string(const std::string& str) + { + if (str == "SIGN") + { + return StreamEncodings::SIGN; + } + if (str == "OB") + { + return StreamEncodings::OB; + } + if (str == "SM") + { + return StreamEncodings::SM; + } + if (str == "MS") + { + return StreamEncodings::MS; + } + if (str == "TC") + { + return StreamEncodings::TC; + } + if (str == "OG") + { + return StreamEncodings::OG; + } + if (str == "OBA") + { + return StreamEncodings::OBA; + } + if (str == "SMA") + { + return StreamEncodings::SMA; + } + if (str == "MSA") + { + return StreamEncodings::MSA; + } + if (str == "TCA") + { + return StreamEncodings::TCA; + } + if (str == "OGA") + { + return StreamEncodings::OGA; + } + if (str == "FP") + { + return StreamEncodings::FP; + } + return 0; + } + + template + inline T two_bit_look_up[11][4] + { + [0] = {}, + [1 /*OB*/] = {-2, -1, 0, 1}, + [2 /*SM*/] = {0, 1, 0, -1}, + [3 /*MS*/] = {0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, -2, -1}, + [5 /*OG*/] = {-2, -1, 1, 0}, + [6 /*OBA*/] = {-3, -1, 1, 3}, + [7 /*SMA*/] = {1, 3, -1, -3}, + [8 /*MSA*/] = {1, -1, 3, -3}, + [9 /*TCA*/] = {1, 3, -3, -1}, + [10 /*OGA*/] = {-3, -1, 3, 1}, + }; + + template + inline T three_bit_look_up[11][8] + { + [0] = {}, + [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, + [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, + [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, + [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, + [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, + [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, + [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, + }; + + template + inline T four_bit_look_up[11][16] + { + [0] = {}, + [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, + [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, + }; + + template + inline T five_bit_look_up[11][32] + { + [0] = {}, + [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, + [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, + }; +} + +#endif //ION_GSM_STREAM_ENCODINGS_H From cd2614a4dc2d6acaca3f1ee90ae4137ee765f53f Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sun, 28 Jul 2024 17:36:29 +0200 Subject: [PATCH 09/66] Bufferef IO & propagate configuration inside ION source --- .../adapters/ion_gsms_signal_source.cc | 2 +- src/algorithms/signal_source/libs/ion_gsms.cc | 43 ++++++++++++++++--- src/algorithms/signal_source/libs/ion_gsms.h | 7 +++ .../signal_source/libs/ion_gsms_chunk_data.cc | 9 +++- .../signal_source/libs/ion_gsms_chunk_data.h | 2 +- .../libs/ion_gsms_metadata_handler.cc | 4 +- .../libs/ion_gsms_metadata_handler.h | 3 +- 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index d01268d67..0be954a4a 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -66,7 +66,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura LOG(ERROR) << "A signal source does not have an input stream"; } - sources_ = metadata_.make_stream_sources(stream_ids_); + sources_ = metadata_.make_stream_sources(configuration, role, stream_ids_); for (const auto& source : sources_) { diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 2034f12d1..66acb865c 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -25,8 +25,11 @@ #include #endif +using namespace std::string_literals; IONGSMSFileSource::IONGSMSFileSource( + const ConfigurationInterface* configuration, + const std::string& role, const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, @@ -36,7 +39,9 @@ IONGSMSFileSource::IONGSMSFileSource( gr::io_signature::make(0, 0, 0), make_output_signature(block, stream_ids)), file_metadata_(file), - block_metadata_(block) + block_metadata_(block), + io_buffer_offset_(0), + chunk_cycle_length_(0) { std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); fd_ = std::fopen(data_filepath.c_str(), "rb"); @@ -47,6 +52,7 @@ IONGSMSFileSource::IONGSMSFileSource( for (const auto& chunk : block.Chunks()) { chunk_data_.emplace_back(std::make_shared(chunk, stream_ids, output_stream_offset)); + chunk_cycle_length_ += chunk.CountWords() * chunk.SizeWord(); const std::size_t out_count = chunk_data_.back()->output_stream_count(); output_stream_offset += out_count; for (std::size_t i = 0; i < out_count; ++i) @@ -55,6 +61,8 @@ IONGSMSFileSource::IONGSMSFileSource( } } output_stream_count_ = output_stream_offset; + + io_buffer_.resize(1024 * chunk_cycle_length_); } IONGSMSFileSource::~IONGSMSFileSource() @@ -67,16 +75,39 @@ int IONGSMSFileSource::work( gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) { - // for (int i = 0; i < noutput_items; ++i) - // { + io_buffer_offset_ = 0; + std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); + std::vector items_produced{}; + + items_produced.resize(output_items.size()); + for (int i = 0; i < items_produced.size(); ++i) + { + items_produced[i] = 0; + } + + + while (io_buffer_offset_ < io_buffer_.size()) + { for (auto& c : chunk_data_) { - c->read_from_file(fd_); + io_buffer_offset_ += c->read_from_buffer(io_buffer_.data(), io_buffer_offset_); c->write_to_output(output_items, [&](int output, int nitems) { - produce(output, nitems); + items_produced[output] += nitems; + + // if (nitems_written(output) % 100 == 0) + // { + // add_item_tag(output, nitems_written(output), pmt::mp("tag_test"), pmt::from_uint64(nitems_written(output))); + // } }); } - // } + } + + std::cout << "produced: " << std::to_string(items_produced[0]) << std::endl; + for (int i = 0; i < items_produced.size(); ++i) + { + produce(i, items_produced[i]); + } + return WORK_CALLED_PRODUCE; } diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index a15206b84..a1091e700 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -19,10 +19,12 @@ #include "gnss_block_interface.h" #include "ion_gsms_chunk_data.h" +#include "configuration_interface.h" #include #include #include #include +#include class IONGSMSFileSource : public gr::sync_block @@ -31,6 +33,8 @@ public: using sptr = gnss_shared_ptr; IONGSMSFileSource( + const ConfigurationInterface* configuration, + const std::string& role, const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, @@ -53,9 +57,12 @@ private: const GnssMetadata::File& file_metadata_; const GnssMetadata::Block& block_metadata_; FILE* fd_; + std::vector io_buffer_; + std::size_t io_buffer_offset_; std::size_t output_stream_count_; std::vector output_stream_item_sizes_; std::vector> chunk_data_; + std::size_t chunk_cycle_length_; }; #include "ion_gsms_metadata_handler.h" diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index 8a0d1a7b4..54d74e084 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -76,9 +76,11 @@ IONGSMSChunkData::~IONGSMSChunkData() }); } -void IONGSMSChunkData::read_from_file(FILE* fd) +std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offset) { - std::fread(buffer_, sizeword_, countwords_, fd); + memset(buffer_, 0, sizeword_ * countwords_); + memcpy(buffer_, &buffer[offset], sizeword_ * countwords_); + return sizeword_ * countwords_; } void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, const std::function& produce) @@ -89,6 +91,7 @@ void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, const std:: }); } + std::size_t IONGSMSChunkData::output_stream_count() const { return output_stream_count_; @@ -203,6 +206,8 @@ void IONGSMSChunkData::write_n_samples( ++sample; } } + + out += sample_count * sizeof(OT); } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index c5fc3e6f7..6a4f7e49e 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -87,7 +87,7 @@ public: IONGSMSChunkData(IONGSMSChunkData&& rhl) = delete; IONGSMSChunkData& operator=(IONGSMSChunkData&& rhl) = delete; - void read_from_file(FILE* fd); + std::size_t read_from_buffer(uint8_t* buffer, std::size_t offset); void write_to_output(gr_vector_void_star& outputs, const std::function& produce); diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index 48aced035..e9568bb93 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -53,7 +53,7 @@ void IONGSMSMetadataHandler::load_metadata() } } -std::vector IONGSMSMetadataHandler::make_stream_sources(const std::vector& stream_ids) const +std::vector IONGSMSMetadataHandler::make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector& stream_ids) const { std::vector sources{}; for (const auto& file : metadata_.Files()) @@ -75,6 +75,8 @@ std::vector IONGSMSMetadataHandler::make_stream_sources })) { auto source = gnss_make_shared( + configuration, + role, metadata_filepath_, file, block, diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 0cbf634f6..28da13564 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -18,6 +18,7 @@ #define ION_GSMS_METADATA_HANDLER_H #include "GnssMetadata.h" +#include "configuration_interface.h" #include #if USE_GLOG_AND_GFLAGS @@ -31,7 +32,7 @@ class IONGSMSMetadataHandler public: explicit IONGSMSMetadataHandler(const std::string& metadata_filepath); - std::vector make_stream_sources(const std::vector& stream_ids) const; + std::vector make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector& stream_ids) const; public: // Getters const std::string& metadata_filepath() const; From 38a24f525040e4079ac86984e0b8bc2fd9aef8b1 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Fri, 16 Aug 2024 15:51:24 +0200 Subject: [PATCH 10/66] Reset sample value before writing new one Sample values are ORed into the output buffer because they may need a few read/write operations depending on alignment. So, if we don't set the value to 0 before doing this, all samples quickly become 0xFF after a few cycles of the output buffer. --- src/algorithms/signal_source/libs/ion_gsms.cc | 4 ++-- src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc | 2 ++ .../signal_source/libs/ion_gsms_metadata_handler.cc | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 66acb865c..fed13c8a2 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -62,7 +62,7 @@ IONGSMSFileSource::IONGSMSFileSource( } output_stream_count_ = output_stream_offset; - io_buffer_.resize(1024 * chunk_cycle_length_); + io_buffer_.resize((16*1024 - 1) * chunk_cycle_length_); } IONGSMSFileSource::~IONGSMSFileSource() @@ -102,7 +102,7 @@ int IONGSMSFileSource::work( } } - std::cout << "produced: " << std::to_string(items_produced[0]) << std::endl; + // std::cout << "produced: " << std::to_string(items_produced[0]) << " out of " << std::to_string(noutput_items) << std::endl; for (int i = 0; i < items_produced.size(); ++i) { produce(i, items_produced[i]); diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index 54d74e084..e8fb0157a 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -189,6 +189,7 @@ void IONGSMSChunkData::write_n_samples( sample += sample_count; for (std::size_t i = 0; i < sample_count; ++i) { + *sample = 0; ctx.shift_sample(sample_bitsize, sample); dump_sample(*sample); decode_sample(sample_bitsize, sample, stream_encoding); @@ -200,6 +201,7 @@ void IONGSMSChunkData::write_n_samples( auto* sample = static_cast(out); for (std::size_t i = 0; i < sample_count; ++i) { + *sample = 0; ctx.shift_sample(sample_bitsize, sample); dump_sample(*sample); decode_sample(sample_bitsize, sample, stream_encoding); diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index e9568bb93..47ae4e6ed 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -45,7 +45,7 @@ void IONGSMSMetadataHandler::load_metadata() } catch (GnssMetadata::ApiException& e) { - LOG(ERROR) << "API Exception while loadind XML metadata file: " << e.what(); + LOG(ERROR) << "API Exception while loading XML metadata file: " << std::to_string(e.Error()); } catch (std::exception& e) { From 01bbc39fa64f018839f035644f5d4a6fd45f858b Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 20:14:31 +0200 Subject: [PATCH 11/66] Simpler handling of simpler bit formats If a sample is the same size as a word, it is much easier to read. --- .../libs/ion_gsms_chunk_unpacking_ctx.h | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 249063e4d..758e9b197 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -34,7 +34,7 @@ struct IONGSMSChunkUnpackingCtx static constexpr uint8_t word_bitsize_ = sizeof(WT) * 8; const GnssMetadata::Chunk::WordShift word_shift_direction_; - WT* iterator_; // Not owned by this class, must not destroy + WT* iterator_; // Not owned by this class, MUST NOT destroy WT current_word_; uint8_t bitshift_ = 0; @@ -71,6 +71,15 @@ struct IONGSMSChunkUnpackingCtx void shift_current_word(uint8_t n) { + if ((n % word_bitsize_) == 0) + { + for (uint8_t i = 0; i < (n / word_bitsize_); ++i) + { + advance_word(); + } + return; + } + if (word_shift_direction_ == GnssMetadata::Chunk::Left) { current_word_ <<= n; @@ -111,7 +120,24 @@ struct IONGSMSChunkUnpackingCtx template void shift_sample(const uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) { - if ((sample_bitsize + (bitshift_ % word_bitsize_)) > word_bitsize_) + if (sample_bitsize % word_bitsize_ == 0) + { + const uint8_t words_per_sample = sample_bitsize / word_bitsize_; + for (uint8_t i = 0; i < words_per_sample; ++i) + { + if (word_shift_direction_ == GnssMetadata::Chunk::Left) + { + *output |= (current_word_ << ((words_per_sample - 1 - i) * word_bitsize_)); + } + else if (word_shift_direction_ == GnssMetadata::Chunk::Right) + { + *output |= (current_word_ << (i * word_bitsize_)); + // TODO - reverse bit order of sample? maybe? + } + advance_word(); + } + } + else if ((sample_bitsize + (bitshift_ % word_bitsize_)) > word_bitsize_) { const uint8_t bits_shifted = word_bitsize_ - (bitshift_ % word_bitsize_); From 33067d631d1398c5b41ec7f952fee93d00858426 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 20:20:27 +0200 Subject: [PATCH 12/66] Less callback shenanigans --- src/algorithms/signal_source/libs/ion_gsms.cc | 25 ++++++----------- src/algorithms/signal_source/libs/ion_gsms.h | 1 + .../signal_source/libs/ion_gsms_chunk_data.cc | 28 ++++++++++++++----- .../signal_source/libs/ion_gsms_chunk_data.h | 4 +-- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index fed13c8a2..1f6841224 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -77,35 +77,26 @@ int IONGSMSFileSource::work( { io_buffer_offset_ = 0; std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); - std::vector items_produced{}; - items_produced.resize(output_items.size()); - for (int i = 0; i < items_produced.size(); ++i) + items_produced_.resize(output_items.size()); + for (int i = 0; i < items_produced_.size(); ++i) { - items_produced[i] = 0; + items_produced_[i] = 0; } - while (io_buffer_offset_ < io_buffer_.size()) { for (auto& c : chunk_data_) { - io_buffer_offset_ += c->read_from_buffer(io_buffer_.data(), io_buffer_offset_); - c->write_to_output(output_items, [&](int output, int nitems) { - items_produced[output] += nitems; - - // if (nitems_written(output) % 100 == 0) - // { - // add_item_tag(output, nitems_written(output), pmt::mp("tag_test"), pmt::from_uint64(nitems_written(output))); - // } - }); + auto* chunk = c.get(); + io_buffer_offset_ += chunk->read_from_buffer(io_buffer_.data(), io_buffer_offset_); + chunk->write_to_output(output_items, items_produced_); } } - // std::cout << "produced: " << std::to_string(items_produced[0]) << " out of " << std::to_string(noutput_items) << std::endl; - for (int i = 0; i < items_produced.size(); ++i) + for (int i = 0; i < items_produced_.size(); ++i) { - produce(i, items_produced[i]); + produce(i, items_produced_[i]); } return WORK_CALLED_PRODUCE; diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index a1091e700..629e00866 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -59,6 +59,7 @@ private: FILE* fd_; std::vector io_buffer_; std::size_t io_buffer_offset_; + std::vector items_produced_; std::size_t output_stream_count_; std::vector output_stream_item_sizes_; std::vector> chunk_data_; diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index e8fb0157a..dd2a09865 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -83,12 +83,26 @@ std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offs return sizeword_ * countwords_; } -void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, const std::function& produce) +void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, std::vector& output_items) { - with_word_type(sizeword_, [&] - { - unpack_words(outputs, produce); - }); + switch (sizeword_) + { + case 1: + unpack_words(outputs, output_items); + break; + case 2: + unpack_words(outputs, output_items); + break; + case 4: + unpack_words(outputs, output_items); + break; + case 8: + unpack_words(outputs, output_items); + break; + default: + LOG(ERROR) << "Unknown word size (" << std::to_string(sizeword_) << "), unpacking nothing."; + break; + } } @@ -104,7 +118,7 @@ std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) template -void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::function& produce) +void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector& output_items) { WT* data = static_cast(buffer_); // TODO - Swap endiannes if needed @@ -131,7 +145,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, const std::fun } else { - produce(output_index, write_stream_samples(ctx, lump, stream, encoding, outputs[output_index])); + output_items[output_index] += write_stream_samples(ctx, lump, stream, encoding, outputs[output_index]); } } } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 6a4f7e49e..4f517cf3f 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -89,14 +89,14 @@ public: std::size_t read_from_buffer(uint8_t* buffer, std::size_t offset); - void write_to_output(gr_vector_void_star& outputs, const std::function& produce); + void write_to_output(gr_vector_void_star& outputs, std::vector& output_items); std::size_t output_stream_count() const; std::size_t output_stream_item_size(std::size_t stream_index) const; private: template - void unpack_words(gr_vector_void_star& outputs, const std::function& produce); + void unpack_words(gr_vector_void_star& outputs, std::vector& output_items); template std::size_t write_stream_samples( From b36894246393f691b211432e8a475393e05029d7 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 20:22:39 +0200 Subject: [PATCH 13/66] Fix wrong buffer size --- src/algorithms/signal_source/libs/ion_gsms.cc | 6 ++++-- src/algorithms/signal_source/libs/ion_gsms.h | 1 + src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc | 8 ++++++++ src/algorithms/signal_source/libs/ion_gsms_chunk_data.h | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 1f6841224..d7036907a 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -41,6 +41,7 @@ IONGSMSFileSource::IONGSMSFileSource( file_metadata_(file), block_metadata_(block), io_buffer_offset_(0), + maximum_item_rate_(0), chunk_cycle_length_(0) { std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); @@ -58,11 +59,10 @@ IONGSMSFileSource::IONGSMSFileSource( for (std::size_t i = 0; i < out_count; ++i) { output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); + maximum_item_rate_ = std::max(chunk_data_.back()->output_stream_item_rate(i), maximum_item_rate_); } } output_stream_count_ = output_stream_offset; - - io_buffer_.resize((16*1024 - 1) * chunk_cycle_length_); } IONGSMSFileSource::~IONGSMSFileSource() @@ -75,6 +75,8 @@ int IONGSMSFileSource::work( gr_vector_const_void_star& input_items, gr_vector_void_star& output_items) { + const std::size_t max_sample_output = std::floor((noutput_items-1.0) / maximum_item_rate_); + io_buffer_.resize(max_sample_output * chunk_cycle_length_); io_buffer_offset_ = 0; std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 629e00866..443ed3a81 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -62,6 +62,7 @@ private: std::vector items_produced_; std::size_t output_stream_count_; std::vector output_stream_item_sizes_; + std::size_t maximum_item_rate_; std::vector> chunk_data_; std::size_t chunk_cycle_length_; }; diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index dd2a09865..229d7a0d5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -49,12 +49,15 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()),output_streams + output_stream_offset); ++output_streams; std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); + std::size_t sample_rate = stream.RateFactor(); if (stream.Packedbits() >= 2 * stream.RateFactor() * stream.Quantization()) { // Samples have 'Complex' format sample_bitsize /= 2; + sample_rate *= 2; } output_stream_item_size_.push_back(bits_to_item_size(sample_bitsize)); + output_stream_item_rate_.push_back(sample_rate); } else { @@ -116,6 +119,11 @@ std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) return output_stream_item_size_[stream_index]; } +std::size_t IONGSMSChunkData::output_stream_item_rate(std::size_t stream_index) const +{ + return output_stream_item_rate_[stream_index]; +} + template void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector& output_items) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 4f517cf3f..97ce022c4 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -93,6 +93,7 @@ public: std::size_t output_stream_count() const; std::size_t output_stream_item_size(std::size_t stream_index) const; + std::size_t output_stream_item_rate(std::size_t stream_index) const; private: template @@ -126,6 +127,7 @@ private: uint8_t padding_bitsize_; std::size_t output_stream_count_; std::vector output_stream_item_size_; + std::vector output_stream_item_rate_; struct stream_metadata_t { From cf01a2d37a3ab9317489bad69792db7f7ff81e82 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 20:40:13 +0200 Subject: [PATCH 14/66] Fixed conditional compilation issues And added a comment --- .../signal_source/libs/ion_gsms_stream_encodings.h | 2 ++ src/core/receiver/CMakeLists.txt | 4 ++++ src/core/receiver/gnss_block_factory.cc | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h index 8f965ad99..f8551159b 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -3,6 +3,8 @@ * \brief Implements look up tables for all encodings in the standard * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com * + * These tables are taken from the stardard's official document. + * * ----------------------------------------------------------------------------- * * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt index cacef7f6f..604449390 100644 --- a/src/core/receiver/CMakeLists.txt +++ b/src/core/receiver/CMakeLists.txt @@ -70,6 +70,10 @@ if(ENABLE_FPGA) target_compile_definitions(core_receiver PUBLIC -DENABLE_FPGA=1) endif() +if(ENABLE_ION) + target_compile_definitions(core_receiver PRIVATE -DENABLE_ION_SOURCE=1) +endif() + if(GNURADIO_USES_STD_POINTERS) target_compile_definitions(core_receiver PUBLIC -DGNURADIO_USES_STD_POINTERS=1) endif() diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 99a05e95c..07069ed9e 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -93,7 +93,6 @@ #include "ibyte_to_complex.h" #include "ibyte_to_cshort.h" #include "in_memory_configuration.h" -#include "ion_gsms_signal_source.h" #include "ishort_to_complex.h" #include "ishort_to_cshort.h" #include "labsat_signal_source.h" @@ -197,6 +196,10 @@ #include "gps_l1_ca_dll_pll_tracking_gpu.h" #endif +#if ENABLE_ION_SOURCE +#include "ion_gsms_signal_source.h" +#endif + using namespace std::string_literals; namespace @@ -760,13 +763,14 @@ std::unique_ptr GNSSBlockFactory::GetBlock( block = std::move(block_); } #endif +#if ENABLE_ION_SOURCE else if (implementation == "ION_GSMS_Signal_Source") { std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, out_streams, queue); block = std::move(block_); } - +#endif #if RAW_ARRAY_DRIVER else if (implementation == "Raw_Array_Signal_Source") { From 61a9e179b061aa2432aa1b0b6c26423b7c854415 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 23:05:38 +0200 Subject: [PATCH 15/66] Linting fixes --- .../adapters/ion_gsms_signal_source.cc | 1 + .../adapters/ion_gsms_signal_source.h | 1 + src/algorithms/signal_source/libs/ion_gsms.cc | 3 + src/algorithms/signal_source/libs/ion_gsms.h | 3 +- .../signal_source/libs/ion_gsms_chunk_data.cc | 4 +- .../signal_source/libs/ion_gsms_chunk_data.h | 4 +- .../libs/ion_gsms_chunk_unpacking_ctx.h | 2 +- .../libs/ion_gsms_metadata_handler.h | 8 +- .../libs/ion_gsms_stream_encodings.h | 266 +++++++++--------- 9 files changed, 155 insertions(+), 137 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index 0be954a4a..9a6d9d9a0 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -19,6 +19,7 @@ #include "ion_gsms_signal_source.h" #include #include +#include #include #if USE_GLOG_AND_GFLAGS diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 9d959279f..19d91083c 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -23,6 +23,7 @@ #include "gnss_sdr_timestamp.h" #include "ion_gsms.h" #include +#include /** \addtogroup Signal_Source * \{ */ diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index d7036907a..c19011dfd 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -16,6 +16,9 @@ #include "gnuradio/block.h" #include "ion_gsms.h" +#include +#include +#include #if USE_GLOG_AND_GFLAGS #include diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 443ed3a81..b7aa06b0b 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -24,7 +24,8 @@ #include #include #include -#include +#include +#include class IONGSMSFileSource : public gr::sync_block diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index 229d7a0d5..03bcab79c 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -16,6 +16,8 @@ #include "ion_gsms_chunk_data.h" #include +#include +#include #if USE_GLOG_AND_GFLAGS #include @@ -46,7 +48,7 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: return stream.Id() == it; })) { - streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()),output_streams + output_stream_offset); + streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()), output_streams + output_stream_offset); ++output_streams; std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); std::size_t sample_rate = stream.RateFactor(); diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 97ce022c4..bc0c5834d 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -21,6 +21,8 @@ #include "ion_gsms_stream_encodings.h" #include "ion_gsms_chunk_unpacking_ctx.h" #include +#include +#include #if USE_GLOG_AND_GFLAGS #include @@ -141,4 +143,4 @@ private: void* buffer_; }; -#endif //ION_GSM_CHUNK_DATA_H +#endif // ION_GSM_CHUNK_DATA_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 758e9b197..1dad11902 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -176,4 +176,4 @@ struct IONGSMSChunkUnpackingCtx } }; -#endif //ION_GSM_CHUNK_UNPACKING_CTX_H +#endif // ION_GSM_CHUNK_UNPACKING_CTX_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 28da13564..710233d72 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -20,6 +20,8 @@ #include "GnssMetadata.h" #include "configuration_interface.h" #include +#include +#include #if USE_GLOG_AND_GFLAGS #include @@ -37,12 +39,12 @@ public: public: // Getters const std::string& metadata_filepath() const; -private: // Private methods +private: // Private methods void load_metadata(); -private: // State +private: // State std::string metadata_filepath_; GnssMetadata::Metadata metadata_; }; -#endif //ION_GSMS_METADATA_HANDLER_H +#endif // ION_GSMS_METADATA_HANDLER_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h index f8551159b..8bae4b7e5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -19,6 +19,8 @@ #ifndef ION_GSM_STREAM_ENCODINGS_H #define ION_GSM_STREAM_ENCODINGS_H +#include + #if USE_GLOG_AND_GFLAGS #include #else @@ -27,140 +29,144 @@ namespace GnssMetadata { - using StreamEncoding = unsigned char; - namespace StreamEncodings - { - constexpr unsigned char SIGN = 0; - constexpr unsigned char OB = 1; - constexpr unsigned char SM = 2; - constexpr unsigned char MS = 3; - constexpr unsigned char TC = 4; - constexpr unsigned char OG = 5; - constexpr unsigned char OBA = 6; - constexpr unsigned char SMA = 7; - constexpr unsigned char MSA = 8; - constexpr unsigned char TCA = 9; - constexpr unsigned char OGA = 10; - constexpr unsigned char FP = 11; - } +using StreamEncoding = unsigned char; - inline StreamEncoding encoding_from_string(const std::string& str) - { - if (str == "SIGN") - { - return StreamEncodings::SIGN; - } - if (str == "OB") - { - return StreamEncodings::OB; - } - if (str == "SM") - { - return StreamEncodings::SM; - } - if (str == "MS") - { - return StreamEncodings::MS; - } - if (str == "TC") - { - return StreamEncodings::TC; - } - if (str == "OG") - { - return StreamEncodings::OG; - } - if (str == "OBA") - { - return StreamEncodings::OBA; - } - if (str == "SMA") - { - return StreamEncodings::SMA; - } - if (str == "MSA") - { - return StreamEncodings::MSA; - } - if (str == "TCA") - { - return StreamEncodings::TCA; - } - if (str == "OGA") - { - return StreamEncodings::OGA; - } - if (str == "FP") - { - return StreamEncodings::FP; - } - return 0; - } +namespace StreamEncodings +{ - template - inline T two_bit_look_up[11][4] - { - [0] = {}, - [1 /*OB*/] = {-2, -1, 0, 1}, - [2 /*SM*/] = {0, 1, 0, -1}, - [3 /*MS*/] = {0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, -2, -1}, - [5 /*OG*/] = {-2, -1, 1, 0}, - [6 /*OBA*/] = {-3, -1, 1, 3}, - [7 /*SMA*/] = {1, 3, -1, -3}, - [8 /*MSA*/] = {1, -1, 3, -3}, - [9 /*TCA*/] = {1, 3, -3, -1}, - [10 /*OGA*/] = {-3, -1, 3, 1}, - }; +constexpr unsigned char SIGN = 0; +constexpr unsigned char OB = 1; +constexpr unsigned char SM = 2; +constexpr unsigned char MS = 3; +constexpr unsigned char TC = 4; +constexpr unsigned char OG = 5; +constexpr unsigned char OBA = 6; +constexpr unsigned char SMA = 7; +constexpr unsigned char MSA = 8; +constexpr unsigned char TCA = 9; +constexpr unsigned char OGA = 10; +constexpr unsigned char FP = 11; - template - inline T three_bit_look_up[11][8] - { - [0] = {}, - [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, - [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, - [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, - [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, - [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, - [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, - [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, - }; +} // namespace StreamEncodings - template - inline T four_bit_look_up[11][16] - { - [0] = {}, - [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, - [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, - }; - - template - inline T five_bit_look_up[11][32] - { - [0] = {}, - [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, - [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, - }; +inline StreamEncoding encoding_from_string(const std::string& str) +{ + if (str == "SIGN") + { + return StreamEncodings::SIGN; + } + if (str == "OB") + { + return StreamEncodings::OB; + } + if (str == "SM") + { + return StreamEncodings::SM; + } + if (str == "MS") + { + return StreamEncodings::MS; + } + if (str == "TC") + { + return StreamEncodings::TC; + } + if (str == "OG") + { + return StreamEncodings::OG; + } + if (str == "OBA") + { + return StreamEncodings::OBA; + } + if (str == "SMA") + { + return StreamEncodings::SMA; + } + if (str == "MSA") + { + return StreamEncodings::MSA; + } + if (str == "TCA") + { + return StreamEncodings::TCA; + } + if (str == "OGA") + { + return StreamEncodings::OGA; + } + if (str == "FP") + { + return StreamEncodings::FP; + } + return 0; } -#endif //ION_GSM_STREAM_ENCODINGS_H +template +inline T two_bit_look_up[11][4] +{ + [0] = {}, + [1 /*OB*/] = {-2, -1, 0, 1}, + [2 /*SM*/] = {0, 1, 0, -1}, + [3 /*MS*/] = {0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, -2, -1}, + [5 /*OG*/] = {-2, -1, 1, 0}, + [6 /*OBA*/] = {-3, -1, 1, 3}, + [7 /*SMA*/] = {1, 3, -1, -3}, + [8 /*MSA*/] = {1, -1, 3, -3}, + [9 /*TCA*/] = {1, 3, -3, -1}, + [10 /*OGA*/] = {-3, -1, 3, 1}, +}; + +template +inline T three_bit_look_up[11][8] +{ + [0] = {}, + [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, + [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, + [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, + [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, + [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, + [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, + [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, +}; + +template +inline T four_bit_look_up[11][16] +{ + [0] = {}, + [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, + [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, +}; + +template +inline T five_bit_look_up[11][32] +{ + [0] = {}, + [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, + [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, + [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, + [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, + [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, + [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, + [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, + [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, + [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, +}; + +} // namespace GnssMetadata + +#endif // ION_GSM_STREAM_ENCODINGS_H From a99ceafe851ecccaca2633af258bee3e39179080 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 23:06:24 +0200 Subject: [PATCH 16/66] Fixed arithmetic operations on pointers --- src/algorithms/signal_source/libs/ion_gsms.cc | 4 ++-- .../signal_source/libs/ion_gsms_chunk_data.cc | 20 +++++++++---------- .../signal_source/libs/ion_gsms_chunk_data.h | 4 ++-- .../libs/ion_gsms_metadata_handler.cc | 13 +++++++++--- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index c19011dfd..0c9670030 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -84,7 +84,7 @@ int IONGSMSFileSource::work( std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); items_produced_.resize(output_items.size()); - for (int i = 0; i < items_produced_.size(); ++i) + for (std::size_t i = 0; i < items_produced_.size(); ++i) { items_produced_[i] = 0; } @@ -99,7 +99,7 @@ int IONGSMSFileSource::work( } } - for (int i = 0; i < items_produced_.size(); ++i) + for (std::size_t i = 0; i < items_produced_.size(); ++i) { produce(i, items_produced_[i]); } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index 03bcab79c..6e64e23a9 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -155,7 +155,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int8_t**)(out)); } else if (sample_bitsize <= 16) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int16_t**)(out)); } else if (sample_bitsize <= 32) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int32_t**)(out)); } else if (sample_bitsize <= 64) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, out); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int64_t**)(out)); } return sample_count; @@ -205,11 +205,11 @@ void IONGSMSChunkData::write_n_samples( uint8_t sample_bitsize, std::size_t sample_count, GnssMetadata::StreamEncoding stream_encoding, - void*& out) + OT** out) { if (lump_shift == GnssMetadata::Lump::shiftRight) { - auto* sample = static_cast(out); + auto* sample = static_cast(*out); sample += sample_count; for (std::size_t i = 0; i < sample_count; ++i) { @@ -222,7 +222,7 @@ void IONGSMSChunkData::write_n_samples( } else // if (lump_shift == GnssMetadata::Lump::shiftLeft || lump_shift == GnssMetadata::Lump::shiftUndefined) { - auto* sample = static_cast(out); + auto* sample = static_cast(*out); for (std::size_t i = 0; i < sample_count; ++i) { *sample = 0; @@ -233,7 +233,7 @@ void IONGSMSChunkData::write_n_samples( } } - out += sample_count * sizeof(OT); + (*out) += sample_count; } diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index bc0c5834d..3081c823b 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -107,7 +107,7 @@ private: const GnssMetadata::Lump& lump, const GnssMetadata::IonStream& stream, GnssMetadata::StreamEncoding stream_encoding, - void*& out); + void** out); template void write_n_samples( @@ -116,7 +116,7 @@ private: uint8_t sample_bitsize, std::size_t sample_count, GnssMetadata::StreamEncoding stream_encoding, - void*& out); + OT** out); static void decode_sample(uint8_t sample_bitsize, auto* sample, GnssMetadata::StreamEncoding encoding); diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index 47ae4e6ed..c5fccef61 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -70,9 +70,16 @@ std::vector IONGSMSMetadataHandler::make_stream_sources { for (const auto& stream : lump.Streams()) { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) + bool found = false; + for (const auto & stream_id : stream_ids) + { + if (stream_id == stream.Id()) + { + found = true; + break; + } + } + if (found) { auto source = gnss_make_shared( configuration, From 27465f6a70d0a7ce4e90e7254915943ee5ce6249 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Sat, 17 Aug 2024 23:31:27 +0200 Subject: [PATCH 17/66] Fix formatting --- .../adapters/ion_gsms_signal_source.cc | 12 +-- .../adapters/ion_gsms_signal_source.h | 1 + src/algorithms/signal_source/libs/ion_gsms.cc | 36 ++++--- src/algorithms/signal_source/libs/ion_gsms.h | 4 +- .../signal_source/libs/ion_gsms_chunk_data.cc | 37 +++---- .../signal_source/libs/ion_gsms_chunk_data.h | 15 ++- .../libs/ion_gsms_metadata_handler.cc | 17 ++- .../libs/ion_gsms_stream_encodings.h | 100 +++++++++--------- src/core/receiver/gnss_block_factory.cc | 1 + 9 files changed, 117 insertions(+), 106 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index 9a6d9d9a0..b4edd615f 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -14,13 +14,13 @@ * ----------------------------------------------------------------------------- */ +#include "ion_gsms_signal_source.h" #include "gnss_sdr_flags.h" #include "gnss_sdr_string_literals.h" -#include "ion_gsms_signal_source.h" #include #include -#include #include +#include #if USE_GLOG_AND_GFLAGS #include @@ -53,7 +53,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura const std::string& role, unsigned int in_streams, unsigned int out_streams, - Concurrent_Queue* queue) + Concurrent_Queue* queue __attribute__((unused))) : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), metadata_file_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), @@ -71,7 +71,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura for (const auto& source : sources_) { - for (int i = 0; i < source->output_stream_count(); ++i) + for (std::size_t i = 0; i < source->output_stream_count(); ++i) { copy_blocks_.push_back(gr::blocks::copy::make(source->output_stream_item_size(i))); } @@ -84,7 +84,7 @@ void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) std::size_t cumulative_index = 0; for (const auto& source : sources_) { - for (int i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) + for (std::size_t i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) { top_block->connect(source, i, copy_blocks_[cumulative_index], 0); } @@ -96,7 +96,7 @@ void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) std::size_t cumulative_index = 0; for (const auto& source : sources_) { - for (int i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) + for (std::size_t i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) { top_block->disconnect(source, i, copy_blocks_[cumulative_index], 0); } diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 19d91083c..5063b4e80 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -57,6 +57,7 @@ protected: { return (*sources_.begin())->output_stream_item_size(0); } + private: std::string metadata_file_; std::vector stream_ids_; diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 0c9670030..8389afd10 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -14,25 +14,24 @@ * ----------------------------------------------------------------------------- */ -#include "gnuradio/block.h" #include "ion_gsms.h" -#include +#include "gnuradio/block.h" #include +#include #include #if USE_GLOG_AND_GFLAGS #include #else #include - #include #endif using namespace std::string_literals; IONGSMSFileSource::IONGSMSFileSource( - const ConfigurationInterface* configuration, - const std::string& role, + const ConfigurationInterface* configuration __attribute__((unused)), + const std::string& role __attribute__((unused)), const std::filesystem::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, @@ -75,18 +74,18 @@ IONGSMSFileSource::~IONGSMSFileSource() int IONGSMSFileSource::work( int noutput_items, - gr_vector_const_void_star& input_items, + gr_vector_const_void_star& input_items __attribute__((unused)), gr_vector_void_star& output_items) { - const std::size_t max_sample_output = std::floor((noutput_items-1.0) / maximum_item_rate_); + const std::size_t max_sample_output = std::floor((noutput_items - 1.0) / maximum_item_rate_); io_buffer_.resize(max_sample_output * chunk_cycle_length_); io_buffer_offset_ = 0; std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); items_produced_.resize(output_items.size()); - for (std::size_t i = 0; i < items_produced_.size(); ++i) + for (int& i : items_produced_) { - items_produced_[i] = 0; + i = 0; } while (io_buffer_offset_ < io_buffer_.size()) @@ -121,7 +120,7 @@ std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) { int nstreams = 0; - std::vector item_sizes{}; + std::vector item_sizes{}; for (const auto& chunk : block.Chunks()) { @@ -129,9 +128,16 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada { for (const auto& stream : lump.Streams()) { - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) + bool found = false; + for (const auto& stream_id : stream_ids) + { + if (stream_id == stream.Id()) + { + found = true; + break; + } + } + if (found) { ++nstreams; std::size_t sample_bitsize = stream.Packedbits() / stream.RateFactor(); @@ -146,10 +152,8 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada } } - return gr::io_signature::make( + return gr::io_signature::makev( nstreams, nstreams, item_sizes); } - - diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index b7aa06b0b..5164e3581 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -17,14 +17,14 @@ #ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H #define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#include "configuration_interface.h" #include "gnss_block_interface.h" #include "ion_gsms_chunk_data.h" -#include "configuration_interface.h" #include #include #include -#include #include +#include #include diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index 6e64e23a9..f6d1b18b9 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -30,9 +30,8 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: sizeword_(chunk_.SizeWord()), countwords_(chunk_.CountWords()) { - with_word_type(sizeword_, [&] - { - buffer_ = new WordType[countwords_]; + with_word_type(sizeword_, [&] { + buffer_ = new WordType[countwords_]; }); const std::size_t total_bitsize = sizeword_ * countwords_ * 8; @@ -44,9 +43,16 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: { used_bitsize += stream.Packedbits(); - if (std::ranges::any_of(stream_ids.begin(), stream_ids.end(), [&](const std::string& it) { - return stream.Id() == it; - })) + bool found = false; + for (const auto& stream_id : stream_ids) + { + if (stream_id == stream.Id()) + { + found = true; + break; + } + } + if (found) { streams_.emplace_back(lump, stream, GnssMetadata::encoding_from_string(stream.Encoding()), output_streams + output_stream_offset); ++output_streams; @@ -75,9 +81,8 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: IONGSMSChunkData::~IONGSMSChunkData() { - with_word_type(sizeword_, [&] - { - delete[] static_cast(buffer_); + with_word_type(sizeword_, [&] { + delete[] static_cast(buffer_); }); } @@ -215,7 +220,6 @@ void IONGSMSChunkData::write_n_samples( { *sample = 0; ctx.shift_sample(sample_bitsize, sample); - dump_sample(*sample); decode_sample(sample_bitsize, sample, stream_encoding); --sample; } @@ -227,7 +231,6 @@ void IONGSMSChunkData::write_n_samples( { *sample = 0; ctx.shift_sample(sample_bitsize, sample); - dump_sample(*sample); decode_sample(sample_bitsize, sample, stream_encoding); ++sample; } @@ -237,7 +240,6 @@ void IONGSMSChunkData::write_n_samples( } - // Static utilities void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, auto* sample, const GnssMetadata::StreamEncoding encoding) { @@ -262,14 +264,3 @@ void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, auto* sample, break; } } - -void IONGSMSChunkData::dump_sample(auto value) -{ - static int count = 100; - if (count > 0) - { - --count; - // std::cout << "SAMPLE: [0x" << std::hex << value << "] " << std::bitset<32>(value) << std::endl; - } -} - diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 3081c823b..881c431f6 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -18,8 +18,8 @@ #define ION_GSM_CHUNK_DATA_H #include "GnssMetadata.h" -#include "ion_gsms_stream_encodings.h" #include "ion_gsms_chunk_unpacking_ctx.h" +#include "ion_gsms_stream_encodings.h" #include #include #include @@ -120,8 +120,6 @@ private: static void decode_sample(uint8_t sample_bitsize, auto* sample, GnssMetadata::StreamEncoding encoding); - static void dump_sample(auto value); - private: const GnssMetadata::Chunk& chunk_; uint8_t sizeword_; @@ -137,6 +135,17 @@ private: const GnssMetadata::IonStream& stream; GnssMetadata::StreamEncoding stream_encoding; int output_index = -1; + + stream_metadata_t( + const GnssMetadata::Lump& lump_, + const GnssMetadata::IonStream& stream_, + GnssMetadata::StreamEncoding stream_encoding_, + int output_index_ = -1) : lump(lump_), + stream(stream_), + stream_encoding(stream_encoding_), + output_index(output_index_) + { + } }; std::vector streams_; diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index c5fccef61..9a05e372d 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -64,6 +64,7 @@ std::vector IONGSMSMetadataHandler::make_stream_sources { for (const auto& block : lane.Blocks()) { + bool block_done = false; for (const auto& chunk : block.Chunks()) { for (const auto& lump : chunk.Lumps()) @@ -71,7 +72,7 @@ std::vector IONGSMSMetadataHandler::make_stream_sources for (const auto& stream : lump.Streams()) { bool found = false; - for (const auto & stream_id : stream_ids) + for (const auto& stream_id : stream_ids) { if (stream_id == stream.Id()) { @@ -93,12 +94,21 @@ std::vector IONGSMSMetadataHandler::make_stream_sources // This file source will take care of any other matching streams in this block // We can skip the rest of this block - goto next_block; + block_done = true; + break; } } + + if (block_done) + { + break; + } + } + if (block_done) + { + break; } } - next_block: } break; } @@ -107,4 +117,3 @@ std::vector IONGSMSMetadataHandler::make_stream_sources return sources; } - diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h index 8bae4b7e5..443a6e823 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -104,67 +104,63 @@ inline StreamEncoding encoding_from_string(const std::string& str) } template -inline T two_bit_look_up[11][4] -{ - [0] = {}, - [1 /*OB*/] = {-2, -1, 0, 1}, - [2 /*SM*/] = {0, 1, 0, -1}, - [3 /*MS*/] = {0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, -2, -1}, - [5 /*OG*/] = {-2, -1, 1, 0}, - [6 /*OBA*/] = {-3, -1, 1, 3}, - [7 /*SMA*/] = {1, 3, -1, -3}, - [8 /*MSA*/] = {1, -1, 3, -3}, - [9 /*TCA*/] = {1, 3, -3, -1}, - [10 /*OGA*/] = {-3, -1, 3, 1}, +inline T two_bit_look_up[11][4]{ + {}, // [0] + {-2, -1, 0, 1}, // [1 /*OB*/] + {0, 1, 0, -1}, // [2 /*SM*/] + {0, 0, 1, -1}, // [3 /*MS*/] + {0, 1, -2, -1}, // [4 /*TC*/] + {-2, -1, 1, 0}, // [5 /*OG*/] + {-3, -1, 1, 3}, // [6 /*OBA*/] + {1, 3, -1, -3}, // [7 /*SMA*/] + {1, -1, 3, -3}, // [8 /*MSA*/] + {1, 3, -3, -1}, // [9 /*TCA*/] + {-3, -1, 3, 1}, // [10 /*OGA*/] }; template -inline T three_bit_look_up[11][8] -{ - [0] = {}, - [1 /*OB*/] = {-4, -3, -2, -1, 0, 1, 2, 3}, - [2 /*SM*/] = {0, 1, 2, 3, 0, -1, -2, -3}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, -4, -3, -2, -1}, - [5 /*OG*/] = {-4, -3, -1, -2, 3, 2, 0, 1}, - [6 /*OBA*/] = {-7, -5, -3, -1, 1, 3, 5, 7}, - [7 /*SMA*/] = {1, 3, 5, 7, -1, -3, -5, -7}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7}, - [9 /*TCA*/] = {1, 3, 5, 7, -7, -5, -3, -1}, - [10 /*OGA*/] = {-7, -5, -1, -3, 7, 5, 1, 3}, +inline T three_bit_look_up[11][8]{ + {}, // [0] + {-4, -3, -2, -1, 0, 1, 2, 3}, // [1 /*OB*/] + {0, 1, 2, 3, 0, -1, -2, -3}, // [2 /*SM*/] + {0, 0, 1, -1, 0, 0, 1, -1}, // [3 /*MS*/] + {0, 1, 2, 3, -4, -3, -2, -1}, // [4 /*TC*/] + {-4, -3, -1, -2, 3, 2, 0, 1}, // [5 /*OG*/] + {-7, -5, -3, -1, 1, 3, 5, 7}, // [6 /*OBA*/] + {1, 3, 5, 7, -1, -3, -5, -7}, // [7 /*SMA*/] + {1, -1, 3, -3, 5, -5, 7, -7}, // [8 /*MSA*/] + {1, 3, 5, 7, -7, -5, -3, -1}, // [9 /*TCA*/] + {-7, -5, -1, -3, 7, 5, 1, 3}, // [10 /*OGA*/] }; template -inline T four_bit_look_up[11][16] -{ - [0] = {}, - [1 /*OB*/] = {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, - [6 /*OBA*/] = {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, +inline T four_bit_look_up[11][16]{ + {}, // [0] + {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7}, // [1 /*OB*/] + {0, 1, 2, 3, 4, 5, 6, 7, 0, -1, -2, -3, -4, -5, -6, -7}, // [2 /*SM*/] + {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, // [3 /*MS*/] + {0, 1, 2, 3, 4, 5, 6, 7, -8, -7, -6, -5, -4, -3, -2, -1}, // [4 /*TC*/] + {-8, -7, -5, -6, -1, -2, -4, -3, 7, 6, 4, 5, 0, 1, 3, 2}, // [5 /*OG*/] + {-15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15}, // [6 /*OBA*/] + {1, 3, 5, 7, 9, 11, 13, 15, -1, -3, -5, -7, -9, -11, -13, -15}, // [7 /*SMA*/] + {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15}, // [8 /*MSA*/] + {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1}, // [9 /*TCA*/] + {-15, -13, -9, -11, -1, -3, -7, -5, 15, 13, 9, 11, 1, 3, 7, 5}, // [10 /*OGA*/] }; template -inline T five_bit_look_up[11][32] -{ - [0] = {}, - [1 /*OB*/] = {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, - [2 /*SM*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, - [3 /*MS*/] = {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, - [4 /*TC*/] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, - [5 /*OG*/] = {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, - [6 /*OBA*/] = {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, - [7 /*SMA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, - [8 /*MSA*/] = {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, - [9 /*TCA*/] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, - [10 /*OGA*/] = {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, +inline T five_bit_look_up[11][32]{ + {}, // [0] + {-16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, // [1 /*OB*/] + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15}, // [2 /*SM*/] + {0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1, 0, 0, 1, -1}, // [3 /*MS*/] + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1}, // [4 /*TC*/] + {-16, -15, -13, -14, -9, -10, -12, -11, -1, -2, -4, -3, -8, -7, -5, -6, 15, 14, 12, 13, 8, 9, 11, 10, 0, 1, 3, 2, 7, 6, 4, 5}, // [5 /*OG*/] + {-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31}, // [6 /*OBA*/] + {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -1, -3, -5, -7, -9, -11, -13, -15, -17, -19, -21, -23, -25, -27, -29, -31}, // [7 /*SMA*/] + {1, -1, 3, -3, 5, -5, 7, -7, 9, -9, 11, -11, 13, -13, 15, -15, 17, -17, 19, -19, 21, -21, 23, -23, 25, -25, 27, -27, 29, -29, 31, -31}, // [8 /*MSA*/] + {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1}, // [9 /*TCA*/] + {-31, -29, -25, -27, -17, -19, -23, -21, -1, -3, -7, -5, -15, -13, -9, -11, 31, 29, 25, 27, 17, 19, 23, 21, 1, 3, 7, 5, 15, 13, 9, 11}, // [10 /*OGA*/] }; } // namespace GnssMetadata diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 07069ed9e..222b93cad 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -197,6 +197,7 @@ #endif #if ENABLE_ION_SOURCE +#undef Owner #include "ion_gsms_signal_source.h" #endif From 7aa19d9642bcc730087681cc2e982106fedb05ca Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 18 Aug 2024 10:57:40 +0200 Subject: [PATCH 18/66] Use lock_guard instead of unique_lock --- .../adrv9361_z7035_signal_source_fpga.cc | 35 +++++++++---------- .../adrv9361_z7035_signal_source_fpga.h | 10 +++--- .../adapters/fmcomms5_signal_source_fpga.cc | 35 +++++++++---------- .../adapters/fmcomms5_signal_source_fpga.h | 11 +++--- .../max2771_evkit_signal_source_fpga.cc | 21 +++++------ .../max2771_evkit_signal_source_fpga.h | 4 +-- 6 files changed, 52 insertions(+), 64 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index 9d29e2de2..392d91b13 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -1,6 +1,6 @@ /*! * \file adrv9361_z7035_signal_source_fpga.cc - * \brief signal source for the Analog Devices ADRV9361-Z7035 evaluation board + * \brief Signal source for the Analog Devices ADRV9361-Z7035 evaluation board * directly connected to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -257,7 +257,6 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration buffer_monitor_fpga = std::make_shared(num_freq_bands, dump_, dump_filename); thread_buffer_monitor = std::thread([&] { run_buffer_monitor_process(); }); - // dynamic bits selection if (enable_dynamic_bit_selection_) { @@ -278,8 +277,7 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { std::cout << "* AD9361 Disabling RX streaming channels\n"; @@ -301,24 +299,27 @@ Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { thread_buffer_monitor.join(); } - - std::unique_lock lock_dyn_bit_sel(dynamic_bit_selection_mutex); - bool bit_selection_enabled = enable_dynamic_bit_selection_; - lock_dyn_bit_sel.unlock(); + bool bit_selection_enabled = false; + { + std::lock_guard lock_dyn_bit_sel(dynamic_bit_selection_mutex); + bit_selection_enabled = enable_dynamic_bit_selection_; + } if (bit_selection_enabled == true) { - std::unique_lock lock(dynamic_bit_selection_mutex); - enable_dynamic_bit_selection_ = false; - lock.unlock(); + { + std::lock_guard lock(dynamic_bit_selection_mutex); + enable_dynamic_bit_selection_ = false; + } if (thread_dynamic_bit_selection.joinable()) { @@ -337,12 +338,11 @@ void Adrv9361z7035SignalSourceFPGA::run_dynamic_bit_selection_process() // setting the bit selection to the top bits dynamic_bit_selection_fpga->bit_selection(); std::this_thread::sleep_for(std::chrono::milliseconds(Gain_control_period_ms)); - std::unique_lock lock(dynamic_bit_selection_mutex); + std::lock_guard lock(dynamic_bit_selection_mutex); if (enable_dynamic_bit_selection_ == false) { dynamic_bit_selection_active = false; } - lock.unlock(); } } @@ -357,12 +357,11 @@ void Adrv9361z7035SignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h index 5e7e8b7e4..beffb3c70 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h @@ -1,6 +1,6 @@ /*! * \file adrv9361_z7035_signal_source_fpga.h - * \brief signal source for the Analog Devices ADRV9361-Z7035 evaluation board + * \brief Signal source for the Analog Devices ADRV9361-Z7035 evaluation board * directly connected to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -78,13 +78,14 @@ private: const uint32_t buffer_monitor_period_ms = 1000; // buffer overflow and buffer monitoring initial delay const uint32_t buffer_monitoring_initial_delay_ms = 2000; - // sample block size when running in post-processing mode - const int sample_block_size = 16384; const int32_t switch_to_real_time_mode = 2; void run_dynamic_bit_selection_process(); void run_buffer_monitor_process(); + mutable std::mutex dynamic_bit_selection_mutex; + mutable std::mutex buffer_monitor_mutex; + std::thread thread_dynamic_bit_selection; std::thread thread_buffer_monitor; @@ -92,9 +93,6 @@ private: std::shared_ptr dynamic_bit_selection_fpga; std::shared_ptr buffer_monitor_fpga; - std::mutex dynamic_bit_selection_mutex; - std::mutex buffer_monitor_mutex; - std::string gain_mode_rx1_; std::string gain_mode_rx2_; std::string rf_port_select_; diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc index d8c5a65c0..096e422db 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc @@ -1,6 +1,6 @@ /*! * \file fmcomms5_signal_source_fpga.cc - * \brief signal source for the Analog Devices FMCOMMS5 directly connected + * \brief Signal source for the Analog Devices FMCOMMS5 directly connected * to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -217,7 +217,6 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface buffer_monitor_fpga = std::make_shared(num_freq_bands, dump_, dump_filename); thread_buffer_monitor = std::thread([&] { run_buffer_monitor_process(); }); - // dynamic bits selection if (enable_dynamic_bit_selection_) { @@ -238,8 +237,7 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { std::cout << "* Disabling RX streaming channels\n"; @@ -250,24 +248,27 @@ Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { thread_buffer_monitor.join(); } - - std::unique_lock lock_dyn_bit_sel(dynamic_bit_selection_mutex); - bool bit_selection_enabled = enable_dynamic_bit_selection_; - lock_dyn_bit_sel.unlock(); + bool bit_selection_enabled = false; + { + std::lock_guard lock_dyn_bit_sel(dynamic_bit_selection_mutex); + bit_selection_enabled = enable_dynamic_bit_selection_; + } if (bit_selection_enabled == true) { - std::unique_lock lock(dynamic_bit_selection_mutex); - enable_dynamic_bit_selection_ = false; - lock.unlock(); + { + std::lock_guard lock(dynamic_bit_selection_mutex); + enable_dynamic_bit_selection_ = false; + } if (thread_dynamic_bit_selection.joinable()) { @@ -286,12 +287,11 @@ void Fmcomms5SignalSourceFPGA::run_dynamic_bit_selection_process() // setting the bit selection to the top bits dynamic_bit_selection_fpga->bit_selection(); std::this_thread::sleep_for(std::chrono::milliseconds(Gain_control_period_ms)); - std::unique_lock lock(dynamic_bit_selection_mutex); + std::lock_guard lock(dynamic_bit_selection_mutex); if (enable_dynamic_bit_selection_ == false) { dynamic_bit_selection_active = false; } - lock.unlock(); } } @@ -306,12 +306,11 @@ void Fmcomms5SignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h index 1bdcf4e6f..1c5c37c73 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h @@ -1,6 +1,6 @@ /*! * \file fmcomms5_signal_source_fpga.h - * \brief signal source for the Analog Devices FMCOMMS5 directly connected + * \brief Signal source for the Analog Devices FMCOMMS5 directly connected * to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -67,7 +67,6 @@ private: const std::string default_dump_filename = std::string("FPGA_buffer_monitor_dump.dat"); const std::string default_rf_port_select = std::string("A_BALANCED"); const std::string default_gain_mode = std::string("slow_attack"); - const double default_tx_attenuation_db = -10.0; const double default_manual_gain_rx1 = 64.0; const double default_manual_gain_rx2 = 64.0; const uint64_t default_bandwidth = 12500000; @@ -78,13 +77,14 @@ private: const uint32_t buffer_monitor_period_ms = 1000; // buffer overflow and buffer monitoring initial delay const uint32_t buffer_monitoring_initial_delay_ms = 2000; - // sample block size when running in post-processing mode - const int sample_block_size = 16384; const int32_t switch_to_real_time_mode = 2; void run_dynamic_bit_selection_process(); void run_buffer_monitor_process(); + mutable std::mutex dynamic_bit_selection_mutex; + mutable std::mutex buffer_monitor_mutex; + std::thread thread_dynamic_bit_selection; std::thread thread_buffer_monitor; @@ -92,9 +92,6 @@ private: std::shared_ptr dynamic_bit_selection_fpga; std::shared_ptr buffer_monitor_fpga; - std::mutex dynamic_bit_selection_mutex; - std::mutex buffer_monitor_mutex; - std::string gain_mode_rx1_; std::string gain_mode_rx2_; std::string rf_port_select_; diff --git a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc index 788b50e77..80b310034 100644 --- a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc @@ -140,13 +140,11 @@ MAX2771EVKITSignalSourceFPGA::MAX2771EVKITSignalSourceFPGA(const ConfigurationIn } } + std::vector MAX2771EVKITSignalSourceFPGA::setup_regs(void) { - std::vector register_values = std::vector(MAX2771_NUM_REGS); - - + auto register_values = std::vector(MAX2771_NUM_REGS); uint32_t LNA_mode = (LNA_active_) ? 0x0 : 0x2; - uint32_t Filter_Bandwidth; switch (bandwidth_) @@ -376,10 +374,10 @@ bool MAX2771EVKITSignalSourceFPGA::configure(std::vector register_valu return 0; } + MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { chipen_ = false; @@ -392,7 +390,6 @@ MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() return; } - if (configure(register_values)) { std::cerr << "Error disabling the MAX2771 device " << '\n'; @@ -405,9 +402,10 @@ MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { @@ -426,12 +424,11 @@ void MAX2771EVKITSignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h index 3008aa384..5ba036ca3 100644 --- a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h @@ -53,7 +53,6 @@ public: std::vector setup_regs(void); - inline size_t item_size() override { return item_size_; @@ -130,14 +129,13 @@ private: bool configure(std::vector register_values); void run_buffer_monitor_process(); + mutable std::mutex buffer_monitor_mutex; std::thread thread_buffer_monitor; std::shared_ptr buffer_monitor_fpga; std::shared_ptr spidev_fpga; - std::mutex buffer_monitor_mutex; - uint64_t freq_; // frequency of local oscillator uint64_t sample_rate_; From 62cb96ae03a5f3ae14b6ba7062e93ffdf7e67e2e Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:25:05 +0200 Subject: [PATCH 19/66] Create a CMake target for the ION dependency for consistency --- CMakeLists.txt | 68 +++++++++++++++---- .../signal_source/libs/CMakeLists.txt | 9 ++- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f70609a92..8b081522b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ option(ENABLE_ARRAY "Enable the use of CTTC's antenna array front-end as signal option(ENABLE_ZMQ "Enable GNU Radio ZeroMQ Messaging, requires gr-zeromq" ON) -option(ENABLE_ION "Enable ION GNSS-SDR Metadata Standard signal source" ON) +option(ENABLE_ION "Enable ION GNSS-SDR Metadata Standard signal source" OFF) # Performance analysis tools option(ENABLE_GPERFTOOLS "Enable linking to Gperftools libraries (tcmalloc and profiler)" OFF) @@ -1424,20 +1424,6 @@ else() endif() -################################################################################ -# ION GNSS-SDR Metadata Standard -################################################################################ -include(FetchContent) -FetchContent_Declare( - gnss_metadata_standard - GIT_REPOSITORY https://github.com/IonMetadataWorkingGroup/GNSS-Metadata-Standard - GIT_TAG master - SOURCE_DIR ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard - CMAKE_ARGS -DABSL_PROPAGATE_CXX_STD=ON -ABSL_BUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=${GNSSSDR_BINARY_DIR}/gnss-metadata-standard ${ABSEIL_TOOLCHAIN_FILE} - BINARY_DIR ${GNSSSDR_BINARY_DIR}/gnss-metadata-standard -) -FetchContent_MakeAvailable(gnss_metadata_standard) - ################################################################################ # Abseil C++ - https://abseil.io/docs/cpp/ ################################################################################ @@ -3371,6 +3357,57 @@ if(ENABLE_AD9361 OR ENABLE_FMCOMMS2) endif() +################################################################################ +# ION GNSS-SDR Metadata Standard https://sdr.ion.org/ (OPTIONAL) +################################################################################ +if(ENABLE_ION) + include(FetchContent) + set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) + FetchContent_Declare( + gnss_metadata_standard + GIT_REPOSITORY https://github.com/IonMetadataWorkingGroup/GNSS-Metadata-Standard + GIT_TAG origin/master + SOURCE_DIR ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GNSSSDR_BINARY_DIR}/gnss-metadata-standard + BINARY_DIR ${GNSSSDR_BINARY_DIR}/gnss-metadata-standard + ) + FetchContent_MakeAvailable(gnss_metadata_standard) + + if(NOT TARGET ION::ion) + add_library(ION::ion STATIC IMPORTED) + add_dependencies(ION::ion gnss_metadata_standard) + if(CMAKE_GENERATOR STREQUAL "Xcode") + set_target_properties(ION::ion PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION_DEBUG "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX}" + IMPORTED_LOCATION_RELEASE "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Release/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX}" + IMPORTED_LOCATION_RELWITHDEBINFO "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX}" + IMPORTED_LOCATION_MINSIZEREL "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/MinSizeRel/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES "${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard/source/api/inc" + ) + set_property(TARGET ION::ion APPEND PROPERTY + INTERFACE_LINK_LIBRARIES + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Release/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/Release/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/MinSizeRel/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/MinSizeRel/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/RelWithDebInfo/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + "$<$:${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/Debug/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}>" + ) + else() + set_target_properties(ION::ion PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES "${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard/source/api/inc" + INTERFACE_LINK_LIBRARIES "${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/GnssMetadata/${CMAKE_FIND_LIBRARY_PREFIXES}api${CMAKE_STATIC_LIBRARY_SUFFIX};${GNSSSDR_BINARY_DIR}/gnss-metadata-standard/source/api/lib/tinyxml2/${CMAKE_FIND_LIBRARY_PREFIXES}xml${CMAKE_STATIC_LIBRARY_SUFFIX}" + ) + endif() + endif() +endif() + ##################################################################### # Check signal sources related to FPGA only. @@ -3684,6 +3721,7 @@ add_feature_info(ENABLE_RAW_UDP ENABLE_RAW_UDP "Enables Custom_UDP_Signal_Source add_feature_info(ENABLE_FLEXIBAND ENABLE_FLEXIBAND "Enables Flexiband_Signal_Source for using Teleorbit's Flexiband RF front-end. Requires gr-teleorbit.") add_feature_info(ENABLE_ARRAY ENABLE_ARRAY "Enables Raw_Array_Signal_Source and Array_Signal_Conditioner for using CTTC's antenna array. Requires gr-dbfcttc.") add_feature_info(ENABLE_ZMQ ENABLE_ZMQ "Enables ZMQ_Signal_Source for GNU Radio ZeroMQ messages. Requires gr-zeromq.") +add_feature_info(ENABLE_ION ENABLE_ION "Enables ION_GSMS_Signal_Source for the ION Metadata Standard.") add_feature_info(ENABLE_GPERFTOOLS ENABLE_GPERFTOOLS "Enables performance analysis. Requires Gperftools.") add_feature_info(ENABLE_GPROF ENABLE_GPROF "Enables performance analysis with 'gprof'.") add_feature_info(ENABLE_CLANG_TIDY ENABLE_CLANG_TIDY "Runs clang-tidy along with the compiler. Requires Clang.") diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 36f327931..aa4fa8eea 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -142,6 +142,10 @@ if(ENABLE_FPGA OR ENABLE_AD9361) ) endif() +if(ENABLE_ION) + target_link_libraries(signal_source_libs PUBLIC ION::ion algorithms_libs) +endif() + if(ENABLE_CLANG_TIDY) if(CLANG_TIDY_EXE) set_target_properties(signal_source_libs @@ -151,11 +155,6 @@ if(ENABLE_CLANG_TIDY) endif() endif() -if(ENABLE_ION) - target_include_directories(signal_source_libs PUBLIC ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard/source/api/inc) - target_link_libraries(signal_source_libs PUBLIC api xml) -endif() - set_property(TARGET signal_source_libs APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $ ) From da21ff4fd9747ec52c7122c370e652bc943e1850 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:26:21 +0200 Subject: [PATCH 20/66] Improve formatting, add missing include --- .../adapters/ion_gsms_signal_source.cc | 13 +++++++++++-- .../signal_source/adapters/ion_gsms_signal_source.h | 5 ++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index b4edd615f..c0db26e71 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -49,6 +49,7 @@ std::vector parse_comma_list(const std::string& str) return list; } + IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configuration, const std::string& role, unsigned int in_streams, @@ -62,10 +63,14 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura in_streams_(in_streams), out_streams_(out_streams) { - if (in_streams > 0) + if (in_streams_ > 0) { LOG(ERROR) << "A signal source does not have an input stream"; } + if (out_streams_ <= 0) + { + LOG(ERROR) << "A signal source does not have an output stream"; + } sources_ = metadata_.make_stream_sources(configuration, role, stream_ids_); @@ -91,6 +96,7 @@ void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) } } + void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) { std::size_t cumulative_index = 0; @@ -103,6 +109,7 @@ void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) } } + gr::basic_block_sptr IONGSMSSignalSource::get_left_block() { LOG(WARNING) << "Trying to get signal source left block."; @@ -110,11 +117,13 @@ gr::basic_block_sptr IONGSMSSignalSource::get_left_block() return IONGSMSFileSource::sptr(); } + gr::basic_block_sptr IONGSMSSignalSource::get_right_block() { return get_right_block(0); } + gr::basic_block_sptr IONGSMSSignalSource::get_right_block(int RF_channel) { return copy_blocks_[RF_channel]; diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 5063b4e80..d724d101b 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -22,6 +22,7 @@ #include "file_source_base.h" #include "gnss_sdr_timestamp.h" #include "ion_gsms.h" +#include #include #include @@ -44,8 +45,6 @@ public: ~IONGSMSSignalSource() override = default; protected: - // std::tuple itemTypeToSize() override; - // double packetsPerSample() const override; void connect(gr::top_block_sptr top_block) override; void disconnect(gr::top_block_sptr top_block) override; From e37855d43ee85d10c5ac2ac7e247349407ad6700 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:27:29 +0200 Subject: [PATCH 21/66] Fixes for C++ standards older than 20. Avoid C++20-specific lambda templates --- src/algorithms/signal_source/libs/ion_gsms.cc | 22 +++---- src/algorithms/signal_source/libs/ion_gsms.h | 18 +++--- .../signal_source/libs/ion_gsms_chunk_data.cc | 47 ++++++++------- .../signal_source/libs/ion_gsms_chunk_data.h | 57 +++++++++++++++---- .../libs/ion_gsms_chunk_unpacking_ctx.h | 16 +++--- .../libs/ion_gsms_metadata_handler.cc | 19 +++++-- .../libs/ion_gsms_metadata_handler.h | 21 +++---- .../libs/ion_gsms_stream_encodings.h | 14 +++-- 8 files changed, 132 insertions(+), 82 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 8389afd10..e44c0abab 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -17,22 +17,14 @@ #include "ion_gsms.h" #include "gnuradio/block.h" #include -#include -#include - -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#include -#endif +#include using namespace std::string_literals; IONGSMSFileSource::IONGSMSFileSource( const ConfigurationInterface* configuration __attribute__((unused)), const std::string& role __attribute__((unused)), - const std::filesystem::path& metadata_filepath, + const fs::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids) @@ -40,13 +32,11 @@ IONGSMSFileSource::IONGSMSFileSource( "ion_gsms_file_source", gr::io_signature::make(0, 0, 0), make_output_signature(block, stream_ids)), - file_metadata_(file), - block_metadata_(block), io_buffer_offset_(0), maximum_item_rate_(0), chunk_cycle_length_(0) { - std::filesystem::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); + fs::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); fd_ = std::fopen(data_filepath.c_str(), "rb"); std::size_t block_offset = file.Offset(); std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); @@ -67,11 +57,13 @@ IONGSMSFileSource::IONGSMSFileSource( output_stream_count_ = output_stream_offset; } + IONGSMSFileSource::~IONGSMSFileSource() { std::fclose(fd_); } + int IONGSMSFileSource::work( int noutput_items, gr_vector_const_void_star& input_items __attribute__((unused)), @@ -106,11 +98,13 @@ int IONGSMSFileSource::work( return WORK_CALLED_PRODUCE; } + std::size_t IONGSMSFileSource::output_stream_count() const { return output_stream_count_; } + std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) const { return output_stream_item_sizes_[stream_index]; diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 5164e3581..054b1e9dd 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -19,14 +19,20 @@ #include "configuration_interface.h" #include "gnss_block_interface.h" +#include "gnss_sdr_filesystem.h" #include "ion_gsms_chunk_data.h" #include #include -#include +#include +#include #include #include #include +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ class IONGSMSFileSource : public gr::sync_block { @@ -36,7 +42,7 @@ public: IONGSMSFileSource( const ConfigurationInterface* configuration, const std::string& role, - const std::filesystem::path& metadata_filepath, + const fs::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, const std::vector& stream_ids); @@ -54,9 +60,6 @@ public: private: static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); -private: - const GnssMetadata::File& file_metadata_; - const GnssMetadata::Block& block_metadata_; FILE* fd_; std::vector io_buffer_; std::size_t io_buffer_offset_; @@ -70,5 +73,6 @@ private: #include "ion_gsms_metadata_handler.h" - +/** \} */ +/** \} */ #endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc index f6d1b18b9..5a8cd823c 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.cc @@ -8,31 +8,30 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- */ #include "ion_gsms_chunk_data.h" -#include -#include -#include - +#include #if USE_GLOG_AND_GFLAGS #include #else #include #endif + IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::vector& stream_ids, std::size_t output_stream_offset) : chunk_(chunk), sizeword_(chunk_.SizeWord()), countwords_(chunk_.CountWords()) { - with_word_type(sizeword_, [&] { - buffer_ = new WordType[countwords_]; - }); + // Instantiate the Allocator functor + Allocator allocator(countwords_, buffer_); + // Call with_word_type with the Allocator functor + with_word_type(sizeword_, allocator); const std::size_t total_bitsize = sizeword_ * countwords_ * 8; std::size_t used_bitsize = 0; @@ -81,11 +80,11 @@ IONGSMSChunkData::IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std:: IONGSMSChunkData::~IONGSMSChunkData() { - with_word_type(sizeword_, [&] { - delete[] static_cast(buffer_); - }); + Deleter deleter(static_cast(buffer_)); + with_word_type(sizeword_, deleter); } + std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offset) { memset(buffer_, 0, sizeword_ * countwords_); @@ -93,6 +92,7 @@ std::size_t IONGSMSChunkData::read_from_buffer(uint8_t* buffer, std::size_t offs return sizeword_ * countwords_; } + void IONGSMSChunkData::write_to_output(gr_vector_void_star& outputs, std::vector& output_items) { switch (sizeword_) @@ -121,11 +121,13 @@ std::size_t IONGSMSChunkData::output_stream_count() const return output_stream_count_; } + std::size_t IONGSMSChunkData::output_stream_item_size(std::size_t stream_index) const { return output_stream_item_size_[stream_index]; } + std::size_t IONGSMSChunkData::output_stream_item_rate(std::size_t stream_index) const { return output_stream_item_rate_[stream_index]; @@ -165,6 +167,7 @@ void IONGSMSChunkData::unpack_words(gr_vector_void_star& outputs, std::vector std::size_t IONGSMSChunkData::write_stream_samples( IONGSMSChunkUnpackingCtx& ctx, @@ -185,24 +188,25 @@ std::size_t IONGSMSChunkData::write_stream_samples( if (sample_bitsize <= 8) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int8_t**)(out)); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast(out)); } else if (sample_bitsize <= 16) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int16_t**)(out)); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast(out)); } else if (sample_bitsize <= 32) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int32_t**)(out)); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast(out)); } else if (sample_bitsize <= 64) { - write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, (int64_t**)(out)); + write_n_samples(ctx, lump.Shift(), sample_bitsize, sample_count, stream_encoding, reinterpret_cast(out)); } return sample_count; } + template void IONGSMSChunkData::write_n_samples( IONGSMSChunkUnpackingCtx& ctx, @@ -241,22 +245,23 @@ void IONGSMSChunkData::write_n_samples( // Static utilities -void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, auto* sample, const GnssMetadata::StreamEncoding encoding) +template +void IONGSMSChunkData::decode_sample(const uint8_t sample_bitsize, Sample* sample, const GnssMetadata::StreamEncoding encoding) { - using SampleType = std::remove_pointer_t; + // using SampleType = std::remove_pointer_t; switch (sample_bitsize) { case 2: - *sample = GnssMetadata::two_bit_look_up[encoding][*sample]; + *sample = GnssMetadata::two_bit_look_up[encoding][*sample]; break; case 3: - *sample = GnssMetadata::three_bit_look_up[encoding][*sample]; + *sample = GnssMetadata::three_bit_look_up[encoding][*sample]; break; case 4: - *sample = GnssMetadata::four_bit_look_up[encoding][*sample]; + *sample = GnssMetadata::four_bit_look_up[encoding][*sample]; break; case 5: - *sample = GnssMetadata::five_bit_look_up[encoding][*sample]; + *sample = GnssMetadata::five_bit_look_up[encoding][*sample]; break; default: // TODO - Is this an error that can happen? diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 881c431f6..5a6b98aba 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -21,16 +21,14 @@ #include "ion_gsms_chunk_unpacking_ctx.h" #include "ion_gsms_stream_encodings.h" #include +#include +#include +#include #include #include -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif -inline std::size_t bits_to_item_size(const std::size_t bit_count) +inline std::size_t bits_to_item_size(std::size_t bit_count) { if (bit_count <= 8) { @@ -50,11 +48,46 @@ inline std::size_t bits_to_item_size(const std::size_t bit_count) } // You are asking too much of this humble processor - LOG(ERROR) << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense."; + std::cerr << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense.\n"; return 1; } -void with_word_type(const uint8_t word_size, auto&& callback) + +// Define a functor that has a templated operator() +struct Allocator +{ + size_t countwords_; + void*& buffer_; // Using void* to hold any type of pointer + + Allocator(size_t countwords, void*& buffer) + : countwords_(countwords), buffer_(buffer) {} + + template + void operator()() const + { + buffer_ = new WordType[countwords_]; + } +}; + + +// Define a functor to delete the allocated memory +struct Deleter +{ + void* buffer_; + + explicit Deleter(void* buffer) + : buffer_(buffer) {} + + template + void operator()() const + { + delete[] static_cast(buffer_); + } +}; + + +template +void with_word_type(uint8_t word_size, Callback callback) { switch (word_size) { @@ -71,7 +104,7 @@ void with_word_type(const uint8_t word_size, auto&& callback) callback.template operator()(); break; default: - LOG(ERROR) << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense."; + std::cerr << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense.\n"; break; } } @@ -118,9 +151,9 @@ private: GnssMetadata::StreamEncoding stream_encoding, OT** out); - static void decode_sample(uint8_t sample_bitsize, auto* sample, GnssMetadata::StreamEncoding encoding); + template + static void decode_sample(uint8_t sample_bitsize, Sample* sample, GnssMetadata::StreamEncoding encoding); -private: const GnssMetadata::Chunk& chunk_; uint8_t sizeword_; uint8_t countwords_; diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 1dad11902..c4d839de1 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -10,7 +10,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -21,12 +21,12 @@ #include "GnssMetadata.h" #include +#include -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ template struct IONGSMSChunkUnpackingCtx @@ -118,7 +118,7 @@ struct IONGSMSChunkUnpackingCtx } template - void shift_sample(const uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) + void shift_sample(uint8_t sample_bitsize, OT* output, uint8_t output_bit_offset = 0) { if (sample_bitsize % word_bitsize_ == 0) { @@ -176,4 +176,6 @@ struct IONGSMSChunkUnpackingCtx } }; +/** \} */ +/** \} */ #endif // ION_GSM_CHUNK_UNPACKING_CTX_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index 9a05e372d..eea6e9c5f 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -8,14 +8,14 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- */ #include "ion_gsms.h" - +#include #if USE_GLOG_AND_GFLAGS #include #else @@ -40,16 +40,25 @@ void IONGSMSMetadataHandler::load_metadata() GnssMetadata::XmlProcessor xml_proc; if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) { - LOG(ERROR) << "Could not load XML metadata file:"; + LOG(WARNING) << "Could not load XML metadata file " << metadata_filepath_; + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); } } catch (GnssMetadata::ApiException& e) { - LOG(ERROR) << "API Exception while loading XML metadata file: " << std::to_string(e.Error()); + LOG(WARNING) << "API Exception while loading XML metadata file: " << std::to_string(e.Error()); + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << std::to_string(e.Error()) << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); } catch (std::exception& e) { - LOG(ERROR) << "Exception while loading XML metadata file: " << e.what(); + LOG(WARNING) << "Exception while loading XML metadata file: " << e.what(); + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << e.what() << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); } } diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 710233d72..62077c82a 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -8,7 +8,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -23,11 +23,11 @@ #include #include -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ + class IONGSMSMetadataHandler { @@ -35,16 +35,17 @@ public: explicit IONGSMSMetadataHandler(const std::string& metadata_filepath); std::vector make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector& stream_ids) const; - -public: // Getters const std::string& metadata_filepath() const; -private: // Private methods +private: void load_metadata(); -private: // State + // State std::string metadata_filepath_; GnssMetadata::Metadata metadata_; }; + +/** \} */ +/** \} */ #endif // ION_GSMS_METADATA_HANDLER_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h index 443a6e823..90ba15cac 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -10,7 +10,7 @@ * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. * This file is part of GNSS-SDR. * - * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors) + * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -21,11 +21,10 @@ #include -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ namespace GnssMetadata { @@ -165,4 +164,7 @@ inline T five_bit_look_up[11][32]{ } // namespace GnssMetadata + +/** \} */ +/** \} */ #endif // ION_GSM_STREAM_ENCODINGS_H From bc2a1e02b893be7fafcbf40baa384e41f2cb6d58 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:28:03 +0200 Subject: [PATCH 22/66] Update changelog --- docs/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 931e8988f..abdc04427 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -41,6 +41,11 @@ All notable changes to GNSS-SDR will be documented in this file. - `-DENABLE_DMA_PROXY`: Checks if the DMA proxy driver is installed for controlling the DMA in the FPGA and enables its usage. +- Add the `ION_GSMS_Signal_Source`, which is able to process raw data files + described with the + [ION GNSS Software Defined Receiver Metadata Standard](https://sdr.ion.org/). + It requires the `-DENABLE_ION=ON` building configuration option. + ### Improvements in Portability: - Fix building against google-glog 0.7.x. From fc5148bf44377e9062a697f4d1ae01b9d8276ae6 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:28:35 +0200 Subject: [PATCH 23/66] Add Victor to the list of authors --- AUTHORS | 1 + CITATION.cff | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS b/AUTHORS index ad0660662..d1251f1fc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -64,6 +64,7 @@ Marc Sales marcsales92@gmail.com Contributor Piyush Gupta piyush04111999@gmail.com Contributor Rodrigo Muñoz rodrigo.munoz@proteinlab.cl Contributor Stefan van der Linden spvdlinden@gmail.com Contributor +Victor Castillo-Agüero victorcastilloaguero@gmail.com Contributor Will Silberman wsilberm@google.com Contributor Carlos Paniego carpanie@hotmail.com Artwork diff --git a/CITATION.cff b/CITATION.cff index 0f11b55f1..2be1e1880 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -34,6 +34,11 @@ authors: email: mara.branzanti@gmail.com family-names: Branzanti given-names: Mara + - alias: castle055 + affiliation: "Instituto Nacional de Técnica Aeroespacial" + email: victorcastilloaguero@gmail.com + family-names: "Castillo-Agüero" + given-names: Victor - alias: acebrianjuan email: acebrianjuan@gmail.com family-names: "Cebrián-Juan" From c212bac26d856308bd01040625639b39a280c2af Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 09:58:33 +0200 Subject: [PATCH 24/66] Fix CMake error --- src/algorithms/signal_source/adapters/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 9ff0ab434..d6491098f 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -171,7 +171,7 @@ target_include_directories(signal_source_adapters ${GNSSSDR_SOURCE_DIR}/src/core/interfaces ) -if(ENABLE_FPGA OR ENABLE_AD9361) +if(ENABLE_FPGA OR ENABLE_AD9361 OR ENABLE_ION) target_link_libraries(signal_source_adapters PUBLIC signal_source_libs From 614693ea0f34fed42aa35c5e4fa788c05a116478 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 10:21:51 +0200 Subject: [PATCH 25/66] Fix building error --- src/algorithms/signal_source/libs/ion_gsms_chunk_data.h | 2 +- .../signal_source/libs/ion_gsms_chunk_unpacking_ctx.h | 2 +- src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 5a6b98aba..1dd712351 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -17,10 +17,10 @@ #ifndef ION_GSM_CHUNK_DATA_H #define ION_GSM_CHUNK_DATA_H -#include "GnssMetadata.h" #include "ion_gsms_chunk_unpacking_ctx.h" #include "ion_gsms_stream_encodings.h" #include +#include #include #include #include diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index c4d839de1..44c125889 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -19,8 +19,8 @@ #ifndef ION_GSM_CHUNK_UNPACKING_CTX_H #define ION_GSM_CHUNK_UNPACKING_CTX_H -#include "GnssMetadata.h" #include +#include #include /** \addtogroup Signal_Source diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 62077c82a..2431fbec8 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -17,9 +17,9 @@ #ifndef ION_GSMS_METADATA_HANDLER_H #define ION_GSMS_METADATA_HANDLER_H -#include "GnssMetadata.h" #include "configuration_interface.h" #include +#include #include #include From f3ba1822b17d95bc1eb25d0ddd18481183aff238 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 10:24:48 +0200 Subject: [PATCH 26/66] Fix building --- src/algorithms/signal_source/adapters/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index d6491098f..6b58e1abe 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -103,6 +103,11 @@ if(ENABLE_ZMQ) list(APPEND OPT_DRIVER_HEADERS zmq_signal_source.h) endif() +if(ENABLE_ION) + list(APPEND OPT_DRIVER_SOURCES ion_gsms_signal_source.cc) + list(APPEND OPT_DRIVER_HEADERS ion_gsms_signal_source.h) +endif() + set(SIGNAL_SOURCE_ADAPTER_SOURCES signal_source_base.cc file_source_base.cc @@ -119,7 +124,6 @@ set(SIGNAL_SOURCE_ADAPTER_SOURCES two_bit_packed_file_signal_source.cc four_bit_cpx_file_signal_source.cc file_timestamp_signal_source.cc - ion_gsms_signal_source.cc ${OPT_DRIVER_SOURCES} ) @@ -139,7 +143,6 @@ set(SIGNAL_SOURCE_ADAPTER_HEADERS two_bit_packed_file_signal_source.h four_bit_cpx_file_signal_source.h file_timestamp_signal_source.h - ion_gsms_signal_source.h ${OPT_DRIVER_HEADERS} ) From 45d31cb3b9a637b14adc4bb497fb1336c27cfd06 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 10:29:48 +0200 Subject: [PATCH 27/66] Add -DENABLE_ION=ON to CI jobs --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 32dc29f9b..7bc294b0f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: libgnutls-openssl-dev libmatio-dev googletest protobuf-compiler libprotobuf-dev \ python3-mako liborc-0.4-dev - name: configure - run: cd build && cmake -GNinja .. + run: cd build && cmake -GNinja -DENABLE_ION=ON .. - name: build run: cd build && ninja - name: check @@ -60,7 +60,7 @@ jobs: brew install ninja hdf5 automake armadillo lapack libmatio gnuradio openssl pugixml protobuf pip3 install mako - name: configure - run: cd build && cmake -GNinja .. + run: cd build && cmake -GNinja -DENABLE_ION=ON .. - name: build run: cd build && ninja - name: check @@ -92,7 +92,7 @@ jobs: brew install ninja pkg-config hdf5 automake armadillo lapack libmatio gnuradio openssl pugixml protobuf pip3 install mako - name: configure - run: cd build && cmake -GXcode .. + run: cd build && cmake -GXcode -DENABLE_ION=ON .. - name: build run: cd build && xcodebuild -configuration Release - name: check From df1314945f43afdb531f9b5df848e26e28e87178 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 10:56:11 +0200 Subject: [PATCH 28/66] Fix CMake lists --- src/algorithms/signal_source/libs/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 3506dc4f7..19235ceac 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -9,12 +9,12 @@ set(OPT_SIGNAL_SOURCE_LIB_SOURCES "") set(OPT_SIGNAL_SOURCE_LIB_HEADERS "") if(ENABLE_FMCOMMS2 OR ENABLE_AD9361) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad9361_manager.h) endif() if(ENABLE_MAX2771) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} fpga_spidev.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} fpga_spidev.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} fpga_spidev.h) endif() if(ENABLE_FPGA) @@ -36,10 +36,10 @@ endif() if(ENABLE_PLUTOSDR) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_samples.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.h) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} pps_samplestamp.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} pps_samplestamp.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.h) endif() From 126421f8476be402d4ab99f7c1aaa2fd0932a50d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 12:30:25 +0200 Subject: [PATCH 29/66] Catch all exceptions --- .../adapters/adrv9361_z7035_signal_source_fpga.cc | 13 +++++++++++-- .../adapters/fmcomms5_signal_source_fpga.cc | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index 392d91b13..cc8f7fe32 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -281,10 +281,19 @@ Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() if (rf_shutdown_) { std::cout << "* AD9361 Disabling RX streaming channels\n"; - if (!disable_ad9361_rx_local()) + try { - LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + if (!disable_ad9361_rx_local()) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + } } + catch (const std::exception &e) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels: " << e.what(); + std::cerr << "Problem shutting down the AD9361 RX channels: " << e.what() << '\n'; + } + if (enable_dds_lo_) { try diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc index 096e422db..be2108aa4 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc @@ -241,9 +241,16 @@ Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() if (rf_shutdown_) { std::cout << "* Disabling RX streaming channels\n"; - if (!disable_ad9361_rx_local()) + try { - LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + if (!disable_ad9361_rx_local()) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + } + } + catch (const std::exception &e) + { + std::cerr << "Problem shutting down the AD9361 RX channels: " << e.what() << '\n'; } } From 6836ac44fb5cb8d9fc5327aac5bb1b8ab1d9b370 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 14:21:59 +0200 Subject: [PATCH 30/66] Fix building for -DENABLE_PLUTOSDR=ON --- CMakeLists.txt | 2 +- .../signal_source/adapters/CMakeLists.txt | 2 +- .../gnuradio_blocks/ad936x_iio_source.cc | 2 +- .../signal_source/libs/ad936x_iio_custom.cc | 3 +- .../signal_source/libs/ad936x_iio_custom.h | 32 +++++++++---------- .../signal_source/libs/ad936x_iio_samples.h | 12 +++++-- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3696eede2..8c0e25d25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3338,7 +3338,7 @@ set_package_properties(LIBIIO PROPERTIES PURPOSE "Used for communication with the AD9361 chipset." TYPE OPTIONAL ) -if(ENABLE_AD9361 OR ENABLE_FMCOMMS2) +if(ENABLE_AD9361 OR ENABLE_FMCOMMS2 OR ENABLE_PLUTOSDR) if(NOT LIBIIO_FOUND) message(STATUS "libiio not found, its installation is required.") message(STATUS "Please build and install the following projects:") diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 0aa745101..6b253d8c7 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -239,7 +239,7 @@ if(ENABLE_LIMESDR AND GRLIMESDR_FOUND) ) endif() -if(ENABLE_AD9361 AND LIBIIO_FOUND) +if(LIBIIO_FOUND) target_link_libraries(signal_source_adapters PRIVATE Iio::iio diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc index 0cf885fe2..375edf7da 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc @@ -87,7 +87,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samples_in, int nchannels, std::vector *files_out) { - int32_t current_byte = 0; + uint32_t current_byte = 0; int16_t ch = 0; // std::cout << "nbytes: " << samples_in->n_bytes << " nsamples: " << samples_in->n_samples << " nch: " << nchannels << "\n"; while (current_byte < samples_in->n_bytes) diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc index 72461bafd..ad983aa6b 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_custom.cc - * \brief A direct IIO custom front-end driver for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end driver for the AD936x AD front-end + * family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * ----------------------------------------------------------------------------- * diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.h b/src/algorithms/signal_source/libs/ad936x_iio_custom.h index 83a61282a..ab58f36cc 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.h @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_custom.h - * \brief A direct IIO custom front-end driver for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end driver for the AD936x AD front-end + * family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * ----------------------------------------------------------------------------- * @@ -14,27 +15,27 @@ */ -#ifndef SRC_LIBS_ad936x_iio_custom_H_ -#define SRC_LIBS_ad936x_iio_custom_H_ +#ifndef GNSS_SDR_AD936X_IIO_CUSTOM_H +#define GNSS_SDR_AD936X_IIO_CUSTOM_H +#include "ad936x_iio_samples.h" #include "concurrent_queue.h" #include "gnss_time.h" #include "pps_samplestamp.h" #include +#include +#include // multichip sync and high level functions #include #include - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#include "ad936x_iio_samples.h" -#include // multichip sync and high level functions #include #include +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ + + class ad936x_iio_custom { public: @@ -121,10 +122,7 @@ private: struct iio_device *dds_dev; // stream - uint64_t sample_rate_sps; - - int debug_level; int log_level; bool PPS_mode; @@ -144,4 +142,6 @@ private: std::thread capture_time_thread; }; -#endif /* SRC_LIBS_ad936x_iio_custom_H_ */ +/** \} */ +/** \} */ +#endif // GNSS_SDR_AD936X_IIO_CUSTOM_H diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.h b/src/algorithms/signal_source/libs/ad936x_iio_samples.h index 63d30545b..53fff2c9e 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_samples.h @@ -15,17 +15,21 @@ */ -#ifndef SRC_LIBS_ad936x_iio_samples_H_ -#define SRC_LIBS_ad936x_iio_samples_H_ +#ifndef GNSS_SDR_AD936X_IIO_SAMPLES_H +#define GNSS_SDR_AD936X_IIO_SAMPLES_H #define IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES 32768 * 4 - #define IIO_INPUTRAMFIFOSIZE 256 #include #include #include +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ + class ad936x_iio_samples { public: @@ -37,4 +41,6 @@ public: char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; // max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q) }; +/** \} */ +/** \} */ #endif From 4d1540181d7dd98ce4fa73db68b4454c052a01c5 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:36:03 +0200 Subject: [PATCH 31/66] Removed unused member fields and function parameters --- .../signal_source/adapters/ion_gsms_signal_source.cc | 5 ++--- .../signal_source/adapters/ion_gsms_signal_source.h | 1 - src/algorithms/signal_source/libs/ion_gsms.cc | 2 -- src/algorithms/signal_source/libs/ion_gsms.h | 3 --- .../signal_source/libs/ion_gsms_metadata_handler.cc | 4 +--- .../signal_source/libs/ion_gsms_metadata_handler.h | 2 +- 6 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index c0db26e71..5dde9915c 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -56,9 +56,8 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura unsigned int out_streams, Concurrent_Queue* queue __attribute__((unused))) : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), - metadata_file_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), - metadata_(metadata_file_), + metadata_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)), in_streams_(in_streams), out_streams_(out_streams) @@ -72,7 +71,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura LOG(ERROR) << "A signal source does not have an output stream"; } - sources_ = metadata_.make_stream_sources(configuration, role, stream_ids_); + sources_ = metadata_.make_stream_sources(stream_ids_); for (const auto& source : sources_) { diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index d724d101b..6e0aa6364 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -58,7 +58,6 @@ protected: } private: - std::string metadata_file_; std::vector stream_ids_; std::vector sources_; std::vector> copy_blocks_; diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index e44c0abab..78f9060bd 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -22,8 +22,6 @@ using namespace std::string_literals; IONGSMSFileSource::IONGSMSFileSource( - const ConfigurationInterface* configuration __attribute__((unused)), - const std::string& role __attribute__((unused)), const fs::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 054b1e9dd..64a3e8c16 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -17,7 +17,6 @@ #ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H #define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H -#include "configuration_interface.h" #include "gnss_block_interface.h" #include "gnss_sdr_filesystem.h" #include "ion_gsms_chunk_data.h" @@ -40,8 +39,6 @@ public: using sptr = gnss_shared_ptr; IONGSMSFileSource( - const ConfigurationInterface* configuration, - const std::string& role, const fs::path& metadata_filepath, const GnssMetadata::File& file, const GnssMetadata::Block& block, diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index eea6e9c5f..7d4c96fa5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -62,7 +62,7 @@ void IONGSMSMetadataHandler::load_metadata() } } -std::vector IONGSMSMetadataHandler::make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector& stream_ids) const +std::vector IONGSMSMetadataHandler::make_stream_sources(const std::vector& stream_ids) const { std::vector sources{}; for (const auto& file : metadata_.Files()) @@ -92,8 +92,6 @@ std::vector IONGSMSMetadataHandler::make_stream_sources if (found) { auto source = gnss_make_shared( - configuration, - role, metadata_filepath_, file, block, diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 2431fbec8..969a3f4be 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -34,7 +34,7 @@ class IONGSMSMetadataHandler public: explicit IONGSMSMetadataHandler(const std::string& metadata_filepath); - std::vector make_stream_sources(const ConfigurationInterface* configuration, const std::string& role, const std::vector& stream_ids) const; + std::vector make_stream_sources(const std::vector& stream_ids) const; const std::string& metadata_filepath() const; private: From f1957476b8b83438a994542b82b10117d63b3587 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:37:58 +0200 Subject: [PATCH 32/66] Use std::ifstream instead of FILE for reading sample data --- src/algorithms/signal_source/libs/ion_gsms.cc | 14 ++++---------- src/algorithms/signal_source/libs/ion_gsms.h | 7 +++---- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index 78f9060bd..ca46c7c53 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -30,14 +30,14 @@ IONGSMSFileSource::IONGSMSFileSource( "ion_gsms_file_source", gr::io_signature::make(0, 0, 0), make_output_signature(block, stream_ids)), + file_stream_(metadata_filepath.parent_path() / file.Url().Value()), io_buffer_offset_(0), maximum_item_rate_(0), chunk_cycle_length_(0) { fs::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); - fd_ = std::fopen(data_filepath.c_str(), "rb"); std::size_t block_offset = file.Offset(); - std::fseek(fd_, file.Offset() + block_offset + block.SizeHeader(), SEEK_SET); + file_stream_.seekg(file.Offset() + block_offset + block.SizeHeader()); std::size_t output_stream_offset = 0; for (const auto& chunk : block.Chunks()) @@ -56,12 +56,6 @@ IONGSMSFileSource::IONGSMSFileSource( } -IONGSMSFileSource::~IONGSMSFileSource() -{ - std::fclose(fd_); -} - - int IONGSMSFileSource::work( int noutput_items, gr_vector_const_void_star& input_items __attribute__((unused)), @@ -70,7 +64,7 @@ int IONGSMSFileSource::work( const std::size_t max_sample_output = std::floor((noutput_items - 1.0) / maximum_item_rate_); io_buffer_.resize(max_sample_output * chunk_cycle_length_); io_buffer_offset_ = 0; - std::fread(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type), io_buffer_.size(), fd_); + file_stream_.read(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type) * io_buffer_.size()); items_produced_.resize(output_items.size()); for (int& i : items_produced_) @@ -83,7 +77,7 @@ int IONGSMSFileSource::work( for (auto& c : chunk_data_) { auto* chunk = c.get(); - io_buffer_offset_ += chunk->read_from_buffer(io_buffer_.data(), io_buffer_offset_); + io_buffer_offset_ += chunk->read_from_buffer(reinterpret_cast(io_buffer_.data()), io_buffer_offset_); chunk->write_to_output(output_items, items_produced_); } } diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index 64a3e8c16..c9bc8efd2 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -27,6 +27,7 @@ #include #include #include +#include /** \addtogroup Signal_Source * \{ */ @@ -44,8 +45,6 @@ public: const GnssMetadata::Block& block, const std::vector& stream_ids); - ~IONGSMSFileSource() override; - int work( int noutput_items, gr_vector_const_void_star& input_items, @@ -57,8 +56,8 @@ public: private: static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); - FILE* fd_; - std::vector io_buffer_; + std::ifstream file_stream_; + std::vector io_buffer_; std::size_t io_buffer_offset_; std::vector items_produced_; std::size_t output_stream_count_; From 3bdc7b9f21452c91a143e68d323ea87765998e28 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:39:17 +0200 Subject: [PATCH 33/66] Fixed includes and code style --- .../signal_source/adapters/ion_gsms_signal_source.h | 2 +- src/algorithms/signal_source/libs/ion_gsms.cc | 5 +---- src/algorithms/signal_source/libs/ion_gsms.h | 2 -- .../signal_source/libs/ion_gsms_metadata_handler.cc | 2 +- .../signal_source/libs/ion_gsms_metadata_handler.h | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 6e0aa6364..5bddfc147 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -21,7 +21,7 @@ #include "configuration_interface.h" #include "file_source_base.h" #include "gnss_sdr_timestamp.h" -#include "ion_gsms.h" +#include "ion_gsms_metadata_handler.h" #include #include #include diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/libs/ion_gsms.cc index ca46c7c53..515bb1cf5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.cc +++ b/src/algorithms/signal_source/libs/ion_gsms.cc @@ -66,11 +66,8 @@ int IONGSMSFileSource::work( io_buffer_offset_ = 0; file_stream_.read(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type) * io_buffer_.size()); + items_produced_.clear(); items_produced_.resize(output_items.size()); - for (int& i : items_produced_) - { - i = 0; - } while (io_buffer_offset_ < io_buffer_.size()) { diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/libs/ion_gsms.h index c9bc8efd2..a4f7e2625 100644 --- a/src/algorithms/signal_source/libs/ion_gsms.h +++ b/src/algorithms/signal_source/libs/ion_gsms.h @@ -67,8 +67,6 @@ private: std::size_t chunk_cycle_length_; }; -#include "ion_gsms_metadata_handler.h" - /** \} */ /** \} */ #endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc index 7d4c96fa5..154ad6904 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc @@ -14,7 +14,7 @@ * ----------------------------------------------------------------------------- */ -#include "ion_gsms.h" +#include "ion_gsms_metadata_handler.h" #include #if USE_GLOG_AND_GFLAGS #include diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 969a3f4be..4b6f5be81 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -17,7 +17,7 @@ #ifndef ION_GSMS_METADATA_HANDLER_H #define ION_GSMS_METADATA_HANDLER_H -#include "configuration_interface.h" +#include "ion_gsms.h" #include #include #include From 7cdda8e0dc1a82e444106c65118d7a13aab47947 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:42:26 +0200 Subject: [PATCH 34/66] Simplified disconnect() function We can disconnect the sources directly instead of disconnecting each of their outputs. --- .../signal_source/adapters/ion_gsms_signal_source.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index 5dde9915c..0a4f065ee 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -98,13 +98,9 @@ void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) { - std::size_t cumulative_index = 0; for (const auto& source : sources_) { - for (std::size_t i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) - { - top_block->disconnect(source, i, copy_blocks_[cumulative_index], 0); - } + top_block->disconnect(source); } } From 174364af319a6686757249dd1f4aca873867ec87 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:46:28 +0200 Subject: [PATCH 35/66] Implemented range check in `IONGSMSSignalSource::get_right_block(int)` --- .../signal_source/adapters/ion_gsms_signal_source.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index 0a4f065ee..e608cf10b 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -121,5 +121,10 @@ gr::basic_block_sptr IONGSMSSignalSource::get_right_block() gr::basic_block_sptr IONGSMSSignalSource::get_right_block(int RF_channel) { + if (RF_channel < 0 || RF_channel >= static_cast(copy_blocks_.size())) + { + LOG(WARNING) << "'RF_channel' out of bounds while trying to get signal source right block."; + return copy_blocks_[0]; + } return copy_blocks_[RF_channel]; } From c10eceb9731c67014935cbfbd397ca364eb52491 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 15:58:37 +0200 Subject: [PATCH 36/66] Moved ION GSMS file source to `gnuradio_blocks/` directory Also fixed some header guards. --- src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt | 5 +++++ .../signal_source/{libs => gnuradio_blocks}/ion_gsms.cc | 0 .../signal_source/{libs => gnuradio_blocks}/ion_gsms.h | 0 src/algorithms/signal_source/libs/CMakeLists.txt | 2 -- src/algorithms/signal_source/libs/ion_gsms_chunk_data.h | 6 +++--- .../signal_source/libs/ion_gsms_chunk_unpacking_ctx.h | 6 +++--- .../signal_source/libs/ion_gsms_metadata_handler.h | 6 +++--- .../signal_source/libs/ion_gsms_stream_encodings.h | 6 +++--- 8 files changed, 17 insertions(+), 14 deletions(-) rename src/algorithms/signal_source/{libs => gnuradio_blocks}/ion_gsms.cc (100%) rename src/algorithms/signal_source/{libs => gnuradio_blocks}/ion_gsms.h (100%) diff --git a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt index 24f067be6..a217648b4 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt @@ -21,6 +21,11 @@ if(ENABLE_PLUTOSDR) set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ad936x_iio_source.h) endif() +if(ENABLE_ION) + set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} ion_gsms.cc) + set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ion_gsms.h) +endif() + set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES fifo_reader.cc unpack_byte_2bit_samples.cc diff --git a/src/algorithms/signal_source/libs/ion_gsms.cc b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc similarity index 100% rename from src/algorithms/signal_source/libs/ion_gsms.cc rename to src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc diff --git a/src/algorithms/signal_source/libs/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h similarity index 100% rename from src/algorithms/signal_source/libs/ion_gsms.h rename to src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index aa4fa8eea..b674ef5f5 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -46,8 +46,6 @@ if(ENABLE_PLUTOSDR) endif() if(ENABLE_ION) - set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_chunk_data.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_data.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_metadata_handler.cc) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h index 1dd712351..5170af848 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_data.h @@ -14,8 +14,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef ION_GSM_CHUNK_DATA_H -#define ION_GSM_CHUNK_DATA_H +#ifndef GNSS_SDR_ION_GSMS_CHUNK_DATA_H +#define GNSS_SDR_ION_GSMS_CHUNK_DATA_H #include "ion_gsms_chunk_unpacking_ctx.h" #include "ion_gsms_stream_encodings.h" @@ -185,4 +185,4 @@ private: void* buffer_; }; -#endif // ION_GSM_CHUNK_DATA_H +#endif // GNSS_SDR_ION_GSMS_CHUNK_DATA_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 44c125889..3c5d7b662 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -16,8 +16,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef ION_GSM_CHUNK_UNPACKING_CTX_H -#define ION_GSM_CHUNK_UNPACKING_CTX_H +#ifndef GNSS_SDR_ION_GSMS_CHUNK_UNPACKING_CTX_H +#define GNSS_SDR_ION_GSMS_CHUNK_UNPACKING_CTX_H #include #include @@ -178,4 +178,4 @@ struct IONGSMSChunkUnpackingCtx /** \} */ /** \} */ -#endif // ION_GSM_CHUNK_UNPACKING_CTX_H +#endif // GNSS_SDR_ION_GSMS_CHUNK_UNPACKING_CTX_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h index 4b6f5be81..6d01567c5 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h @@ -14,8 +14,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef ION_GSMS_METADATA_HANDLER_H -#define ION_GSMS_METADATA_HANDLER_H +#ifndef GNSS_SDR_ION_GSMSS_METADATA_HANDLER_H +#define GNSS_SDR_ION_GSMSS_METADATA_HANDLER_H #include "ion_gsms.h" #include @@ -48,4 +48,4 @@ private: /** \} */ /** \} */ -#endif // ION_GSMS_METADATA_HANDLER_H +#endif // GNSS_SDR_ION_GSMSS_METADATA_HANDLER_H diff --git a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h index 90ba15cac..5b39e6497 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h +++ b/src/algorithms/signal_source/libs/ion_gsms_stream_encodings.h @@ -16,8 +16,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef ION_GSM_STREAM_ENCODINGS_H -#define ION_GSM_STREAM_ENCODINGS_H +#ifndef GNSS_SDR_ION_GSMS_STREAM_ENCODINGS_H +#define GNSS_SDR_ION_GSMS_STREAM_ENCODINGS_H #include @@ -167,4 +167,4 @@ inline T five_bit_look_up[11][32]{ /** \} */ /** \} */ -#endif // ION_GSM_STREAM_ENCODINGS_H +#endif // GNSS_SDR_ION_GSMS_STREAM_ENCODINGS_H From 54e18adb61fc39b741b6ab97de3642814815409d Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 17:39:33 +0200 Subject: [PATCH 37/66] Fixed ION GNSS Metadata Standard dependency version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b081522b..781e98a23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3366,7 +3366,7 @@ if(ENABLE_ION) FetchContent_Declare( gnss_metadata_standard GIT_REPOSITORY https://github.com/IonMetadataWorkingGroup/GNSS-Metadata-Standard - GIT_TAG origin/master + GIT_TAG 220d116e10db5e403e21b77a1fa25aa35feda198 SOURCE_DIR ${GNSSSDR_BINARY_DIR}/thirdparty/gnss-metadata-standard CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${GNSSSDR_BINARY_DIR}/gnss-metadata-standard BINARY_DIR ${GNSSSDR_BINARY_DIR}/gnss-metadata-standard From 92dcec67e076d9db0a0d590d7fadd2eb76ce2663 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 17:43:18 +0200 Subject: [PATCH 38/66] Simplified by removing a very shallow class `ion_gnss_metadata_handler` was only reading the metadata file, which can easily be done in `ion_gsms_signal_source`. --- .../adapters/ion_gsms_signal_source.cc | 99 +++++++++++++- .../adapters/ion_gsms_signal_source.h | 12 +- .../signal_source/libs/CMakeLists.txt | 2 - .../libs/ion_gsms_metadata_handler.cc | 126 ------------------ .../libs/ion_gsms_metadata_handler.h | 51 ------- 5 files changed, 107 insertions(+), 183 deletions(-) delete mode 100644 src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc delete mode 100644 src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index e608cf10b..ba02529b6 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -57,7 +57,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura Concurrent_Queue* queue __attribute__((unused))) : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), - metadata_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), + metadata_filepath_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)), in_streams_(in_streams), out_streams_(out_streams) @@ -71,7 +71,11 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura LOG(ERROR) << "A signal source does not have an output stream"; } - sources_ = metadata_.make_stream_sources(stream_ids_); + // Parse XML metadata file + load_metadata(); + + // Make source vector + sources_ = make_stream_sources(stream_ids_); for (const auto& source : sources_) { @@ -82,6 +86,97 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura } } +void IONGSMSSignalSource::load_metadata() +{ + try + { + GnssMetadata::XmlProcessor xml_proc; + if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) + { + LOG(WARNING) << "Could not load XML metadata file " << metadata_filepath_; + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); + } + } + catch (GnssMetadata::ApiException& e) + { + LOG(WARNING) << "API Exception while loading XML metadata file: " << std::to_string(e.Error()); + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << std::to_string(e.Error()) << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); + } + catch (std::exception& e) + { + LOG(WARNING) << "Exception while loading XML metadata file: " << e.what(); + std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << e.what() << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); + } +} + +std::vector IONGSMSSignalSource::make_stream_sources(const std::vector& stream_ids) const +{ + std::vector sources{}; + for (const auto& file : metadata_.Files()) + { + for (const auto& lane : metadata_.Lanes()) + { + if (lane.Id() == file.Lane().Id()) + { + for (const auto& block : lane.Blocks()) + { + bool block_done = false; + for (const auto& chunk : block.Chunks()) + { + for (const auto& lump : chunk.Lumps()) + { + for (const auto& stream : lump.Streams()) + { + bool found = false; + for (const auto& stream_id : stream_ids) + { + if (stream_id == stream.Id()) + { + found = true; + break; + } + } + if (found) + { + auto source = gnss_make_shared( + metadata_filepath_, + file, + block, + stream_ids); + + sources.push_back(source); + + // This file source will take care of any other matching streams in this block + // We can skip the rest of this block + block_done = true; + break; + } + } + + if (block_done) + { + break; + } + } + if (block_done) + { + break; + } + } + } + break; + } + } + } + + return sources; +} void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) { diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 5bddfc147..31d0f7815 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -21,7 +21,8 @@ #include "configuration_interface.h" #include "file_source_base.h" #include "gnss_sdr_timestamp.h" -#include "ion_gsms_metadata_handler.h" +#include "ion_gsms.h" +#include #include #include #include @@ -58,10 +59,17 @@ protected: } private: + std::vector make_stream_sources(const std::vector& stream_ids) const; + + void load_metadata(); + std::vector stream_ids_; std::vector sources_; std::vector> copy_blocks_; - IONGSMSMetadataHandler metadata_; + std::vector> valves_; + + std::string metadata_filepath_; + GnssMetadata::Metadata metadata_; gnss_shared_ptr timestamp_block_; std::string timestamp_file_; diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index b674ef5f5..4ad4caf93 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -48,8 +48,6 @@ endif() if(ENABLE_ION) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_chunk_data.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_data.h) - set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ion_gsms_metadata_handler.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_metadata_handler.h) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_stream_encodings.h) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_unpacking_ctx.h) endif() diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc deleted file mode 100644 index 154ad6904..000000000 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.cc +++ /dev/null @@ -1,126 +0,0 @@ -/*! - * \file ion_gsms_metadata_handler.cc - * \brief Build instances of IONGSMSFileSource as needed given a list of stream ids - * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com - * - * ----------------------------------------------------------------------------- - * - * 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 "ion_gsms_metadata_handler.h" -#include -#if USE_GLOG_AND_GFLAGS -#include -#else -#include -#endif - -IONGSMSMetadataHandler::IONGSMSMetadataHandler(const std::string& metadata_filepath) - : metadata_filepath_(metadata_filepath) -{ - load_metadata(); -} - -const std::string& IONGSMSMetadataHandler::metadata_filepath() const -{ - return metadata_filepath_; -} - -void IONGSMSMetadataHandler::load_metadata() -{ - try - { - GnssMetadata::XmlProcessor xml_proc; - if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) - { - LOG(WARNING) << "Could not load XML metadata file " << metadata_filepath_; - std::cerr << "Could not load XML metadata file " << metadata_filepath_ << std::endl; - std::cout << "GNSS-SDR program ended.\n"; - exit(1); - } - } - catch (GnssMetadata::ApiException& e) - { - LOG(WARNING) << "API Exception while loading XML metadata file: " << std::to_string(e.Error()); - std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << std::to_string(e.Error()) << std::endl; - std::cout << "GNSS-SDR program ended.\n"; - exit(1); - } - catch (std::exception& e) - { - LOG(WARNING) << "Exception while loading XML metadata file: " << e.what(); - std::cerr << "Could not load XML metadata file " << metadata_filepath_ << " : " << e.what() << std::endl; - std::cout << "GNSS-SDR program ended.\n"; - exit(1); - } -} - -std::vector IONGSMSMetadataHandler::make_stream_sources(const std::vector& stream_ids) const -{ - std::vector sources{}; - for (const auto& file : metadata_.Files()) - { - for (const auto& lane : metadata_.Lanes()) - { - if (lane.Id() == file.Lane().Id()) - { - for (const auto& block : lane.Blocks()) - { - bool block_done = false; - for (const auto& chunk : block.Chunks()) - { - for (const auto& lump : chunk.Lumps()) - { - for (const auto& stream : lump.Streams()) - { - bool found = false; - for (const auto& stream_id : stream_ids) - { - if (stream_id == stream.Id()) - { - found = true; - break; - } - } - if (found) - { - auto source = gnss_make_shared( - metadata_filepath_, - file, - block, - stream_ids); - - sources.push_back(source); - - // This file source will take care of any other matching streams in this block - // We can skip the rest of this block - block_done = true; - break; - } - } - - if (block_done) - { - break; - } - } - if (block_done) - { - break; - } - } - } - break; - } - } - } - - return sources; -} diff --git a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h b/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h deleted file mode 100644 index 6d01567c5..000000000 --- a/src/algorithms/signal_source/libs/ion_gsms_metadata_handler.h +++ /dev/null @@ -1,51 +0,0 @@ -/*! - * \file ion_gsms_metadata_handler.h - * \brief Build instances of IONGSMSFileSource as needed given a list of stream ids - * \author Víctor Castillo Agüero, 2024. victorcastilloaguero(at)gmail.com - * - * ----------------------------------------------------------------------------- - * - * 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_ION_GSMSS_METADATA_HANDLER_H -#define GNSS_SDR_ION_GSMSS_METADATA_HANDLER_H - -#include "ion_gsms.h" -#include -#include -#include -#include - -/** \addtogroup Signal_Source - * \{ */ -/** \addtogroup Signal_Source_libs - * \{ */ - - -class IONGSMSMetadataHandler -{ -public: - explicit IONGSMSMetadataHandler(const std::string& metadata_filepath); - - std::vector make_stream_sources(const std::vector& stream_ids) const; - const std::string& metadata_filepath() const; - -private: - void load_metadata(); - - // State - std::string metadata_filepath_; - GnssMetadata::Metadata metadata_; -}; - - -/** \} */ -/** \} */ -#endif // GNSS_SDR_ION_GSMSS_METADATA_HANDLER_H From 89d73174a87d243ab88792c49736fbc35120b5ba Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 17:44:36 +0200 Subject: [PATCH 39/66] Added valves to properly handle end of samples --- AUTHORS | 2 +- CITATION.cff | 2 +- .../adapters/ion_gsms_signal_source.cc | 16 ++- .../signal_source/gnuradio_blocks/ion_gsms.cc | 108 +++++++++++++----- .../signal_source/gnuradio_blocks/ion_gsms.h | 5 +- 5 files changed, 100 insertions(+), 33 deletions(-) diff --git a/AUTHORS b/AUTHORS index d1251f1fc..7df41ed17 100644 --- a/AUTHORS +++ b/AUTHORS @@ -64,7 +64,7 @@ Marc Sales marcsales92@gmail.com Contributor Piyush Gupta piyush04111999@gmail.com Contributor Rodrigo Muñoz rodrigo.munoz@proteinlab.cl Contributor Stefan van der Linden spvdlinden@gmail.com Contributor -Victor Castillo-Agüero victorcastilloaguero@gmail.com Contributor +Víctor Castillo-Agüero victorcastilloaguero@gmail.com Contributor Will Silberman wsilberm@google.com Contributor Carlos Paniego carpanie@hotmail.com Artwork diff --git a/CITATION.cff b/CITATION.cff index 2be1e1880..4bf27081f 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -38,7 +38,7 @@ authors: affiliation: "Instituto Nacional de Técnica Aeroespacial" email: victorcastilloaguero@gmail.com family-names: "Castillo-Agüero" - given-names: Victor + given-names: Víctor - alias: acebrianjuan email: acebrianjuan@gmail.com family-names: "Cebrián-Juan" diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index ba02529b6..b67ec8a3a 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -17,6 +17,7 @@ #include "ion_gsms_signal_source.h" #include "gnss_sdr_flags.h" #include "gnss_sdr_string_literals.h" +#include "gnss_sdr_valve.h" #include #include #include @@ -54,7 +55,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura const std::string& role, unsigned int in_streams, unsigned int out_streams, - Concurrent_Queue* queue __attribute__((unused))) + Concurrent_Queue* queue) : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), metadata_filepath_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), @@ -82,6 +83,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura for (std::size_t i = 0; i < source->output_stream_count(); ++i) { copy_blocks_.push_back(gr::blocks::copy::make(source->output_stream_item_size(i))); + valves_.push_back(gnss_sdr_make_valve(source->output_stream_item_size(i), source->output_stream_total_sample_count(i), queue)); } } } @@ -186,6 +188,7 @@ void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) for (std::size_t i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) { top_block->connect(source, i, copy_blocks_[cumulative_index], 0); + top_block->connect(copy_blocks_[cumulative_index], 0, valves_[cumulative_index], 0); } } } @@ -193,9 +196,14 @@ void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) void IONGSMSSignalSource::disconnect(gr::top_block_sptr top_block) { + std::size_t cumulative_index = 0; for (const auto& source : sources_) { - top_block->disconnect(source); + for (std::size_t i = 0; i < source->output_stream_count(); ++i, ++cumulative_index) + { + top_block->disconnect(source, i, copy_blocks_[cumulative_index], 0); + top_block->disconnect(copy_blocks_[cumulative_index], 0, valves_[cumulative_index], 0); + } } } @@ -219,7 +227,7 @@ gr::basic_block_sptr IONGSMSSignalSource::get_right_block(int RF_channel) if (RF_channel < 0 || RF_channel >= static_cast(copy_blocks_.size())) { LOG(WARNING) << "'RF_channel' out of bounds while trying to get signal source right block."; - return copy_blocks_[0]; + return valves_[0]; } - return copy_blocks_[RF_channel]; + return valves_[RF_channel]; } diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc index 515bb1cf5..034f43379 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc @@ -19,6 +19,12 @@ #include #include +#if USE_GLOG_AND_GFLAGS +#include +#else +#include +#endif + using namespace std::string_literals; IONGSMSFileSource::IONGSMSFileSource( @@ -30,13 +36,20 @@ IONGSMSFileSource::IONGSMSFileSource( "ion_gsms_file_source", gr::io_signature::make(0, 0, 0), make_output_signature(block, stream_ids)), - file_stream_(metadata_filepath.parent_path() / file.Url().Value()), + file_stream_(metadata_filepath.parent_path() / file.Url().Value(), std::ios::in | std::ios::binary), io_buffer_offset_(0), maximum_item_rate_(0), chunk_cycle_length_(0) { fs::path data_filepath = metadata_filepath.parent_path() / file.Url().Value(); std::size_t block_offset = file.Offset(); + + if (!file_stream_.is_open()) + { + LOG(ERROR) << "ion_gsms_file_source: Unable to open the samples file: " << (data_filepath).c_str(); + } + + // Skip offset and block header file_stream_.seekg(file.Offset() + block_offset + block.SizeHeader()); std::size_t output_stream_offset = 0; @@ -49,42 +62,26 @@ IONGSMSFileSource::IONGSMSFileSource( for (std::size_t i = 0; i < out_count; ++i) { output_stream_item_sizes_.push_back(chunk_data_.back()->output_stream_item_size(i)); + output_stream_item_rates_.push_back(chunk_data_.back()->output_stream_item_rate(i)); maximum_item_rate_ = std::max(chunk_data_.back()->output_stream_item_rate(i), maximum_item_rate_); } } output_stream_count_ = output_stream_offset; -} + output_stream_total_sample_counts_.resize(output_stream_count_); -int IONGSMSFileSource::work( - int noutput_items, - gr_vector_const_void_star& input_items __attribute__((unused)), - gr_vector_void_star& output_items) -{ - const std::size_t max_sample_output = std::floor((noutput_items - 1.0) / maximum_item_rate_); - io_buffer_.resize(max_sample_output * chunk_cycle_length_); - io_buffer_offset_ = 0; - file_stream_.read(io_buffer_.data(), sizeof(decltype(io_buffer_)::value_type) * io_buffer_.size()); - - items_produced_.clear(); - items_produced_.resize(output_items.size()); - - while (io_buffer_offset_ < io_buffer_.size()) + std::size_t cycle_count = block.Cycles(); + if (cycle_count == 0) { - for (auto& c : chunk_data_) - { - auto* chunk = c.get(); - io_buffer_offset_ += chunk->read_from_buffer(reinterpret_cast(io_buffer_.data()), io_buffer_offset_); - chunk->write_to_output(output_items, items_produced_); - } + // Read the whole file + const std::size_t file_size = fs::file_size(data_filepath); + cycle_count = std::floor((file_size - block_offset - block.SizeHeader()) / chunk_cycle_length_); } - for (std::size_t i = 0; i < items_produced_.size(); ++i) + for (std::size_t i = 0; i < output_stream_count_; ++i) { - produce(i, items_produced_[i]); + output_stream_total_sample_counts_[i] = cycle_count * output_stream_item_rates_[i]; } - - return WORK_CALLED_PRODUCE; } @@ -99,6 +96,10 @@ std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) return output_stream_item_sizes_[stream_index]; } +std::size_t IONGSMSFileSource::output_stream_total_sample_count(std::size_t stream_index) const +{ + return output_stream_total_sample_counts_[stream_index]; +} gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) { @@ -140,3 +141,58 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada nstreams, item_sizes); } + +int IONGSMSFileSource::work( + int noutput_items, + gr_vector_const_void_star& input_items __attribute__((unused)), + gr_vector_void_star& output_items) +{ + // Compute the maximum number of samples that will be copied across all output buffer. + // If there are more than one output buffer (multichannel set up), the one with the most samples will be used as the maximum. + // + // Complex samples produce 2 items each (I and Q). In order to account for them, we subtract 1 from `noutput_items` and + // then floor the division. During testing, not doing this caused `max_sample_output` to oscillate between two values, thus + // resizing the `io_buffer_` on each call to `work()`. + const std::size_t max_sample_output = std::floor((noutput_items - 1.0) / maximum_item_rate_); + + // Resize the IO buffer to fit exactly the maximum amount of samples that will be outputted. + io_buffer_.resize(max_sample_output * chunk_cycle_length_); + + // We will be walking the IO buffer with this variable. + io_buffer_offset_ = 0; + + // Read samples from file into IO buffer + const std::size_t bytes_to_read = io_buffer_.size(); + file_stream_.read(io_buffer_.data(), bytes_to_read); + + // Reset `items_produced_` vector. This vector will accumulate the amount of items produced for each output stream. + items_produced_.clear(); + items_produced_.resize(output_items.size()); + + // Walk the IO buffer one chunk cycle at a time. See ION documentation for a definition of chunk and chunk cycle. + while (io_buffer_offset_ < bytes_to_read) + { + // Iterate chunks within a chunk cycle + for (auto& c : chunk_data_) + { + auto* chunk = c.get(); + + // Copy chunk into a separate buffer where the samples will be shifted from. + const std::size_t bytes_copied = chunk->read_from_buffer(reinterpret_cast(io_buffer_.data()), io_buffer_offset_); + + // Advance IO buffer offset + io_buffer_offset_ += bytes_copied; + + // Shift samples into output buffers following the appropriate unpacking strategy for this chunk. + chunk->write_to_output(output_items, items_produced_); + } + } + + // Call `produce(int, int)` with the appropriate item count for each output stream. + for (std::size_t i = 0; i < items_produced_.size(); ++i) + { + produce(i, items_produced_[i]); + } + + return WORK_CALLED_PRODUCE; +} diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h index a4f7e2625..a787344bf 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h @@ -24,10 +24,10 @@ #include #include #include +#include #include #include #include -#include /** \addtogroup Signal_Source * \{ */ @@ -52,6 +52,7 @@ public: std::size_t output_stream_count() const; std::size_t output_stream_item_size(std::size_t stream_index) const; + std::size_t output_stream_total_sample_count(std::size_t stream_index) const; private: static gr::io_signature::sptr make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids); @@ -62,6 +63,8 @@ private: std::vector items_produced_; std::size_t output_stream_count_; std::vector output_stream_item_sizes_; + std::vector output_stream_item_rates_; + std::vector output_stream_total_sample_counts_; std::size_t maximum_item_rate_; std::vector> chunk_data_; std::size_t chunk_cycle_length_; From 9bf3f457c361c67175e4a12563d8204d9b0a3146 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 14:54:15 +0200 Subject: [PATCH 40/66] Cleaner exit if the data file is not found --- .../signal_source/gnuradio_blocks/ion_gsms.cc | 12 +++++++++--- .../signal_source/gnuradio_blocks/ion_gsms.h | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc index 034f43379..60a08ba6c 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc @@ -18,6 +18,8 @@ #include "gnuradio/block.h" #include #include +#include +#include #if USE_GLOG_AND_GFLAGS #include @@ -25,8 +27,6 @@ #include #endif -using namespace std::string_literals; - IONGSMSFileSource::IONGSMSFileSource( const fs::path& metadata_filepath, const GnssMetadata::File& file, @@ -46,7 +46,10 @@ IONGSMSFileSource::IONGSMSFileSource( if (!file_stream_.is_open()) { - LOG(ERROR) << "ion_gsms_file_source: Unable to open the samples file: " << (data_filepath).c_str(); + LOG(WARNING) << "ION_GSMS_Signal_Source - Unable to open the samples file: " << (data_filepath).c_str(); + std::cerr << "ION_GSMS_Signal_Source - Unable to open the samples file: " << (data_filepath).c_str() << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); } // Skip offset and block header @@ -96,11 +99,13 @@ std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) return output_stream_item_sizes_[stream_index]; } + std::size_t IONGSMSFileSource::output_stream_total_sample_count(std::size_t stream_index) const { return output_stream_total_sample_counts_[stream_index]; } + gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) { int nstreams = 0; @@ -142,6 +147,7 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada item_sizes); } + int IONGSMSFileSource::work( int noutput_items, gr_vector_const_void_star& input_items __attribute__((unused)), diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h index a787344bf..c82726b85 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include From 4929d8775921c59f3f0cddf90481e7a4968e5ecc Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 14:58:01 +0200 Subject: [PATCH 41/66] Fix uninitialized warning --- .../signal_source/libs/ion_gsms_chunk_unpacking_ctx.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 3c5d7b662..6799f1080 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -34,8 +34,8 @@ struct IONGSMSChunkUnpackingCtx static constexpr uint8_t word_bitsize_ = sizeof(WT) * 8; const GnssMetadata::Chunk::WordShift word_shift_direction_; - WT* iterator_; // Not owned by this class, MUST NOT destroy - WT current_word_; + WT* iterator_ = nullptr; // Not owned by this class, MUST NOT destroy + WT current_word_{}; uint8_t bitshift_ = 0; IONGSMSChunkUnpackingCtx( @@ -51,7 +51,10 @@ struct IONGSMSChunkUnpackingCtx { iterator_ = &data_buffer[data_buffer_word_count]; } - advance_word(); // Initializes current_word_ + if (iterator_) + { + advance_word(); // Initializes current_word_ + } } void advance_word() From ca150572d10ef0dbbf1e354455bdce17ca822703 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 15:12:38 +0200 Subject: [PATCH 42/66] Remove unused configuration parameter. Uniformize guard names --- .../signal_source/adapters/ion_gsms_signal_source.cc | 7 ++++--- .../signal_source/adapters/ion_gsms_signal_source.h | 7 +++---- src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index b67ec8a3a..2def04c75 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -19,9 +19,8 @@ #include "gnss_sdr_string_literals.h" #include "gnss_sdr_valve.h" #include -#include +#include #include -#include #if USE_GLOG_AND_GFLAGS #include @@ -59,7 +58,6 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), metadata_filepath_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), - timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)), in_streams_(in_streams), out_streams_(out_streams) { @@ -88,6 +86,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura } } + void IONGSMSSignalSource::load_metadata() { try @@ -117,6 +116,7 @@ void IONGSMSSignalSource::load_metadata() } } + std::vector IONGSMSSignalSource::make_stream_sources(const std::vector& stream_ids) const { std::vector sources{}; @@ -180,6 +180,7 @@ std::vector IONGSMSSignalSource::make_stream_sources(co return sources; } + void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) { std::size_t cumulative_index = 0; diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 31d0f7815..fd0a5140c 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -15,8 +15,8 @@ */ -#ifndef GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H -#define GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H +#ifndef GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H +#define GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H #include "configuration_interface.h" #include "file_source_base.h" @@ -73,7 +73,6 @@ private: gnss_shared_ptr timestamp_block_; std::string timestamp_file_; - double timestamp_clock_offset_ms_; uint32_t in_streams_; uint32_t out_streams_; @@ -82,4 +81,4 @@ private: /** \} */ /** \} */ -#endif // GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H +#endif // GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h index c82726b85..4a6baa7e9 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h @@ -14,8 +14,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H -#define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#ifndef GNSS_SDR_ION_GSMS_H +#define GNSS_SDR_ION_GSMS_H #include "gnss_block_interface.h" #include "gnss_sdr_filesystem.h" @@ -30,7 +30,7 @@ /** \addtogroup Signal_Source * \{ */ -/** \addtogroup Signal_Source_libs +/** \addtogroup Signal_Source_gnuradio_blocks * \{ */ class IONGSMSFileSource : public gr::sync_block @@ -71,4 +71,4 @@ private: /** \} */ /** \} */ -#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#endif // GNSS_SDR_ION_GSMS_H From 7f5704917f1ba47bebaa0835ca2b683939fb9654 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 15:21:39 +0200 Subject: [PATCH 43/66] Fix for CMake < 3.14 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18aa2e276..a0606e348 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1424,6 +1424,7 @@ else() endif() + ################################################################################ # Abseil C++ - https://abseil.io/docs/cpp/ ################################################################################ @@ -3360,6 +3361,9 @@ endif() ################################################################################ # ION GNSS-SDR Metadata Standard https://sdr.ion.org/ (OPTIONAL) ################################################################################ +if(CMAKE_VERSION VERSION_LESS 3.14) + set(ENABLE_ION OFF) # FetchContent_MakeAvailable is available from CMake 3.14 +endif() if(ENABLE_ION) include(FetchContent) set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) From 1ac7e0ca1f134ed8ca832f41f850482df2a292b8 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Wed, 21 Aug 2024 14:48:37 +0200 Subject: [PATCH 44/66] fix configuration options for the FPGA-based AD9361-based boards --- .../adrv9361_z7035_signal_source_fpga.cc | 17 +++++------------ .../adrv9361_z7035_signal_source_fpga.h | 2 -- .../adapters/fmcomms5_signal_source_fpga.cc | 11 +---------- .../adapters/fmcomms5_signal_source_fpga.h | 1 - .../signal_source/libs/ad9361_manager.cc | 2 +- 5 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index cc8f7fe32..75ca38492 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -51,6 +51,7 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration gain_mode_rx1_(configuration->property(role + ".gain_mode_rx1", default_gain_mode)), gain_mode_rx2_(configuration->property(role + ".gain_mode_rx2", default_gain_mode)), rf_port_select_(configuration->property(role + ".rf_port_select", default_rf_port_select)), + filter_source_(configuration->property(role + ".filter_source", std::string("Off"))), filter_filename_(configuration->property(role + ".filter_filename", filter_file_)), rf_gain_rx1_(configuration->property(role + ".gain_rx1", default_manual_gain_rx1)), rf_gain_rx2_(configuration->property(role + ".gain_rx2", default_manual_gain_rx2)), @@ -58,7 +59,6 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration phase_dds_deg_(configuration->property(role + ".phase_dds_deg", 0.0)), tx_attenuation_db_(configuration->property(role + ".tx_attenuation_db", default_tx_attenuation_db)), freq0_(configuration->property(role + ".freq", 0)), - freq1_(configuration->property(role + ".freq1", static_cast(GPS_L5_FREQ_HZ))), sample_rate_(configuration->property(role + ".sampling_frequency", default_bandwidth)), bandwidth_(configuration->property(role + ".bandwidth", default_bandwidth)), freq_dds_tx_hz_(configuration->property(role + ".freq_dds_tx_hz", uint64_t(10000))), @@ -70,7 +70,6 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration out_stream_(out_stream), item_size_(sizeof(int8_t)), enable_dds_lo_(configuration->property(role + ".enable_dds_lo", false)), - filter_auto_(configuration->property(role + ".filter_auto", false)), quadrature_(configuration->property(role + ".quadrature", true)), rf_dc_(configuration->property(role + ".rf_dc", true)), bb_dc_(configuration->property(role + ".bb_dc", true)), @@ -98,15 +97,6 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration freq0_ = configuration->property(role + ".freq0", static_cast(GPS_L1_FREQ_HZ)); } - if (filter_auto_) - { - filter_source_ = configuration->property(role + ".filter_source", std::string("Auto")); - } - else - { - filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); - } - switch_fpga = std::make_shared(); switch_fpga->set_switch_position(switch_to_real_time_mode); @@ -190,12 +180,15 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration } std::cout << "LO frequency : " << freq0_ << " Hz\n"; + + uint64_t freq1 = 0; // The local oscillator frequency of the ADRV9361-B is not used when using the ADRV9361-Z7035 board. + try { config_ad9361_rx_local(bandwidth_, sample_rate_, freq0_, - freq1_, + freq1, rf_port_select_, rx1_enable_, rx2_enable_, diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h index beffb3c70..acb84d663 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h @@ -107,7 +107,6 @@ private: double tx_attenuation_db_; uint64_t freq0_; // frequency of local oscillator for ADRV9361-A 0 - uint64_t freq1_; // frequency of local oscillator for ADRV9361-B (if present) uint64_t sample_rate_; uint64_t bandwidth_; uint64_t freq_dds_tx_hz_; @@ -122,7 +121,6 @@ private: size_t item_size_; bool enable_dds_lo_; - bool filter_auto_; bool quadrature_; bool rf_dc_; bool bb_dc_; diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc index be2108aa4..f52c67425 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc @@ -51,6 +51,7 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface gain_mode_rx1_(configuration->property(role + ".gain_mode_rx1", default_gain_mode)), gain_mode_rx2_(configuration->property(role + ".gain_mode_rx2", default_gain_mode)), rf_port_select_(configuration->property(role + ".rf_port_select", default_rf_port_select)), + filter_source_(configuration->property(role + ".filter_source", std::string("Off"))), filter_filename_(configuration->property(role + ".filter_filename", filter_file_)), rf_gain_rx1_(configuration->property(role + ".gain_rx1", default_manual_gain_rx1)), rf_gain_rx2_(configuration->property(role + ".gain_rx2", default_manual_gain_rx2)), @@ -63,7 +64,6 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface in_stream_(in_stream), out_stream_(out_stream), item_size_(sizeof(int8_t)), - filter_auto_(configuration->property(role + ".filter_auto", false)), quadrature_(configuration->property(role + ".quadrature", true)), rf_dc_(configuration->property(role + ".rf_dc", true)), bb_dc_(configuration->property(role + ".bb_dc", true)), @@ -86,15 +86,6 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface const uint32_t num_freq_bands = ((enable_rx1_band == true) and (enable_rx2_band == true)) ? 2 : 1; - if (filter_auto_) - { - filter_source_ = configuration->property(role + ".filter_source", std::string("Auto")); - } - else - { - filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); - } - switch_fpga = std::make_shared(); switch_fpga->set_switch_position(switch_to_real_time_mode); diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h index 1c5c37c73..665403099 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h @@ -114,7 +114,6 @@ private: size_t item_size_; - bool filter_auto_; bool quadrature_; bool rf_dc_; bool bb_dc_; diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 913488287..d2f82b367 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -349,7 +349,7 @@ bool config_ad9361_rx_local(uint64_t bandwidth_, #ifndef LIBAD9361_VERSION_GREATER_THAN_01 if (filter_source_ == "Design") { - std::cout << "Option filter_source=Design is not available in this version. Set to filter_source=Off\n"; + std::cout << "Option filter_source=Design is not available in this version of libad9361. Set to filter_source=Off\n"; filter_source_ = std::string("Off"); } if (Fpass_ != 0.0 or Fstop_ != 0.0) From 8702f9dfc7e889bef4f5e666a50630c1c0e6850b Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 22 Aug 2024 13:26:17 +0200 Subject: [PATCH 45/66] Put the global function into an anonymous namespace Use emplace_back instead of push_back --- .../signal_source/adapters/ion_gsms_signal_source.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index 2def04c75..e4fef62a0 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -30,6 +30,8 @@ using namespace std::string_literals; +namespace +{ std::vector parse_comma_list(const std::string& str) { std::vector list{}; @@ -48,6 +50,7 @@ std::vector parse_comma_list(const std::string& str) return list; } +} // anonymous namespace IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configuration, @@ -80,8 +83,8 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura { for (std::size_t i = 0; i < source->output_stream_count(); ++i) { - copy_blocks_.push_back(gr::blocks::copy::make(source->output_stream_item_size(i))); - valves_.push_back(gnss_sdr_make_valve(source->output_stream_item_size(i), source->output_stream_total_sample_count(i), queue)); + copy_blocks_.emplace_back(gr::blocks::copy::make(source->output_stream_item_size(i))); + valves_.emplace_back(gnss_sdr_make_valve(source->output_stream_item_size(i), source->output_stream_total_sample_count(i), queue)); } } } From d7885036b61e5c85854fd31bd3619c51c5a91015 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 22 Aug 2024 14:49:33 +0200 Subject: [PATCH 46/66] Make private member metadata_ a std::shared_pointer --- .../signal_source/adapters/ion_gsms_signal_source.cc | 8 +++++--- .../signal_source/adapters/ion_gsms_signal_source.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index e4fef62a0..00f2be229 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -20,6 +20,7 @@ #include "gnss_sdr_valve.h" #include #include +#include #include #if USE_GLOG_AND_GFLAGS @@ -92,10 +93,11 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura void IONGSMSSignalSource::load_metadata() { + metadata_ = std::make_shared(); try { GnssMetadata::XmlProcessor xml_proc; - if (!xml_proc.Load(metadata_filepath_.c_str(), false, metadata_)) + if (!xml_proc.Load(metadata_filepath_.c_str(), false, *metadata_)) { LOG(WARNING) << "Could not load XML metadata file " << metadata_filepath_; std::cerr << "Could not load XML metadata file " << metadata_filepath_ << std::endl; @@ -123,9 +125,9 @@ void IONGSMSSignalSource::load_metadata() std::vector IONGSMSSignalSource::make_stream_sources(const std::vector& stream_ids) const { std::vector sources{}; - for (const auto& file : metadata_.Files()) + for (const auto& file : metadata_->Files()) { - for (const auto& lane : metadata_.Lanes()) + for (const auto& lane : metadata_->Lanes()) { if (lane.Id() == file.Lane().Id()) { diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index fd0a5140c..bcdedbc3d 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -24,6 +24,7 @@ #include "ion_gsms.h" #include #include +#include #include #include @@ -69,7 +70,7 @@ private: std::vector> valves_; std::string metadata_filepath_; - GnssMetadata::Metadata metadata_; + std::shared_ptr metadata_; gnss_shared_ptr timestamp_block_; std::string timestamp_file_; From d5122c4e5a3f11bf64bf206abf4fda4ce466786a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 22 Aug 2024 14:50:40 +0200 Subject: [PATCH 47/66] Simplify code --- src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc index 60a08ba6c..22a25868c 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc @@ -179,10 +179,8 @@ int IONGSMSFileSource::work( while (io_buffer_offset_ < bytes_to_read) { // Iterate chunks within a chunk cycle - for (auto& c : chunk_data_) + for (auto& chunk : chunk_data_) { - auto* chunk = c.get(); - // Copy chunk into a separate buffer where the samples will be shifted from. const std::size_t bytes_copied = chunk->read_from_buffer(reinterpret_cast(io_buffer_.data()), io_buffer_offset_); From 4dee92ddf5119e5ca0fc253662253145b3eb4ed9 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 22 Aug 2024 15:44:10 +0200 Subject: [PATCH 48/66] Remove ION source from CI --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7bc294b0f..32dc29f9b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: libgnutls-openssl-dev libmatio-dev googletest protobuf-compiler libprotobuf-dev \ python3-mako liborc-0.4-dev - name: configure - run: cd build && cmake -GNinja -DENABLE_ION=ON .. + run: cd build && cmake -GNinja .. - name: build run: cd build && ninja - name: check @@ -60,7 +60,7 @@ jobs: brew install ninja hdf5 automake armadillo lapack libmatio gnuradio openssl pugixml protobuf pip3 install mako - name: configure - run: cd build && cmake -GNinja -DENABLE_ION=ON .. + run: cd build && cmake -GNinja .. - name: build run: cd build && ninja - name: check @@ -92,7 +92,7 @@ jobs: brew install ninja pkg-config hdf5 automake armadillo lapack libmatio gnuradio openssl pugixml protobuf pip3 install mako - name: configure - run: cd build && cmake -GXcode -DENABLE_ION=ON .. + run: cd build && cmake -GXcode .. - name: build run: cd build && xcodebuild -configuration Release - name: check From c4e84ffcfcb512d89c5bb04f10edb2d58f46490a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 23 Aug 2024 07:02:56 +0200 Subject: [PATCH 49/66] Apply clang-tidy fixes --- .../adapters/ad936x_custom_signal_source.cc | 17 +- .../gnuradio_blocks/ad936x_iio_source.cc | 93 +++++--- .../gnuradio_blocks/ad936x_iio_source.h | 42 ++-- .../signal_source/libs/CMakeLists.txt | 1 - .../signal_source/libs/ad9361_manager.cc | 2 +- .../signal_source/libs/ad936x_iio_custom.cc | 211 +++++++++++------- .../signal_source/libs/ad936x_iio_custom.h | 32 +-- .../signal_source/libs/ad936x_iio_samples.cc | 25 --- .../signal_source/libs/ad936x_iio_samples.h | 10 +- src/algorithms/signal_source/libs/ppstcprx.cc | 25 +-- src/algorithms/signal_source/libs/ppstcprx.h | 12 +- 11 files changed, 257 insertions(+), 213 deletions(-) delete mode 100644 src/algorithms/signal_source/libs/ad936x_iio_samples.cc diff --git a/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc b/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc index b93dc9344..b824a250d 100644 --- a/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc @@ -76,8 +76,11 @@ Ad936xCustomSignalSource::Ad936xCustomSignalSource(const ConfigurationInterface* item_size_ = sizeof(gr_complex); // 1. Make the driver instance bool customsamplesize = false; - if (ssize_ != 12 or spattern_ == true) customsamplesize = true; // custom FPGA DMA firmware - if (ssize_ == 12) // default original FPGA DMA firmware + if (ssize_ != 12 || spattern_ == true) + { + customsamplesize = true; // custom FPGA DMA firmware + } + if (ssize_ == 12) // default original FPGA DMA firmware { ssize_ = 16; // set to 16 bits and do not try to change sample size } @@ -153,8 +156,14 @@ Ad936xCustomSignalSource::Ad936xCustomSignalSource(const ConfigurationInterface* for (int n = 0; n < n_channels; n++) { - if (n == 0) inverted_spectrum_vec.push_back(inverted_spectrum_ch0_); - if (n == 1) inverted_spectrum_vec.push_back(inverted_spectrum_ch1_); + if (n == 0) + { + inverted_spectrum_vec.push_back(inverted_spectrum_ch0_); + } + if (n == 1) + { + inverted_spectrum_vec.push_back(inverted_spectrum_ch1_); + } } for (int n = 0; n < n_channels; n++) diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc index 375edf7da..1f0288dc9 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc @@ -33,15 +33,15 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string& pluto_uri_, + const std::string& board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string& rf_port_select_, + const std::string& rf_filter, + const std::string& gain_mode_rx0_, + const std::string& gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -49,7 +49,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string& fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -85,7 +85,8 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( tx_lo_channel_)); } -void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samples_in, int nchannels, std::vector *files_out) + +void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples* samples_in, int nchannels, std::vector* files_out) { uint32_t current_byte = 0; int16_t ch = 0; @@ -101,16 +102,17 @@ void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samp } } + ad936x_iio_source::ad936x_iio_source( - std::string pluto_uri_, - std::string board_type_, + const std::string& pluto_uri_, + const std::string& board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string& rf_port_select_, + const std::string& rf_filter, + const std::string& gain_mode_rx0_, + const std::string& gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -118,7 +120,7 @@ ad936x_iio_source::ad936x_iio_source( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string& fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -171,54 +173,81 @@ ad936x_iio_source::ad936x_iio_source( case 16: { std::cout << "FPGA sample size set to 16 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=16\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=16\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 8: { std::cout << "FPGA sample size set to 8 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=8\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=8\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 4: { std::cout << "FPGA sample size set to 4 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=4\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=4\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 2: { std::cout << "FPGA sample size set to 2 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=2\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=2\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } default: { std::cout << "WARNING: Unsupported ssize. FPGA sample size set to 16 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=16") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=16") == false) + { + std::cout << "cmd send error!\n"; + } } } if (bshift_ >= 0 and bshift_ <= 14) { std::cout << "FPGA sample bits shift left set to " + std::to_string(bshift_) + " positions.\n"; - if (pps_rx->send_cmd("bshift=" + std::to_string(bshift_) + "\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("bshift=" + std::to_string(bshift_) + "\n") == false) + { + std::cout << "cmd send error!\n"; + } } else { std::cout << "WARNING: Unsupported bshift. FPGA sample bits shift left set to 0.\n"; - if (pps_rx->send_cmd("bshift=0\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("bshift=0\n") == false) + { + std::cout << "cmd send error!\n"; + } } if (spattern_ == true) { std::cout << "FPGA debug sample pattern is active!.\n"; - if (pps_rx->send_cmd("spattern=1\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("spattern=1\n") == false) + { + std::cout << "cmd send error!\n"; + } } else { std::cout << "FPGA debug sample pattern disabled.\n"; - if (pps_rx->send_cmd("spattern=0\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("spattern=0\n") == false) + { + std::cout << "cmd send error!\n"; + } } } else @@ -238,7 +267,7 @@ ad936x_iio_source::ad936x_iio_source( exit(1); } } - catch (std::exception const &ex) + catch (std::exception const& ex) { std::cerr << "STD exception: " << ex.what() << std::endl; exit(1); @@ -267,6 +296,7 @@ ad936x_iio_source::ad936x_iio_source( // } } + ad936x_iio_source::~ad936x_iio_source() { // Terminate PPS thread @@ -284,6 +314,7 @@ bool ad936x_iio_source::start() return ad936x_custom->start_sample_rx(false); } + bool ad936x_iio_source::stop() { std::cout << "stopping ad936x_iio_source...\n"; @@ -291,17 +322,17 @@ bool ad936x_iio_source::stop() return true; } + int ad936x_iio_source::general_work(int noutput_items, - __attribute__((unused)) gr_vector_int &ninput_items, - __attribute__((unused)) gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + __attribute__((unused)) gr_vector_int& ninput_items, + __attribute__((unused)) gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) { std::shared_ptr current_buffer; - ad936x_iio_samples *current_samples; + ad936x_iio_samples* current_samples; ad936x_custom->pop_sample_buffer(current_buffer); current_samples = current_buffer.get(); - // I and Q samples are interleaved in buffer: IQIQIQ... int32_t n_interleaved_iq_samples_per_channel = current_samples->n_bytes / (ad936x_custom->n_channels * 2); if (noutput_items < n_interleaved_iq_samples_per_channel) @@ -312,7 +343,7 @@ int ad936x_iio_source::general_work(int noutput_items, else { // ad9361_channel_demux_and_record(current_samples, ad936x_custom->n_channels, &samplesfile); - auto **out = reinterpret_cast(&output_items[0]); + auto** out = reinterpret_cast(&output_items[0]); uint32_t current_byte = 0; uint32_t current_byte_in_gr = 0; int16_t ch = 0; diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h index 411906a3e..a1a29f6ab 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h @@ -44,15 +44,15 @@ class ad936x_iio_source; using ad936x_iio_source_sptr = gnss_shared_ptr; ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -60,7 +60,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -90,15 +90,15 @@ public: private: friend ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -106,7 +106,7 @@ private: long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -116,15 +116,15 @@ private: int tx_lo_channel_); ad936x_iio_source( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -132,7 +132,7 @@ private: long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index bdbd3aace..9d9732d3c 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -36,7 +36,6 @@ if((ENABLE_FPGA AND ENABLE_AD9361) OR ENABLE_MAX2771) endif() if(ENABLE_PLUTOSDR) - set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_samples.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index d2f82b367..025f97627 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -636,7 +636,7 @@ bool config_ad9361_rx_remote(const std::string &remote_host, { return false; } - if (setup_filter(std::move(filter_source_), bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) { return false; } diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc index ad983aa6b..c41d74b9a 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc @@ -31,29 +31,36 @@ #include #endif -ad936x_iio_custom::ad936x_iio_custom(int debug_level_, int log_level_) +ad936x_iio_custom::ad936x_iio_custom( + int debug_level_, + int log_level_) : n_channels(0), + ctx(nullptr), + phy(nullptr), + stream_dev(nullptr), + dds_dev(nullptr), + receive_samples(false), + fpga_overflow(false), + sample_rate_sps(0), + debug_level(debug_level_), + log_level(log_level_), + PPS_mode(false) { - receive_samples = false; - fpga_overflow = false; - sample_rate_sps = 0; - ctx = NULL; - phy = NULL; - dds_dev = NULL; - stream_dev = NULL; - debug_level = debug_level_; - log_level = log_level_; - PPS_mode = false; - n_channels = 0; } ad936x_iio_custom::~ad936x_iio_custom() { // disable TX - if (phy != NULL) PlutoTxEnable(false); + if (phy != nullptr) + { + PlutoTxEnable(false); + } // Close device - if (ctx != NULL) iio_context_destroy(ctx); + if (ctx != nullptr) + { + iio_context_destroy(ctx); + } } @@ -69,7 +76,7 @@ void ad936x_iio_custom::set_pps_samplestamp_queue(std::shared_ptr ¶ms) { - for (std::vector::const_iterator it = params.begin(); - it != params.end(); ++it) + for (const auto ¶m : params) { - struct iio_channel *chn = NULL; - const char *attr = NULL; + struct iio_channel *chn = nullptr; + const char *attr = nullptr; size_t pos; int ret; - pos = it->find('='); + pos = param.find('='); if (pos == std::string::npos) { - std::cerr << "Malformed line: " << *it << std::endl; + std::cerr << "Malformed line: " << param << std::endl; continue; } - std::string key = it->substr(0, pos); - std::string val = it->substr(pos + 1, std::string::npos); + std::string key = param.substr(0, pos); + std::string val = param.substr(pos + 1, std::string::npos); ret = iio_device_identify_filename(phy, key.c_str(), &chn, &attr); @@ -197,13 +203,19 @@ void ad936x_iio_custom::configure_params(struct iio_device *phy, } if (chn) - ret = iio_channel_attr_write(chn, - attr, val.c_str()); + { + ret = iio_channel_attr_write(chn, + attr, val.c_str()); + } else if (iio_device_find_attr(phy, attr)) - ret = iio_device_attr_write(phy, attr, val.c_str()); + { + ret = iio_device_attr_write(phy, attr, val.c_str()); + } else - ret = iio_device_debug_attr_write(phy, - attr, val.c_str()); + { + ret = iio_device_debug_attr_write(phy, + attr, val.c_str()); + } if (ret < 0) { std::cerr << "Unable to write attribute " << key @@ -217,9 +229,9 @@ void ad936x_iio_custom::set_params_rx(struct iio_device *phy_device, unsigned long long frequency, unsigned long samplerate, unsigned long bandwidth, bool quadrature, bool rfdc, bool bbdc, - std::string gain1, double gain1_value, - std::string gain2, double gain2_value, - std::string port_select) + const std::string &gain1, double gain1_value, + const std::string &gain2, double gain2_value, + const std::string &port_select) { std::vector params; @@ -290,7 +302,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0)); params_dds.push_back("out_altvoltage0_TX1_I_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage0_TX1_I_F1_raw=1"); + params_dds.emplace_back("out_altvoltage0_TX1_I_F1_raw=1"); // DDS TX CH1 Q (tone #1) params_dds.push_back("out_altvoltage2_TX1_Q_F1_frequency=" + std::to_string(freq_dds_tx_hz_)); @@ -298,7 +310,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0 + 270000.0)); params_dds.push_back("out_altvoltage2_TX1_Q_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage2_TX1_Q_F1_raw=1"); + params_dds.emplace_back("out_altvoltage2_TX1_Q_F1_raw=1"); configure_params(dds_dev, params_dds); } @@ -319,7 +331,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0)); params_dds.push_back("out_altvoltage4_TX2_I_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage4_TX2_I_F1_raw=1"); + params_dds.emplace_back("out_altvoltage4_TX2_I_F1_raw=1"); // DDS TX CH2 Q (tone #1) params_dds.push_back("out_altvoltage6_TX2_Q_F1_frequency=" + std::to_string(freq_dds_tx_hz_)); @@ -327,7 +339,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0 + 270000.0)); params_dds.push_back("out_altvoltage6_TX2_Q_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage6_TX2_Q_F1_raw=1"); + params_dds.emplace_back("out_altvoltage6_TX2_Q_F1_raw=1"); configure_params(dds_dev, params_dds); } @@ -338,7 +350,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, bool ad936x_iio_custom::check_device() { - if (stream_dev != NULL) + if (stream_dev != nullptr) { return true; } @@ -351,8 +363,8 @@ bool ad936x_iio_custom::check_device() bool ad936x_iio_custom::get_iio_param(iio_device *dev, const std::string ¶m, std::string &value) { - struct iio_channel *chn = 0; - const char *attr = 0; + struct iio_channel *chn = nullptr; + const char *attr = nullptr; char valuestr[256]; int ret; ssize_t nchars; @@ -399,9 +411,12 @@ bool ad936x_iio_custom::read_die_temp(double &temp_c) { try { - uint32_t temp_mC = boost::lexical_cast(temp_mC_str); + auto temp_mC = boost::lexical_cast(temp_mC_str); temp_c = static_cast(temp_mC) / 1000.0; - if (temp_c > 120) temp_c = -1; + if (temp_c > 120) + { + temp_c = -1; + } return true; } catch (const boost::bad_lexical_cast &e) @@ -420,10 +435,10 @@ bool ad936x_iio_custom::read_die_temp(double &temp_c) bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -433,16 +448,19 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, bool high_side_lo_, int tx_lo_channel_) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } bool no_errors = true; std::cout << "Configuring phy device parameters...\n"; int ret; - if (rf_filter.compare("Disabled") == 0) + if (rf_filter == "Disabled") { std::cout << "LNA Filter switch is disabled.\n"; } - else if (rf_filter.compare("Auto") == 0) + else if (rf_filter == "Auto") { std::cout << "Selecting LNA RF filter based on the selected RF frequency... \n"; if (freq_ == 1575420000) @@ -499,9 +517,9 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, params.push_back("out_voltage_rf_bandwidth=" + std::to_string(bandwidth_)); - params.push_back("in_voltage_quadrature_tracking_en=1"); - params.push_back("in_voltage_rf_dc_offset_tracking_en=1"); - params.push_back("in_voltage_bb_dc_offset_tracking_en=1"); + params.emplace_back("in_voltage_quadrature_tracking_en=1"); + params.emplace_back("in_voltage_rf_dc_offset_tracking_en=1"); + params.emplace_back("in_voltage_bb_dc_offset_tracking_en=1"); configure_params(phy, params); @@ -706,7 +724,10 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, bool ad936x_iio_custom::set_rx_frequency(long long freq_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // Configure RX LO channel (NOTICE that altvoltage0 is the RX LO oscillator!, altvoltage1 is the TX oscillator) struct iio_channel *lo_ch; @@ -729,7 +750,10 @@ bool ad936x_iio_custom::set_rx_frequency(long long freq_hz) bool ad936x_iio_custom::get_rx_frequency(long long &freq_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // Configure RX LO channel (NOTICE that altvoltage0 is the RX LO oscillator!, altvoltage1 is the TX oscillator) struct iio_channel *lo_ch; @@ -750,9 +774,12 @@ bool ad936x_iio_custom::get_rx_frequency(long long &freq_hz) } -bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain_dB) +bool ad936x_iio_custom::setRXGain(int ch_num, const std::string &gain_mode, double gain_dB) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } std::vector params; if (ch_num == 0) { @@ -785,7 +812,10 @@ bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain double ad936x_iio_custom::get_rx_gain(int ch_num) { - if (check_device() == false) return -1; + if (check_device() == false) + { + return -1; + } double gain_dB; // gain in dB int ret = 0; if (ch_num == 0) @@ -816,7 +846,10 @@ double ad936x_iio_custom::get_rx_gain(int ch_num) bool ad936x_iio_custom::calibrate([[maybe_unused]] int ch, [[maybe_unused]] double bw_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // todo return true; } @@ -865,12 +898,13 @@ void ad936x_iio_custom::monitor_thread_fn() { ret = iio_device_reg_write(stream_dev, 0x80000088, val); if (ret) - fprintf(stderr, "Failed to clearn DMA status register: %s\n", - strerror(-ret)); + { + fprintf(stderr, "Failed to clearn DMA status register: %s\n", + strerror(-ret)); + } } sleep(1); } - return; } @@ -941,7 +975,7 @@ void ad936x_iio_custom::setPlutoGpo(int p) } -bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) +bool ad936x_iio_custom::select_rf_filter(const std::string &rf_filter) { // adi,gpo-manual-mode-enable Enables GPO manual mode, this will conflict with automatic ENSM slave and eLNA mode // adi,gpo-manual-mode-enable-mask Enable bit mask, setting or clearing bits will change the level of the corresponding output. Bit0 → GPO, Bit1 → GPO1, Bit2 → GPO2, Bit3 → GP03 @@ -961,7 +995,10 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) // 1 Enable // X Enable Mask if Identifier=0xF - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // int plutoGpo = 0; int ret; ret = iio_device_debug_attr_write(phy, "adi,gpo-manual-mode-enable", "1"); @@ -972,7 +1009,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } - if (rf_filter.compare("E1") == 0) + if (rf_filter == "E1") { // set gpio0 to switch L1 filter // setPlutoGpo(plutoGpo); @@ -983,7 +1020,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } } - else if (rf_filter.compare("E5E6") == 0) + else if (rf_filter == "E5E6") { // set gpio0 to switch L5/L6 filter (GPO0) // plutoGpo = plutoGpo | 0x10; @@ -995,7 +1032,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } } - if (rf_filter.compare("none") == 0) + if (rf_filter == "none") { std::cout << "RF external filter not selected\n"; } @@ -1108,18 +1145,18 @@ bool ad936x_iio_custom::start_sample_rx(bool ppsmode) switch (n_channels) { case 1: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q break; case 2: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q - channels.push_back("voltage2"); // Channel 1 I - channels.push_back("voltage3"); // Channel 1 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage2"); // Channel 1 I + channels.emplace_back("voltage3"); // Channel 1 Q break; default: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q } receive_samples = true; @@ -1151,7 +1188,10 @@ void ad936x_iio_custom::push_sample_buffer(std::shared_ptr & void ad936x_iio_custom::capture(const std::vector &channels) { - if (check_device() == false) return; + if (check_device() == false) + { + return; + } struct iio_buffer *rxbuf; @@ -1179,16 +1219,14 @@ void ad936x_iio_custom::capture(const std::vector &channels) } else { - for (std::vector::const_iterator it = - channels.begin(); - it != channels.end(); ++it) + for (const auto &channel : channels) { struct iio_channel *chn = iio_device_find_channel(stream_dev, - it->c_str(), false); + channel.c_str(), false); if (!chn) { - std::cerr << "Channel " << it->c_str() << " not found\n"; + std::cerr << "Channel " << channel.c_str() << " not found\n"; return; } else @@ -1247,7 +1285,10 @@ void ad936x_iio_custom::capture(const std::vector &channels) items_in_buffer = static_cast(ret) / bytes_to_interleaved_iq_samples; - if (items_in_buffer == 0) return; + if (items_in_buffer == 0) + { + return; + } current_samples->n_channels = n_channels; current_samples->n_interleaved_iq_samples = items_in_buffer; diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.h b/src/algorithms/signal_source/libs/ad936x_iio_custom.h index ab58f36cc..0c6199968 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.h @@ -41,15 +41,15 @@ class ad936x_iio_custom public: ad936x_iio_custom(int debug_level_, int log_level_); virtual ~ad936x_iio_custom(); - bool initialize_device(std::string pluto_device_uri, std::string board_type); + bool initialize_device(const std::string &pluto_device_uri, const std::string &board_type); bool init_config_ad9361_rx(long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -62,7 +62,7 @@ public: bool calibrate(int ch, double bw_hz); double get_rx_gain(int ch_num); - bool setRXGain(int ch_num, std::string gain_mode, double gain_dB); + bool setRXGain(int ch_num, const std::string &gain_mode, double gain_dB); bool set_antenna_port(int ch, int antenna_idx); double get_frequency(int ch); @@ -94,9 +94,9 @@ private: unsigned long long frequency, unsigned long samplerate, unsigned long bandwidth, bool quadrature, bool rfdc, bool bbdc, - std::string gain1, double gain1_value, - std::string gain2, double gain2_value, - std::string port_select); + const std::string &gain1, double gain1_value, + const std::string &gain2, double gain2_value, + const std::string &port_select); bool config_ad9361_dds(uint64_t freq_rf_tx_hz_, double tx_attenuation_db_, @@ -108,7 +108,7 @@ private: void get_PPS_timestamp(); void capture(const std::vector &channels); - bool select_rf_filter(std::string rf_filter); + bool select_rf_filter(const std::string &rf_filter); void monitor_thread_fn(); @@ -121,12 +121,6 @@ private: struct iio_device *stream_dev; struct iio_device *dds_dev; - // stream - uint64_t sample_rate_sps; - int debug_level; - int log_level; - bool PPS_mode; - std::mutex mtx; std::condition_variable cv; @@ -140,6 +134,12 @@ private: std::thread capture_samples_thread; std::thread overflow_monitor_thread; std::thread capture_time_thread; + + // stream + uint64_t sample_rate_sps; + int debug_level; + int log_level; + bool PPS_mode; }; /** \} */ diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.cc b/src/algorithms/signal_source/libs/ad936x_iio_samples.cc deleted file mode 100644 index b9b7b505a..000000000 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.cc +++ /dev/null @@ -1,25 +0,0 @@ -/*! - * \file ad936x_iio_samples.cc - * \brief A class that holds a custom sample buffer for Analog Devices AD936x family front-ends. - * \author Javier Arribas, jarribas(at)cttc.es - * - * ----------------------------------------------------------------------------- - * - * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. - * This file is part of GNSS-SDR. - * - * Copyright (C) 2010-2022 (see AUTHORS file for a list of contributors) - * SPDX-License-Identifier: GPL-3.0-or-later - * - * ----------------------------------------------------------------------------- - */ - -#include "ad936x_iio_samples.h" - -ad936x_iio_samples::ad936x_iio_samples() -{ - n_bytes = 0; - n_interleaved_iq_samples = 0; - step_bytes = 0; - n_channels = 0; -} diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.h b/src/algorithms/signal_source/libs/ad936x_iio_samples.h index 53fff2c9e..9a1d7ce90 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_samples.h @@ -33,11 +33,11 @@ class ad936x_iio_samples { public: - ad936x_iio_samples(); - uint32_t n_bytes; - uint32_t n_interleaved_iq_samples; - uint16_t n_channels; - uint16_t step_bytes; + ad936x_iio_samples() = default; + uint32_t n_bytes{0}; + uint32_t n_interleaved_iq_samples{0}; + uint16_t n_channels{0}; + uint16_t step_bytes{0}; char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; // max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q) }; diff --git a/src/algorithms/signal_source/libs/ppstcprx.cc b/src/algorithms/signal_source/libs/ppstcprx.cc index c23261aff..94dda2052 100644 --- a/src/algorithms/signal_source/libs/ppstcprx.cc +++ b/src/algorithms/signal_source/libs/ppstcprx.cc @@ -20,19 +20,6 @@ #include #include -pps_tcp_rx::pps_tcp_rx() -{ - // TODO Auto-generated constructor stub - is_connected = false; - clientSd = -1; -} - - -pps_tcp_rx::~pps_tcp_rx() -{ - // TODO Auto-generated destructor stub -} - void pps_tcp_rx::set_pps_samplestamp_queue(std::shared_ptr> queue) { @@ -40,7 +27,7 @@ void pps_tcp_rx::set_pps_samplestamp_queue(std::shared_ptr> Pps_queue; - int clientSd; + int clientSd{-1}; public: - volatile bool is_connected; - pps_tcp_rx(); - virtual ~pps_tcp_rx(); + volatile bool is_connected{false}; + pps_tcp_rx() = default; + virtual ~pps_tcp_rx() = default; - void receive_pps(std::string ip_address, int port); - bool send_cmd(std::string cmd); + void receive_pps(const std::string& ip_address, int port); + bool send_cmd(std::string cmd) const; void set_pps_samplestamp_queue(std::shared_ptr> queue); }; From 1384ebef5557978c4d53febe9dbc2823c526bc12 Mon Sep 17 00:00:00 2001 From: Marc Majoral Date: Mon, 26 Aug 2024 09:03:56 +0200 Subject: [PATCH 50/66] Initialize the receiver local oscillator frequency to GPS_L5_FREQ_HZ by default in the ADRV9361Z7035 FPGA signal source and remove unnecessary include files. --- .../signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc | 2 +- .../signal_source/adapters/adrv9361_z7035_signal_source_fpga.h | 1 - .../signal_source/adapters/fmcomms5_signal_source_fpga.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index 75ca38492..897dd7777 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -58,7 +58,7 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration scale_dds_dbfs_(configuration->property(role + ".scale_dds_dbfs", -3.0)), phase_dds_deg_(configuration->property(role + ".phase_dds_deg", 0.0)), tx_attenuation_db_(configuration->property(role + ".tx_attenuation_db", default_tx_attenuation_db)), - freq0_(configuration->property(role + ".freq", 0)), + freq0_(configuration->property(role + ".freq", GPS_L5_FREQ_HZ)), sample_rate_(configuration->property(role + ".sampling_frequency", default_bandwidth)), bandwidth_(configuration->property(role + ".bandwidth", default_bandwidth)), freq_dds_tx_hz_(configuration->property(role + ".freq_dds_tx_hz", uint64_t(10000))), diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h index acb84d663..286cde2d5 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h @@ -23,7 +23,6 @@ #include "concurrent_queue.h" #include "fpga_buffer_monitor.h" -#include "fpga_dma-proxy.h" #include "fpga_dynamic_bit_selection.h" #include "fpga_switch.h" #include "gnss_block_interface.h" diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h index 665403099..fbb10bf67 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h @@ -23,7 +23,6 @@ #include "concurrent_queue.h" #include "fpga_buffer_monitor.h" -#include "fpga_dma-proxy.h" #include "fpga_dynamic_bit_selection.h" #include "fpga_switch.h" #include "gnss_block_interface.h" From 3f3321f5a72053c62d0af53fb1bc2af698cdaa5b Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 27 Aug 2024 15:14:01 +0200 Subject: [PATCH 51/66] Sort out building flags and improve their reporting --- CMakeLists.txt | 14 +++++----- .../signal_source/adapters/CMakeLists.txt | 8 ++++++ .../gnuradio_blocks/CMakeLists.txt | 8 +----- .../gnuradio_blocks/ad936x_iio_source.cc | 19 +++++++------ .../gnuradio_blocks/ad936x_iio_source.h | 28 +++++++++---------- .../signal_source/libs/CMakeLists.txt | 3 +- .../signal_source/libs/ad936x_iio_samples.h | 2 +- 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0606e348..a978c673f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3715,12 +3715,13 @@ add_subdirectory(src) add_feature_info(ENABLE_UHD ENABLE_UHD "Enables UHD_Signal_Source for using RF front-ends from the USRP family. Requires gr-uhd.") add_feature_info(ENABLE_OSMOSDR ENABLE_OSMOSDR "Enables Osmosdr_Signal_Source and RtlTcp_Signal_Source for using RF front-ends compatible with the OsmoSDR driver. Requires gr-osmosdr.") add_feature_info(ENABLE_LIMESDR ENABLE_LIMESDR "Enables Limesdr_Signal_Source. Requires gr-limesdr.") -add_feature_info(ENABLE_FMCOMMS2 ENABLE_FMCOMMS2 "Enables Fmcomms2_Signal_Source for FMCOMMS2/3/4 devices. Requires gr-iio and libad9361-dev.") -add_feature_info(ENABLE_PLUTOSDR ENABLE_PLUTOSDR "Enables Plutosdr_Signal_Source for using ADALM-PLUTO boards. Requires gr-iio.") -add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables Ad9361_Fpga_Signal_Source for devices with the AD9361 chipset. Requires libiio and libad9361-dev.") -add_feature_info(ENABLE_MAX2771 ENABLE_MAX2771 "Enables FPGA_MAX2771_EVKIT_Signal_Source for devices with the MAX2771 chipset. Requires the spidev driver") -add_feature_info(ENABLE_DMA_PROXY ENABLE_DMA_PROXY "Enables DMA Signal_Source. Requires the DMA Proxy driver") -add_feature_info(ENABLE_AD936X_SDR ENABLE_AD936X_SDR "Enables Ad936x_Iio_Signal_Source to access AD936X front-ends using libiio. Requires libiio and libad9361-dev.") +add_feature_info(ENABLE_FMCOMMS2 ENABLE_FMCOMMS2 "Enables Fmcomms2_Signal_Source for FMCOMMS2/3/4 devices. Requires libiio, libad9361-dev, and gr-iio.") +add_feature_info(ENABLE_PLUTOSDR ENABLE_PLUTOSDR "Enables Plutosdr_Signal_Source and Ad936x_Custom_Signal_Source for using ADALM-PLUTO boards. Requires libiio, libad9361-dev, and gr-iio.") +add_feature_info(ENABLE_AD936X_SDR ENABLE_AD936X_SDR "Enables Ad936x_Custom_Signal_Source for using ADALM-PLUTO boards with custom firmware. Requires libiio and libad9361-dev.") +add_feature_info(ENABLE_FPGA ENABLE_FPGA "Enables building of processing blocks for FPGA offloading.") +add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables ADRV9361_Z7035_Signal_Source_FPGA and the FMCOMMS5_Signal_Source_FPGA for FPGA SoC devices with the AD9361 chipset. Requires libiio, libad9361-dev, and -DENABLE_FPGA=ON.") +add_feature_info(ENABLE_MAX2771 ENABLE_MAX2771 "Enables FPGA_MAX2771_EVKIT_Signal_Source for FPGA SoC devices with the with the MAX2771 chipset. Requires the spidev driver and -DENABLE_FPGA=ON.") +add_feature_info(ENABLE_DMA_PROXY ENABLE_DMA_PROXY "Enables DMA_Signal_Source_FPGA for file post-processing in FPGA SoC devices. Requires the DMA Proxy driver and -DENABLE_FPGA=ON.") add_feature_info(ENABLE_RAW_UDP ENABLE_RAW_UDP "Enables Custom_UDP_Signal_Source for custom UDP packet sample source. Requires libpcap.") add_feature_info(ENABLE_FLEXIBAND ENABLE_FLEXIBAND "Enables Flexiband_Signal_Source for using Teleorbit's Flexiband RF front-end. Requires gr-teleorbit.") add_feature_info(ENABLE_ARRAY ENABLE_ARRAY "Enables Raw_Array_Signal_Source and Array_Signal_Conditioner for using CTTC's antenna array. Requires gr-dbfcttc.") @@ -3732,7 +3733,6 @@ add_feature_info(ENABLE_CLANG_TIDY ENABLE_CLANG_TIDY "Runs clang-tidy along with add_feature_info(ENABLE_PROFILING ENABLE_PROFILING "Runs volk_gnsssdr_profile at the end of the building.") add_feature_info(ENABLE_OPENCL ENABLE_OPENCL "Enables GPS_L1_CA_PCPS_OpenCl_Acquisition (experimental). Requires OpenCL.") add_feature_info(ENABLE_CUDA ENABLE_CUDA "Enables GPS_L1_CA_DLL_PLL_Tracking_GPU (experimental). Requires CUDA.") -add_feature_info(ENABLE_FPGA ENABLE_FPGA "Enables building of processing blocks for FPGA offloading.") add_feature_info(ENABLE_ARMA_NO_DEBUG ENABLE_ARMA_NO_DEBUG "Enables passing the ARMA_NO_DEBUG macro to Armadillo, hence disabling bound checking.") add_feature_info(ENABLE_PACKAGING ENABLE_PACKAGING "Enables software packaging.") add_feature_info(ENABLE_OWN_GLOG ENABLE_OWN_GLOG "Forces the downloading and building of Google glog.") diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 5f5d4ce3b..9c0300522 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -25,6 +25,14 @@ if(ENABLE_PLUTOSDR) set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ad936x_custom_signal_source.h) endif() +if(ENABLE_AD936X_SDR AND NOT ENABLE_PLUTOSDR) + ############################################## + # CUSTOM AD936X IIO SOURCE + ############################################## + set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} ad936x_custom_signal_source.cc) + set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ad936x_custom_signal_source.h) +endif() + if(ENABLE_FMCOMMS2) ############################################### # FMCOMMS2 based SDR Hardware diff --git a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt index a217648b4..2eca5157a 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/signal_source/gnuradio_blocks/CMakeLists.txt @@ -10,13 +10,7 @@ if(ENABLE_RAW_UDP AND PCAP_FOUND) list(APPEND OPT_DRIVER_HEADERS gr_complex_ip_packet_source.h) endif() -if(ENABLE_AD936X_SDR) - set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} gr_complex_ip_packet_source.cc) - set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} gr_complex_ip_packet_source.h) -endif() - - -if(ENABLE_PLUTOSDR) +if(ENABLE_PLUTOSDR OR ENABLE_AD936X_SDR) set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} ad936x_iio_source.cc) set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ad936x_iio_source.h) endif() diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc index 1f0288dc9..c87006bd5 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_source.cc - * \brief A direct IIO custom front-end gnss-sdr signal gnuradio block for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end gnss-sdr signal gnuradio block for the + * AD936x AD front-end family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * * ----------------------------------------------------------------------------- @@ -35,9 +36,9 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( const std::string& pluto_uri_, const std::string& board_type_, - long long bandwidth_, - long long sample_rate_, - long long freq_, + int64_t bandwidth_, + int64_t sample_rate_, + int64_t freq_, const std::string& rf_port_select_, const std::string& rf_filter, const std::string& gain_mode_rx0_, @@ -46,7 +47,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( double rf_gain_rx1_, bool enable_ch0, bool enable_ch1, - long long freq_2ch, + int64_t freq_2ch, bool ppsmode_, bool customsamplesize_, const std::string& fe_ip_, @@ -106,9 +107,9 @@ void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples* samp ad936x_iio_source::ad936x_iio_source( const std::string& pluto_uri_, const std::string& board_type_, - long long bandwidth_, - long long sample_rate_, - long long freq_, + int64_t bandwidth_, + int64_t sample_rate_, + int64_t freq_, const std::string& rf_port_select_, const std::string& rf_filter, const std::string& gain_mode_rx0_, @@ -117,7 +118,7 @@ ad936x_iio_source::ad936x_iio_source( double rf_gain_rx1_, bool enable_ch0, bool enable_ch1, - long long freq_2ch, + int64_t freq_2ch, bool ppsmode_, bool customsamplesize_, const std::string& fe_ip_, diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h index a1a29f6ab..8f5a34c7c 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_source.h - * \brief A direct IIO custom front-end gnss-sdr signal gnuradio block for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end gnss-sdr signal gnuradio block for the + * AD936x AD front-end family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * * ----------------------------------------------------------------------------- @@ -46,9 +47,9 @@ using ad936x_iio_source_sptr = gnss_shared_ptr; ad936x_iio_source_sptr ad936x_iio_make_source_sptr( const std::string &pluto_uri_, const std::string &board_type_, - long long bandwidth_, - long long sample_rate_, - long long freq_, + int64_t bandwidth_, + int64_t sample_rate_, + int64_t freq_, const std::string &rf_port_select_, const std::string &rf_filter, const std::string &gain_mode_rx0_, @@ -57,7 +58,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( double rf_gain_rx1_, bool enable_ch0, bool enable_ch1, - long long freq_2ch, + int64_t freq_2ch, bool ppsmode_, bool customsamplesize_, const std::string &fe_ip_, @@ -92,9 +93,9 @@ private: friend ad936x_iio_source_sptr ad936x_iio_make_source_sptr( const std::string &pluto_uri_, const std::string &board_type_, - long long bandwidth_, - long long sample_rate_, - long long freq_, + int64_t bandwidth_, + int64_t sample_rate_, + int64_t freq_, const std::string &rf_port_select_, const std::string &rf_filter, const std::string &gain_mode_rx0_, @@ -103,7 +104,7 @@ private: double rf_gain_rx1_, bool enable_ch0, bool enable_ch1, - long long freq_2ch, + int64_t freq_2ch, bool ppsmode_, bool customsamplesize_, const std::string &fe_ip_, @@ -118,9 +119,9 @@ private: ad936x_iio_source( const std::string &pluto_uri_, const std::string &board_type_, - long long bandwidth_, - long long sample_rate_, - long long freq_, + int64_t bandwidth_, + int64_t sample_rate_, + int64_t freq_, const std::string &rf_port_select_, const std::string &rf_filter, const std::string &gain_mode_rx0_, @@ -129,7 +130,7 @@ private: double rf_gain_rx1_, bool enable_ch0, bool enable_ch1, - long long freq_2ch, + int64_t freq_2ch, bool ppsmode_, bool customsamplesize_, const std::string &fe_ip_, @@ -141,7 +142,6 @@ private: bool high_side_lo_, int tx_lo_channel_); - void ad9361_channel_demux_to_buffer(ad936x_iio_samples *samples_in, int nchannels, gr_vector_void_star &output_items); void ad9361_channel_demux_and_record(ad936x_iio_samples *samples_in, int nchannels, std::vector *files_out); diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 9d9732d3c..9c39f7dc7 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -35,7 +35,7 @@ if((ENABLE_FPGA AND ENABLE_AD9361) OR ENABLE_MAX2771) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} fpga_buffer_monitor.h) endif() -if(ENABLE_PLUTOSDR) +if(ENABLE_PLUTOSDR OR ENABLE_AD936X_SDR) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_samples.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) @@ -51,7 +51,6 @@ if(ENABLE_ION) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ion_gsms_chunk_unpacking_ctx.h) endif() - set(SIGNAL_SOURCE_LIB_SOURCES rtl_tcp_commands.cc rtl_tcp_dongle_info.cc diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.h b/src/algorithms/signal_source/libs/ad936x_iio_samples.h index 9a1d7ce90..5ff43d065 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_samples.h @@ -21,8 +21,8 @@ #define IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES 32768 * 4 #define IIO_INPUTRAMFIFOSIZE 256 +#include #include -#include #include /** \addtogroup Signal_Source From 310685cd20d9426f1f8038a442ff0ed7e208a7ea Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Wed, 28 Aug 2024 11:09:56 +0200 Subject: [PATCH 52/66] Allow building Ad936x_Custom_Signal_Source when gnuradio-iio is not available --- src/algorithms/signal_source/adapters/CMakeLists.txt | 2 +- src/algorithms/signal_source/libs/CMakeLists.txt | 2 +- src/core/receiver/CMakeLists.txt | 4 ++++ src/core/receiver/gnss_block_factory.cc | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 9c0300522..48e18e5f3 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -259,7 +259,7 @@ if(LIBIIO_FOUND) ) endif() -if(ENABLE_AD9361 OR ENABLE_FMCOMMS2 OR ENABLE_PLUTOSDR) +if(ENABLE_AD9361 OR ENABLE_FMCOMMS2 OR ENABLE_PLUTOSDR OR ENABLE_AD936X_SDR) if(LIBAD9361_VERSION) if(LIBAD9361_VERSION VERSION_GREATER 0.1) target_compile_definitions(signal_source_adapters diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 9c39f7dc7..0df4f3303 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -113,7 +113,7 @@ if(GNURADIO_USES_STD_POINTERS) ) endif() -if(ENABLE_FMCOMMS2 OR ENABLE_AD9361 OR ENABLE_PLUTOSDR) +if(ENABLE_FMCOMMS2 OR ENABLE_AD9361 OR ENABLE_PLUTOSDR OR ENABLE_AD936X_SDR) target_link_libraries(signal_source_libs PUBLIC Iio::iio diff --git a/src/core/receiver/CMakeLists.txt b/src/core/receiver/CMakeLists.txt index 604449390..ba945f69b 100644 --- a/src/core/receiver/CMakeLists.txt +++ b/src/core/receiver/CMakeLists.txt @@ -94,6 +94,10 @@ if(ENABLE_PLUTOSDR) target_compile_definitions(core_receiver PRIVATE -DPLUTOSDR_DRIVER=1) endif() +if(ENABLE_AD936X_SDR) + target_compile_definitions(core_receiver PRIVATE -DAD936X_SDR_DRIVER=1) +endif() + if(ENABLE_FMCOMMS2) target_compile_definitions(core_receiver PRIVATE -DFMCOMMS2_DRIVER=1) endif() diff --git a/src/core/receiver/gnss_block_factory.cc b/src/core/receiver/gnss_block_factory.cc index 222b93cad..fceadefb9 100644 --- a/src/core/receiver/gnss_block_factory.cc +++ b/src/core/receiver/gnss_block_factory.cc @@ -163,6 +163,10 @@ #include "plutosdr_signal_source.h" #endif +#if AD936X_SDR_DRIVER +#include "ad936x_custom_signal_source.h" +#endif + #if FMCOMMS2_DRIVER #include "fmcomms2_signal_source.h" #endif @@ -807,6 +811,8 @@ std::unique_ptr GNSSBlockFactory::GetBlock( out_streams, queue); block = std::move(block_); } +#endif +#if PLUTOSDR_DRIVER || AD936X_SDR_DRIVER else if (implementation == "Ad936x_Custom_Signal_Source") { std::unique_ptr block_ = std::make_unique(configuration, role, in_streams, From 89dfadb535d4d5038d86375dea1b0dab9e53bfe1 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 29 Aug 2024 08:53:39 +0200 Subject: [PATCH 53/66] Bump local version of Protocol Buffers to v28.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a978c673f..35ccd15a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,7 +358,7 @@ set(GNSSSDR_ARMADILLO_LOCAL_VERSION "14.0.x") set(GNSSSDR_GFLAGS_LOCAL_VERSION "2.2.2") set(GNSSSDR_GLOG_LOCAL_VERSION "0.7.1") set(GNSSSDR_MATIO_LOCAL_VERSION "1.5.27") -set(GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION "27.3") +set(GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION "28.0") set(GNSSSDR_PUGIXML_LOCAL_VERSION "1.14") set(GNSSSDR_GTEST_LOCAL_VERSION "1.15.2") set(GNSSSDR_GNSS_SIM_LOCAL_VERSION "origin/master") From 792ec38989a057b75e061b05846f25064a124983 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 29 Aug 2024 20:30:54 +0200 Subject: [PATCH 54/66] Update AArch64 features to Linux 6.10.6 --- .../include/cpu_features_macros.h | 4 +- .../cpu_features/include/cpuinfo_aarch64.h | 43 +++++++++++++++++++ .../src/impl_aarch64__base_implementation.inl | 23 +++++++++- .../cpu_features/test/cpuinfo_aarch64_test.cc | 18 ++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h index 42b4e55b1..c800d0c32 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h @@ -227,11 +227,11 @@ #endif // defined(CPU_FEATURES_ARCH_X86) #if defined(CPU_FEATURES_ARCH_ANY_ARM) -#if defined(__ARM_NEON__) +#if defined(__ARM_NEON) #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 1 #else #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 0 -#endif // defined(__ARM_NEON__) +#endif // defined(__ARM_NEON) #endif // defined(CPU_FEATURES_ARCH_ANY_ARM) #if defined(CPU_FEATURES_ARCH_MIPS) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpuinfo_aarch64.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpuinfo_aarch64.h index a8cb0d41a..41108b6ec 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpuinfo_aarch64.h +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpuinfo_aarch64.h @@ -182,6 +182,31 @@ typedef struct int smef16f16 : 1; // FP16 to FP16 outer product. int mops : 1; // Standardized memory operations. int hbc : 1; // Hinted conditional branches. + int sveb16b16 : 1; // Non-widening BFloat16 to BFloat16 arithmetic for SVE2 + // and SME2. + int lrcpc3 : 1; // Load-Acquire RCpc instructions version 3. + int lse128 : 1; // 128-bit Atomics. + int fpmr : 1; // Floating-point Mode Register. + int lut : 1; // Lookup table instructions with 2-bit and 4-bit indices. + int faminmax : 1; // Maximum and minimum absolute value instructions. + int f8cvt : 1; // FP scaling instructions and FP8 convert instructions. + int f8fma : 1; // FP8 to single-precision and half-precision + // multiply-accumulate instructions. + int f8dp4 : 1; // FP8 to single-precision 4-way dot product FDOT (4-way) + // instructions. + int f8dp2 : 1; // FP8 to half-precision 2-way dot product FDOT (2-way) + // instructions. + int f8e4m3 : 1; // Arm FP8 E4M3 format. + int f8e5m2 : 1; // Arm FP8 E5M2 format. + int smelutv2 : 1; // SME2 lookup table LUTI4 and MOVT instructions. + int smef8f16 : 1; // SME2 F8F16 instructions. + int smef8f32 : 1; // SME2 F8F32 instructions. + int smesf8fma : 1; // SVE2 FP8 to single-precision and half-precision + // multiply-accumulate instructions. + int smesf8dp4 : 1; // SVE2 FP8 to single-precision 4-way dot product FDOT + // (4-way) instructions. + int smesf8dp2 : 1; // SVE2 FP8 to half-precision 2-way dot product FDOT + // (2-way) instructions. // Make sure to update Aarch64FeaturesEnum below if you add a field here. } Aarch64Features; @@ -280,6 +305,24 @@ typedef enum AARCH64_SME_F16F16, AARCH64_MOPS, AARCH64_HBC, + AARCH64_SVE_B16B16, + AARCH64_LRCPC3, + AARCH64_LSE128, + AARCH64_FPMR, + AARCH64_LUT, + AARCH64_FAMINMAX, + AARCH64_F8CVT, + AARCH64_F8FMA, + AARCH64_F8DP4, + AARCH64_F8DP2, + AARCH64_F8E4M3, + AARCH64_F8E5M2, + AARCH64_SME_LUTV2, + AARCH64_SME_F8F16, + AARCH64_SME_F8F32, + AARCH64_SME_SF8FMA, + AARCH64_SME_SF8DP4, + AARCH64_SME_SF8DP2, AARCH64_LAST_, } Aarch64FeaturesEnum; diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64__base_implementation.inl b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64__base_implementation.inl index 14be5a726..d0057ee10 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64__base_implementation.inl +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/src/impl_aarch64__base_implementation.inl @@ -103,7 +103,28 @@ LINE(AARCH64_SME_F16F16, smef16f16, "smef16f16", 0, \ AARCH64_HWCAP2_SME_F16F16) \ LINE(AARCH64_MOPS, mops, "mops", 0, AARCH64_HWCAP2_MOPS) \ - LINE(AARCH64_HBC, hbc, "hbc", 0, AARCH64_HWCAP2_HBC) + LINE(AARCH64_HBC, hbc, "hbc", 0, AARCH64_HWCAP2_HBC) \ + LINE(AARCH64_SVE_B16B16, sveb16b16, "sveb16b16", 0, \ + AARCH64_HWCAP2_SVE_B16B16) \ + LINE(AARCH64_LRCPC3, lrcpc3, "lrcpc3", 0, AARCH64_HWCAP2_LRCPC3) \ + LINE(AARCH64_LSE128, lse128, "lse128", 0, AARCH64_HWCAP2_LSE128) \ + LINE(AARCH64_FPMR, fpmr, "fpmr", 0, AARCH64_HWCAP2_FPMR) \ + LINE(AARCH64_LUT, lut, "lut", 0, AARCH64_HWCAP2_LUT) \ + LINE(AARCH64_FAMINMAX, faminmax, "faminmax", 0, AARCH64_HWCAP2_FAMINMAX) \ + LINE(AARCH64_F8CVT, f8cvt, "f8cvt", 0, AARCH64_HWCAP2_F8CVT) \ + LINE(AARCH64_F8FMA, f8fma, "f8fma", 0, AARCH64_HWCAP2_F8FMA) \ + LINE(AARCH64_F8DP4, f8dp4, "f8dp4", 0, AARCH64_HWCAP2_F8DP4) \ + LINE(AARCH64_F8DP2, f8dp2, "f8dp2", 0, AARCH64_HWCAP2_F8DP2) \ + LINE(AARCH64_F8E4M3, f8e4m3, "f8e4m3", 0, AARCH64_HWCAP2_F8E4M3) \ + LINE(AARCH64_F8E5M2, f8e5m2, "f8e5m2", 0, AARCH64_HWCAP2_F8E5M2) \ + LINE(AARCH64_SME_LUTV2, smelutv2, "smelutv1", 0, AARCH64_HWCAP2_SME_LUTV2) \ + LINE(AARCH64_SME_F8F16, smef8f16, "smef8f16", 0, AARCH64_HWCAP2_SME_F8F16) \ + LINE(AARCH64_SME_F8F32, smef8f32, "smef8f32", 0, AARCH64_HWCAP2_SME_F8F32) \ + LINE(AARCH64_SME_SF8FMA, smesf8fma, "smesf8fma", 0, \ + AARCH64_HWCAP2_SME_SF8FMA) \ + LINE(AARCH64_SME_SF8DP4, smesf8dp4, "smesf8dp4", 0, \ + AARCH64_HWCAP2_SME_SF8DP4) \ + LINE(AARCH64_SME_SF8DP2, smesf8dp2, "smesf8dp2", 0, AARCH64_HWCAP2_SME_SF8DP2) #define INTROSPECTION_PREFIX Aarch64 #define INTROSPECTION_ENUM_PREFIX AARCH64 #include "define_introspection_and_hwcaps.inl" \ No newline at end of file diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc index fc8abf8fe..e69c5ef78 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/test/cpuinfo_aarch64_test.cc @@ -326,6 +326,24 @@ CPU revision : 3)"); EXPECT_FALSE(info.features.smef16f16); EXPECT_FALSE(info.features.mops); EXPECT_FALSE(info.features.hbc); + EXPECT_FALSE(info.features.sveb16b16); + EXPECT_FALSE(info.features.lrcpc3); + EXPECT_FALSE(info.features.lse128); + EXPECT_FALSE(info.features.fpmr); + EXPECT_FALSE(info.features.lut); + EXPECT_FALSE(info.features.faminmax); + EXPECT_FALSE(info.features.f8cvt); + EXPECT_FALSE(info.features.f8fma); + EXPECT_FALSE(info.features.f8dp4); + EXPECT_FALSE(info.features.f8dp2); + EXPECT_FALSE(info.features.f8e4m3); + EXPECT_FALSE(info.features.f8e5m2); + EXPECT_FALSE(info.features.smelutv2); + EXPECT_FALSE(info.features.smef8f16); + EXPECT_FALSE(info.features.smef8f32); + EXPECT_FALSE(info.features.smesf8fma); + EXPECT_FALSE(info.features.smesf8dp4); + EXPECT_FALSE(info.features.smesf8dp2); } #elif defined(CPU_FEATURES_OS_MACOS) TEST_F(CpuidAarch64Test, FromDarwinSysctlFromName) From 1088387f75169abd500dff93c3798176c058d5d2 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 30 Aug 2024 07:52:37 +0200 Subject: [PATCH 55/66] Update AArch64 features to Linux 6.10.6 --- .../cpu_features/include/internal/hwcaps.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/internal/hwcaps.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/internal/hwcaps.h index 63baa1fff..3f500f606 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/internal/hwcaps.h +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/internal/hwcaps.h @@ -94,6 +94,24 @@ CPU_FEATURES_START_CPP_NAMESPACE #define AARCH64_HWCAP2_SME_F16F16 (1UL << 42) #define AARCH64_HWCAP2_MOPS (1UL << 43) #define AARCH64_HWCAP2_HBC (1UL << 44) +#define AARCH64_HWCAP2_SVE_B16B16 (1UL << 45) +#define AARCH64_HWCAP2_LRCPC3 (1UL << 46) +#define AARCH64_HWCAP2_LSE128 (1UL << 47) +#define AARCH64_HWCAP2_FPMR (1UL << 48) +#define AARCH64_HWCAP2_LUT (1UL << 49) +#define AARCH64_HWCAP2_FAMINMAX (1UL << 50) +#define AARCH64_HWCAP2_F8CVT (1UL << 51) +#define AARCH64_HWCAP2_F8FMA (1UL << 52) +#define AARCH64_HWCAP2_F8DP4 (1UL << 53) +#define AARCH64_HWCAP2_F8DP2 (1UL << 54) +#define AARCH64_HWCAP2_F8E4M3 (1UL << 55) +#define AARCH64_HWCAP2_F8E5M2 (1UL << 56) +#define AARCH64_HWCAP2_SME_LUTV2 (1UL << 57) +#define AARCH64_HWCAP2_SME_F8F16 (1UL << 58) +#define AARCH64_HWCAP2_SME_F8F32 (1UL << 59) +#define AARCH64_HWCAP2_SME_SF8FMA (1UL << 60) +#define AARCH64_HWCAP2_SME_SF8DP4 (1UL << 61) +#define AARCH64_HWCAP2_SME_SF8DP2 (1UL << 62) // http://elixir.free-electrons.com/linux/latest/source/arch/arm/include/uapi/asm/hwcap.h #define ARM_HWCAP_SWP (1UL << 0) From 951520f581bd7c1cd15264efda570489d24a3387 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 5 Sep 2024 16:38:04 +0200 Subject: [PATCH 56/66] Fix: Windows does not define __ARM_NEON --- .../cpu_features/include/cpu_features_macros.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h index c800d0c32..b595a22f2 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/cpu_features/include/cpu_features_macros.h @@ -226,13 +226,14 @@ #endif // defined(CPU_FEATURES_ARCH_X86) -#if defined(CPU_FEATURES_ARCH_ANY_ARM) -#if defined(__ARM_NEON) +// Note: MSVC targeting ARM does not define `__ARM_NEON` but Windows on ARM +// requires it. In that case we force NEON detection. +#if defined(__ARM_NEON) || \ + (defined(CPU_FEATURES_COMPILER_MSC) && defined(CPU_FEATURES_ARCH_ANY_ARM)) #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 1 #else #define CPU_FEATURES_COMPILED_ANY_ARM_NEON 0 -#endif // defined(__ARM_NEON) -#endif // defined(CPU_FEATURES_ARCH_ANY_ARM) +#endif #if defined(CPU_FEATURES_ARCH_MIPS) #if defined(__mips_msa) From 85f935afe9cb3b8990c9e4352122449550fc44c0 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 6 Sep 2024 15:46:23 +0200 Subject: [PATCH 57/66] Improve detection of the dma_proxy module and the spidev driver --- CMakeLists.txt | 60 ++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35ccd15a5..b93750b3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3444,46 +3444,23 @@ if(ENABLE_MAX2771) if(DEFINED ENV{SDKTARGETSYSROOT}) set(TARGET_ROOTFS_PATH $ENV{SDKTARGETSYSROOT}) else() - set(TARGET_ROOTFS_PATH "") - endif() - find_program(STRINGS_EXECUTABLE strings) - if(NOT STRINGS_EXECUTABLE) - message(STATUS "The 'strings' command could not be found. See https://www.gnu.org/software/binutils/") - message(STATUS " You can try to install it by typing:") - if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|kFreeBSD|GNU") - if(${LINUX_DISTRIBUTION} MATCHES "Fedora" OR ${LINUX_DISTRIBUTION} MATCHES "Red Hat") - message(STATUS " sudo yum install binutils") - elseif(${LINUX_DISTRIBUTION} MATCHES "openSUSE") - message(STATUS " sudo zypper install binutils") - else() - message(STATUS " sudo apt-get install binutils") - endif() - endif() - message(FATAL_ERROR "Binutils are required to build GNSS-SDR for SoC FPGA devices using the MAX2771 option.") - endif() - set(DTB_FILE "${TARGET_ROOTFS_PATH}/boot/devicetree/system-top.dtb") - if(EXISTS "${DTB_FILE}") - message(STATUS "Found DTB file: ${DTB_FILE}") - # Run the strings command and grep for "spidev" - execute_process( - COMMAND ${STRINGS_EXECUTABLE} ${DTB_FILE} - COMMAND grep "spidev" - OUTPUT_VARIABLE GREP_OUTPUT - RESULT_VARIABLE GREP_RESULT - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(GREP_RESULT EQUAL 0) - message(STATUS "Found spidev-compatible peripheral in ${DTB_FILE}.") + string(REGEX MATCH "(.*/tmp-glibc)" MATCHED_PATH "${GNURADIO_RUNTIME_INCLUDE_DIRS}") + if(MATCHED_PATH) + set(TARGET_ROOTFS_PATH "${MATCHED_PATH}/sysroots-components") else() - message(STATUS "SPIdev driver not found, its installation is required.") - if(ENABLE_PACKAGING) - set(ENABLE_MAX2771 OFF) - else() - message(FATAL_ERROR "SPIdev driver is required for building gnss-sdr with -DENABLE_MAX2271=ON.") - endif() + set(TARGET_ROOTFS_PATH "") endif() + endif() + file(GLOB_RECURSE SPIDEV_FILE "${TARGET_ROOTFS_PATH}/*/spidev.h") + if(EXISTS "${SPIDEV_FILE}") + message(STATUS "SPIdev driver found: ${SPIDEV_FILE}") else() - message(FATAL_ERROR "The device tree (DTB) file ${DTB_FILE} cannot be found.") + message(STATUS "SPIdev driver not found, its installation is required.") + if(ENABLE_PACKAGING) + set(ENABLE_MAX2771 OFF) + else() + message(FATAL_ERROR "SPIdev driver is required for building gnss-sdr with -DENABLE_MAX2271=ON.") + endif() endif() endif() @@ -3498,9 +3475,14 @@ if(ENABLE_DMA_PROXY) if(DEFINED ENV{SDKTARGETSYSROOT}) set(TARGET_ROOTFS_PATH $ENV{SDKTARGETSYSROOT}) else() - set(TARGET_ROOTFS_PATH "") + string(REGEX MATCH "(.*/tmp-glibc)" MATCHED_PATH "${GNURADIO_RUNTIME_INCLUDE_DIRS}") + if(MATCHED_PATH) + set(TARGET_ROOTFS_PATH "${MATCHED_PATH}/sysroots-components") + else() + set(TARGET_ROOTFS_PATH "") + endif() endif() - set(DMA_PROXY_FILE "${TARGET_ROOTFS_PATH}/lib/modules/5.10.0-xilinx-v2021.2/extra/dma-proxy.ko") + file(GLOB_RECURSE DMA_PROXY_FILE "${TARGET_ROOTFS_PATH}/*/dma-proxy.ko") if(EXISTS "${DMA_PROXY_FILE}") message(STATUS "Found dma-proxy.ko file: ${DMA_PROXY_FILE}") else() From b981f8065e486a288f60769d28898b8a08165d20 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 8 Sep 2024 09:41:36 +0200 Subject: [PATCH 58/66] Add missing include (fixes building with modern GCC) --- src/algorithms/signal_source/libs/fpga_spidev.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/algorithms/signal_source/libs/fpga_spidev.h b/src/algorithms/signal_source/libs/fpga_spidev.h index 5fbe2f41c..ccef015d2 100644 --- a/src/algorithms/signal_source/libs/fpga_spidev.h +++ b/src/algorithms/signal_source/libs/fpga_spidev.h @@ -16,6 +16,7 @@ #ifndef GNSS_SDR_FPGA_SPIDEV_H #define GNSS_SDR_FPGA_SPIDEV_H +#include #include class Fpga_spidev From 94ab8a7006c7114c4823d710c897168503f630f4 Mon Sep 17 00:00:00 2001 From: Xavier Guerrero-Pau Date: Thu, 29 Aug 2024 16:30:13 +0200 Subject: [PATCH 59/66] Adapted udp_port to multiple ports --- src/algorithms/PVT/adapters/rtklib_pvt.cc | 2 +- .../PVT/gnuradio_blocks/rtklib_pvt_gs.cc | 7 ++++- .../PVT/libs/monitor_pvt_udp_sink.cc | 11 +++++-- .../PVT/libs/monitor_pvt_udp_sink.h | 5 +++- src/algorithms/PVT/libs/pvt_conf.h | 2 +- src/core/monitor/gnss_synchro_monitor.cc | 17 +++++------ src/core/monitor/gnss_synchro_monitor.h | 6 ++-- src/core/monitor/gnss_synchro_udp_sink.cc | 15 +++++++--- src/core/monitor/gnss_synchro_udp_sink.h | 2 +- src/core/receiver/gnss_flowgraph.cc | 30 +++++++++++++++---- 10 files changed, 67 insertions(+), 30 deletions(-) diff --git a/src/algorithms/PVT/adapters/rtklib_pvt.cc b/src/algorithms/PVT/adapters/rtklib_pvt.cc index bdd1f97c6..bfdf6c4b8 100644 --- a/src/algorithms/PVT/adapters/rtklib_pvt.cc +++ b/src/algorithms/PVT/adapters/rtklib_pvt.cc @@ -887,7 +887,7 @@ Rtklib_Pvt::Rtklib_Pvt(const ConfigurationInterface* configuration, // Read PVT MONITOR Configuration pvt_output_parameters.monitor_enabled = configuration->property(role + ".enable_monitor", false); pvt_output_parameters.udp_addresses = configuration->property(role + ".monitor_client_addresses", std::string("127.0.0.1")); - pvt_output_parameters.udp_port = configuration->property(role + ".monitor_udp_port", 1234); + pvt_output_parameters.udp_ports = configuration->property(role + ".monitor_udp_port", std::string("1234")); pvt_output_parameters.protobuf_enabled = configuration->property(role + ".enable_protobuf", true); if (configuration->property("Monitor.enable_protobuf", false) == true) { diff --git a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc index 5f33ecaed..bae417cbb 100644 --- a/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc +++ b/src/algorithms/PVT/gnuradio_blocks/rtklib_pvt_gs.cc @@ -467,7 +467,12 @@ rtklib_pvt_gs::rtklib_pvt_gs(uint32_t nchannels, std::sort(udp_addr_vec.begin(), udp_addr_vec.end()); udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end()); - d_udp_sink_ptr = std::make_unique(udp_addr_vec, conf_.udp_port, conf_.protobuf_enabled); + std::string port_string = conf_.udp_ports; + std::vector udp_port_vec = split_string(port_string, '_'); + std::sort(udp_port_vec.begin(), udp_port_vec.end()); + udp_port_vec.erase(std::unique(udp_port_vec.begin(), udp_port_vec.end()), udp_port_vec.end()); + + d_udp_sink_ptr = std::make_unique(udp_addr_vec, udp_port_vec, conf_.protobuf_enabled); } else { diff --git a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc index 9caef6f4d..e284bf4b2 100644 --- a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc +++ b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc @@ -17,19 +17,24 @@ #include "monitor_pvt_udp_sink.h" #include +#include #include #include -Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink(const std::vector& addresses, - const uint16_t& port, +Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink( + const std::vector& addresses, + const std::vector& ports, bool protobuf_enabled) : socket{io_context}, use_protobuf(protobuf_enabled) { for (const auto& address : addresses) { - boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), port); + for (const auto& port : ports) + { + boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), boost::lexical_cast (port)); endpoints.push_back(endpoint); + } } if (use_protobuf) diff --git a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h index 1fbe3219d..bfe1c00e5 100644 --- a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h +++ b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h @@ -40,7 +40,10 @@ using b_io_context = boost::asio::io_service; class Monitor_Pvt_Udp_Sink { public: - Monitor_Pvt_Udp_Sink(const std::vector& addresses, const uint16_t& port, bool protobuf_enabled); + Monitor_Pvt_Udp_Sink( + const std::vector& addresses, + const std::vector& ports, + bool protobuf_enabled); bool write_monitor_pvt(const Monitor_Pvt* const monitor_pvt); private: diff --git a/src/algorithms/PVT/libs/pvt_conf.h b/src/algorithms/PVT/libs/pvt_conf.h index 37d9b5aac..b38cfe788 100644 --- a/src/algorithms/PVT/libs/pvt_conf.h +++ b/src/algorithms/PVT/libs/pvt_conf.h @@ -48,6 +48,7 @@ public: std::string rtcm_output_file_path = std::string("."); std::string has_output_file_path = std::string("."); std::string udp_addresses; + std::string udp_ports; std::string udp_eph_addresses; std::string log_source_timetag_file; @@ -64,7 +65,6 @@ public: int32_t rinexobs_rate_ms = 0; int32_t an_rate_ms = 20; int32_t max_obs_block_rx_clock_offset_ms = 40; - int udp_port = 0; int udp_eph_port = 0; int rtk_trace_level = 0; diff --git a/src/core/monitor/gnss_synchro_monitor.cc b/src/core/monitor/gnss_synchro_monitor.cc index 98526fe60..0b74b7b8c 100644 --- a/src/core/monitor/gnss_synchro_monitor.cc +++ b/src/core/monitor/gnss_synchro_monitor.cc @@ -26,29 +26,28 @@ gnss_synchro_monitor_sptr gnss_synchro_make_monitor(int n_channels, int decimation_factor, - int udp_port, + const std::vector& udp_ports, const std::vector& udp_addresses, bool enable_protobuf) { return gnss_synchro_monitor_sptr(new gnss_synchro_monitor(n_channels, decimation_factor, - udp_port, + udp_ports, udp_addresses, enable_protobuf)); } - gnss_synchro_monitor::gnss_synchro_monitor(int n_channels, int decimation_factor, - int udp_port, + const std::vector& udp_ports, const std::vector& udp_addresses, bool enable_protobuf) : gr::block("gnss_synchro_monitor", - gr::io_signature::make(n_channels, n_channels, sizeof(Gnss_Synchro)), - gr::io_signature::make(0, 0, 0)), - count(0), - d_nchannels(n_channels), - d_decimation_factor(decimation_factor) + gr::io_signature::make(n_channels, n_channels, sizeof(Gnss_Synchro)), + gr::io_signature::make(0, 0, 0)), + count(0), + d_nchannels(n_channels), + d_decimation_factor(decimation_factor) { udp_sink_ptr = std::make_unique(udp_addresses, udp_port, enable_protobuf); } diff --git a/src/core/monitor/gnss_synchro_monitor.h b/src/core/monitor/gnss_synchro_monitor.h index 64749a001..4edd012e1 100644 --- a/src/core/monitor/gnss_synchro_monitor.h +++ b/src/core/monitor/gnss_synchro_monitor.h @@ -41,7 +41,7 @@ using gnss_synchro_monitor_sptr = gnss_shared_ptr; gnss_synchro_monitor_sptr gnss_synchro_make_monitor(int n_channels, int decimation_factor, - int udp_port, + const std::vector& udp_ports, const std::vector& udp_addresses, bool enable_protobuf); @@ -61,13 +61,13 @@ public: private: friend gnss_synchro_monitor_sptr gnss_synchro_make_monitor(int n_channels, int decimation_factor, - int udp_port, + const std::vector& udp_ports, const std::vector& udp_addresses, bool enable_protobuf); gnss_synchro_monitor(int n_channels, int decimation_factor, - int udp_port, + const std::vector& udp_ports, const std::vector& udp_addresses, bool enable_protobuf); diff --git a/src/core/monitor/gnss_synchro_udp_sink.cc b/src/core/monitor/gnss_synchro_udp_sink.cc index 336f834cb..67f76a431 100644 --- a/src/core/monitor/gnss_synchro_udp_sink.cc +++ b/src/core/monitor/gnss_synchro_udp_sink.cc @@ -18,11 +18,13 @@ #include "gnss_synchro_udp_sink.h" #include #include +#include #include #include -Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink(const std::vector& addresses, - const uint16_t& port, +Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink( + const std::vector& addresses, + const std::vector& ports, bool enable_protobuf) : socket{io_context}, use_protobuf(enable_protobuf) @@ -33,8 +35,13 @@ Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink(const std::vector& add } for (const auto& address : addresses) { - boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), port); - endpoints.push_back(endpoint); + for (const auto& port : ports) + { + boost::asio::ip::udp::endpoint endpoint( + boost::asio::ip::address::from_string(address, error), + boost::lexical_cast (port)); + endpoints.push_back(endpoint); + } } } diff --git a/src/core/monitor/gnss_synchro_udp_sink.h b/src/core/monitor/gnss_synchro_udp_sink.h index cf777cc12..699a6043f 100644 --- a/src/core/monitor/gnss_synchro_udp_sink.h +++ b/src/core/monitor/gnss_synchro_udp_sink.h @@ -45,7 +45,7 @@ using b_io_context = boost::asio::io_service; class Gnss_Synchro_Udp_Sink { public: - Gnss_Synchro_Udp_Sink(const std::vector& addresses, const uint16_t& port, bool enable_protobuf); + Gnss_Synchro_Udp_Sink(const std::vector& addresses, const std::vector& ports, bool enable_protobuf); bool write_gnss_synchro(const std::vector& stocks); private: diff --git a/src/core/receiver/gnss_flowgraph.cc b/src/core/receiver/gnss_flowgraph.cc index c7cbb9f07..599dadab3 100644 --- a/src/core/receiver/gnss_flowgraph.cc +++ b/src/core/receiver/gnss_flowgraph.cc @@ -217,11 +217,17 @@ void GNSSFlowgraph::init() std::sort(udp_addr_vec.begin(), udp_addr_vec.end()); udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end()); + std::string udp_port_string = configuration_->property("Monitor.udp_port", std::string("1234")); + std::vector udp_port_vec = split_string(udp_port_string, '_'); + std::sort(udp_port_vec.begin(), udp_port_vec.end()); + udp_port_vec.erase(std::unique(udp_port_vec.begin(), udp_port_vec.end()), udp_port_vec.end()); + // Instantiate monitor object GnssSynchroMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("Monitor.decimation_factor", 1), - configuration_->property("Monitor.udp_port", 1234), - udp_addr_vec, enable_protobuf); + udp_port_vec, + udp_addr_vec, + enable_protobuf); } /* @@ -241,10 +247,16 @@ void GNSSFlowgraph::init() std::sort(udp_addr_vec.begin(), udp_addr_vec.end()); udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end()); + std::string udp_port_string = configuration_->property("AcquisitionMonitor.udp_port", std::string("1235")); + std::vector udp_port_vec = split_string(udp_port_string, '_'); + std::sort(udp_port_vec.begin(), udp_port_vec.end()); + udp_port_vec.erase(std::unique(udp_port_vec.begin(), udp_port_vec.end()), udp_port_vec.end()); + GnssSynchroAcquisitionMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("AcquisitionMonitor.decimation_factor", 1), - configuration_->property("AcquisitionMonitor.udp_port", 1235), - udp_addr_vec, enable_protobuf); + udp_port_vec, + udp_addr_vec, + enable_protobuf); } /* @@ -264,10 +276,16 @@ void GNSSFlowgraph::init() std::sort(udp_addr_vec.begin(), udp_addr_vec.end()); udp_addr_vec.erase(std::unique(udp_addr_vec.begin(), udp_addr_vec.end()), udp_addr_vec.end()); + std::string udp_port_string = configuration_->property("TrackingMonitor.udp_port", std::string("1236")); + std::vector udp_port_vec = split_string(udp_port_string, '_'); + std::sort(udp_port_vec.begin(), udp_port_vec.end()); + udp_port_vec.erase(std::unique(udp_port_vec.begin(), udp_port_vec.end()), udp_port_vec.end()); + GnssSynchroTrackingMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("TrackingMonitor.decimation_factor", 1), - configuration_->property("TrackingMonitor.udp_port", 1236), - udp_addr_vec, enable_protobuf); + udp_port_vec, + udp_addr_vec, + enable_protobuf); } /* From fdc4e4078e440f36611532eeb16e721b66aad88a Mon Sep 17 00:00:00 2001 From: Xavier Guerrero-Pau Date: Thu, 29 Aug 2024 17:39:23 +0200 Subject: [PATCH 60/66] Fixed typo --- src/core/monitor/gnss_synchro_monitor.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/monitor/gnss_synchro_monitor.cc b/src/core/monitor/gnss_synchro_monitor.cc index 0b74b7b8c..d670d342a 100644 --- a/src/core/monitor/gnss_synchro_monitor.cc +++ b/src/core/monitor/gnss_synchro_monitor.cc @@ -49,7 +49,7 @@ gnss_synchro_monitor::gnss_synchro_monitor(int n_channels, d_nchannels(n_channels), d_decimation_factor(decimation_factor) { - udp_sink_ptr = std::make_unique(udp_addresses, udp_port, enable_protobuf); + udp_sink_ptr = std::make_unique(udp_addresses, udp_ports, enable_protobuf); } From c9277539ff64666f3c0f53167a305e824d0aebdb Mon Sep 17 00:00:00 2001 From: Xavier Guerrero-Pau Date: Mon, 9 Sep 2024 15:43:24 +0200 Subject: [PATCH 61/66] Fixed clang format --- src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc | 12 ++++++------ src/algorithms/PVT/libs/monitor_pvt_udp_sink.h | 4 ++-- src/core/monitor/gnss_synchro_monitor.cc | 10 +++++----- src/core/monitor/gnss_synchro_udp_sink.cc | 16 ++++++++-------- src/core/receiver/gnss_flowgraph.cc | 6 +++--- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc index e284bf4b2..f9a60e0ac 100644 --- a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc +++ b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.cc @@ -24,17 +24,17 @@ Monitor_Pvt_Udp_Sink::Monitor_Pvt_Udp_Sink( const std::vector& addresses, - const std::vector& ports, + const std::vector& ports, bool protobuf_enabled) : socket{io_context}, use_protobuf(protobuf_enabled) { for (const auto& address : addresses) { - for (const auto& port : ports) - { - boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), boost::lexical_cast (port)); - endpoints.push_back(endpoint); - } + for (const auto& port : ports) + { + boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(address, error), boost::lexical_cast(port)); + endpoints.push_back(endpoint); + } } if (use_protobuf) diff --git a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h index bfe1c00e5..393e4e5e2 100644 --- a/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h +++ b/src/algorithms/PVT/libs/monitor_pvt_udp_sink.h @@ -41,8 +41,8 @@ class Monitor_Pvt_Udp_Sink { public: Monitor_Pvt_Udp_Sink( - const std::vector& addresses, - const std::vector& ports, + const std::vector& addresses, + const std::vector& ports, bool protobuf_enabled); bool write_monitor_pvt(const Monitor_Pvt* const monitor_pvt); diff --git a/src/core/monitor/gnss_synchro_monitor.cc b/src/core/monitor/gnss_synchro_monitor.cc index d670d342a..f63811a73 100644 --- a/src/core/monitor/gnss_synchro_monitor.cc +++ b/src/core/monitor/gnss_synchro_monitor.cc @@ -43,11 +43,11 @@ gnss_synchro_monitor::gnss_synchro_monitor(int n_channels, const std::vector& udp_addresses, bool enable_protobuf) : gr::block("gnss_synchro_monitor", - gr::io_signature::make(n_channels, n_channels, sizeof(Gnss_Synchro)), - gr::io_signature::make(0, 0, 0)), - count(0), - d_nchannels(n_channels), - d_decimation_factor(decimation_factor) + gr::io_signature::make(n_channels, n_channels, sizeof(Gnss_Synchro)), + gr::io_signature::make(0, 0, 0)), + count(0), + d_nchannels(n_channels), + d_decimation_factor(decimation_factor) { udp_sink_ptr = std::make_unique(udp_addresses, udp_ports, enable_protobuf); } diff --git a/src/core/monitor/gnss_synchro_udp_sink.cc b/src/core/monitor/gnss_synchro_udp_sink.cc index 67f76a431..45a6e441e 100644 --- a/src/core/monitor/gnss_synchro_udp_sink.cc +++ b/src/core/monitor/gnss_synchro_udp_sink.cc @@ -17,8 +17,8 @@ #include "gnss_synchro_udp_sink.h" #include -#include #include +#include #include #include @@ -35,13 +35,13 @@ Gnss_Synchro_Udp_Sink::Gnss_Synchro_Udp_Sink( } for (const auto& address : addresses) { - for (const auto& port : ports) - { - boost::asio::ip::udp::endpoint endpoint( - boost::asio::ip::address::from_string(address, error), - boost::lexical_cast (port)); - endpoints.push_back(endpoint); - } + for (const auto& port : ports) + { + boost::asio::ip::udp::endpoint endpoint( + boost::asio::ip::address::from_string(address, error), + boost::lexical_cast(port)); + endpoints.push_back(endpoint); + } } } diff --git a/src/core/receiver/gnss_flowgraph.cc b/src/core/receiver/gnss_flowgraph.cc index 599dadab3..2963b03a5 100644 --- a/src/core/receiver/gnss_flowgraph.cc +++ b/src/core/receiver/gnss_flowgraph.cc @@ -226,7 +226,7 @@ void GNSSFlowgraph::init() GnssSynchroMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("Monitor.decimation_factor", 1), udp_port_vec, - udp_addr_vec, + udp_addr_vec, enable_protobuf); } @@ -255,7 +255,7 @@ void GNSSFlowgraph::init() GnssSynchroAcquisitionMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("AcquisitionMonitor.decimation_factor", 1), udp_port_vec, - udp_addr_vec, + udp_addr_vec, enable_protobuf); } @@ -284,7 +284,7 @@ void GNSSFlowgraph::init() GnssSynchroTrackingMonitor_ = gnss_synchro_make_monitor(channels_count_, configuration_->property("TrackingMonitor.decimation_factor", 1), udp_port_vec, - udp_addr_vec, + udp_addr_vec, enable_protobuf); } From d449465a25c333e7878ae27b1d9619dea46a8333 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 9 Sep 2024 17:10:24 +0200 Subject: [PATCH 62/66] Update changelog --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index abdc04427..70108de49 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -45,6 +45,7 @@ All notable changes to GNSS-SDR will be documented in this file. described with the [ION GNSS Software Defined Receiver Metadata Standard](https://sdr.ion.org/). It requires the `-DENABLE_ION=ON` building configuration option. +- The `Monitor` block is now able to send data to multiple ports. ### Improvements in Portability: From 3bd38a1ca0715e49d9c4e281e6e5d87d115f7f7f Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 9 Sep 2024 17:12:27 +0200 Subject: [PATCH 63/66] Add Xavier Guerrero to the authors list --- AUTHORS | 1 + CITATION.cff | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/AUTHORS b/AUTHORS index 7df41ed17..9f305c3a3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -37,6 +37,7 @@ Carles Fernández-Prades carles.fernandez@cttc.cat Project manager Javier Arribas javier.arribas@cttc.es Developer Luis Esteve Elfau luis@epsilon-formacion.com Developer Marc Majoral marc.majoral@cttc.cat Developer +Xavier Guerrero xavier.guerrero@cttc.es Developer Jordi Vilà-Valls jordi.vila-valls@isae-supaero.fr Consultant Pau Closas pau.closas@northeastern.edu Consultant Álvaro Cebrián Juan acebrianjuan@gmail.com Contributor diff --git a/CITATION.cff b/CITATION.cff index 4bf27081f..4851a8b1b 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -20,6 +20,11 @@ authors: family-names: Majoral given-names: Marc orcid: "https://orcid.org/0000-0001-6161-6747" + - affiliation: "Centre Tecnològic de Telecomunicacions de Catalunya (CTTC)" + alias: xguerreropau + email: xavier.guerrero@cttc.es + family-names: Guerrero + given-names: Xavier - alias: Gastd email: gabriel.araujo.5000@gmail.com family-names: Araujo From fe58ba563c02f11eb6e96d20cf3d1dbbd54e49e8 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 12 Sep 2024 21:22:54 +0200 Subject: [PATCH 64/66] Update changelog --- docs/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 70108de49..1f067e6d6 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -45,7 +45,8 @@ All notable changes to GNSS-SDR will be documented in this file. described with the [ION GNSS Software Defined Receiver Metadata Standard](https://sdr.ion.org/). It requires the `-DENABLE_ION=ON` building configuration option. -- The `Monitor` block is now able to send data to multiple ports. +- The `Monitor` and `PVT` blocks are now able to send data to multiple UDP + ports. ### Improvements in Portability: From c61d69b6272dda7f4978d76e20b4424709eb732e Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 12 Sep 2024 21:24:01 +0200 Subject: [PATCH 65/66] Bump local version of Protocol Buffers to 28.1 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b93750b3e..aa4c671b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,7 +358,7 @@ set(GNSSSDR_ARMADILLO_LOCAL_VERSION "14.0.x") set(GNSSSDR_GFLAGS_LOCAL_VERSION "2.2.2") set(GNSSSDR_GLOG_LOCAL_VERSION "0.7.1") set(GNSSSDR_MATIO_LOCAL_VERSION "1.5.27") -set(GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION "28.0") +set(GNSSSDR_PROTOCOLBUFFERS_LOCAL_VERSION "28.1") set(GNSSSDR_PUGIXML_LOCAL_VERSION "1.14") set(GNSSSDR_GTEST_LOCAL_VERSION "1.15.2") set(GNSSSDR_GNSS_SIM_LOCAL_VERSION "origin/master") From d40e3427d423324f96d6f394698d62f3e63a08af Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 16 Sep 2024 18:13:12 +0200 Subject: [PATCH 66/66] Add install and uninstall targets to nav_msg_listener --- docs/CHANGELOG.md | 1 + src/utils/nav-listener/CMakeLists.txt | 16 +++++++++ src/utils/nav-listener/README.md | 12 +++++++ .../cmake/cmake_uninstall.cmake.in | 35 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 src/utils/nav-listener/cmake/cmake_uninstall.cmake.in diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1f067e6d6..aa7bef842 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -85,6 +85,7 @@ All notable changes to GNSS-SDR will be documented in this file. ### Improvements in Usability: - Tidy up the `conf/` folder. +- Add `install` and `uninstall` targets to the `nav_msg_listener` utility. See the definitions of concepts and metrics at https://gnss-sdr.org/design-forces/ diff --git a/src/utils/nav-listener/CMakeLists.txt b/src/utils/nav-listener/CMakeLists.txt index cc86a7bf4..ea9c5d36e 100644 --- a/src/utils/nav-listener/CMakeLists.txt +++ b/src/utils/nav-listener/CMakeLists.txt @@ -39,3 +39,19 @@ target_include_directories(navmsg_lib add_executable(nav_msg_listener ${NAVLISTENER_SOURCE_DIR}/main.cc) target_link_libraries(nav_msg_listener PUBLIC navmsg_lib) + +install(TARGETS nav_msg_listener + RUNTIME DESTINATION bin + COMPONENT "nav_msg_listener" +) + +if(NOT TARGET uninstall) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY + ) + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake + ) +endif() diff --git a/src/utils/nav-listener/README.md b/src/utils/nav-listener/README.md index 76b2aedaf..4bd90658e 100644 --- a/src/utils/nav-listener/README.md +++ b/src/utils/nav-listener/README.md @@ -27,6 +27,18 @@ $ cmake .. $ make ``` +Optionally, you can install it: + +``` +$ sudo make install +``` + +and uninstall it later with: + +``` +$ sudo make uninstall +``` + ## Usage In order to tell GNSS-SDR to generate those messages, you need to include the diff --git a/src/utils/nav-listener/cmake/cmake_uninstall.cmake.in b/src/utils/nav-listener/cmake/cmake_uninstall.cmake.in new file mode 100644 index 000000000..fc57491c4 --- /dev/null +++ b/src/utils/nav-listener/cmake/cmake_uninstall.cmake.in @@ -0,0 +1,35 @@ +# GNSS-SDR is a Global Navigation Satellite System software-defined receiver. +# This file is part of GNSS-SDR. +# +# SPDX-FileCopyrightText: 2011-2020 C. Fernandez-Prades cfernandez(at)cttc.es +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif() + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + if(CMAKE_VERSION VERSION_LESS 3.17) + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + else() + execute_process( + COMMAND @CMAKE_COMMAND@ -E rm "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + endif() + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif() + else() + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif() +endforeach()