GNU Radio's SATNOGS Package
amsat_duv_decoder.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
4 *
5 * Copyright (C) 2019, Libre Space Foundation <http://libre.space>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef INCLUDED_SATNOGS_AMSAT_DUV_DECODER_H
22#define INCLUDED_SATNOGS_AMSAT_DUV_DECODER_H
23
26#include <deque>
27#include <string>
28
29namespace gr {
30namespace satnogs {
31
32/*!
33 * \brief AMSAT 8b10b + CCSDS RS DUV decoder
34 *
35 */
37{
38public:
39 static const size_t amsat_fox_duv_frame_size;
40
41 static const uint8_t amsat_fox_spacecraft_id[];
42 using sptr = std::shared_ptr<amsat_duv_decoder>;
43 static sptr make(const std::string& control_symbol, size_t max_frame_len = 96);
44
45 amsat_duv_decoder(const std::string& control_symbol, size_t max_frame_len);
47
48 decoder_status_t decode(const void* in, int len);
49
50 void reset();
51
52private:
53 typedef enum { SEARCH_SYNC, DECODING } d_state_t;
54
55 size_t d_erasure_cnt;
56 uint16_t d_control_symbol_pos;
57 uint16_t d_control_symbol_neg;
58 uint16_t d_data_reg;
59 uint16_t d_wrong_bits;
60 uint16_t d_wrong_bits_neg;
61 uint8_t d_nwrong;
62 uint8_t d_nwrong_neg;
63 size_t d_word_cnt;
64
65 uint8_t* d_8b_words;
66 int* d_erasures_indexes;
67 d_state_t d_state;
68 size_t d_bitstream_idx;
69 std::deque<uint8_t> d_bitstream;
70
71 bool set_access_code(const std::string& control_symbol);
72
73 void process_10b(uint16_t word, size_t write_pos);
74
75 inline uint16_t pack_10b_word(size_t idx);
76
77 int d_lookup_8b10b[2][256] = { // RD = -1 cases
78 {
79 /* 00 */ 0x274,
80 /* 01 */ 0x1d4,
81 /* 02 */ 0x2d4,
82 /* 03 */ 0x71b,
83 /* 04 */ 0x354,
84 /* 05 */ 0x69b,
85 /* 06 */ 0x59b,
86 /* 07 */ 0x78b,
87 /* 08 */ 0x394,
88 /* 09 */ 0x65b,
89 /* 0a */ 0x55b,
90 /* 0b */ 0x74b,
91 /* 0c */ 0x4db,
92 /* 0d */ 0x6cb,
93 /* 0e */ 0x5cb,
94 /* 0f */ 0x174,
95 /* 10 */ 0x1b4,
96 /* 11 */ 0x63b,
97 /* 12 */ 0x53b,
98 /* 13 */ 0x72b,
99 /* 14 */ 0x4bb,
100 /* 15 */ 0x6ab,
101 /* 16 */ 0x5ab,
102 /* 17 */ 0x3a4,
103 /* 18 */ 0x334,
104 /* 19 */ 0x66b,
105 /* 1a */ 0x56b,
106 /* 1b */ 0x364,
107 /* 1c */ 0x4eb,
108 /* 1d */ 0x2e4,
109 /* 1e */ 0x1e4,
110 /* 1f */ 0x2b4,
111 /* 20 */ 0x679,
112 /* 21 */ 0x5d9,
113 /* 22 */ 0x6d9,
114 /* 23 */ 0x319,
115 /* 24 */ 0x759,
116 /* 25 */ 0x299,
117 /* 26 */ 0x199,
118 /* 27 */ 0x389,
119 /* 28 */ 0x799,
120 /* 29 */ 0x259,
121 /* 2a */ 0x159,
122 /* 2b */ 0x349,
123 /* 2c */ 0x0d9,
124 /* 2d */ 0x2c9,
125 /* 2e */ 0x1c9,
126 /* 2f */ 0x579,
127 /* 30 */ 0x5b9,
128 /* 31 */ 0x239,
129 /* 32 */ 0x139,
130 /* 33 */ 0x329,
131 /* 34 */ 0x0b9,
132 /* 35 */ 0x2a9,
133 /* 36 */ 0x1a9,
134 /* 37 */ 0x7a9,
135 /* 38 */ 0x739,
136 /* 39 */ 0x269,
137 /* 3a */ 0x169,
138 /* 3b */ 0x769,
139 /* 3c */ 0x0e9,
140 /* 3d */ 0x6e9,
141 /* 3e */ 0x5e9,
142 /* 3f */ 0x6b9,
143 /* 40 */ 0x675,
144 /* 41 */ 0x5d5,
145 /* 42 */ 0x6d5,
146 /* 43 */ 0x315,
147 /* 44 */ 0x755,
148 /* 45 */ 0x295,
149 /* 46 */ 0x195,
150 /* 47 */ 0x385,
151 /* 48 */ 0x795,
152 /* 49 */ 0x255,
153 /* 4a */ 0x155,
154 /* 4b */ 0x345,
155 /* 4c */ 0x0d5,
156 /* 4d */ 0x2c5,
157 /* 4e */ 0x1c5,
158 /* 4f */ 0x575,
159 /* 50 */ 0x5b5,
160 /* 51 */ 0x235,
161 /* 52 */ 0x135,
162 /* 53 */ 0x325,
163 /* 54 */ 0x0b5,
164 /* 55 */ 0x2a5,
165 /* 56 */ 0x1a5,
166 /* 57 */ 0x7a5,
167 /* 58 */ 0x735,
168 /* 59 */ 0x265,
169 /* 5a */ 0x165,
170 /* 5b */ 0x765,
171 /* 5c */ 0x0e5,
172 /* 5d */ 0x6e5,
173 /* 5e */ 0x5e5,
174 /* 5f */ 0x6b5,
175 /* 60 */ 0x673,
176 /* 61 */ 0x5d3,
177 /* 62 */ 0x6d3,
178 /* 63 */ 0x31c,
179 /* 64 */ 0x753,
180 /* 65 */ 0x29c,
181 /* 66 */ 0x19c,
182 /* 67 */ 0x38c,
183 /* 68 */ 0x793,
184 /* 69 */ 0x25c,
185 /* 6a */ 0x15c,
186 /* 6b */ 0x34c,
187 /* 6c */ 0x0dc,
188 /* 6d */ 0x2cc,
189 /* 6e */ 0x1cc,
190 /* 6f */ 0x573,
191 /* 70 */ 0x5b3,
192 /* 71 */ 0x23c,
193 /* 72 */ 0x13c,
194 /* 73 */ 0x32c,
195 /* 74 */ 0x0bc,
196 /* 75 */ 0x2ac,
197 /* 76 */ 0x1ac,
198 /* 77 */ 0x7a3,
199 /* 78 */ 0x733,
200 /* 79 */ 0x26c,
201 /* 7a */ 0x16c,
202 /* 7b */ 0x763,
203 /* 7c */ 0x0ec,
204 /* 7d */ 0x6e3,
205 /* 7e */ 0x5e3,
206 /* 7f */ 0x6b3,
207 /* 80 */ 0x272,
208 /* 81 */ 0x1d2,
209 /* 82 */ 0x2d2,
210 /* 83 */ 0x71d,
211 /* 84 */ 0x352,
212 /* 85 */ 0x69d,
213 /* 86 */ 0x59d,
214 /* 87 */ 0x78d,
215 /* 88 */ 0x392,
216 /* 89 */ 0x65d,
217 /* 8a */ 0x55d,
218 /* 8b */ 0x74d,
219 /* 8c */ 0x4dd,
220 /* 8d */ 0x6cd,
221 /* 8e */ 0x5cd,
222 /* 8f */ 0x172,
223 /* 90 */ 0x1b2,
224 /* 91 */ 0x63d,
225 /* 92 */ 0x53d,
226 /* 93 */ 0x72d,
227 /* 94 */ 0x4bd,
228 /* 95 */ 0x6ad,
229 /* 96 */ 0x5ad,
230 /* 97 */ 0x3a2,
231 /* 98 */ 0x332,
232 /* 99 */ 0x66d,
233 /* 9a */ 0x56d,
234 /* 9b */ 0x362,
235 /* 9c */ 0x4ed,
236 /* 9d */ 0x2e2,
237 /* 9e */ 0x1e2,
238 /* 9f */ 0x2b2,
239 /* a0 */ 0x67a,
240 /* a1 */ 0x5da,
241 /* a2 */ 0x6da,
242 /* a3 */ 0x31a,
243 /* a4 */ 0x75a,
244 /* a5 */ 0x29a,
245 /* a6 */ 0x19a,
246 /* a7 */ 0x38a,
247 /* a8 */ 0x79a,
248 /* a9 */ 0x25a,
249 /* aa */ 0x15a,
250 /* ab */ 0x34a,
251 /* ac */ 0x0da,
252 /* ad */ 0x2ca,
253 /* ae */ 0x1ca,
254 /* af */ 0x57a,
255 /* b0 */ 0x5ba,
256 /* b1 */ 0x23a,
257 /* b2 */ 0x13a,
258 /* b3 */ 0x32a,
259 /* b4 */ 0x0ba,
260 /* b5 */ 0x2aa,
261 /* b6 */ 0x1aa,
262 /* b7 */ 0x7aa,
263 /* b8 */ 0x73a,
264 /* b9 */ 0x26a,
265 /* ba */ 0x16a,
266 /* bb */ 0x76a,
267 /* bc */ 0x0ea,
268 /* bd */ 0x6ea,
269 /* be */ 0x5ea,
270 /* bf */ 0x6ba,
271 /* c0 */ 0x676,
272 /* c1 */ 0x5d6,
273 /* c2 */ 0x6d6,
274 /* c3 */ 0x316,
275 /* c4 */ 0x756,
276 /* c5 */ 0x296,
277 /* c6 */ 0x196,
278 /* c7 */ 0x386,
279 /* c8 */ 0x796,
280 /* c9 */ 0x256,
281 /* ca */ 0x156,
282 /* cb */ 0x346,
283 /* cc */ 0x0d6,
284 /* cd */ 0x2c6,
285 /* ce */ 0x1c6,
286 /* cf */ 0x576,
287 /* d0 */ 0x5b6,
288 /* d1 */ 0x236,
289 /* d2 */ 0x136,
290 /* d3 */ 0x326,
291 /* d4 */ 0x0b6,
292 /* d5 */ 0x2a6,
293 /* d6 */ 0x1a6,
294 /* d7 */ 0x7a6,
295 /* d8 */ 0x736,
296 /* d9 */ 0x266,
297 /* da */ 0x166,
298 /* db */ 0x766,
299 /* dc */ 0x0e6,
300 /* dd */ 0x6e6,
301 /* de */ 0x5e6,
302 /* df */ 0x6b6,
303 /* e0 */ 0x271,
304 /* e1 */ 0x1d1,
305 /* e2 */ 0x2d1,
306 /* e3 */ 0x71e,
307 /* e4 */ 0x351,
308 /* e5 */ 0x69e,
309 /* e6 */ 0x59e,
310 /* e7 */ 0x78e,
311 /* e8 */ 0x391,
312 /* e9 */ 0x65e,
313 /* ea */ 0x55e,
314 /* eb */ 0x74e,
315 /* ec */ 0x4de,
316 /* ed */ 0x6ce,
317 /* ee */ 0x5ce,
318 /* ef */ 0x171,
319 /* f0 */ 0x1b1,
320 /* f1 */ 0x637,
321 /* f2 */ 0x537,
322 /* f3 */ 0x72e,
323 /* f4 */ 0x4b7,
324 /* f5 */ 0x6ae,
325 /* f6 */ 0x5ae,
326 /* f7 */ 0x3a1,
327 /* f8 */ 0x331,
328 /* f9 */ 0x66e,
329 /* fa */ 0x56e,
330 /* fb */ 0x361,
331 /* fc */ 0x4ee,
332 /* fd */ 0x2e1,
333 /* fe */ 0x1e1,
334 /* ff */ 0x2b1,
335 }, // RD = +1 cases
336 {
337 /* 00 */ 0x58b,
338 /* 01 */ 0x62b,
339 /* 02 */ 0x52b,
340 /* 03 */ 0x314,
341 /* 04 */ 0x4ab,
342 /* 05 */ 0x294,
343 /* 06 */ 0x194,
344 /* 07 */ 0x074,
345 /* 08 */ 0x46b,
346 /* 09 */ 0x254,
347 /* 0a */ 0x154,
348 /* 0b */ 0x344,
349 /* 0c */ 0x0d4,
350 /* 0d */ 0x2c4,
351 /* 0e */ 0x1c4,
352 /* 0f */ 0x68b,
353 /* 10 */ 0x64b,
354 /* 11 */ 0x234,
355 /* 12 */ 0x134,
356 /* 13 */ 0x324,
357 /* 14 */ 0x0b4,
358 /* 15 */ 0x2a4,
359 /* 16 */ 0x1a4,
360 /* 17 */ 0x45b,
361 /* 18 */ 0x4cb,
362 /* 19 */ 0x264,
363 /* 1a */ 0x164,
364 /* 1b */ 0x49b,
365 /* 1c */ 0x0e4,
366 /* 1d */ 0x51b,
367 /* 1e */ 0x61b,
368 /* 1f */ 0x54b,
369 /* 20 */ 0x189,
370 /* 21 */ 0x229,
371 /* 22 */ 0x129,
372 /* 23 */ 0x719,
373 /* 24 */ 0x0a9,
374 /* 25 */ 0x699,
375 /* 26 */ 0x599,
376 /* 27 */ 0x479,
377 /* 28 */ 0x069,
378 /* 29 */ 0x659,
379 /* 2a */ 0x559,
380 /* 2b */ 0x749,
381 /* 2c */ 0x4d9,
382 /* 2d */ 0x6c9,
383 /* 2e */ 0x5c9,
384 /* 2f */ 0x289,
385 /* 30 */ 0x249,
386 /* 31 */ 0x639,
387 /* 32 */ 0x539,
388 /* 33 */ 0x729,
389 /* 34 */ 0x4b9,
390 /* 35 */ 0x6a9,
391 /* 36 */ 0x5a9,
392 /* 37 */ 0x059,
393 /* 38 */ 0x0c9,
394 /* 39 */ 0x669,
395 /* 3a */ 0x569,
396 /* 3b */ 0x099,
397 /* 3c */ 0x4e9,
398 /* 3d */ 0x119,
399 /* 3e */ 0x219,
400 /* 3f */ 0x149,
401 /* 40 */ 0x185,
402 /* 41 */ 0x225,
403 /* 42 */ 0x125,
404 /* 43 */ 0x715,
405 /* 44 */ 0x0a5,
406 /* 45 */ 0x695,
407 /* 46 */ 0x595,
408 /* 47 */ 0x475,
409 /* 48 */ 0x065,
410 /* 49 */ 0x655,
411 /* 4a */ 0x555,
412 /* 4b */ 0x745,
413 /* 4c */ 0x4d5,
414 /* 4d */ 0x6c5,
415 /* 4e */ 0x5c5,
416 /* 4f */ 0x285,
417 /* 50 */ 0x245,
418 /* 51 */ 0x635,
419 /* 52 */ 0x535,
420 /* 53 */ 0x725,
421 /* 54 */ 0x4b5,
422 /* 55 */ 0x6a5,
423 /* 56 */ 0x5a5,
424 /* 57 */ 0x055,
425 /* 58 */ 0x0c5,
426 /* 59 */ 0x665,
427 /* 5a */ 0x565,
428 /* 5b */ 0x095,
429 /* 5c */ 0x4e5,
430 /* 5d */ 0x115,
431 /* 5e */ 0x215,
432 /* 5f */ 0x145,
433 /* 60 */ 0x18c,
434 /* 61 */ 0x22c,
435 /* 62 */ 0x12c,
436 /* 63 */ 0x713,
437 /* 64 */ 0x0ac,
438 /* 65 */ 0x693,
439 /* 66 */ 0x593,
440 /* 67 */ 0x473,
441 /* 68 */ 0x06c,
442 /* 69 */ 0x653,
443 /* 6a */ 0x553,
444 /* 6b */ 0x743,
445 /* 6c */ 0x4d3,
446 /* 6d */ 0x6c3,
447 /* 6e */ 0x5c3,
448 /* 6f */ 0x28c,
449 /* 70 */ 0x24c,
450 /* 71 */ 0x633,
451 /* 72 */ 0x533,
452 /* 73 */ 0x723,
453 /* 74 */ 0x4b3,
454 /* 75 */ 0x6a3,
455 /* 76 */ 0x5a3,
456 /* 77 */ 0x05c,
457 /* 78 */ 0x0cc,
458 /* 79 */ 0x663,
459 /* 7a */ 0x563,
460 /* 7b */ 0x09c,
461 /* 7c */ 0x4e3,
462 /* 7d */ 0x11c,
463 /* 7e */ 0x21c,
464 /* 7f */ 0x14c,
465 /* 80 */ 0x58d,
466 /* 81 */ 0x62d,
467 /* 82 */ 0x52d,
468 /* 83 */ 0x312,
469 /* 84 */ 0x4ad,
470 /* 85 */ 0x292,
471 /* 86 */ 0x192,
472 /* 87 */ 0x072,
473 /* 88 */ 0x46d,
474 /* 89 */ 0x252,
475 /* 8a */ 0x152,
476 /* 8b */ 0x342,
477 /* 8c */ 0x0d2,
478 /* 8d */ 0x2c2,
479 /* 8e */ 0x1c2,
480 /* 8f */ 0x68d,
481 /* 90 */ 0x64d,
482 /* 91 */ 0x232,
483 /* 92 */ 0x132,
484 /* 93 */ 0x322,
485 /* 94 */ 0x0b2,
486 /* 95 */ 0x2a2,
487 /* 96 */ 0x1a2,
488 /* 97 */ 0x45d,
489 /* 98 */ 0x4cd,
490 /* 99 */ 0x262,
491 /* 9a */ 0x162,
492 /* 9b */ 0x49d,
493 /* 9c */ 0x0e2,
494 /* 9d */ 0x51d,
495 /* 9e */ 0x61d,
496 /* 9f */ 0x54d,
497 /* a0 */ 0x18a,
498 /* a1 */ 0x22a,
499 /* a2 */ 0x12a,
500 /* a3 */ 0x71a,
501 /* a4 */ 0x0aa,
502 /* a5 */ 0x69a,
503 /* a6 */ 0x59a,
504 /* a7 */ 0x47a,
505 /* a8 */ 0x06a,
506 /* a9 */ 0x65a,
507 /* aa */ 0x55a,
508 /* ab */ 0x74a,
509 /* ac */ 0x4da,
510 /* ad */ 0x6ca,
511 /* ae */ 0x5ca,
512 /* af */ 0x28a,
513 /* b0 */ 0x24a,
514 /* b1 */ 0x63a,
515 /* b2 */ 0x53a,
516 /* b3 */ 0x72a,
517 /* b4 */ 0x4ba,
518 /* b5 */ 0x6aa,
519 /* b6 */ 0x5aa,
520 /* b7 */ 0x05a,
521 /* b8 */ 0x0ca,
522 /* b9 */ 0x66a,
523 /* ba */ 0x56a,
524 /* bb */ 0x09a,
525 /* bc */ 0x4ea,
526 /* bd */ 0x11a,
527 /* be */ 0x21a,
528 /* bf */ 0x14a,
529 /* c0 */ 0x186,
530 /* c1 */ 0x226,
531 /* c2 */ 0x126,
532 /* c3 */ 0x716,
533 /* c4 */ 0x0a6,
534 /* c5 */ 0x696,
535 /* c6 */ 0x596,
536 /* c7 */ 0x476,
537 /* c8 */ 0x066,
538 /* c9 */ 0x656,
539 /* ca */ 0x556,
540 /* cb */ 0x746,
541 /* cc */ 0x4d6,
542 /* cd */ 0x6c6,
543 /* ce */ 0x5c6,
544 /* cf */ 0x286,
545 /* d0 */ 0x246,
546 /* d1 */ 0x636,
547 /* d2 */ 0x536,
548 /* d3 */ 0x726,
549 /* d4 */ 0x4b6,
550 /* d5 */ 0x6a6,
551 /* d6 */ 0x5a6,
552 /* d7 */ 0x056,
553 /* d8 */ 0x0c6,
554 /* d9 */ 0x666,
555 /* da */ 0x566,
556 /* db */ 0x096,
557 /* dc */ 0x4e6,
558 /* dd */ 0x116,
559 /* de */ 0x216,
560 /* df */ 0x146,
561 /* e0 */ 0x58e,
562 /* e1 */ 0x62e,
563 /* e2 */ 0x52e,
564 /* e3 */ 0x311,
565 /* e4 */ 0x4ae,
566 /* e5 */ 0x291,
567 /* e6 */ 0x191,
568 /* e7 */ 0x071,
569 /* e8 */ 0x46e,
570 /* e9 */ 0x251,
571 /* ea */ 0x151,
572 /* eb */ 0x348,
573 /* ec */ 0x0d1,
574 /* ed */ 0x2c8,
575 /* ee */ 0x1c8,
576 /* ef */ 0x68e,
577 /* f0 */ 0x64e,
578 /* f1 */ 0x231,
579 /* f2 */ 0x131,
580 /* f3 */ 0x321,
581 /* f4 */ 0x0b1,
582 /* f5 */ 0x2a1,
583 /* f6 */ 0x1a1,
584 /* f7 */ 0x45e,
585 /* f8 */ 0x4ce,
586 /* f9 */ 0x261,
587 /* fa */ 0x161,
588 /* fb */ 0x49e,
589 /* fc */ 0x0e1,
590 /* fd */ 0x51e,
591 /* fe */ 0x61e,
592 /* ff */ 0x54e,
593 }
594 };
595};
596
597} // namespace satnogs
598} // namespace gr
599
600#endif /* INCLUDED_SATNOGS_AMSAT_DUV_DECODER_H */
#define SATNOGS_API
Definition: api.h:19
AMSAT 8b10b + CCSDS RS DUV decoder.
Definition: amsat_duv_decoder.h:37
static const size_t amsat_fox_duv_frame_size
Definition: amsat_duv_decoder.h:39
std::shared_ptr< amsat_duv_decoder > sptr
Definition: amsat_duv_decoder.h:42
amsat_duv_decoder(const std::string &control_symbol, size_t max_frame_len)
decoder_status_t decode(const void *in, int len)
static sptr make(const std::string &control_symbol, size_t max_frame_len=96)
Abstract class that provided the API for the c decoders.
Definition: decoder.h:71
class decoder_status decoder_status_t
Definition: decoder.h:56
Definition: amsat_duv_decoder.h:29