-
Notifications
You must be signed in to change notification settings - Fork 212
/
multimon.h
372 lines (314 loc) · 10.9 KB
/
multimon.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
* multimon.h -- Monitor for many different modulation formats
*
* Copyright (C) 1996
* Thomas Sailer ([email protected], [email protected])
*
* Added eas parts - A. Maitland Bottoms 27 June 2000
*
* Copyright (C) 2012-2014
* Elias Oenal ([email protected])
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ---------------------------------------------------------------------- */
#ifndef _MULTIMON_H
#define _MULTIMON_H
#include <stdint.h>
#include <stdbool.h>
#ifdef _MSC_VER
#include "msvc_support.h"
#endif
/* ---------------------------------------------------------------------- */
extern const float costabf[0x400];
#define COS(x) costabf[(((x)>>6)&0x3ffu)]
#define SIN(x) COS((x)+0xc000)
/* ---------------------------------------------------------------------- */
enum
{
POCSAG_MODE_STANDARD = 0,
POCSAG_MODE_NUMERIC = 1,
POCSAG_MODE_ALPHA = 2,
POCSAG_MODE_SKYPER = 3,
POCSAG_MODE_AUTO = 4,
};
enum EAS_L2_State
{
EAS_L2_IDLE = 0,
EAS_L2_HEADER_SEARCH = 1,
EAS_L2_READING_MESSAGE = 2,
EAS_L2_READING_EOM = 3,
};
enum EAS_L1_State
{
EAS_L1_IDLE = 0,
EAS_L1_SYNC = 1,
};
struct l2_state_clipfsk {
unsigned char rxbuf[512];
unsigned char *rxptr;
uint32_t rxstate;
uint32_t rxbitstream;
uint32_t rxbitbuf;
};
struct l2_state_fmsfsk {
unsigned char rxbuf[512];
unsigned char *rxptr;
uint32_t rxstate; // used to track the SYNC pattern
uint64_t rxbitstream; // holds RXed bits
uint32_t rxbitcount; // counts RXed bits
};
struct demod_state {
const struct demod_param *dem_par;
union {
struct l2_state_fmsfsk fmsfsk;
struct l2_state_clipfsk clipfsk;
struct l2_state_uart {
unsigned char rxbuf[8192];
unsigned char *rxptr;
uint32_t rxstate;
uint32_t rxbitstream;
uint32_t rxbitbuf;
} uart;
struct l2_state_hdlc {
unsigned char rxbuf[512];
unsigned char *rxptr;
uint32_t rxstate;
uint32_t rxbitstream;
uint32_t rxbitbuf;
} hdlc;
struct l2_state_eas {
char last_message[269];
char msg_buf[4][269];
char head_buf[4];
uint32_t headlen;
uint32_t msglen;
uint32_t msgno;
uint32_t state;
} eas;
struct l2_state_pocsag {
uint32_t rx_data;
unsigned char state; // state machine
unsigned char rx_bit; // bit counter, counts 32bits
unsigned char rx_word;
int32_t function; // POCSAG function
int32_t address; // POCSAG address
unsigned char buffer[512];
uint32_t numnibbles;
uint32_t pocsag_total_error_count;
uint32_t pocsag_corrected_error_count;
uint32_t pocsag_corrected_1bit_error_count;
uint32_t pocsag_corrected_2bit_error_count;
uint32_t pocsag_uncorrected_error_count;
uint32_t pocsag_total_bits_received;
uint32_t pocsag_bits_processed_while_synced;
uint32_t pocsag_bits_processed_while_not_synced;
} pocsag;
} l2;
union {
struct l1_state_poc5 {
uint32_t dcd_shreg;
uint32_t sphase;
uint32_t subsamp;
} poc5;
struct l1_state_poc12 {
uint32_t dcd_shreg;
uint32_t sphase;
uint32_t subsamp;
} poc12;
struct l1_state_poc24 {
uint32_t dcd_shreg;
uint32_t sphase;
} poc24;
struct l1_state_eas {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned char lasts;
unsigned int subsamp;
unsigned char byte_counter;
int dcd_integrator;
uint32_t state;
} eas;
struct l1_state_ufsk12 {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned int subsamp;
} ufsk12;
struct l1_state_clipfsk {
unsigned int dcd_shreg;
unsigned int sphase;
uint32_t subsamp;
} clipfsk;
struct l1_state_fmsfsk {
unsigned int dcd_shreg;
unsigned int sphase;
uint32_t subsamp;
} fmsfsk;
struct l1_state_afsk12 {
uint32_t dcd_shreg;
uint32_t sphase;
uint32_t lasts;
uint32_t subsamp;
} afsk12;
struct l1_state_afsk24 {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned int lasts;
} afsk24;
struct l1_state_hapn48 {
unsigned int shreg;
unsigned int sphase;
float lvllo, lvlhi;
} hapn48;
struct l1_state_fsk96 {
unsigned int dcd_shreg;
unsigned int sphase;
unsigned int descram;
} fsk96;
struct l1_state_dtmf {
unsigned int ph[8];
float energy[4];
float tenergy[4][16];
int blkcount;
int lastch;
} dtmf;
struct l1_state_selcall {
unsigned int ph[16];
float energy[4];
float tenergy[4][32];
int blkcount;
int lastch;
int timeout;
} selcall;
struct l1_state_morse {
uint64_t current_sequence;
int_fast16_t threshold_ctr;
int_fast32_t detection_threshold;
int_fast32_t filtered;
int_fast32_t samples_since_change;
int_fast32_t signal_max;
int_fast32_t glitches;
int_fast32_t erroneous_chars;
int_fast32_t decoded_chars;
int_fast16_t time_unit_dit_dah_samples;
int_fast16_t time_unit_gaps_samples;
int_fast16_t lowpass_strength;
int_fast16_t holdoff_samples;
int_fast8_t current_state; // High = 1, Low = 0
} morse;
struct l1_state_dumpcsv {
uint32_t current_sequence;
} dumpcsv;
struct Flex * flex;
struct Flex_Next * flex_next;
struct l1_state_x10 {
uint32_t current_sequence;
uint32_t last_rise;
short current_state;
short current_stage;
char b[4];
char bi;
char bstring[42];
} x10;
#ifndef NO_X11
struct l1_state_scope {
int datalen;
int dispnum;
float data[512];
} scope;
#endif
} l1;
};
typedef struct buffer
{
const short* sbuffer;
const float* fbuffer;
} buffer_t;
struct demod_param {
const char *name;
bool float_samples; // if false samples are short instead
unsigned int samplerate;
unsigned int overlap;
void (*init)(struct demod_state *s);
void (*demod)(struct demod_state *s, buffer_t buffer, int length);
void (*deinit)(struct demod_state *s);
};
/* ---------------------------------------------------------------------- */
extern const struct demod_param demod_poc5;
extern const struct demod_param demod_poc12;
extern const struct demod_param demod_poc24;
extern const struct demod_param demod_flex;
extern const struct demod_param demod_flex_next;
extern const struct demod_param demod_eas;
extern const struct demod_param demod_ufsk1200;
extern const struct demod_param demod_clipfsk;
extern const struct demod_param demod_fmsfsk;
extern const struct demod_param demod_afsk1200;
extern const struct demod_param demod_afsk2400;
extern const struct demod_param demod_afsk2400_2;
extern const struct demod_param demod_afsk2400_3;
extern const struct demod_param demod_hapn4800;
extern const struct demod_param demod_fsk9600;
extern const struct demod_param demod_dtmf;
extern const struct demod_param demod_zvei1;
extern const struct demod_param demod_zvei2;
extern const struct demod_param demod_zvei3;
extern const struct demod_param demod_dzvei;
extern const struct demod_param demod_pzvei;
extern const struct demod_param demod_eea;
extern const struct demod_param demod_eia;
extern const struct demod_param demod_ccir;
extern const struct demod_param demod_morse;
extern const struct demod_param demod_x10;
extern const struct demod_param demod_dumpcsv;
#ifndef NO_X11
extern const struct demod_param demod_scope;
#endif
#ifndef NO_X11
#define SCOPE_DEMOD , &demod_scope
#else
#define SCOPE_DEMOD
#endif
#define ALL_DEMOD &demod_poc5, &demod_poc12, &demod_poc24, &demod_flex, &demod_flex_next, &demod_eas, &demod_ufsk1200, &demod_clipfsk, &demod_fmsfsk, \
&demod_afsk1200, &demod_afsk2400, &demod_afsk2400_2, &demod_afsk2400_3, &demod_hapn4800, \
&demod_fsk9600, &demod_dtmf, &demod_zvei1, &demod_zvei2, &demod_zvei3, &demod_dzvei, \
&demod_pzvei, &demod_eea, &demod_eia, &demod_ccir, &demod_morse, &demod_dumpcsv, &demod_x10 SCOPE_DEMOD
/* ---------------------------------------------------------------------- */
void _verbprintf(int verb_level, const char *fmt, ...);
#if !defined(MAX_VERBOSE_LEVEL)
# define MAX_VERBOSE_LEVEL 0
#endif
#define verbprintf(level, ...) \
do { if (level <= MAX_VERBOSE_LEVEL) _verbprintf(level, __VA_ARGS__); } while (0)
void hdlc_init(struct demod_state *s);
void hdlc_rxbit(struct demod_state *s, int bit);
void uart_init(struct demod_state *s);
void uart_rxbit(struct demod_state *s, int bit);
void clip_init(struct demod_state *s);
void clip_rxbit(struct demod_state *s, int bit);
void fms_init(struct demod_state *s);
void fms_rxbit(struct demod_state *s, int bit);
void pocsag_init(struct demod_state *s);
void pocsag_rxbit(struct demod_state *s, int32_t bit);
void pocsag_deinit(struct demod_state *s);
void selcall_init(struct demod_state *s);
void selcall_demod(struct demod_state *s, const float *buffer, int length,
const unsigned int *selcall_freq, const char *const name);
void selcall_deinit(struct demod_state *s);
void xdisp_terminate(int cnum);
int xdisp_start(void);
int xdisp_update(int cnum, float *f);
/* ---------------------------------------------------------------------- */
#endif /* _MULTIMON_H */