1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-09-21 03:39:48 +00:00

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`.
This commit is contained in:
Victor Castillo 2024-08-19 17:43:18 +02:00
parent 54e18adb61
commit 92dcec67e0
No known key found for this signature in database
GPG Key ID: 8EF1FC8B7182F608
5 changed files with 107 additions and 183 deletions

View File

@ -57,7 +57,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura
Concurrent_Queue<pmt::pmt_t>* 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<IONGSMSFileSource::sptr> IONGSMSSignalSource::make_stream_sources(const std::vector<std::string>& stream_ids) const
{
std::vector<IONGSMSFileSource::sptr> 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<IONGSMSFileSource>(
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)
{

View File

@ -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 <GnssMetadata.h>
#include <cstdint>
#include <string>
#include <vector>
@ -58,10 +59,17 @@ protected:
}
private:
std::vector<IONGSMSFileSource::sptr> make_stream_sources(const std::vector<std::string>& stream_ids) const;
void load_metadata();
std::vector<std::string> stream_ids_;
std::vector<IONGSMSFileSource::sptr> sources_;
std::vector<gnss_shared_ptr<gr::block>> copy_blocks_;
IONGSMSMetadataHandler metadata_;
std::vector<gnss_shared_ptr<gr::block>> valves_;
std::string metadata_filepath_;
GnssMetadata::Metadata metadata_;
gnss_shared_ptr<Gnss_Sdr_Timestamp> timestamp_block_;
std::string timestamp_file_;

View File

@ -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()

View File

@ -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 <cstdlib>
#if USE_GLOG_AND_GFLAGS
#include <glog/logging.h>
#else
#include <absl/log/log.h>
#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<IONGSMSFileSource::sptr> IONGSMSMetadataHandler::make_stream_sources(const std::vector<std::string>& stream_ids) const
{
std::vector<IONGSMSFileSource::sptr> 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<IONGSMSFileSource>(
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;
}

View File

@ -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 <gnuradio/block.h>
#include <GnssMetadata.h>
#include <string>
#include <vector>
/** \addtogroup Signal_Source
* \{ */
/** \addtogroup Signal_Source_libs
* \{ */
class IONGSMSMetadataHandler
{
public:
explicit IONGSMSMetadataHandler(const std::string& metadata_filepath);
std::vector<IONGSMSFileSource::sptr> make_stream_sources(const std::vector<std::string>& 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