forked from f4exb/dsdcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsd_decoder.h
341 lines (301 loc) · 10.4 KB
/
dsd_decoder.h
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB. //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program 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 General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef DSDCC_DSD_DECODER_H_
#define DSDCC_DSD_DECODER_H_
#include "dsd_opts.h"
#include "dsd_state.h"
#include "dsd_logger.h"
#include "dsd_symbol.h"
#include "dsd_mbe.h"
#include "dmr.h"
#include "ysf.h"
#include "dpmr.h"
#include "dstar.h"
#include "nxdn.h"
#include "locator.h"
#include "export.h"
#define DSD_SQUELCH_TIMEOUT_SAMPLES 960 // 200ms timeout after return to sync search
namespace DSDcc
{
class DSDCC_API DSDDecoder
{
friend class DSDSymbol;
friend class DSDMBEDecoder;
friend class DSDDMR;
friend class DSDDstar;
friend class DSDDstarOld;
friend class DSDYSF;
friend class DSDdPMR;
friend class DSDNXDN;
public:
typedef enum
{
DSDDecodeAuto,
DSDDecodeNone,
DSDDecodeP25P1,
DSDDecodeDStar,
DSDDecodeNXDN48,
DSDDecodeNXDN96,
DSDDecodeProVoice,
DSDDecodeDMR,
DSDDecodeX2TDMA,
DSDDecodeDPMR,
DSDDecodeYSF
} DSDDecodeMode;
typedef enum
{
DSDRate2400,
DSDRate4800,
DSDRate9600
} DSDRate;
typedef enum
{
DSDShowP25EncryptionSyncBits,
DSDShowP25LinkControlBits,
DSDShowP25StatusBitsAndLowSpeedData,
DSDShowP25TalkGroupInfo
} DSDShowP25;
typedef enum
{
DSDLookForSync,
DSDSyncFound,
DSDprocessFrame,
DSDprocessNXDNVoice,
DSDprocessNXDNData,
DSDprocessDSTAR,
DSDprocessDSTAR_HD,
DSDprocessDMRvoice,
DSDprocessDMRdata,
DSDprocessDMRvoiceMS,
DSDprocessDMRdataMS,
DSDprocessDMRsyncOrSkip,
DSDprocessDMRSkipMS,
DSDprocessX2TDMAvoice,
DSDprocessX2TDMAdata,
DSDprocessProVoice,
DSDprocessYSF,
DSDprocessDPMR,
DSDprocessNXDN,
DSDprocessUnknown
} DSDFSMState;
typedef enum
{
DSDSyncP25p1P, // 0
DSDSyncP25p1N, // 1
DSDSyncX2TDMADataP, // 2
DSDSyncX2TDMAVoiceN, // 3
DSDSyncX2TDMAVoiceP, // 4
DSDSyncX2TDMADataN, // 5
DSDSyncDStarP, // 6
DSDSyncDStarN, // 7
DSDSyncNXDNP, // 8
DSDSyncNXDNN, // 9
DSDSyncDMRDataP, // 10
DSDSyncDMRDataMS, // 11
DSDSyncDMRVoiceP, // 12
DSDSyncDMRVoiceMS, // 13
DSDSyncProVoiceP, // 14
DSDSyncProVoiceN, // 15
DSDSyncNXDNDataP, // 16
DSDSyncNXDNDataN, // 17
DSDSyncDStarHeaderP, // 18
DSDSyncDStarHeaderN, // 19
DSDSyncDPMR, // 20
DSDSyncDPMRPacket, // 21
DSDSyncDPMRPayload, // 22
DSDSyncDPMREnd, // 23
DSDSyncYSF, // 24
DSDSyncNone
} DSDSyncType;
typedef enum
{
DSDStationTypeNotApplicable,
DSDBaseStation,
DSDMobileStation
} DSDStationType;
typedef enum
{
DSDMBERateNone,
DSDMBERate3600x2400, //!< D-Star
DSDMBERate3600x2450, //!< DMR, dPMR, YSF V/D type 1, NXDN
DSDMBERate7200x4400,
DSDMBERate7100x4400,
DSDMBERate2400,
DSDMBERate2450, //!< YSF V/D type 2 (does not use FEC in AMBE codec)
DSDMBERate4400
} DSDMBERate;
DSDDecoder();
~DSDDecoder();
void run(short sample);
short getFilteredSample() const { return m_dsdSymbol.getFilteredSample(); }
short getSymbolSyncSample() const { return m_dsdSymbol.getSymbolSyncSample(); }
/** DVSI support */
const unsigned char *getMbeDVFrame1() const {
return m_mbeDVFrame1;
}
bool mbeDVReady1() const {
return m_mbeDVReady1;
}
void resetMbeDV1() {
m_mbeDVReady1 = false;
}
const unsigned char *getMbeDVFrame2() const {
return m_mbeDVFrame2;
}
bool mbeDVReady2() const {
return m_mbeDVReady2;
}
void resetMbeDV2() {
m_mbeDVReady2 = false;
}
/** MBElib support */
short *getAudio1(int& nbSamples)
{
return m_mbeDecoder1.getAudio(nbSamples);
}
void resetAudio1()
{
m_mbeDecoder1.resetAudio();
}
short *getAudio2(int& nbSamples)
{
return m_mbeDecoder2.getAudio(nbSamples);
}
void resetAudio2()
{
m_mbeDecoder2.resetAudio();
}
//DSDOpts *getOpts() { return &m_opts; }
//DSDState *getState() { return &m_state; }
void setLogVerbosity(int verbosity) { m_dsdLogger.setVerbosity(verbosity); }
void setLogFile(const char *filename) { m_dsdLogger.setFile(filename); }
const DSDLogger& getLogger() const { return m_dsdLogger; }
DSDSyncType getSyncType() const
{
return m_lastSyncType;
}
DSDStationType getStationType() const { return m_stationType; }
const char *getFrameTypeText() const { return m_state.ftype; }
const char *getFrameSubtypeText() const { return m_state.fsubtype; }
int getInLevel() const { return m_dsdSymbol.getLevel(); }
int getCarrierPos() const { return m_dsdSymbol.getCarrierPos(); }
int getZeroCrossingPos() const { return m_dsdSymbol.getZeroCrossingPos(); }
int getSymbolSyncQuality() const { return m_dsdSymbol.getSymbolSyncQuality(); }
int getSamplesPerSymbol() const { return m_dsdSymbol.getSamplesPerSymbol(); }
DSDRate getDataRate() const { return m_dataRate; };
bool getVoice1On() const { return m_voice1On; }
bool getVoice2On() const { return m_voice2On; }
void setTDMAStereo(bool tdmaStereo);
void formatStatusText(char *statusText);
bool getSymbolPLLLocked() const { return m_dsdSymbol.getPLLLocked(); }
const DSDDMR& getDMRDecoder() const { return m_dsdDMR; }
const DSDDstar& getDStarDecoder() const { return m_dsdDstar; }
const DSDdPMR& getDPMRDecoder() const { return m_dsdDPMR; }
const DSDYSF& getYSFDecoder() const { return m_dsdYSF; }
const DSDNXDN& getNXDNDecoder() const { return m_dsdNXDN; }
void enableMbelib(bool enable) { m_mbelibEnable = enable; }
// Initializations:
void setQuiet();
void setVerbosity(int verbosity);
void showErrorBars();
void showSymbolTiming();
void setP25DisplayOptions(DSDShowP25 mode, bool on);
void muteEncryptedP25(bool on);
void setDecodeMode(DSDDecodeMode mode, bool on);
void setAudioGain(float gain);
void setUvQuality(int uvquality);
void setUpsampling(int upsampling);
void setStereo(bool on);
void setInvertedXTDMA(bool on);
void enableCosineFiltering(bool on);
void enableAudioOut(bool on);
void enableScanResumeAfterTDULCFrames(int nbFrames);
void setDataRate(DSDRate dataRate);
void setMyPoint(float lat, float lon) { m_myPoint.setLatLon(lat, lon); }
void setSymbolPLLLock(bool pllLock) { m_dsdSymbol.setPLLLock(pllLock); }
void setDMRBasicPrivacyKey(unsigned char key);
// parameter getters:
int upsampling() const { return m_mbeDecoder1.getUpsamplingFactor(); }
DSDMBERate getMbeRate() const { return m_mbeRate; }
void setMbeRate(DSDMBERate mbeRate) { m_mbeRate = mbeRate; }
void useHPMbelib(bool useHP) {
m_mbeDecoder1.useHP(useHP);
m_mbeDecoder2.useHP(useHP);
}
private:
typedef enum
{
signalFormatNone,
signalFormatDMR,
signalFormatDStar,
signalFormatDPMR,
signalFormatYSF,
signalFormatNXDN
} SignalFormat;
int getFrameSync();
void resetFrameSync();
void printFrameSync(const char *frametype, int offset);
void noCarrier();
void printFrameInfo();
void processFrameInit();
static int comp(const void *a, const void *b);
static int countDiff(const unsigned char *a, const unsigned char *b, unsigned char *t, unsigned int len);
DSDOpts m_opts;
DSDState m_state;
DSDLogger m_dsdLogger;
DSDFSMState m_fsmState;
DSDStationType m_stationType;
DSDDMR::DSDDMRBurstType m_dmrBurstType;
// sync engine:
int m_sync; //!< The current internal sync type
int m_dibit, m_synctest_pos;
int m_lsum;
char m_spectrum[64];
int m_t;
int m_squelchTimeoutCount;
int m_nxdnInterSyncCount;
// Symbol extraction and operations
DSDSymbol m_dsdSymbol;
// MBE decoder
char ambe_fr[4][24];
char imbe_fr[8][23];
bool m_mbelibEnable;
DSDMBERate m_mbeRate;
DSDMBEDecoder m_mbeDecoder1; //!< AMBE decoder for TDMA unique or first slot
DSDMBEDecoder m_mbeDecoder2; //!< AMBE decoder for TDMA second slot
// DVSI AMBE3000 serial device support
unsigned char m_mbeDVFrame1[18]; //!< AMBE/IMBE encoded frame for TDMA unique or first slot
bool m_mbeDVReady1; //!< AMBE/IMBE encoded frame ready status for TDMA unique or first slot
unsigned char m_mbeDVFrame2[9]; //!< AMBE encoded frame for TDMA second slot
bool m_mbeDVReady2; //!< AMBE encoded frame ready status for TDMA second slot
// Voice announcements
bool m_voice1On;
bool m_voice2On;
// Frame decoders
DSDDMR m_dsdDMR;
DSDDstar m_dsdDstar;
DSDYSF m_dsdYSF;
DSDdPMR m_dsdDPMR;
DSDNXDN m_dsdNXDN;
DSDRate m_dataRate;
DSDSyncType m_syncType;
DSDSyncType m_lastSyncType;
LocPoint m_myPoint;
// status text
SignalFormat m_signalFormat;
};
} // namespace dsdcc
#endif /* DSDCC_DSD_DECODER_H_ */