From 75483e1d2d89bdc807483be38476495e57bfa0b3 Mon Sep 17 00:00:00 2001 From: Jim Melton Date: Fri, 12 Feb 2021 18:23:10 -0700 Subject: [PATCH] refactor two_bit_packed_file_signal_source (signed for DCO) --- .../adapters/file_source_base.cc | 87 +++-- .../signal_source/adapters/file_source_base.h | 9 +- .../adapters/nsr_file_signal_source.cc | 2 +- .../adapters/nsr_file_signal_source.h | 2 +- .../adapters/spir_file_signal_source.cc | 2 +- .../adapters/spir_file_signal_source.h | 2 +- .../two_bit_cpx_file_signal_source.cc | 2 +- .../adapters/two_bit_cpx_file_signal_source.h | 2 +- .../two_bit_packed_file_signal_source.cc | 347 +++++------------- .../two_bit_packed_file_signal_source.h | 82 +---- 10 files changed, 160 insertions(+), 377 deletions(-) diff --git a/src/algorithms/signal_source/adapters/file_source_base.cc b/src/algorithms/signal_source/adapters/file_source_base.cc index 0adebc616..6dfc796d5 100644 --- a/src/algorithms/signal_source/adapters/file_source_base.cc +++ b/src/algorithms/signal_source/adapters/file_source_base.cc @@ -174,39 +174,6 @@ uint64_t FileSourceBase::samples() const } -void FileSourceBase::init() -{ - create_file_source(); - - // At this point, we know that the file exists - samples_ = computeSamplesInFile(); - auto signal_duration_s = 1.0 * samples_ / sampling_frequency_; - - if (is_complex_) - { - signal_duration_s /= 2.0; - } - - DLOG(INFO) << "Total number samples to be processed= " << samples_ << " GNSS signal duration= " << signal_duration_s << " [s]"; - std::cout << "GNSS signal recorded time to be processed: " << signal_duration_s << " [s]\n"; - - - DLOG(INFO) << "File source filename " << filename_; - DLOG(INFO) << "Samples " << samples_; - DLOG(INFO) << "Sampling frequency " << sampling_frequency_; - DLOG(INFO) << "Item type " << item_type_; - DLOG(INFO) << "Item size " << item_size_; - DLOG(INFO) << "Repeat " << repeat_; - - DLOG(INFO) << "Dump " << dump_; - DLOG(INFO) << "Dump filename " << dump_filename_; - - create_throttle(); - create_valve(); - create_sink(); -} - - FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl, Concurrent_Queue* queue, std::string default_item_type) @@ -245,9 +212,42 @@ FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std: } } -std::tuple FileSourceBase::itemTypeToSize() const +void FileSourceBase::init() { - auto is_complex = false; + create_file_source(); + + // At this point, we know that the file exists + samples_ = computeSamplesInFile(); + auto signal_duration_s = 1.0 * samples_ / sampling_frequency_; + + if (is_complex()) + { + signal_duration_s /= 2.0; + } + + DLOG(INFO) << "Total number samples to be processed= " << samples_ << " GNSS signal duration= " << signal_duration_s << " [s]"; + std::cout << "GNSS signal recorded time to be processed: " << signal_duration_s << " [s]\n"; + + + DLOG(INFO) << "File source filename " << filename_; + DLOG(INFO) << "Samples " << samples_; + DLOG(INFO) << "Sampling frequency " << sampling_frequency_; + DLOG(INFO) << "Item type " << item_type_; + DLOG(INFO) << "Item size " << item_size_; + DLOG(INFO) << "Repeat " << repeat_; + + DLOG(INFO) << "Dump " << dump_; + DLOG(INFO) << "Dump filename " << dump_filename_; + + create_throttle(); + create_valve(); + create_sink(); +} + + +std::tuple FileSourceBase::itemTypeToSize() +{ + auto is_complex_t = false; auto item_size = size_t(0); if (item_type_ == "gr_complex") @@ -265,7 +265,7 @@ std::tuple FileSourceBase::itemTypeToSize() const else if (item_type_ == "ishort") { item_size = sizeof(int16_t); - is_complex = true; + is_complex_t = true; } else if (item_type_ == "byte") { @@ -274,7 +274,7 @@ std::tuple FileSourceBase::itemTypeToSize() const else if (item_type_ == "ibyte") { item_size = sizeof(int8_t); - is_complex = true; + is_complex_t = true; } else { @@ -283,7 +283,7 @@ std::tuple FileSourceBase::itemTypeToSize() const item_size = sizeof(gr_complex); } - return std::make_tuple(item_size, is_complex); + return std::make_tuple(item_size, is_complex_t); } // Default case is one decoded packet per one read sample @@ -295,9 +295,17 @@ size_t FileSourceBase::samplesToSkip() const if (seconds_to_skip_ > 0) { + // sampling_frequency is in terms of actual samples (output packets). If this source is + // compressed, there may be multiple packets per file (read) sample. First compute the + // actual number of samples to skip (function of time and sample rate) samples_to_skip = static_cast(seconds_to_skip_ * sampling_frequency_); - if (is_complex_) + // convert from sample to input items, scaling this value to input item space + // (rounding up) + samples_to_skip = std::ceil(samples_to_skip / packetsPerSample()); + + // complex inputs require two input items for one sample (arguably, packetsPerSample could be scaled by 0.5) + if (is_complex()) { samples_to_skip *= 2; } @@ -360,6 +368,7 @@ size_t FileSourceBase::source_item_size() const DLOG(INFO) << "source_item_size is " << source()->output_signature()->sizeof_stream_item(0); return source()->output_signature()->sizeof_stream_item(0); } +bool FileSourceBase::is_complex() const { return is_complex_; } // Simple accessors gnss_shared_ptr FileSourceBase::file_source() const { return file_source_; } diff --git a/src/algorithms/signal_source/adapters/file_source_base.h b/src/algorithms/signal_source/adapters/file_source_base.h index 7e7af4432..51bb44c5d 100644 --- a/src/algorithms/signal_source/adapters/file_source_base.h +++ b/src/algorithms/signal_source/adapters/file_source_base.h @@ -79,9 +79,6 @@ public: //! the number of samples in the file uint64_t samples() const; - //! perform post-construction initialization - void init(); - protected: //! Constructor // Subclasses may want to assert default item types that are appropriate to the specific file @@ -91,9 +88,12 @@ protected: Concurrent_Queue* queue, std::string default_item_type="short"); + //! perform post-construction initialization + void init(); + //! compute the item size, from the item_type(). Subclasses may constrain types that don't make // sense. The return of this method is a tuple of item_size and is_complex - virtual std::tuple itemTypeToSize() const; + virtual std::tuple itemTypeToSize(); //! the number of (possibly unpacked) samples in a (raw) file sample (default=1) virtual double packetsPerSample() const; @@ -111,6 +111,7 @@ protected: //! for complex source chains, the size of the file item may not be the same as the size of the // "source" (decoded) item. This method allows subclasses to handle these differences virtual size_t source_item_size() const; + bool is_complex() const; //! generic access to created objects gnss_shared_ptr file_source() const; diff --git a/src/algorithms/signal_source/adapters/nsr_file_signal_source.cc b/src/algorithms/signal_source/adapters/nsr_file_signal_source.cc index b957d785e..ae1cc9700 100644 --- a/src/algorithms/signal_source/adapters/nsr_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/nsr_file_signal_source.cc @@ -36,7 +36,7 @@ NsrFileSignalSource::NsrFileSignalSource(const ConfigurationInterface* configura } } -std::tuple NsrFileSignalSource::itemTypeToSize() const +std::tuple NsrFileSignalSource::itemTypeToSize() { auto is_complex = false; auto item_size = size_t(sizeof(char)); // default diff --git a/src/algorithms/signal_source/adapters/nsr_file_signal_source.h b/src/algorithms/signal_source/adapters/nsr_file_signal_source.h index 3a6455aa4..d1957565c 100644 --- a/src/algorithms/signal_source/adapters/nsr_file_signal_source.h +++ b/src/algorithms/signal_source/adapters/nsr_file_signal_source.h @@ -46,7 +46,7 @@ public: ~NsrFileSignalSource() = default; protected: - std::tuple itemTypeToSize() const override; + std::tuple itemTypeToSize() override; double packetsPerSample() const override; gnss_shared_ptr source() const override; void create_file_source_hook() override; diff --git a/src/algorithms/signal_source/adapters/spir_file_signal_source.cc b/src/algorithms/signal_source/adapters/spir_file_signal_source.cc index e9a93dedd..e60ba1b3b 100644 --- a/src/algorithms/signal_source/adapters/spir_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/spir_file_signal_source.cc @@ -36,7 +36,7 @@ SpirFileSignalSource::SpirFileSignalSource(const ConfigurationInterface* configu } } -std::tuple SpirFileSignalSource::itemTypeToSize() const +std::tuple SpirFileSignalSource::itemTypeToSize() { auto is_complex = false; auto item_size = size_t(0); diff --git a/src/algorithms/signal_source/adapters/spir_file_signal_source.h b/src/algorithms/signal_source/adapters/spir_file_signal_source.h index e8f452229..f73ee356c 100644 --- a/src/algorithms/signal_source/adapters/spir_file_signal_source.h +++ b/src/algorithms/signal_source/adapters/spir_file_signal_source.h @@ -44,7 +44,7 @@ public: ~SpirFileSignalSource() = default; protected: - std::tuple itemTypeToSize() const override; + std::tuple itemTypeToSize() override; gnss_shared_ptr source() const override; void create_file_source_hook() override; void pre_connect_hook(gr::top_block_sptr top_block) override; diff --git a/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.cc b/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.cc index 6df4af185..40ba1295f 100644 --- a/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.cc @@ -39,7 +39,7 @@ TwoBitCpxFileSignalSource::TwoBitCpxFileSignalSource( } -std::tuple TwoBitCpxFileSignalSource::itemTypeToSize() const +std::tuple TwoBitCpxFileSignalSource::itemTypeToSize() { auto is_complex = false; auto item_size = size_t(sizeof(char)); // default diff --git a/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.h b/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.h index df72176b8..2c924918f 100644 --- a/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.h +++ b/src/algorithms/signal_source/adapters/two_bit_cpx_file_signal_source.h @@ -48,7 +48,7 @@ public: ~TwoBitCpxFileSignalSource() = default; protected: - std::tuple itemTypeToSize() const override; + std::tuple itemTypeToSize() override; double packetsPerSample() const override; gnss_shared_ptr source() const override; void create_file_source_hook() override; diff --git a/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.cc b/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.cc index fffd1c773..2cecf5f10 100644 --- a/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.cc @@ -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-2021 (see AUTHORS file for a list of contributors) * SPDX-License-Identifier: GPL-3.0-or-later * * ----------------------------------------------------------------------------- @@ -18,15 +18,8 @@ #include "two_bit_packed_file_signal_source.h" #include "configuration_interface.h" -#include "gnss_sdr_flags.h" -#include "gnss_sdr_valve.h" #include #include -#include -#include -#include -#include -#include using namespace std::string_literals; @@ -36,275 +29,111 @@ TwoBitPackedFileSignalSource::TwoBitPackedFileSignalSource( unsigned int in_streams, unsigned int out_streams, Concurrent_Queue* queue) - : SignalSourceBase(configuration, role, "Two_Bit_Packed_File_Signal_Source"s) - , in_streams_(in_streams) - , out_streams_(out_streams) + : FileSourceBase(configuration, role, "Two_Bit_Packed_File_Signal_Source"s, queue, "byte"s) + , sample_type_(configuration->property(role + ".sample_type", "real"s)) // options: "real", "iq", "qi" + , big_endian_items_(configuration->property(role + ".big_endian_items", true)) + , big_endian_bytes_(configuration->property(role + ".big_endian_bytes", false)) + , reverse_interleaving_(false) { - const std::string default_filename("../data/my_capture.dat"); - const std::string default_item_type("byte"); - const std::string default_dump_filename("../data/my_capture_dump.dat"); - const std::string default_sample_type("real"); - const double default_seconds_to_skip = 0.0; - - samples_ = configuration->property(role + ".samples", static_cast(0)); - sampling_frequency_ = configuration->property(role + ".sampling_frequency", static_cast(0)); - filename_ = configuration->property(role + ".filename", default_filename); - - // override value with commandline flag, if present - if (FLAGS_signal_source != "-") - { - filename_ = FLAGS_signal_source; - } - if (FLAGS_s != "-") - { - filename_ = FLAGS_s; - } - - item_type_ = configuration->property(role + ".item_type", default_item_type); - big_endian_items_ = configuration->property(role + ".big_endian_items", true); - big_endian_bytes_ = configuration->property(role + ".big_endian_bytes", false); - sample_type_ = configuration->property(role + ".sample_type", default_sample_type); // options: "real", "iq", "qi" - repeat_ = configuration->property(role + ".repeat", false); - dump_ = configuration->property(role + ".dump", false); - dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename); - enable_throttle_control_ = configuration->property(role + ".enable_throttle_control", false); - const double seconds_to_skip = configuration->property(role + ".seconds_to_skip", default_seconds_to_skip); - int64_t bytes_to_skip = 0; - - if (item_type_ == "byte") - { - item_size_ = sizeof(char); - } - else if (item_type_ == "short") - { - // If we have shorts stored in little endian format, might as - // well read them in as bytes. - if (big_endian_items_) - { - item_size_ = sizeof(int16_t); - } - else - { - item_size_ = sizeof(char); - } - } - else - { - LOG(WARNING) << item_type_ << " unrecognized item type. Using byte."; - item_size_ = sizeof(char); - } - - reverse_interleaving_ = false; - is_complex_ = true; - if (sample_type_ == "real") - { - is_complex_ = false; - } - else if (sample_type_ == "iq") - { - is_complex_ = true; - } - else if (sample_type_ == "qi") - { - is_complex_ = true; - reverse_interleaving_ = true; - } - else - { - LOG(WARNING) << sample_type_ << " unrecognized sample type. Assuming: " - << (is_complex_ ? (reverse_interleaving_ ? "qi" : "iq") : "real"); - } - try - { - file_source_ = gr::blocks::file_source::make(item_size_, filename_.c_str(), repeat_); - - if (seconds_to_skip > 0) - { - bytes_to_skip = static_cast( - seconds_to_skip * sampling_frequency_ / 4); - if (is_complex_) - { - bytes_to_skip <<= 1; - } - file_source_->seek(bytes_to_skip, SEEK_SET); - } - - unpack_samples_ = make_unpack_2bit_samples(big_endian_bytes_, - item_size_, big_endian_items_, reverse_interleaving_); - if (is_complex_) - { - char_to_float_ = - gr::blocks::interleaved_char_to_complex::make(false); - } - else - { - char_to_float_ = - gr::blocks::char_to_float::make(); - } - } - catch (const std::exception& e) - { - std::cerr - << "The receiver was configured to work with a file signal source\n" - << "but the specified file is unreachable by GNSS-SDR.\n" - << "Please modify your configuration file\n" - << "and point SignalSource.filename to a valid raw data file. Then:\n" - << "$ gnss-sdr --config_file=/path/to/my_GNSS_SDR_configuration.conf\n" - << "Examples of configuration files available at:\n" - << GNSSSDR_INSTALL_DIR "/share/gnss-sdr/conf/\n"; - - LOG(WARNING) << "file_signal_source: Unable to open the samples file " - << filename_.c_str() << ", exiting the program."; - throw(e); - } - - DLOG(INFO) << "file_source(" << file_source_->unique_id() << ")"; - - const size_t output_item_size = (is_complex_ ? sizeof(gr_complex) : sizeof(float)); - - if (samples_ == 0) // read all file - { - /*! - * BUG workaround: The GNU Radio file source does not stop the receiver after reaching the End of File. - * A possible solution is to compute the file length in samples using file size, excluding the last 2 milliseconds, and enable always the - * valve block - */ - std::ifstream file(filename_.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - std::ifstream::pos_type size; - - if (file.is_open()) - { - size = file.tellg(); - samples_ = floor(static_cast(size) * (is_complex_ ? 2.0 : 4.0)); - LOG(INFO) << "Total samples in the file= " << samples_; // 4 samples per byte - samples_ -= bytes_to_skip; - - // Also skip the last two milliseconds: - samples_ -= ceil(0.002 * sampling_frequency_ / (is_complex_ ? 2.0 : 4.0)); - } - else - { - std::cout << "file_signal_source: Unable to open the samples file " << filename_.c_str() << '\n'; - LOG(ERROR) << "file_signal_source: Unable to open the samples file " << filename_.c_str(); - } - std::streamsize ss = std::cout.precision(); - std::cout << std::setprecision(16); - std::cout << "Processing file " << filename_ << ", which contains " << size << " [bytes]\n"; - std::cout.precision(ss); - } - - CHECK(samples_ > 0) << "File does not contain enough samples to process."; - double signal_duration_s; - signal_duration_s = static_cast(samples_) * (1 / static_cast(sampling_frequency_)); - LOG(INFO) << "Total number samples to be processed= " << samples_ << " GNSS signal duration= " << signal_duration_s << " [s]"; - std::cout << "GNSS signal recorded time to be processed: " << signal_duration_s << " [s]\n"; - - valve_ = gnss_sdr_make_valve(output_item_size, samples_, queue); - DLOG(INFO) << "valve(" << valve_->unique_id() << ")"; - - if (dump_) - { - // sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str()); - sink_ = gr::blocks::file_sink::make(output_item_size, dump_filename_.c_str()); - DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")"; - } - - if (enable_throttle_control_) - { - throttle_ = gr::blocks::throttle::make(output_item_size, sampling_frequency_); - } - DLOG(INFO) << "File source filename " << filename_; - DLOG(INFO) << "Samples " << samples_; - DLOG(INFO) << "Sampling frequency " << sampling_frequency_; - DLOG(INFO) << "Item type " << item_type_; - DLOG(INFO) << "Item size " << item_size_; - DLOG(INFO) << "Repeat " << repeat_; - DLOG(INFO) << "Dump " << dump_; - DLOG(INFO) << "Dump filename " << dump_filename_; - if (in_streams_ > 0) + if (in_streams > 0) { LOG(ERROR) << "A signal source does not have an input stream"; } - if (out_streams_ > 1) + if (out_streams > 1) { LOG(ERROR) << "This implementation only supports one output stream"; } } -void TwoBitPackedFileSignalSource::connect(gr::top_block_sptr top_block) +std::tuple TwoBitPackedFileSignalSource::itemTypeToSize() { - gr::basic_block_sptr left_block = file_source_; - gr::basic_block_sptr right_block = unpack_samples_; + auto is_complex_t = false; + auto item_size = size_t(sizeof(char)); // default - top_block->connect(file_source_, 0, unpack_samples_, 0); - left_block = right_block; + if (item_type() == "byte") + { + item_size = sizeof(char); + } + else if (item_type() == "short") + { + // If we have shorts stored in little endian format, might as + // well read them in as bytes. + // TODO: this seems to make assumptions about the endianness of this machine + if (big_endian_items_) + { + item_size = sizeof(int16_t); + } + else + { + // how can this be right? the number of samples is computed based on this value + item_size = sizeof(char); + } + } + else + { + LOG(WARNING) << item_type() << " unrecognized item type. Using byte."; + } + // the complex-ness of the input is inferred from the output type + if (sample_type_ == "real") + { + is_complex_t = false; + } + else if (sample_type_ == "iq") + { + is_complex_t = true; + } + else if (sample_type_ == "qi") + { + is_complex_t = true; + reverse_interleaving_ = true; + } + else + { + LOG(WARNING) << sample_type_ << " unrecognized sample type. Assuming: " + << (is_complex_t ? (reverse_interleaving_ ? "qi" : "iq") : "real"); + } + + + return std::make_tuple(item_size, is_complex_t); +} + +// Each sample is 2 bits; if the item_type() is char, then the size is 8/2 = 4 packets per sample +// If the item_type() is short, then the size is 16/2 = 8 packets per sample +double TwoBitPackedFileSignalSource::packetsPerSample() const { return item_size() / 2.0; } +gnss_shared_ptr TwoBitPackedFileSignalSource::source() const { return char_to_float_; } + +void TwoBitPackedFileSignalSource::create_file_source_hook() +{ + unpack_samples_ = make_unpack_2bit_samples(big_endian_bytes_, item_size(), + big_endian_items_, reverse_interleaving_); + DLOG(INFO) << "unpack_byte_2bit_samples(" << unpack_samples_->unique_id() << ")"; + + if (is_complex()) + { + char_to_float_ = gr::blocks::interleaved_char_to_complex::make(false); + DLOG(INFO) << "interleaved_char_to_complex(" << char_to_float_->unique_id() << ")"; + } + else + { + char_to_float_ = gr::blocks::char_to_float::make(); + DLOG(INFO) << "char_to_float(" << char_to_float_->unique_id() << ")"; + } +} + +void TwoBitPackedFileSignalSource::pre_connect_hook(gr::top_block_sptr top_block) +{ + top_block->connect(file_source(), 0, unpack_samples_, 0); DLOG(INFO) << "connected file source to unpack samples"; - right_block = char_to_float_; - top_block->connect(left_block, 0, right_block, 0); - left_block = right_block; + top_block->connect(unpack_samples_, 0, char_to_float_, 0); DLOG(INFO) << "connected unpack samples to char to float"; - - if (enable_throttle_control_) - { - right_block = throttle_; - top_block->connect(left_block, 0, right_block, 0); - left_block = right_block; - DLOG(INFO) << " connected to throttle"; - } - - top_block->connect(left_block, 0, valve_, 0); - DLOG(INFO) << "connected to valve"; - if (dump_) - { - top_block->connect(valve_, 0, sink_, 0); - DLOG(INFO) << "connected valve to file sink"; - } } - -void TwoBitPackedFileSignalSource::disconnect(gr::top_block_sptr top_block) +void TwoBitPackedFileSignalSource::pre_disconnect_hook(gr::top_block_sptr top_block) { - gr::basic_block_sptr left_block = file_source_; - gr::basic_block_sptr right_block = unpack_samples_; - - top_block->disconnect(file_source_, 0, unpack_samples_, 0); - left_block = right_block; - + top_block->disconnect(file_source(), 0, unpack_samples_, 0); DLOG(INFO) << "disconnected file source to unpack samples"; - right_block = char_to_float_; - top_block->disconnect(left_block, 0, right_block, 0); - left_block = right_block; + top_block->disconnect(unpack_samples_, 0, char_to_float_, 0); DLOG(INFO) << "disconnected unpack samples to char to float"; - - if (enable_throttle_control_) - { - right_block = throttle_; - top_block->disconnect(left_block, 0, right_block, 0); - left_block = right_block; - DLOG(INFO) << " disconnected to throttle"; - } - - top_block->disconnect(left_block, 0, valve_, 0); - DLOG(INFO) << "disconnected to valve"; - if (dump_) - { - top_block->disconnect(valve_, 0, sink_, 0); - DLOG(INFO) << "disconnected valve to file sink"; - } -} - - -gr::basic_block_sptr TwoBitPackedFileSignalSource::get_left_block() -{ - LOG(WARNING) << "Left block of a signal source should not be retrieved"; - // return gr_block_sptr(); - return gr::blocks::file_source::sptr(); -} - - -gr::basic_block_sptr TwoBitPackedFileSignalSource::get_right_block() -{ - return valve_; } diff --git a/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.h b/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.h index 672fc99f1..d4f53da62 100644 --- a/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.h +++ b/src/algorithms/signal_source/adapters/two_bit_packed_file_signal_source.h @@ -21,18 +21,9 @@ #ifndef GNSS_SDR_TWO_BIT_PACKED_FILE_SIGNAL_SOURCE_H #define GNSS_SDR_TWO_BIT_PACKED_FILE_SIGNAL_SOURCE_H -#include "signal_source_base.h" - -#include "concurrent_queue.h" +#include "file_source_base.h" #include "unpack_2bit_samples.h" -#include -#include #include -#include -#include -#include -#include -#include /** \addtogroup Signal_Source @@ -47,7 +38,7 @@ class ConfigurationInterface; * \brief Class that reads signals samples from a file * and adapts it to a SignalSourceInterface */ -class TwoBitPackedFileSignalSource : public SignalSourceBase +class TwoBitPackedFileSignalSource : public FileSourceBase { public: TwoBitPackedFileSignalSource(const ConfigurationInterface* configuration, const std::string& role, @@ -56,41 +47,7 @@ public: ~TwoBitPackedFileSignalSource() = default; - inline size_t item_size() override - { - return item_size_; - } - - 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; - - inline std::string filename() const - { - return filename_; - } - - inline std::string item_type() const - { - return item_type_; - } - - inline bool repeat() const - { - return repeat_; - } - - inline int64_t sampling_frequency() const - { - return sampling_frequency_; - } - - inline uint64_t samples() const - { - return samples_; - } - +private: inline bool big_endian_items() const { return big_endian_items_; @@ -101,40 +58,27 @@ public: return big_endian_bytes_; } - inline bool is_complex() const - { - return is_complex_; - } inline bool reverse_interleaving() const { return reverse_interleaving_; } +protected: + std::tuple itemTypeToSize() override; + double packetsPerSample() const override; + gnss_shared_ptr source() const override; + void create_file_source_hook() override; + void pre_connect_hook(gr::top_block_sptr top_block) override; + void pre_disconnect_hook(gr::top_block_sptr top_block) override; + private: - gr::blocks::file_source::sptr file_source_; - unpack_2bit_samples_sptr unpack_samples_; - gr::basic_block_sptr char_to_float_; - gnss_shared_ptr valve_; - gr::blocks::file_sink::sptr sink_; - gr::blocks::throttle::sptr throttle_; - std::string filename_; - std::string item_type_; - std::string dump_filename_; std::string sample_type_; - uint64_t samples_; - int64_t sampling_frequency_; - size_t item_size_; - unsigned int in_streams_; - unsigned int out_streams_; bool big_endian_items_; bool big_endian_bytes_; - bool is_complex_; bool reverse_interleaving_; - bool repeat_; - bool dump_; - // Throttle control - bool enable_throttle_control_; + unpack_2bit_samples_sptr unpack_samples_; + gnss_shared_ptr char_to_float_; };