From d9f7a1f96e1de5201a548aa5894424d031d82a78 Mon Sep 17 00:00:00 2001 From: Victor Castillo Date: Mon, 29 Jul 2024 00:28:17 +0200 Subject: [PATCH] Composed ExtraDataSource into FileSourceBase --- .../adapters/file_source_base.cc | 46 ++++++++++++++++++- .../signal_source/adapters/file_source_base.h | 14 ++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/algorithms/signal_source/adapters/file_source_base.cc b/src/algorithms/signal_source/adapters/file_source_base.cc index 7b9efcbc2..eab0b5629 100644 --- a/src/algorithms/signal_source/adapters/file_source_base.cc +++ b/src/algorithms/signal_source/adapters/file_source_base.cc @@ -60,7 +60,15 @@ FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std: is_complex_(false), repeat_(configuration->property(role_ + ".repeat"s, false)), enable_throttle_control_(configuration->property(role_ + ".enable_throttle_control"s, false)), - dump_(configuration->property(role_ + ".dump"s, false)) + dump_(configuration->property(role_ + ".dump"s, false)), + // Configuration for attaching extra data to the sample stream + attach_extra_data_(configuration->property(role_ + ".extra_data.enabled"s, false)), + ed_path_(configuration->property(role_ + ".extra_data.filename"s, "../data/extra_data.dat"s)), + ed_offset_in_file_(configuration->property(role_ + ".extra_data.file_offset"s, 0UL)), + ed_item_size_(configuration->property(role_ + ".extra_data.item_size"s, 1UL)), + ed_repeat_(configuration->property(role_ + ".extra_data.repeat"s, false)), + ed_offset_in_samples_(configuration->property(role_ + ".extra_data.sample_offset"s, 0UL)), + ed_sample_period_(configuration->property(role_ + ".extra_data.sample_period"s, 1UL)) { minimum_tail_s_ = std::max(configuration->property("Acquisition_1C.coherent_integration_time_ms", 0.0) * 0.001 * 2.0, minimum_tail_s_); minimum_tail_s_ = std::max(configuration->property("Acquisition_2S.coherent_integration_time_ms", 0.0) * 0.001 * 2.0, minimum_tail_s_); @@ -157,6 +165,7 @@ void FileSourceBase::init() create_throttle(); create_valve(); create_sink(); + create_extra_data_source(); } @@ -205,6 +214,14 @@ void FileSourceBase::connect(gr::top_block_sptr top_block) DLOG(INFO) << "connected output to file sink"; } + // EXTRA DATA + if (extra_data_source()) + { + top_block->connect(std::move(output), 0, extra_data_source(), 0); + DLOG(INFO) << "connected output to extra data source, which now becomes the new output"; + output = extra_data_source(); + } + post_connect_hook(std::move(top_block)); } @@ -253,6 +270,15 @@ void FileSourceBase::disconnect(gr::top_block_sptr top_block) DLOG(INFO) << "disconnected output to file sink"; } + // EXTRA DATA + if (extra_data_source()) + { + // TODO - FIXME: This is NOT okay, `output` is the extra data source, not the valve/source/throttle/whatever is left of this + top_block->disconnect(std::move(output), 0, extra_data_source(), 0); + DLOG(INFO) << "disconnected output to extra data source"; + output = extra_data_source(); + } + post_disconnect_hook(std::move(top_block)); } @@ -478,6 +504,7 @@ gnss_shared_ptr FileSourceBase::file_source() const { return file_sou gnss_shared_ptr FileSourceBase::valve() const { return valve_; } gnss_shared_ptr FileSourceBase::throttle() const { return throttle_; } gnss_shared_ptr FileSourceBase::sink() const { return sink_; } +ExtraDataSource::sptr FileSourceBase::extra_data_source() const { return extra_data_source_; } gr::blocks::file_source::sptr FileSourceBase::create_file_source() @@ -574,6 +601,23 @@ gr::blocks::file_sink::sptr FileSourceBase::create_sink() return sink_; } +ExtraDataSource::sptr FileSourceBase::create_extra_data_source() +{ + if (attach_extra_data_) + { + extra_data_source_ = std::make_shared( + ed_path_, + ed_offset_in_file_, + ed_item_size_, + ed_repeat_, + ed_offset_in_samples_, + ed_sample_period_, + gr::io_signature::make(1, 1, item_size_)); + } + return extra_data_source_; +} + + // Subclass hooks to augment created objects, as required void FileSourceBase::create_file_source_hook() {} diff --git a/src/algorithms/signal_source/adapters/file_source_base.h b/src/algorithms/signal_source/adapters/file_source_base.h index 5933d3520..9f9737ff5 100644 --- a/src/algorithms/signal_source/adapters/file_source_base.h +++ b/src/algorithms/signal_source/adapters/file_source_base.h @@ -28,6 +28,8 @@ #include #include +#include "extra_data_source.h" + /** \addtogroup Signal_Source * \{ */ /** \addtogroup Signal_Source_adapters @@ -131,6 +133,7 @@ protected: gnss_shared_ptr valve() const; gnss_shared_ptr throttle() const; gnss_shared_ptr sink() const; + ExtraDataSource::sptr extra_data_source() const; // The methods create the various blocks, if enabled, and return access to them. The created // object is also held in this class @@ -138,6 +141,7 @@ protected: gr::blocks::throttle::sptr create_throttle(); gnss_shared_ptr create_valve(); gr::blocks::file_sink::sptr create_sink(); + ExtraDataSource::sptr create_extra_data_source(); // Subclass hooks to augment created objects, as required virtual void create_file_source_hook(); @@ -155,6 +159,7 @@ private: gr::blocks::file_source::sptr file_source_; gr::blocks::throttle::sptr throttle_; gr::blocks::file_sink::sptr sink_; + ExtraDataSource::sptr extra_data_source_; // The valve allows only the configured number of samples through, then it closes. @@ -179,6 +184,15 @@ private: bool repeat_; bool enable_throttle_control_; bool dump_; + + // Configuration for Extra Data source + bool attach_extra_data_; + std::string ed_path_; + std::size_t ed_offset_in_file_; + std::size_t ed_item_size_; + bool ed_repeat_; + std::size_t ed_offset_in_samples_; + std::size_t ed_sample_period_; }; /** \} */