This repository was archived by the owner on May 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathIQStream.hpp
More file actions
240 lines (187 loc) · 7.45 KB
/
IQStream.hpp
File metadata and controls
240 lines (187 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
//============================================================================
//
// This file is part of GPSTk, the GPS Toolkit.
//
// The GPSTk is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 3.0 of the License, or
// any later version.
//
// The GPSTk is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with GPSTk; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
//
// Copyright 2004, The University of Texas at Austin
//
//============================================================================
//============================================================================
//
//This software developed by Applied Research Laboratories at the University of
//Texas at Austin, under contract to an agency or agencies within the U.S.
//Department of Defense. The U.S. Government retains all rights to use,
//duplicate, distribute, disclose, or release this software.
//
//Pursuant to DoD Directive 523024
//
// DISTRIBUTION STATEMENT A: This software has been approved for public
// release, distribution is unlimited.
//
//=============================================================================
#ifndef IQSTREAM_HPP
#define IQSTREAM_HPP
#include <vector>
#include <map>
#include <complex>
#include "gpstkplatform.h"
#include "FFBinaryStream.hpp"
namespace gpstk
{
/**
* This is a stream used to parse an IQ data file
*/
class IQStream : public FFBinaryStream
{
public:
IQStream()
: frameLength(500),
frameCounter(0),
frameBuffer(NULL),
sampleCounter(0),
debugLevel(0),
bands(1)
{ init(); }
IQStream(const char* fn, std::ios::openmode mode = std::ios::in)
: FFBinaryStream(fn, mode),
frameLength(500),
frameCounter(0),
frameBuffer(NULL),
sampleCounter(0),
debugLevel(0),
bands(1)
{ init(); }
/// destructor per the coding standards
virtual ~IQStream()
{ delete frameBuffer; }
/// Just a common place to set up a default object
virtual void init(void);
/// overrides open to reset the header
virtual void open(const char* fn, std::ios::openmode mode = std::ios::in)
{
FFBinaryStream::open(fn, mode);
readPtr = frameLength;
writePtr = 0;
frameCounter = 0;
sampleCounter = 0;
}
unsigned frameLength;
/// The frame count that is at the end of each block
unsigned frameCounter;
/// The current frame of data
char* frameBuffer;
/// Used to keep track of where we are in the frame
unsigned readPtr;
unsigned writePtr;
/// used to figure out which nibble of readPtr we are in...
unsigned long sampleCounter;
/// This is where the meta data of the frame starts
unsigned metaPtr;
int debugLevel;
std::string desc;
/// The number of bands of data in this file.
/// This can't be determined from the input stream at the moment
int bands;
/// These are used to read and write the buffer
void readBuffer(void);
void writeBuffer(void);
/// Returns single complex sample
virtual void readComplex(std::complex<short>& v) = 0;
virtual void readComplex(std::complex<float>& v) = 0;
/// Writes a single complex sample,
virtual void writeComplex(const std::complex<short>& v) = 0;
virtual void writeComplex(const std::complex<float>& v) = 0;
protected:
/** @warning This is used by FFBinaryStream's getData and
* writeData methods to determine how to write binary encoded
* data. Current implementation does not use these methods
* and any further updates should not use getData or
* writeData without verifying the validity of this
* method. */
virtual bool isStreamLittleEndian() const throw()
{ return true; }
}; // class IQStream
inline IQStream& operator>>(IQStream& s, std::complex<short>& v)
{ s.readComplex(v); return s; };
inline IQStream& operator>>(IQStream& s, std::complex<float>& v)
{ s.readComplex(v); return s; };
inline IQStream& operator<<(IQStream& s, const std::complex<short>& v)
{ s.writeComplex(v); return s; };
inline IQStream& operator<<(IQStream& s, const std::complex<float>& v)
{ s.writeComplex(v); return s; };
class IQ1Stream : public IQStream
{
public:
IQ1Stream() : IQStream() {init();}
IQ1Stream(const char* fn, std::ios::openmode mode = std::ios::in)
: IQStream(fn, mode)
{init(); desc="1 bit";}
/// destructor per the coding standards
virtual ~IQ1Stream() {};
/// Just a common place to set up a default object
virtual void init(void) {};
/// Returns single complex sample
virtual void readComplex(std::complex<short>& v);
virtual void readComplex(std::complex<float>& v);
/// Writes a single complex sample,
virtual void writeComplex(const std::complex<short>& v);
virtual void writeComplex(const std::complex<float>& v);
}; // class IQ1Stream
class IQ2Stream : public IQStream
{
public:
IQ2Stream() : IQStream() {init();desc="2 bit";}
IQ2Stream(const char* fn, std::ios::openmode mode = std::ios::in)
: IQStream(fn, mode)
{init();desc="2 bit";}
/// destructor per the coding standards
virtual ~IQ2Stream() {};
/// Just a common place to set up a default object
virtual void init(void);
/// Maps the bits of each sample to the actual levels
std::vector<short> sample2Level;
/// Encodes levels into the appropriate bits
template<class T>
uint8_t l2s(T v);
/// Returns single complex sample
virtual void readComplex(std::complex<short>& v);
virtual void readComplex(std::complex<float>& v);
/// Writes a single complex sample,
virtual void writeComplex(const std::complex<short>& v);
virtual void writeComplex(const std::complex<float>& v);
private:
void writeNibble(uint8_t i, uint8_t q);
}; // class IQ2Stream
class IQFloatStream : public IQStream
{
public:
IQFloatStream() : IQStream() {init();desc="float";}
IQFloatStream(const char* fn, std::ios::openmode mode = std::ios::in)
: IQStream(fn, mode)
{init();desc="float";}
/// destructor per the coding standards
virtual ~IQFloatStream() {};
/// Just a common place to set up a default object
virtual void init(void) {};
/// Returns single complex sample
virtual void readComplex(std::complex<short>& v);
virtual void readComplex(std::complex<float>& v);
/// Writes a single complex sample,
virtual void writeComplex(const std::complex<short>& v);
virtual void writeComplex(const std::complex<float>& v);
}; // class IQ2Stream
} // namespace gpstk
#endif