FreeCalypso > hg > gsm-net-reveng
comparison trau-decode/parse-data.c @ 77:729dbac9df82
trau-decode: factor out parse-data.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Feb 2025 05:16:35 +0000 |
parents | trau-decode/parse-main.c@d4ee42801cdc |
children |
comparison
equal
deleted
inserted
replaced
76:d4ee42801cdc | 77:729dbac9df82 |
---|---|
1 /* | |
2 * This module contains a bit of code that has been factored out of | |
3 * trau-parse program; it handles data frames. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 | |
12 static unsigned | |
13 bits_to_num(bits, nbits) | |
14 uint8_t *bits; | |
15 unsigned nbits; | |
16 { | |
17 unsigned accum; | |
18 unsigned n; | |
19 | |
20 accum = 0; | |
21 for (n = 0; n < nbits; n++) { | |
22 accum <<= 1; | |
23 if (*bits) | |
24 accum |= 1; | |
25 bits++; | |
26 } | |
27 return accum; | |
28 } | |
29 | |
30 static void | |
31 print_data_subframe(nf, bits) | |
32 uint8_t *bits; | |
33 { | |
34 unsigned nb; | |
35 | |
36 printf(" Data frame %d:", nf); | |
37 for (nb = 0; nb < 9; nb++) { | |
38 printf(" %02X", bits_to_num(bits, 8)); | |
39 bits += 8; | |
40 } | |
41 putchar('\n'); | |
42 } | |
43 | |
44 void | |
45 print_data_frame(frame_bits) | |
46 uint8_t *frame_bits; | |
47 { | |
48 printf(" C6-C15: %u%u%u%u%u%u%u%u%u%u\n", frame_bits[22], | |
49 frame_bits[23], frame_bits[24], frame_bits[25], | |
50 frame_bits[26], frame_bits[27], frame_bits[28], | |
51 frame_bits[29], frame_bits[30], frame_bits[31]); | |
52 print_data_subframe(0, frame_bits + 4 * 8); | |
53 print_data_subframe(1, frame_bits + 13 * 8); | |
54 print_data_subframe(2, frame_bits + 22 * 8); | |
55 print_data_subframe(3, frame_bits + 31 * 8); | |
56 } | |
57 | |
58 void | |
59 print_edata_frame(frame_bits) | |
60 uint8_t *frame_bits; | |
61 { | |
62 printf(" C6-C13: %u%u%u%u%u%u%u%u\n", frame_bits[22], | |
63 frame_bits[23], frame_bits[24], frame_bits[25], | |
64 frame_bits[26], frame_bits[27], frame_bits[28], | |
65 frame_bits[29]); | |
66 printf(" M1=%u M2=%u\n", frame_bits[30], frame_bits[31]); | |
67 } |