From 92dcec67e076d9db0a0d590d7fadd2eb76ce2663 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 19 Aug 2024 17:43:18 +0200 Subject: [PATCH] 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