mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-14 20:20:35 +00:00
first subclass of file_source_base
Refactored the base implementation to add appropriate virtual hooks so subclasses can easily extend without duplicating a lot of code.
This commit is contained in:
parent
6d4ddc16e7
commit
1854cec106
@ -10,21 +10,14 @@
|
|||||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||||
* This file is part of GNSS-SDR.
|
* 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
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "file_signal_source.h"
|
#include "file_signal_source.h"
|
||||||
#include "configuration_interface.h"
|
|
||||||
#include "gnss_sdr_flags.h"
|
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <exception>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream> // for std::cerr
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
|
@ -23,15 +23,6 @@
|
|||||||
|
|
||||||
#include "file_source_base.h"
|
#include "file_source_base.h"
|
||||||
|
|
||||||
#include "concurrent_queue.h"
|
|
||||||
#include <gnuradio/blocks/file_sink.h>
|
|
||||||
#include <gnuradio/blocks/file_source.h>
|
|
||||||
#include <gnuradio/blocks/throttle.h>
|
|
||||||
#include <gnuradio/hier_block2.h>
|
|
||||||
#include <pmt/pmt.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/** \addtogroup Signal_Source Signal Source
|
/** \addtogroup Signal_Source Signal Source
|
||||||
* Classes for Signal Source management.
|
* Classes for Signal Source management.
|
||||||
* \{ */
|
* \{ */
|
||||||
|
@ -15,128 +15,117 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "file_source_base.h"
|
#include "file_source_base.h"
|
||||||
|
|
||||||
#include "configuration_interface.h"
|
#include "configuration_interface.h"
|
||||||
#include "gnss_sdr_flags.h"
|
|
||||||
#include "gnss_sdr_filesystem.h"
|
#include "gnss_sdr_filesystem.h"
|
||||||
|
#include "gnss_sdr_flags.h"
|
||||||
#include "gnss_sdr_valve.h"
|
#include "gnss_sdr_valve.h"
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
|
#include <cmath> // ceil, floor
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cmath> // ceil, floor
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
void FileSourceBase::connect(gr::top_block_sptr top_block)
|
void FileSourceBase::connect(gr::top_block_sptr top_block)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
pre_connect_hook(top_block);
|
||||||
|
|
||||||
auto source = gr::basic_block_sptr();
|
auto input = gr::basic_block_sptr();
|
||||||
auto output = gr::basic_block_sptr();
|
auto output = gr::basic_block_sptr();
|
||||||
|
|
||||||
// THROTTLE
|
// THROTTLE
|
||||||
if (enable_throttle_control_)
|
if (throttle())
|
||||||
{
|
{
|
||||||
// if we are throttling...
|
// if we are throttling...
|
||||||
throttle_ = gr::blocks::throttle::make(item_size_, sampling_frequency_);
|
top_block->connect(source(), 0, throttle(), 0);
|
||||||
|
|
||||||
top_block->connect(file_source_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to throttle";
|
DLOG(INFO) << "connected file source to throttle";
|
||||||
|
|
||||||
source = throttle_;
|
input = throttle();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no throttle; let 'er rip
|
// no throttle; let 'er rip
|
||||||
source = file_source_;
|
input = source();
|
||||||
}
|
}
|
||||||
|
|
||||||
// VALVE
|
// VALVE
|
||||||
if (samples_ > 0)
|
if (valve())
|
||||||
{
|
{
|
||||||
// if a number of samples is specified, honor it by creating a valve
|
top_block->connect(input, 0, valve(), 0);
|
||||||
// In practice, this is always true
|
|
||||||
valve_ = gnss_sdr_make_valve(item_size_, samples_, queue_);
|
|
||||||
DLOG(INFO) << "valve(" << valve_->unique_id() << ")";
|
|
||||||
|
|
||||||
top_block->connect(source, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "connected source to valve";
|
DLOG(INFO) << "connected source to valve";
|
||||||
|
|
||||||
output = valve_;
|
output = valve();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: dumping a file source is unlikely, but should this be the raw file source or the
|
// TODO: dumping a file source is unlikely, but should this be the raw file source or the
|
||||||
// throttle if there is one? I'm leaning towards "output=source"
|
// throttle if there is one? I'm leaning towards "output=input"
|
||||||
output = file_source_;
|
output = source(); // output = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DUMP
|
// DUMP
|
||||||
if (dump_)
|
if (sink())
|
||||||
{
|
{
|
||||||
sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str());
|
top_block->connect(output, 0, sink(), 0);
|
||||||
DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")";
|
|
||||||
|
|
||||||
top_block->connect(output, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "connected output to file sink";
|
DLOG(INFO) << "connected output to file sink";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post_connect_hook(top_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileSourceBase::disconnect(gr::top_block_sptr top_block)
|
void FileSourceBase::disconnect(gr::top_block_sptr top_block)
|
||||||
{
|
{
|
||||||
if (samples_ > 0)
|
auto input = gr::basic_block_sptr();
|
||||||
|
auto output = gr::basic_block_sptr();
|
||||||
|
|
||||||
|
pre_disconnect_hook(top_block);
|
||||||
|
|
||||||
|
// THROTTLE
|
||||||
|
if (throttle())
|
||||||
{
|
{
|
||||||
if (enable_throttle_control_ == true)
|
// if we are throttling...
|
||||||
{
|
top_block->disconnect(source(), 0, throttle(), 0);
|
||||||
top_block->disconnect(file_source_, 0, throttle_, 0);
|
DLOG(INFO) << "disconnected file source from throttle";
|
||||||
DLOG(INFO) << "disconnected file source to throttle";
|
|
||||||
top_block->disconnect(throttle_, 0, valve_, 0);
|
input = throttle();
|
||||||
DLOG(INFO) << "disconnected throttle to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (enable_throttle_control_ == true)
|
// no throttle; let 'er rip
|
||||||
{
|
input = source();
|
||||||
top_block->disconnect(file_source_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to throttle";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VALVE
|
||||||
|
if (valve())
|
||||||
|
{
|
||||||
|
top_block->disconnect(input, 0, valve(), 0);
|
||||||
|
DLOG(INFO) << "disconnected source to valve";
|
||||||
|
|
||||||
|
output = valve();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: dumping a file source is unlikely, but should this be the raw file source or the
|
||||||
|
// throttle if there is one? I'm leaning towards "output=input"
|
||||||
|
output = source(); // output = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
// DUMP
|
||||||
|
if (sink())
|
||||||
|
{
|
||||||
|
top_block->disconnect(output, 0, sink(), 0);
|
||||||
|
DLOG(INFO) << "disconnected output to file sink";
|
||||||
|
}
|
||||||
|
|
||||||
|
post_disconnect_hook(top_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gr::basic_block_sptr FileSourceBase::get_left_block()
|
gr::basic_block_sptr FileSourceBase::get_left_block()
|
||||||
{
|
{
|
||||||
// TODO: is this right? Shouldn't the left block be a nullptr?
|
// TODO: is this right? Shouldn't the left block be a nullptr?
|
||||||
LOG(WARNING) << "Left block of a signal source should not be retrieved";
|
LOG(WARNING) << "Left block of a signal source should not be retrieved";
|
||||||
return gr::blocks::file_source::sptr();
|
return gr::blocks::file_source::sptr();
|
||||||
}
|
}
|
||||||
@ -146,7 +135,7 @@ gr::basic_block_sptr FileSourceBase::get_right_block()
|
|||||||
{
|
{
|
||||||
if (valve_) return valve_;
|
if (valve_) return valve_;
|
||||||
if (throttle_) return throttle_;
|
if (throttle_) return throttle_;
|
||||||
return file_source_;
|
return source();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -187,47 +176,7 @@ uint64_t FileSourceBase::samples() const
|
|||||||
|
|
||||||
void FileSourceBase::init()
|
void FileSourceBase::init()
|
||||||
{
|
{
|
||||||
auto item_tuple = itemTypeToSize();
|
create_file_source();
|
||||||
item_size_ = std::get<0>(item_tuple);
|
|
||||||
is_complex_ = std::get<1>(item_tuple);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// TODO: why are we manually seeking, instead of passing the samples_to_skip to the file_source factory?
|
|
||||||
auto samples_to_skip = samplesToSkip();
|
|
||||||
|
|
||||||
file_source_ = gr::blocks::file_source::make(item_size(), filename().data(), repeat());
|
|
||||||
|
|
||||||
if (samples_to_skip > 0)
|
|
||||||
{
|
|
||||||
LOG(INFO) << "Skipping " << samples_to_skip << " samples of the input file";
|
|
||||||
if (not file_source_->seek(samples_to_skip, SEEK_SET))
|
|
||||||
{
|
|
||||||
LOG(ERROR) << "Error skipping bytes!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
std::cerr
|
|
||||||
<< "The receiver was configured to work with a file-based signal source\n"
|
|
||||||
<< "but the specified file is unreachable by GNSS-SDR.\n"
|
|
||||||
<< "[" << filename() << "]\n"
|
|
||||||
<< "\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"
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
LOG(ERROR) << "file_signal_source: Unable to open the samples file "
|
|
||||||
<< filename() << ", exiting the program.";
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG(INFO) << implementation() << "(" << file_source_->unique_id() << ")";
|
|
||||||
|
|
||||||
// At this point, we know that the file exists
|
// At this point, we know that the file exists
|
||||||
samples_ = computeSamplesInFile();
|
samples_ = computeSamplesInFile();
|
||||||
auto signal_duration_s = 1.0 * samples_ / sampling_frequency_;
|
auto signal_duration_s = 1.0 * samples_ / sampling_frequency_;
|
||||||
@ -249,17 +198,21 @@ void FileSourceBase::init()
|
|||||||
DLOG(INFO) << "Repeat " << repeat_;
|
DLOG(INFO) << "Repeat " << repeat_;
|
||||||
DLOG(INFO) << "Dump " << dump_;
|
DLOG(INFO) << "Dump " << dump_;
|
||||||
DLOG(INFO) << "Dump filename " << dump_filename_;
|
DLOG(INFO) << "Dump filename " << dump_filename_;
|
||||||
|
|
||||||
|
create_throttle();
|
||||||
|
create_valve();
|
||||||
|
create_sink();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl,
|
FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl,
|
||||||
Concurrent_Queue<pmt::pmt_t>* queue)
|
Concurrent_Queue<pmt::pmt_t>* queue)
|
||||||
: SignalSourceBase(configuration, role, impl)
|
: SignalSourceBase(configuration, role, impl)
|
||||||
, filename_(configuration->property(role + ".filename"s, "../data/example_capture.dat"s))
|
, filename_(configuration->property(role + ".filename"s, "../data/example_capture.dat"s))
|
||||||
, file_source_()
|
, file_source_()
|
||||||
|
|
||||||
, item_type_(configuration->property(role + ".item_type"s, "short"s))
|
, item_type_(configuration->property(role + ".item_type"s, "short"s))
|
||||||
, item_size_(0) // invalid
|
, item_size_(0) // invalid
|
||||||
, is_complex_(false)
|
, is_complex_(false)
|
||||||
|
|
||||||
, header_size_(configuration->property(role + ".header_size"s, 0UL))
|
, header_size_(configuration->property(role + ".header_size"s, 0UL))
|
||||||
@ -287,7 +240,6 @@ FileSourceBase::FileSourceBase(ConfigurationInterface const* configuration, std:
|
|||||||
{
|
{
|
||||||
filename_ = FLAGS_s;
|
filename_ = FLAGS_s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<size_t, bool> FileSourceBase::itemTypeToSize() const
|
std::tuple<size_t, bool> FileSourceBase::itemTypeToSize() const
|
||||||
@ -381,10 +333,129 @@ size_t FileSourceBase::computeSamplesInFile() const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// this will terminate the program
|
// this will terminate the program
|
||||||
LOG(FATAL) << "Skipping " << to_skip << " samples from the front and truncating 2ms (" << tail << " samples)\n"
|
LOG(FATAL) << "Skipping " << to_skip << " samples from the front and truncating 2ms (" << tail << " samples)\n"
|
||||||
<< "is greater than the number of samples in the file (" << n_samples << ")";
|
<< "is greater than the number of samples in the file (" << n_samples << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
return n_samples;
|
return n_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::source() const { return file_source(); }
|
||||||
|
size_t FileSourceBase::source_item_size() const
|
||||||
|
{
|
||||||
|
// delegate the size of the source to the source() object, so sub-classes have less work to do
|
||||||
|
DLOG(INFO) << "source_item_size is " << source()->output_signature()->sizeof_stream_item(0);
|
||||||
|
return source()->output_signature()->sizeof_stream_item(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple accessors
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::file_source() const { return file_source_; }
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::valve() const { return valve_; }
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::throttle() const { return throttle_; }
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::sink() const { return sink_; }
|
||||||
|
|
||||||
|
gr::blocks::file_source::sptr FileSourceBase::create_file_source()
|
||||||
|
{
|
||||||
|
auto item_tuple = itemTypeToSize();
|
||||||
|
item_size_ = std::get<0>(item_tuple);
|
||||||
|
is_complex_ = std::get<1>(item_tuple);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// TODO: why are we manually seeking, instead of passing the samples_to_skip to the file_source factory?
|
||||||
|
auto samples_to_skip = samplesToSkip();
|
||||||
|
|
||||||
|
file_source_ = gr::blocks::file_source::make(item_size(), filename().data(), repeat());
|
||||||
|
|
||||||
|
if (samples_to_skip > 0)
|
||||||
|
{
|
||||||
|
LOG(INFO) << "Skipping " << samples_to_skip << " samples of the input file";
|
||||||
|
if (not file_source_->seek(samples_to_skip, SEEK_SET))
|
||||||
|
{
|
||||||
|
LOG(ERROR) << "Error skipping bytes!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr
|
||||||
|
<< "The receiver was configured to work with a file-based signal source\n"
|
||||||
|
<< "but the specified file is unreachable by GNSS-SDR.\n"
|
||||||
|
<< "[" << filename() << "]\n"
|
||||||
|
<< "\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"
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
LOG(ERROR) << "file_signal_source: Unable to open the samples file "
|
||||||
|
<< filename() << ", exiting the program.";
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
DLOG(INFO) << implementation() << "(" << file_source_->unique_id() << ")";
|
||||||
|
|
||||||
|
// enable subclass hooks
|
||||||
|
create_file_source_hook();
|
||||||
|
|
||||||
|
|
||||||
|
return file_source_;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr::blocks::throttle::sptr FileSourceBase::create_throttle()
|
||||||
|
{
|
||||||
|
if (enable_throttle_control_)
|
||||||
|
{
|
||||||
|
// if we are throttling...
|
||||||
|
throttle_ = gr::blocks::throttle::make(source_item_size(), sampling_frequency());
|
||||||
|
DLOG(INFO) << "throttle(" << throttle_->unique_id() << ")";
|
||||||
|
|
||||||
|
// enable subclass hooks
|
||||||
|
create_throttle_hook();
|
||||||
|
}
|
||||||
|
return throttle_;
|
||||||
|
}
|
||||||
|
|
||||||
|
gnss_shared_ptr<gr::block> FileSourceBase::create_valve()
|
||||||
|
{
|
||||||
|
if (samples() > 0)
|
||||||
|
{
|
||||||
|
// if a number of samples is specified, honor it by creating a valve
|
||||||
|
// In practice, this is always true
|
||||||
|
valve_ = gnss_sdr_make_valve(source_item_size(), samples(), queue_);
|
||||||
|
DLOG(INFO) << "valve(" << valve_->unique_id() << ")";
|
||||||
|
|
||||||
|
// enable subclass hooks
|
||||||
|
create_valve_hook();
|
||||||
|
}
|
||||||
|
return valve_;
|
||||||
|
}
|
||||||
|
|
||||||
|
gr::blocks::file_sink::sptr FileSourceBase::create_sink()
|
||||||
|
{
|
||||||
|
if (dump_)
|
||||||
|
{
|
||||||
|
sink_ = gr::blocks::file_sink::make(source_item_size(), dump_filename_.c_str());
|
||||||
|
DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")";
|
||||||
|
|
||||||
|
// enable subclass hooks
|
||||||
|
create_sink_hook();
|
||||||
|
}
|
||||||
|
return sink_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subclass hooks to augment created objects, as required
|
||||||
|
void FileSourceBase::create_file_source_hook() {}
|
||||||
|
void FileSourceBase::create_throttle_hook() {}
|
||||||
|
void FileSourceBase::create_valve_hook() {}
|
||||||
|
void FileSourceBase::create_sink_hook() {}
|
||||||
|
|
||||||
|
// Subclass hooks for connection/disconnectino
|
||||||
|
void FileSourceBase::pre_connect_hook(gr::top_block_sptr top_block [[maybe_unused]]) {}
|
||||||
|
void FileSourceBase::post_connect_hook(gr::top_block_sptr top_block [[maybe_unused]]) {}
|
||||||
|
void FileSourceBase::pre_disconnect_hook(gr::top_block_sptr top_block [[maybe_unused]]) {}
|
||||||
|
void FileSourceBase::post_disconnect_hook(gr::top_block_sptr top_block [[maybe_unused]]) {}
|
||||||
|
|
||||||
|
@ -18,17 +18,14 @@
|
|||||||
#ifndef GNSS_SDR_FILE_SOURCE_BASE_H
|
#ifndef GNSS_SDR_FILE_SOURCE_BASE_H
|
||||||
#define GNSS_SDR_FILE_SOURCE_BASE_H
|
#define GNSS_SDR_FILE_SOURCE_BASE_H
|
||||||
|
|
||||||
#include "signal_source_base.h"
|
|
||||||
|
|
||||||
#include "concurrent_queue.h"
|
#include "concurrent_queue.h"
|
||||||
#include <pmt/pmt.h>
|
#include "signal_source_base.h"
|
||||||
#include <gnuradio/blocks/file_source.h>
|
#include <gnuradio/blocks/file_source.h>
|
||||||
#include <gnuradio/blocks/throttle.h>
|
#include <gnuradio/blocks/throttle.h>
|
||||||
|
#include <pmt/pmt.h>
|
||||||
|
|
||||||
// for dump
|
// for dump
|
||||||
#include <gnuradio/blocks/file_sink.h>
|
#include <gnuradio/blocks/file_sink.h>
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -56,8 +53,7 @@ class ConfigurationInterface;
|
|||||||
class FileSourceBase : public SignalSourceBase
|
class FileSourceBase : public SignalSourceBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
//! virtual overrides
|
||||||
//! virtual overrides
|
|
||||||
void connect(gr::top_block_sptr top_block) override;
|
void connect(gr::top_block_sptr top_block) override;
|
||||||
void disconnect(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_left_block() override;
|
||||||
@ -70,9 +66,12 @@ public:
|
|||||||
//! the item type
|
//! the item type
|
||||||
std::string item_type() const;
|
std::string item_type() const;
|
||||||
|
|
||||||
|
// the size of the file data
|
||||||
|
// the size of the post-processed data
|
||||||
|
|
||||||
//! the configured size of each item
|
//! the configured size of each item
|
||||||
size_t item_size() override;
|
size_t item_size() override;
|
||||||
virtual size_t item_size() const; // what the interface **should** have declared
|
virtual size_t item_size() const; // what the interface **should** have declared
|
||||||
|
|
||||||
//! Whether to repeat reading after end-of-file
|
//! Whether to repeat reading after end-of-file
|
||||||
bool repeat() const;
|
bool repeat() const;
|
||||||
@ -91,9 +90,11 @@ protected:
|
|||||||
FileSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl,
|
FileSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl,
|
||||||
Concurrent_Queue<pmt::pmt_t>* queue);
|
Concurrent_Queue<pmt::pmt_t>* queue);
|
||||||
|
|
||||||
|
// item type override. Rather than make a bunch of arguments to the ctor, allow sub-classes to restrict the range of acceptable item types
|
||||||
|
|
||||||
//! compute the item size, from the item_type(). Subclasses may constrain types that don't make
|
//! 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
|
// sense. The return of this method is a tuple of item_size and is_complex
|
||||||
virtual std::tuple<size_t,bool> itemTypeToSize() const;
|
virtual std::tuple<size_t, bool> itemTypeToSize() const;
|
||||||
|
|
||||||
//! compute the number of samples to skip
|
//! compute the number of samples to skip
|
||||||
virtual size_t samplesToSkip() const;
|
virtual size_t samplesToSkip() const;
|
||||||
@ -101,15 +102,48 @@ protected:
|
|||||||
//! compute the number of samples in the file
|
//! compute the number of samples in the file
|
||||||
size_t computeSamplesInFile() const;
|
size_t computeSamplesInFile() const;
|
||||||
|
|
||||||
|
//! abstracted front-end source. Sub-classes may override if they create specialized chains to
|
||||||
|
//! decode source files into a usable format
|
||||||
|
virtual gnss_shared_ptr<gr::block> source() const;
|
||||||
|
|
||||||
|
//! 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;
|
||||||
|
|
||||||
|
//! generic access to created objects
|
||||||
|
gnss_shared_ptr<gr::block> file_source() const;
|
||||||
|
gnss_shared_ptr<gr::block> valve() const;
|
||||||
|
gnss_shared_ptr<gr::block> throttle() const;
|
||||||
|
gnss_shared_ptr<gr::block> sink() const;
|
||||||
|
|
||||||
|
// The methods create the various blocks, if enabled, and return access to them. The created
|
||||||
|
// object is also held in this class
|
||||||
|
gr::blocks::file_source::sptr create_file_source();
|
||||||
|
gr::blocks::throttle::sptr create_throttle();
|
||||||
|
gnss_shared_ptr<gr::block> create_valve();
|
||||||
|
gr::blocks::file_sink::sptr create_sink();
|
||||||
|
|
||||||
|
// Subclass hooks to augment created objects, as required
|
||||||
|
virtual void create_file_source_hook();
|
||||||
|
virtual void create_throttle_hook();
|
||||||
|
virtual void create_valve_hook();
|
||||||
|
virtual void create_sink_hook();
|
||||||
|
|
||||||
|
// Subclass hooks for connection/disconnection
|
||||||
|
virtual void pre_connect_hook(gr::top_block_sptr top_block);
|
||||||
|
virtual void post_connect_hook(gr::top_block_sptr top_block);
|
||||||
|
virtual void pre_disconnect_hook(gr::top_block_sptr top_block);
|
||||||
|
virtual void post_disconnect_hook(gr::top_block_sptr top_block);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string filename_;
|
std::string filename_;
|
||||||
gr::blocks::file_source::sptr file_source_;
|
gr::blocks::file_source::sptr file_source_;
|
||||||
|
|
||||||
std::string item_type_;
|
std::string item_type_;
|
||||||
size_t item_size_;
|
size_t item_size_;
|
||||||
bool is_complex_; // a misnomer; if I/Q are interleaved as integer values
|
bool is_complex_; // a misnomer; if I/Q are interleaved as integer values
|
||||||
|
|
||||||
size_t header_size_; // length (in samples) of the header (if any)
|
size_t header_size_; // length (in samples) of the header (if any)
|
||||||
double seconds_to_skip_;
|
double seconds_to_skip_;
|
||||||
bool repeat_;
|
bool repeat_;
|
||||||
|
|
||||||
@ -130,9 +164,6 @@ private:
|
|||||||
bool dump_;
|
bool dump_;
|
||||||
std::string dump_filename_;
|
std::string dump_filename_;
|
||||||
gr::blocks::file_sink::sptr sink_;
|
gr::blocks::file_sink::sptr sink_;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,10 @@ size_t SignalSourceBase::getRfChannels() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
SignalSourceBase::SignalSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl)
|
SignalSourceBase::SignalSourceBase(ConfigurationInterface const* configuration, std::string role, std::string impl)
|
||||||
: SignalSourceInterface(), role_(role), implementation_(impl), connected_(false), rfChannels_(configuration->property(role + ".RF_channels"s, 1u))
|
: SignalSourceInterface()
|
||||||
|
, role_(role)
|
||||||
|
, implementation_(impl)
|
||||||
|
, rfChannels_(configuration->property(role + ".RF_channels"s, 1u))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::string const role_;
|
std::string const role_;
|
||||||
std::string const implementation_;
|
std::string const implementation_;
|
||||||
bool connected_;
|
|
||||||
size_t rfChannels_;
|
size_t rfChannels_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,26 +6,17 @@
|
|||||||
*
|
*
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
|
||||||
*
|
|
||||||
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||||
* This file is not part of GNSS-SDR.
|
* 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
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "spir_file_signal_source.h"
|
#include "spir_file_signal_source.h"
|
||||||
#include "configuration_interface.h"
|
|
||||||
#include "gnss_sdr_flags.h"
|
|
||||||
#include "gnss_sdr_valve.h"
|
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
#include <exception>
|
|
||||||
#include <fstream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
@ -33,267 +24,55 @@ using namespace std::string_literals;
|
|||||||
SpirFileSignalSource::SpirFileSignalSource(const ConfigurationInterface* configuration,
|
SpirFileSignalSource::SpirFileSignalSource(const ConfigurationInterface* configuration,
|
||||||
const std::string& role, unsigned int in_streams, unsigned int out_streams,
|
const std::string& role, unsigned int in_streams, unsigned int out_streams,
|
||||||
Concurrent_Queue<pmt::pmt_t>* queue)
|
Concurrent_Queue<pmt::pmt_t>* queue)
|
||||||
: SignalSourceBase(configuration, role, "Spir_File_Signal_Source"s)
|
: FileSourceBase(configuration, role, "Spir_File_Signal_Source"s, queue)
|
||||||
, in_streams_(in_streams), out_streams_(out_streams)
|
|
||||||
{
|
{
|
||||||
const std::string default_filename("../data/my_capture.dat");
|
if (in_streams > 0)
|
||||||
const std::string default_item_type("int");
|
|
||||||
const std::string default_dump_filename("../data/my_capture_dump.dat");
|
|
||||||
|
|
||||||
samples_ = configuration->property(role + ".samples", static_cast<uint64_t>(0));
|
|
||||||
sampling_frequency_ = configuration->property(role + ".sampling_frequency", static_cast<int64_t>(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);
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (item_type_ == "int")
|
|
||||||
{
|
|
||||||
item_size_ = sizeof(int);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOG(WARNING) << item_type_ << " unrecognized item type. Using int.";
|
|
||||||
item_size_ = sizeof(int);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file_source_ = gr::blocks::file_source::make(item_size_, filename_.c_str(), repeat_);
|
|
||||||
unpack_intspir_ = make_unpack_intspir_1bit_samples();
|
|
||||||
}
|
|
||||||
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() << ")";
|
|
||||||
|
|
||||||
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 100 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();
|
|
||||||
LOG(INFO) << "Total samples in the file= " << floor(static_cast<double>(size) / static_cast<double>(item_size()));
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (size > 0)
|
|
||||||
{
|
|
||||||
int sample_packet_factor = 1; // 1 int -> 1 complex sample (I&Q from 1 channel)
|
|
||||||
samples_ = floor(static_cast<double>(size) / static_cast<double>(item_size())) * sample_packet_factor;
|
|
||||||
samples_ = samples_ - ceil(0.002 * static_cast<double>(sampling_frequency_)); // process all the samples available in the file excluding the last 2 ms
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CHECK(samples_ > 0) << "File does not contain enough samples to process.";
|
|
||||||
double signal_duration_s = static_cast<double>(samples_) * (1 / static_cast<double>(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(sizeof(float), 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(sizeof(float), dump_filename_.c_str());
|
|
||||||
DLOG(INFO) << "file_sink(" << sink_->unique_id() << ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enable_throttle_control_)
|
|
||||||
{
|
|
||||||
throttle_ = gr::blocks::throttle::make(sizeof(float), 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)
|
|
||||||
{
|
{
|
||||||
LOG(ERROR) << "A signal source does not have an input stream";
|
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";
|
LOG(ERROR) << "This implementation only supports one output stream";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<size_t, bool> SpirFileSignalSource::itemTypeToSize() const
|
||||||
void SpirFileSignalSource::connect(gr::top_block_sptr top_block)
|
|
||||||
{
|
{
|
||||||
if (samples_ > 0)
|
auto is_complex = false;
|
||||||
|
auto item_size = size_t(0);
|
||||||
|
|
||||||
|
if (item_type() == "int")
|
||||||
{
|
{
|
||||||
if (enable_throttle_control_ == true)
|
item_size = sizeof(int);
|
||||||
{
|
|
||||||
top_block->connect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
top_block->connect(unpack_intspir_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to throttle";
|
|
||||||
top_block->connect(throttle_, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "connected throttle to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->connect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "connected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
top_block->connect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
top_block->connect(unpack_intspir_, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->connect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "connected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (enable_throttle_control_ == true)
|
LOG(WARNING) << item_type() << " unsupported item type. Using int.";
|
||||||
{
|
item_size = sizeof(int);
|
||||||
top_block->connect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
top_block->connect(unpack_intspir_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to throttle";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->connect(throttle_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->connect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
top_block->connect(unpack_intspir_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "connected file source to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return std::make_tuple(item_size, is_complex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This class feeds the file data through a decoder to produce samples; for all intents this is the "source"
|
||||||
|
gnss_shared_ptr<gr::block> SpirFileSignalSource::source() const { return unpack_intspir_; }
|
||||||
|
|
||||||
void SpirFileSignalSource::disconnect(gr::top_block_sptr top_block)
|
|
||||||
|
void SpirFileSignalSource::create_file_source_hook()
|
||||||
{
|
{
|
||||||
if (samples_ > 0)
|
// connect the file to the decoder
|
||||||
{
|
unpack_intspir_ = make_unpack_intspir_1bit_samples();
|
||||||
if (enable_throttle_control_ == true)
|
DLOG(INFO) << "unpack_intspir_1bit_samples(" << unpack_intspir_->unique_id() << ")";
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to unpack_intspir_";
|
|
||||||
top_block->connect(unpack_intspir_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "disconnected unpack_intspir_ to throttle_";
|
|
||||||
top_block->disconnect(throttle_, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "disconnected throttle to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to unpack_intspir_";
|
|
||||||
top_block->disconnect(unpack_intspir_, 0, valve_, 0);
|
|
||||||
DLOG(INFO) << "disconnected unpack_intspir_ to valve";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(valve_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected valve to file sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (enable_throttle_control_ == true)
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to unpack_intspir_";
|
|
||||||
top_block->disconnect(unpack_intspir_, 0, throttle_, 0);
|
|
||||||
DLOG(INFO) << "disconnected unpack_intspir_ to throttle";
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(unpack_intspir_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected funpack_intspir_ to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (dump_)
|
|
||||||
{
|
|
||||||
top_block->disconnect(file_source_, 0, unpack_intspir_, 0);
|
|
||||||
DLOG(INFO) << "disconnected file source to unpack_intspir_";
|
|
||||||
top_block->disconnect(unpack_intspir_, 0, sink_, 0);
|
|
||||||
DLOG(INFO) << "disconnected unpack_intspir_ to sink";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpirFileSignalSource::pre_connect_hook(gr::top_block_sptr top_block)
|
||||||
gr::basic_block_sptr SpirFileSignalSource::get_left_block()
|
|
||||||
{
|
{
|
||||||
LOG(WARNING) << "Left block of a signal source should not be retrieved";
|
top_block->connect(file_source(), 0, unpack_intspir_, 0);
|
||||||
// return gr_block_sptr();
|
DLOG(INFO) << "connected file_source to unpacker";
|
||||||
return gr::blocks::file_source::sptr();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpirFileSignalSource::post_disconnect_hook(gr::top_block_sptr top_block)
|
||||||
gr::basic_block_sptr SpirFileSignalSource::get_right_block()
|
|
||||||
{
|
{
|
||||||
if (samples_ > 0)
|
top_block->disconnect(file_source(), 0, unpack_intspir_, 0);
|
||||||
{
|
DLOG(INFO) << "disconnected file_source from unpacker";
|
||||||
return valve_;
|
|
||||||
}
|
|
||||||
if (enable_throttle_control_ == true)
|
|
||||||
{
|
|
||||||
return throttle_;
|
|
||||||
}
|
|
||||||
return unpack_intspir_;
|
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,10 @@
|
|||||||
*
|
*
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
||||||
*
|
* This file is part of GNSS-SDR.
|
||||||
* GNSS-SDR is a software defined Global Navigation
|
|
||||||
* Satellite Systems receiver
|
|
||||||
*
|
|
||||||
* This file is not part of GNSS-SDR.
|
|
||||||
*
|
*
|
||||||
|
* Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------------------
|
* -----------------------------------------------------------------------------
|
||||||
@ -21,18 +18,9 @@
|
|||||||
#ifndef GNSS_SDR_SPIR_FILE_SIGNAL_SOURCE_H
|
#ifndef GNSS_SDR_SPIR_FILE_SIGNAL_SOURCE_H
|
||||||
#define GNSS_SDR_SPIR_FILE_SIGNAL_SOURCE_H
|
#define GNSS_SDR_SPIR_FILE_SIGNAL_SOURCE_H
|
||||||
|
|
||||||
#include "signal_source_base.h"
|
#include "file_source_base.h"
|
||||||
|
|
||||||
#include "concurrent_queue.h"
|
|
||||||
#include "gnss_block_interface.h"
|
|
||||||
#include "unpack_intspir_1bit_samples.h"
|
#include "unpack_intspir_1bit_samples.h"
|
||||||
#include <gnuradio/blocks/file_sink.h>
|
|
||||||
#include <gnuradio/blocks/file_source.h>
|
|
||||||
#include <gnuradio/blocks/throttle.h>
|
|
||||||
#include <gnuradio/hier_block2.h>
|
|
||||||
#include <pmt/pmt.h>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
|
|
||||||
/** \addtogroup Signal_Source
|
/** \addtogroup Signal_Source
|
||||||
@ -47,7 +35,7 @@ class ConfigurationInterface;
|
|||||||
* \brief Class that reads signals samples from a file
|
* \brief Class that reads signals samples from a file
|
||||||
* and adapts it to a SignalSourceInterface
|
* and adapts it to a SignalSourceInterface
|
||||||
*/
|
*/
|
||||||
class SpirFileSignalSource : public SignalSourceBase
|
class SpirFileSignalSource : public FileSourceBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SpirFileSignalSource(const ConfigurationInterface* configuration, const std::string& role,
|
SpirFileSignalSource(const ConfigurationInterface* configuration, const std::string& role,
|
||||||
@ -56,64 +44,17 @@ public:
|
|||||||
|
|
||||||
~SpirFileSignalSource() = default;
|
~SpirFileSignalSource() = default;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::tuple<size_t, bool> itemTypeToSize() const override;
|
||||||
|
gnss_shared_ptr<gr::block> source() const override;
|
||||||
|
void create_file_source_hook() override;
|
||||||
|
void pre_connect_hook(gr::top_block_sptr top_block) override;
|
||||||
|
void post_disconnect_hook(gr::top_block_sptr top_block) override;
|
||||||
|
|
||||||
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:
|
private:
|
||||||
gr::blocks::file_source::sptr file_source_;
|
|
||||||
unpack_intspir_1bit_samples_sptr unpack_intspir_;
|
unpack_intspir_1bit_samples_sptr unpack_intspir_;
|
||||||
gnss_shared_ptr<gr::block> valve_;
|
|
||||||
gr::blocks::file_sink::sptr sink_;
|
|
||||||
gr::blocks::throttle::sptr throttle_;
|
|
||||||
std::string filename_;
|
|
||||||
std::string item_type_;
|
|
||||||
std::string dump_filename_;
|
|
||||||
|
|
||||||
uint64_t samples_;
|
|
||||||
int64_t sampling_frequency_;
|
|
||||||
size_t item_size_;
|
|
||||||
|
|
||||||
unsigned int in_streams_;
|
|
||||||
unsigned int out_streams_;
|
|
||||||
|
|
||||||
bool repeat_;
|
|
||||||
bool dump_;
|
|
||||||
|
|
||||||
// Throttle control
|
|
||||||
bool enable_throttle_control_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user