GNSS-SDR  0.0.21
An Open Source GNSS Software Defined Receiver
sensor_data_file.h
Go to the documentation of this file.
1 /*!
2  * \file sensor_data_file.h
3  * \brief Provides a simple abstraction for reading contiguous binary data from a file
4  * \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
5  *
6  * -----------------------------------------------------------------------------
7  *
8  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
9  * This file is part of GNSS-SDR.
10  *
11  * Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
12  * SPDX-License-Identifier: GPL-3.0-or-later
13  *
14  * -----------------------------------------------------------------------------
15  */
16 
17 
18 #ifndef GNSS_SDR_SENSOR_DATA_FILE_H
19 #define GNSS_SDR_SENSOR_DATA_FILE_H
20 
21 #include <cstddef> // for size_t
22 #include <cstdint>
23 #include <fstream>
24 #include <gnss_block_interface.h>
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 /** \addtogroup Algorithms_Library
30  * \{ */
31 /** \addtogroup Algorithm_libs algorithms_libs
32  * \{ */
33 
34 
36 {
37 public:
38  using sptr = gnss_shared_ptr<SensorDataFile>;
39  using id_type = std::size_t;
40 
42  const std::string& path,
43  const std::size_t& sample_delay,
44  const std::size_t& sample_period,
45  const std::size_t& offset_in_file,
46  const std::size_t& item_size,
47  const bool& repeat);
48 
49  void reset();
50 
51  bool read_until_sample(std::size_t end_sample, std::size_t& sample_stamp, std::vector<uint8_t>& buffer);
52 
53  std::size_t get_chunks_read() const;
54 
55 private:
56  bool read_item(std::vector<uint8_t>& buffer);
57 
58  void read_into_io_buffer();
59 
60  void read_into_item_buffer(std::vector<uint8_t>& item_buf);
61 
62  std::string path_;
63  std::ifstream file_;
64  std::size_t sample_period_;
65  std::size_t offset_in_file_;
66  std::size_t item_size_;
67 
68  std::size_t chunks_read_;
69  std::size_t next_sample_stamp_;
70  std::vector<uint8_t> io_buffer_;
71  std::size_t io_buffer_size_;
72  std::size_t offset_in_io_buffer_;
73  bool repeat_;
74  bool done_;
75 };
76 
77 /** \} */
78 /** \} */
79 #endif // GNSS_SDR_SENSOR_DATA_FILE_H
This interface represents a GNSS block.