diff --git a/src/algorithms/signal_source/adapters/file_timestamp_signal_source.cc b/src/algorithms/signal_source/adapters/file_timestamp_signal_source.cc index 1cc29e40a..32d27ac19 100644 --- a/src/algorithms/signal_source/adapters/file_timestamp_signal_source.cc +++ b/src/algorithms/signal_source/adapters/file_timestamp_signal_source.cc @@ -16,7 +16,6 @@ #include "file_timestamp_signal_source.h" #include "gnss_sdr_flags.h" #include "gnss_sdr_string_literals.h" -#include "gnss_sdr_timestamp.h" #include #include @@ -51,10 +50,22 @@ gnss_shared_ptr FileTimestampSignalSource::source() const { return ti void FileTimestampSignalSource::create_file_source_hook() { - timestamp_block_ = gnss_sdr_make_Timestamp( - std::get<0>(itemTypeToSize()), - timestamp_file_, - timestamp_clock_offset_ms_); + if (is_complex() == false) + { + timestamp_block_ = gnss_sdr_make_Timestamp( + std::get<0>(itemTypeToSize()), + timestamp_file_, + timestamp_clock_offset_ms_, + source_item_size() * 2); + } + else + { + timestamp_block_ = gnss_sdr_make_Timestamp( + std::get<0>(itemTypeToSize()), + timestamp_file_, + timestamp_clock_offset_ms_, + source_item_size()); + } DLOG(INFO) << "timestamp_block_(" << timestamp_block_->unique_id() << ")"; } diff --git a/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.cc b/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.cc index 0fc521fe9..c22ababb3 100644 --- a/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.cc +++ b/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.cc @@ -17,6 +17,7 @@ #include "four_bit_cpx_file_signal_source.h" #include "configuration_interface.h" +#include "gnss_sdr_flags.h" #include "gnss_sdr_string_literals.h" #include @@ -28,7 +29,9 @@ FourBitCpxFileSignalSource::FourBitCpxFileSignalSource( const std::string& role, unsigned int in_streams, unsigned int out_streams, Concurrent_Queue* queue) - : FileSourceBase(configuration, role, "Four_Bit_Cpx_File_Signal_Source"s, queue, "byte"s) + : FileSourceBase(configuration, role, "Four_Bit_Cpx_File_Signal_Source"s, queue, "byte"s), + timestamp_file_(configuration->property(role + ".timestamp_filename"s, ""s)), + timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)) { sample_type_ = configuration->property(role + ".sample_type", "iq"s); // the complex-ness of the input is inferred from the output type @@ -54,6 +57,12 @@ FourBitCpxFileSignalSource::FourBitCpxFileSignalSource( { LOG(ERROR) << "This implementation only supports one output stream"; } + + // override value with commandline flag, if present + if (FLAGS_timestamp_source != "-") + { + timestamp_file_ = FLAGS_timestamp_source; + } } @@ -76,7 +85,7 @@ std::tuple FourBitCpxFileSignalSource::itemTypeToSize() // 1 byte -> 1 complex samples double FourBitCpxFileSignalSource::packetsPerSample() const { return 1.0; } -gnss_shared_ptr FourBitCpxFileSignalSource::source() const { return inter_shorts_to_cpx_; } +gnss_shared_ptr FourBitCpxFileSignalSource::source() const { return timestamp_block_; } void FourBitCpxFileSignalSource::create_file_source_hook() @@ -85,6 +94,14 @@ void FourBitCpxFileSignalSource::create_file_source_hook() DLOG(INFO) << "unpack_byte_2bit_cpx_samples(" << unpack_byte_->unique_id() << ")"; inter_shorts_to_cpx_ = gr::blocks::interleaved_short_to_complex::make(false, reverse_interleaving_); // I/Q swap enabled DLOG(INFO) << "interleaved_short_to_complex(" << inter_shorts_to_cpx_->unique_id() << ")"; + if (timestamp_file_.size() > 1) + { + timestamp_block_ = gnss_sdr_make_Timestamp(sizeof(gr_complex), + timestamp_file_, + timestamp_clock_offset_ms_, + 1); + DLOG(INFO) << "timestamp_block_(" << timestamp_block_->unique_id() << ")"; + } } void FourBitCpxFileSignalSource::pre_connect_hook(gr::top_block_sptr top_block) @@ -92,10 +109,20 @@ void FourBitCpxFileSignalSource::pre_connect_hook(gr::top_block_sptr top_block) top_block->connect(file_source(), 0, unpack_byte_, 0); top_block->connect(unpack_byte_, 0, inter_shorts_to_cpx_, 0); DLOG(INFO) << "connected file_source to unpacker"; + if (timestamp_file_.size() > 1) + { + top_block->connect(inter_shorts_to_cpx_, 0, timestamp_block_, 0); + DLOG(INFO) << "connected file_source to timestamp_block_"; + } } void FourBitCpxFileSignalSource::pre_disconnect_hook(gr::top_block_sptr top_block) { + if (timestamp_file_.size() > 1) + { + top_block->disconnect(inter_shorts_to_cpx_, 0, timestamp_block_, 0); + DLOG(INFO) << "disconnected file_source from timestamp_block_"; + } top_block->disconnect(file_source(), 0, unpack_byte_, 0); top_block->disconnect(unpack_byte_, 0, inter_shorts_to_cpx_, 0); DLOG(INFO) << "disconnected file_source from unpacker"; diff --git a/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.h b/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.h index ac9b5c3fb..a36776afb 100644 --- a/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.h +++ b/src/algorithms/signal_source/adapters/four_bit_cpx_file_signal_source.h @@ -21,6 +21,7 @@ #define GNSS_SDR_FOUR_BIT_CPX_FILE_SIGNAL_SOURCE_H #include "file_source_base.h" +#include "gnss_sdr_timestamp.h" #include "unpack_byte_4bit_samples.h" #include #include @@ -63,6 +64,10 @@ private: gr::blocks::interleaved_short_to_complex::sptr inter_shorts_to_cpx_; std::string sample_type_; bool reverse_interleaving_; + + gnss_shared_ptr timestamp_block_; + std::string timestamp_file_; + double timestamp_clock_offset_ms_; }; diff --git a/src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc b/src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc index 9ac458c04..857acf1e7 100644 --- a/src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc +++ b/src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc @@ -28,22 +28,23 @@ Gnss_Sdr_Timestamp::Gnss_Sdr_Timestamp(size_t sizeof_stream_item, - std::string timestamp_file, double clock_offset_ms) + std::string timestamp_file, double clock_offset_ms, int items_to_samples) : gr::sync_block("Timestamp", gr::io_signature::make(1, 20, sizeof_stream_item), gr::io_signature::make(1, 20, sizeof_stream_item)), d_timefile(std::move(timestamp_file)), d_clock_offset_ms(clock_offset_ms), d_fraction_ms_offset(modf(d_clock_offset_ms, &d_integer_ms_offset)), // optional clockoffset parameter to convert UTC timestamps to GPS time in some receiver's configuration + d_items_to_samples(items_to_samples), d_next_timetag_samplecount(0), d_get_next_timetag(true) { } -gnss_shared_ptr gnss_sdr_make_Timestamp(size_t sizeof_stream_item, std::string timestamp_file, double clock_offset_ms) +gnss_shared_ptr gnss_sdr_make_Timestamp(size_t sizeof_stream_item, std::string timestamp_file, double clock_offset_ms, int items_to_samples) { - gnss_shared_ptr Timestamp_(new Gnss_Sdr_Timestamp(sizeof_stream_item, std::move(timestamp_file), clock_offset_ms)); + gnss_shared_ptr Timestamp_(new Gnss_Sdr_Timestamp(sizeof_stream_item, std::move(timestamp_file), clock_offset_ms, items_to_samples)); return Timestamp_; } @@ -110,8 +111,7 @@ int Gnss_Sdr_Timestamp::work(int noutput_items, for (size_t ch = 0; ch < output_items.size(); ch++) { std::memcpy(output_items[ch], input_items[ch], noutput_items * input_signature()->sizeof_stream_item(ch)); - uint64_t bytes_to_samples = 2; // todo: improve this.. hardcoded 2 bytes -> 1 complex sample! - int64_t diff_samplecount = uint64diff(this->nitems_written(ch), d_next_timetag_samplecount * bytes_to_samples); + int64_t diff_samplecount = uint64diff(this->nitems_written(ch), d_next_timetag_samplecount * d_items_to_samples); // std::cout << "diff_samplecount: " << diff_samplecount << ", noutput_items: " << noutput_items << "\n"; if (diff_samplecount <= noutput_items and std::labs(diff_samplecount) <= noutput_items) { diff --git a/src/algorithms/signal_source/libs/gnss_sdr_timestamp.h b/src/algorithms/signal_source/libs/gnss_sdr_timestamp.h index 6a7f762e2..11716ca82 100644 --- a/src/algorithms/signal_source/libs/gnss_sdr_timestamp.h +++ b/src/algorithms/signal_source/libs/gnss_sdr_timestamp.h @@ -39,7 +39,8 @@ class Gnss_Sdr_Timestamp; gnss_shared_ptr gnss_sdr_make_Timestamp( size_t sizeof_stream_item, std::string timestamp_file, - double clock_offset_ms); + double clock_offset_ms, + int items_to_samples); class Gnss_Sdr_Timestamp : public gr::sync_block @@ -54,11 +55,13 @@ private: friend gnss_shared_ptr gnss_sdr_make_Timestamp( size_t sizeof_stream_item, std::string timestamp_file, - double clock_offset_ms); + double clock_offset_ms, + int items_to_samples); Gnss_Sdr_Timestamp(size_t sizeof_stream_item, std::string timestamp_file, - double clock_offset_ms); + double clock_offset_ms, + int items_to_samples); int64_t uint64diff(uint64_t first, uint64_t second); bool read_next_timetag(); @@ -69,6 +72,7 @@ private: double d_fraction_ms_offset; double d_integer_ms_offset; uint64_t d_next_timetag_samplecount; + int d_items_to_samples; bool d_get_next_timetag; };