mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-11-10 20:23:09 +00:00
Added experimental FileTimestampSignalSource to generate timestamp information using stream tags
This commit is contained in:
@@ -25,6 +25,7 @@ set(SIGNAL_SOURCE_LIB_SOURCES
|
||||
rtl_tcp_commands.cc
|
||||
rtl_tcp_dongle_info.cc
|
||||
gnss_sdr_valve.cc
|
||||
gnss_sdr_timestamp.cc
|
||||
${OPT_SIGNAL_SOURCE_LIB_SOURCES}
|
||||
)
|
||||
|
||||
@@ -68,6 +69,7 @@ target_include_directories(signal_source_libs
|
||||
PUBLIC
|
||||
${CMAKE_SOURCE_DIR}/src/core/receiver
|
||||
${CMAKE_SOURCE_DIR}/src/core/interfaces
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/libs
|
||||
)
|
||||
|
||||
if(GNURADIO_USES_STD_POINTERS)
|
||||
|
||||
114
src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc
Normal file
114
src/algorithms/signal_source/libs/gnss_sdr_timestamp.cc
Normal file
@@ -0,0 +1,114 @@
|
||||
/*!
|
||||
* \file gnss_sdr_timestamp.h
|
||||
* \brief GNURadio block that adds to sample stream timestamp metadata information stored on a sepparated file
|
||||
* \author Javier Arribas, 2021. jarribas(at)cttc.es
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "gnss_sdr_timestamp.h"
|
||||
#include "command_event.h"
|
||||
#include <glog/logging.h> // for LOG
|
||||
#include <gnuradio/io_signature.h> // for io_signature
|
||||
#include <pmt/pmt.h> // for make_any
|
||||
#include <pmt/pmt_sugar.h> // for mp
|
||||
#include <algorithm> // for min
|
||||
#include <cmath>
|
||||
#include <cstring> // for memcpy
|
||||
|
||||
Gnss_Sdr_Timestamp::Gnss_Sdr_Timestamp(size_t sizeof_stream_item,
|
||||
std::string timestamp_file) : gr::sync_block("Timestamp",
|
||||
gr::io_signature::make(1, 20, sizeof_stream_item),
|
||||
gr::io_signature::make(1, 20, sizeof_stream_item)),
|
||||
d_timefile(timestamp_file)
|
||||
{
|
||||
get_next_timetag = true;
|
||||
next_timetag_samplecount = 0;
|
||||
}
|
||||
|
||||
|
||||
gnss_shared_ptr<Gnss_Sdr_Timestamp> gnss_sdr_make_Timestamp(size_t sizeof_stream_item, std::string timestamp_file)
|
||||
{
|
||||
gnss_shared_ptr<Gnss_Sdr_Timestamp> Timestamp_(new Gnss_Sdr_Timestamp(sizeof_stream_item, timestamp_file));
|
||||
return Timestamp_;
|
||||
}
|
||||
|
||||
bool Gnss_Sdr_Timestamp::read_next_timetag()
|
||||
{
|
||||
d_timefilestream.read(reinterpret_cast<char*>(&next_timetag_samplecount), sizeof(uint64_t));
|
||||
if (!d_timefilestream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
d_timefilestream.read(reinterpret_cast<char*>(&next_timetag.week), sizeof(int32_t));
|
||||
if (!d_timefilestream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
d_timefilestream.read(reinterpret_cast<char*>(&next_timetag.tow_ms), sizeof(int32_t));
|
||||
if (!d_timefilestream)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Gnss_Sdr_Timestamp::start()
|
||||
{
|
||||
d_timefilestream.open(d_timefile, std::ios::in | std::ios::binary);
|
||||
|
||||
if (d_timefilestream.is_open() == false)
|
||||
{
|
||||
std::cout << "ERROR: Could not open timestamp file: " << d_timefile << "\n";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Gnss_Sdr_Timestamp::uint64diff(uint64_t first, uint64_t second)
|
||||
{
|
||||
uint64_t abs_diff = (first > second) ? (first - second) : (second - first);
|
||||
assert(abs_diff <= INT64_MAX);
|
||||
return (first > second) ? (int64_t)abs_diff : -(int64_t)abs_diff;
|
||||
}
|
||||
|
||||
|
||||
int Gnss_Sdr_Timestamp::work(int noutput_items,
|
||||
gr_vector_const_void_star& input_items,
|
||||
gr_vector_void_star& output_items)
|
||||
{
|
||||
// multichannel support
|
||||
if (get_next_timetag == true)
|
||||
{
|
||||
if (read_next_timetag() == false)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
get_next_timetag = false;
|
||||
}
|
||||
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));
|
||||
int64_t diff_samplecount = uint64diff(nitems_read(ch), next_timetag_samplecount);
|
||||
if (diff_samplecount > 0 and diff_samplecount < noutput_items)
|
||||
{
|
||||
add_item_tag(ch, this->nitems_written(0) + diff_samplecount, pmt::mp("timetag"), pmt::make_any(next_timetag));
|
||||
get_next_timetag = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return noutput_items;
|
||||
}
|
||||
72
src/algorithms/signal_source/libs/gnss_sdr_timestamp.h
Normal file
72
src/algorithms/signal_source/libs/gnss_sdr_timestamp.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*!
|
||||
* \file gnss_sdr_timestamp.h
|
||||
* \brief GNURadio block that adds to sample stream timestamp metadata information stored on a sepparated file
|
||||
* \author Javier Arribas, 2021. jarribas(at)cttc.es
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GNSS_SDR_GNSS_SDR_TIMESTAMP_H
|
||||
#define GNSS_SDR_GNSS_SDR_TIMESTAMP_H
|
||||
|
||||
#include "gnss_block_interface.h"
|
||||
#include "gnss_time.h"
|
||||
#include <gnuradio/sync_block.h> // for sync_block
|
||||
#include <gnuradio/types.h> // for gr_vector_const_void_star
|
||||
#include <pmt/pmt.h>
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
/** \addtogroup Signal_Source
|
||||
* \{ */
|
||||
/** \addtogroup Signal_Source_libs
|
||||
* \{ */
|
||||
|
||||
|
||||
class Gnss_Sdr_Timestamp;
|
||||
|
||||
gnss_shared_ptr<Gnss_Sdr_Timestamp> gnss_sdr_make_Timestamp(
|
||||
size_t sizeof_stream_item,
|
||||
std::string timestamp_file);
|
||||
|
||||
|
||||
class Gnss_Sdr_Timestamp : public gr::sync_block
|
||||
{
|
||||
public:
|
||||
int work(int noutput_items,
|
||||
gr_vector_const_void_star& input_items,
|
||||
gr_vector_void_star& output_items);
|
||||
bool start();
|
||||
|
||||
private:
|
||||
friend gnss_shared_ptr<Gnss_Sdr_Timestamp> gnss_sdr_make_Timestamp(
|
||||
size_t sizeof_stream_item,
|
||||
std::string timestamp_file);
|
||||
|
||||
Gnss_Sdr_Timestamp(size_t sizeof_stream_item,
|
||||
std::string timestamp_file);
|
||||
|
||||
int64_t uint64diff(uint64_t first, uint64_t second);
|
||||
bool read_next_timetag();
|
||||
std::string d_timefile;
|
||||
std::fstream d_timefilestream;
|
||||
GnssTime next_timetag;
|
||||
uint64_t next_timetag_samplecount;
|
||||
bool get_next_timetag;
|
||||
};
|
||||
|
||||
|
||||
/** \} */
|
||||
/** \} */
|
||||
#endif // GNSS_SDR_GNSS_SDR_TIMESTAMP_H
|
||||
Reference in New Issue
Block a user