comparison miscutil/tw5a-dump.c @ 523:86d4ec69b36c

miscutil: new program tw5a-dump
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 04:13:28 +0000
parents miscutil/gsmrec-dump.c@b5f8ea41362b
children
comparison
equal deleted inserted replaced
522:4d2cccaeb4a7 523:86d4ec69b36c
1 /*
2 * This program reads a TW-TS-005 Annex A hexadecimal file
3 * and dumps all frames in human-readable form.
4 */
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <strings.h>
11 #include "../libgsmfr2/tw_gsmfr.h"
12 #include "../libgsmefr/gsm_efr.h"
13 #include "../libtest/tw5reader.h"
14
15 static void
16 dump_fr_frame(frame)
17 uint8_t *frame;
18 {
19 int16_t params[GSMFR_NUM_PARAMS];
20 int i, j, n;
21
22 printf(" SID=%d LARc", gsmfr_preproc_sid_classify(frame));
23 gsmfr_unpack_to_array(frame, params);
24 n = 0;
25 for (i = 0; i < 8; i++)
26 printf(" %d", params[n++]);
27 if (!bcmp(frame, gsmfr_decoder_homing_frame, GSMFR_RTP_FRAME_LEN))
28 fputs(" (DHF)", stdout);
29 putchar('\n');
30 for (i = 0; i < 4; i++) {
31 putchar(' ');
32 for (j = 0; j < 17; j++)
33 printf(" %d", params[n++]);
34 putchar('\n');
35 }
36 }
37
38 static void
39 dump_efr_frame(frame)
40 uint8_t *frame;
41 {
42 int16_t params[EFR_NUM_PARAMS];
43 int i, j, n;
44
45 printf(" SID=%d LPC", EFR_sid_classify(frame));
46 EFR_frame2params(frame, params);
47 n = 0;
48 for (i = 0; i < 5; i++)
49 printf(" %d", params[n++]);
50 if (!bcmp(frame, EFR_decoder_homing_frame, EFR_RTP_FRAME_LEN))
51 fputs(" (DHF)", stdout);
52 putchar('\n');
53 for (i = 0; i < 4; i++) {
54 putchar(' ');
55 for (j = 0; j < 13; j++)
56 printf(" %d", params[n++]);
57 putchar('\n');
58 }
59 }
60
61 main(argc, argv)
62 char **argv;
63 {
64 FILE *hexf;
65 unsigned lineno;
66 uint8_t frame[TWTS005_MAX_FRAME];
67 unsigned frame_len, bfi;
68 int rc;
69
70 if (argc != 2) {
71 fprintf(stderr, "usage: %s hex-file\n", argv[0]);
72 exit(1);
73 }
74 hexf = fopen(argv[1], "r");
75 if (!hexf) {
76 perror(argv[1]);
77 exit(1);
78 }
79 lineno = 0;
80 for (;;) {
81 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len);
82 if (rc < 0) {
83 fprintf(stderr, "%s line %u: not valid TW-TS-005\n",
84 argv[1], lineno);
85 exit(1);
86 }
87 if (!rc)
88 break;
89 switch (frame_len) {
90 case 0:
91 printf("line %u: NULL frame\n", lineno);
92 break;
93 case 1:
94 if ((frame[0] & 0xF6) != 0xE6)
95 goto invalid;
96 printf("line %u: No_Data frame\n", lineno);
97 printf(" TEH=%02X (DTXd=%u TAF=%u)\n", frame[0],
98 (frame[0] >> 3) & 1, frame[0] & 1);
99 break;
100 case GSMFR_RTP_FRAME_LEN:
101 if ((frame[0] & 0xF0) != 0xD0)
102 goto invalid;
103 printf("line %u: FR basic frame\n", lineno);
104 dump_fr_frame(frame);
105 break;
106 case GSMFR_RTP_FRAME_LEN+1:
107 if ((frame[0] & 0xF4) != 0xE0)
108 goto invalid;
109 if ((frame[1] & 0xF0) != 0xD0)
110 goto invalid;
111 bfi = (frame[0] >> 1) & 1;
112 printf("line %u: FR %s frame\n", lineno,
113 bfi ? "bad" : "extended");
114 printf(" TEH=%02X (DTXd=%u BFI=%u TAF=%u)\n", frame[0],
115 (frame[0] >> 3) & 1, bfi, frame[0] & 1);
116 dump_fr_frame(frame + 1);
117 break;
118 case EFR_RTP_FRAME_LEN:
119 if ((frame[0] & 0xF0) != 0xC0)
120 goto invalid;
121 printf("line %u: EFR basic frame\n", lineno);
122 dump_efr_frame(frame);
123 break;
124 case EFR_RTP_FRAME_LEN+1:
125 if ((frame[0] & 0xF4) != 0xE0)
126 goto invalid;
127 if ((frame[1] & 0xF0) != 0xC0)
128 goto invalid;
129 bfi = (frame[0] >> 1) & 1;
130 printf("line %u: EFR %s frame\n", lineno,
131 bfi ? "bad" : "extended");
132 printf(" TEH=%02X (DTXd=%u BFI=%u TAF=%u)\n", frame[0],
133 (frame[0] >> 3) & 1, bfi, frame[0] & 1);
134 dump_efr_frame(frame + 1);
135 break;
136 default:
137 invalid:
138 fprintf(stderr,
139 "%s line %u: not a valid FR or EFR frame\n",
140 argv[1], lineno);
141 exit(1);
142 }
143 }
144 exit(0);
145 }