GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
file_source_base.h
Go to the documentation of this file.
1/*!
2 * \file file_source_base.h
3 * \brief Header file of the base class to file-oriented signal_source GNSS blocks.
4 * \author Jim Melton, 2021. jim.melton(at)sncorp.com
5 *
6 *
7 * -----------------------------------------------------------------------------
8 *
9 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
10 * This file is part of GNSS-SDR.
11 *
12 * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
13 * SPDX-License-Identifier: GPL-3.0-or-later
14 *
15 * -----------------------------------------------------------------------------
16 */
17
18#ifndef GNSS_SDR_FILE_SOURCE_BASE_H
19#define GNSS_SDR_FILE_SOURCE_BASE_H
20
21#include "concurrent_queue.h"
23#include "signal_source_base.h"
24#include <gnuradio/blocks/file_sink.h> // for dump
25#include <gnuradio/blocks/file_source.h>
26#include <gnuradio/blocks/throttle.h>
27#include <pmt/pmt.h>
28#include <cstddef>
29#include <string>
30#include <tuple>
31
32
33/** \addtogroup Signal_Source
34 * \{ */
35/** \addtogroup Signal_Source_adapters
36 * \{ */
37
39
40
41//! \brief Base class to file-oriented SignalSourceBase GNSS blocks.
42//!
43//! This class supports the following properties:
44//!
45//! .filename - the path to the input file
46//! - may be overridden by the -signal_source or -s command-line arguments
47//!
48//! .samples - number of samples to process (default 0)
49//! - if not specified or 0, read the entire file; otherwise stop after that many samples
50//!
51//! .sampling_frequency - the frequency of the sampled data (samples/second)
52//!
53//! .item_type - data type of the samples (default "short")
54//!
55//! .header_size - the size of a prefixed header to skip in "samples" (default 0)
56//!
57//! .seconds_to_skip - number of seconds of lead-in data to skip over (default 0)
58//!
59//! .enable_throttle_control - whether to stop reading if the upstream buffer is full (default false)
60//!
61//! .repeat - whether to rewind and continue at end of file (default false)
62//!
63//! (probably abstracted to the base class)
64//!
65//! .dump - whether to archive input data
66//!
67//! .dump_filename - if dumping, path to file for output
69{
70public:
71 // Virtual overrides
72 void connect(gr::top_block_sptr top_block) override;
73 void disconnect(gr::top_block_sptr top_block) override;
74 gr::basic_block_sptr get_left_block() override;
75 gr::basic_block_sptr get_right_block() override;
76
77 //! The file to read
78 std::string filename() const;
79
80 //! The item type
81 std::string item_type() const;
82
83 //! The configured size of each item
84 size_t item_size() override;
85 virtual size_t item_size() const; // what the interface **should** have declared
86
87 //! Whether to repeat reading after end-of-file
88 bool repeat() const;
89
90 //! The sampling frequency of the source file
91 int64_t sampling_frequency() const;
92
93 //! The number of samples in the file
94 uint64_t samples() const;
95
96protected:
97 //! \brief Constructor
98 //!
99 //! Subclasses may want to assert default item types that are appropriate to the specific file
100 //! type supported. Rather than require the item type to be specified in the config file, allow
101 //! sub-classes to impose their will
102 FileSourceBase(ConfigurationInterface const* configuration, std::string const& role, std::string impl,
104 std::string default_item_type = "short");
105
106 //! Perform post-construction initialization
107 void init();
108
109 //! Compute the item size, from the item_type(). Subclasses may constrain types that don't make
110 // sense. The return of this method is a tuple of item_size and is_complex
111 virtual std::tuple<size_t, bool> itemTypeToSize();
112
113 //! The number of (possibly unpacked) samples in a (raw) file sample (default=1)
114 virtual double packetsPerSample() const;
115
116 //! Compute the number of samples to skip
117 virtual uint64_t samplesToSkip() const;
118
119 //! Compute the number of samples in the file
120 uint64_t computeSamplesInFile() const;
121
122 //! Abstracted front-end source. Sub-classes may override if they create specialized chains to
123 //! decode source files into a usable format
124 virtual gnss_shared_ptr<gr::block> source() const;
125
126 //! For complex source chains, the size of the file item may not be the same as the size of the
127 // "source" (decoded) item. This method allows subclasses to handle these differences
128 virtual size_t source_item_size() const;
129 bool is_complex() const;
130
131 // Generic access to created objects
132 gnss_shared_ptr<gr::block> file_source() const;
133 gnss_shared_ptr<gr::block> valve() const;
134 gnss_shared_ptr<gr::block> throttle() const;
135 gnss_shared_ptr<gr::block> sink() const;
136 SensorDataSource::sptr sensor_data_source() const;
137
138 // The methods create the various blocks, if enabled, and return access to them. The created
139 // object is also held in this class
140 gr::blocks::file_source::sptr create_file_source();
141 gr::blocks::throttle::sptr create_throttle();
142 gnss_shared_ptr<gr::block> create_valve();
143 gr::blocks::file_sink::sptr create_sink();
144 SensorDataSource::sptr create_sensor_data_source();
145
146 // Subclass hooks to augment created objects, as required
147 virtual void create_file_source_hook();
148 virtual void create_throttle_hook();
149 virtual void create_valve_hook();
150 virtual void create_sink_hook();
151
152 // Subclass hooks for connection/disconnection
153 virtual void pre_connect_hook(gr::top_block_sptr top_block);
154 virtual void post_connect_hook(gr::top_block_sptr top_block);
155 virtual void pre_disconnect_hook(gr::top_block_sptr top_block);
156 virtual void post_disconnect_hook(gr::top_block_sptr top_block);
157
158private:
159 gr::blocks::file_source::sptr file_source_;
160 gr::blocks::throttle::sptr throttle_;
161 gr::blocks::file_sink::sptr sink_;
162 SensorDataSource::sptr sensor_data_source_;
163
164 // The valve allows only the configured number of samples through, then it closes.
165
166 // The framework passes the queue as a naked pointer, rather than a shared pointer, so this
167 // class has two choices: construct the valve in the ctor, or hold onto the pointer, possibly
168 // beyond its lifetime. Fortunately, the queue is only used to create the valve, so the
169 // likelihood of holding a stale pointer is mitigated
170 gnss_shared_ptr<gr::block> valve_;
172
173 std::string role_;
174 std::string filename_;
175 std::string dump_filename_;
176 std::string item_type_;
177 size_t item_size_;
178 size_t header_size_; // length (in samples) of the header (if any)
179 uint64_t samples_;
180 int64_t sampling_frequency_; // why is this signed
181 double minimum_tail_s_;
182 double seconds_to_skip_;
183 bool is_complex_; // a misnomer; if I/Q are interleaved as integer values
184 bool repeat_;
185 bool enable_throttle_control_;
186 bool dump_;
187
188 // Configuration for Extra Data source
189 SensorDataSourceConfiguration sensor_data_source_configuration_;
190};
191
192/** \} */
193/** \} */
194#endif // GNSS_SDR_FILE_SOURCE_BASE_H
This class implements a thread-safe std::queue.
This abstract class represents an interface to configuration parameters.
uint64_t computeSamplesInFile() const
Compute the number of samples in the file.
std::string item_type() const
The item type.
uint64_t samples() const
The number of samples in the file.
virtual size_t source_item_size() const
For complex source chains, the size of the file item may not be the same as the size of the.
bool repeat() const
Whether to repeat reading after end-of-file.
FileSourceBase(ConfigurationInterface const *configuration, std::string const &role, std::string impl, Concurrent_Queue< pmt::pmt_t > *queue, std::string default_item_type="short")
Constructor.
std::string filename() const
The file to read.
size_t item_size() override
The configured size of each item.
virtual std::tuple< size_t, bool > itemTypeToSize()
Compute the item size, from the item_type(). Subclasses may constrain types that don't make.
virtual gnss_shared_ptr< gr::block > source() const
Abstracted front-end source. Sub-classes may override if they create specialized chains to decode sou...
void init()
Perform post-construction initialization.
int64_t sampling_frequency() const
The sampling frequency of the source file.
virtual double packetsPerSample() const
The number of (possibly unpacked) samples in a (raw) file sample (default=1).
virtual uint64_t samplesToSkip() const
Compute the number of samples to skip.
SignalSourceBase(ConfigurationInterface const *configuration, std::string role, std::string impl)
Constructor.
Interface of a thread-safe std::queue.
GNURadio block that adds extra data to the sample stream.
Header file of the base class to signal_source GNSS blocks.