GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
ion_gsms_chunk_data.h
Go to the documentation of this file.
1/*!
2 * \file ion_gsms_chunk_data.h
3 * \brief Holds logic for reading and decoding samples from a chunk
4 * \author Víctor Castillo Agüero, 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) 2010-2024 (see AUTHORS file for a list of contributors)
12 * SPDX-License-Identifier: GPL-3.0-or-later
13 *
14 * -----------------------------------------------------------------------------
15 */
16
17#ifndef GNSS_SDR_ION_GSMS_CHUNK_DATA_H
18#define GNSS_SDR_ION_GSMS_CHUNK_DATA_H
19
22#include <gnuradio/block.h>
23#include <GnssMetadata.h>
24#include <cstddef>
25#include <cstdint>
26#include <iostream>
27#include <string>
28#include <vector>
29
30
31inline std::size_t bits_to_item_size(std::size_t bit_count)
32{
33 if (bit_count <= 8)
34 {
35 return 1;
36 }
37 if (bit_count <= 16)
38 {
39 return 2;
40 }
41 if (bit_count <= 32)
42 {
43 return 4;
44 }
45 if (bit_count <= 64)
46 {
47 return 8;
48 }
49
50 // You are asking too much of this humble processor
51 std::cerr << "Item size too large (" << std::to_string(bit_count) << "), returning nonsense.\n";
52 return 1;
53}
54
55
56// Define a functor that has a templated operator()
57struct Allocator
58{
59 size_t countwords_;
60 void*& buffer_; // Using void* to hold any type of pointer
61
62 Allocator(size_t countwords, void*& buffer)
63 : countwords_(countwords), buffer_(buffer) {}
64
65 template <typename WordType>
66 void operator()() const
67 {
68 buffer_ = new WordType[countwords_];
69 }
70};
71
72
73// Define a functor to delete the allocated memory
74struct Deleter
75{
76 void* buffer_;
77
78 explicit Deleter(void* buffer)
79 : buffer_(buffer) {}
80
81 template <typename WordType>
82 void operator()() const
83 {
84 delete[] static_cast<WordType*>(buffer_);
85 }
86};
87
88
89template <typename Callback>
90void with_word_type(uint8_t word_size, Callback callback)
91{
92 switch (word_size)
93 {
94 case 1:
95 callback.template operator()<int8_t>();
96 break;
97 case 2:
98 callback.template operator()<int16_t>();
99 break;
100 case 4:
101 callback.template operator()<int32_t>();
102 break;
103 case 8:
104 callback.template operator()<int64_t>();
105 break;
106 default:
107 std::cerr << "Unknown word size (" << std::to_string(word_size) << "), returning nonsense.\n";
108 break;
109 }
110}
111
112class IONGSMSChunkData
113{
114public:
115 IONGSMSChunkData(const GnssMetadata::Chunk& chunk, const std::vector<std::string>& stream_ids, std::size_t output_stream_offset);
116
117 ~IONGSMSChunkData();
118
119 IONGSMSChunkData(const IONGSMSChunkData& rhl) = delete;
120 IONGSMSChunkData& operator=(const IONGSMSChunkData& rhl) = delete;
121
122 IONGSMSChunkData(IONGSMSChunkData&& rhl) = delete;
123 IONGSMSChunkData& operator=(IONGSMSChunkData&& rhl) = delete;
124
125 std::size_t read_from_buffer(uint8_t* buffer, std::size_t offset);
126
127 void write_to_output(gr_vector_void_star& outputs, std::vector<int>& output_items);
128
129 std::size_t output_stream_count() const;
130 std::size_t output_stream_item_size(std::size_t stream_index) const;
131 std::size_t output_stream_item_rate(std::size_t stream_index) const;
132
133private:
134 template <typename WT>
135 void unpack_words(gr_vector_void_star& outputs, std::vector<int>& output_items);
136
137 template <typename WT>
138 std::size_t write_stream_samples(
140 const GnssMetadata::Lump& lump,
141 const GnssMetadata::IonStream& stream,
142 GnssMetadata::StreamEncoding stream_encoding,
143 void** out);
144
145 template <typename WT, typename OT>
146 void write_n_samples(
148 GnssMetadata::Lump::LumpShift lump_shift,
149 uint8_t sample_bitsize,
150 std::size_t sample_count,
151 GnssMetadata::StreamEncoding stream_encoding,
152 OT** out);
153
154 template <typename Sample>
155 static void decode_sample(uint8_t sample_bitsize, Sample* sample, GnssMetadata::StreamEncoding encoding);
156
157 const GnssMetadata::Chunk& chunk_;
158 uint8_t sizeword_;
159 uint8_t countwords_;
160 uint8_t padding_bitsize_;
161 std::size_t output_stream_count_;
162 std::vector<std::size_t> output_stream_item_size_;
163 std::vector<std::size_t> output_stream_item_rate_;
164
165 struct stream_metadata_t
166 {
167 const GnssMetadata::Lump& lump;
168 const GnssMetadata::IonStream& stream;
169 GnssMetadata::StreamEncoding stream_encoding;
170 int output_index = -1;
171
172 stream_metadata_t(
173 const GnssMetadata::Lump& lump_,
174 const GnssMetadata::IonStream& stream_,
175 GnssMetadata::StreamEncoding stream_encoding_,
176 int output_index_ = -1) : lump(lump_),
177 stream(stream_),
178 stream_encoding(stream_encoding_),
179 output_index(output_index_)
180 {
181 }
182 };
183 std::vector<stream_metadata_t> streams_;
184
185 void* buffer_;
186};
187
188#endif // GNSS_SDR_ION_GSMS_CHUNK_DATA_H
Holds state and provides utilities for unpacking samples from a chunk.
Implements look up tables for all encodings in the standard.