annotate miscutil/gsmrec-dump.c @ 169:0c965c3c5e6e

doc/Utils-overview: new Calypso TCH DL utils
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Dec 2022 09:53:04 +0000
parents a5ffec18e4cd
children 3816ba89a5a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a binary file in our extended-libgsm format
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and dumps all frames in human-readable form.
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <gsm.h>
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
10 #include "../libgsmefr/gsm_efr.h"
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libtest/binreader.h"
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 main(argc, argv)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 FILE *binf;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 gsm dummy_state;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned frame_index;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 uint8_t frame[BINFILE_MAX_FRAME];
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
20 gsm_signal params[76];
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int rc, i, j, n;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (argc != 2) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "usage: %s bin-stream-file\n", argv[0]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 binf = fopen(argv[1], "r");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!binf) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 perror(argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 dummy_state = gsm_create();
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!dummy_state) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr, "gsm_create() failed!\n");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 for (frame_index = 0; ; frame_index++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 rc = binfile_read_frame(binf, frame);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (rc < 0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(stderr, "error: garbage in %s\n", argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (!rc)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 printf("#%u: ", frame_index);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 switch (frame[0] & 0xF0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case 0xB0:
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 printf("BFI TAF=%u\n", frame[1] & 1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 case 0xC0:
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
51 printf("EFR SID=%d LPC", EFR_sid_classify(frame));
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
52 EFR_frame2params(frame, params);
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
53 n = 0;
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
54 for (i = 0; i < 5; i++)
128
a5ffec18e4cd test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
55 printf(" %d", params[n++]);
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
56 putchar('\n');
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
57 for (i = 0; i < 4; i++) {
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
58 putchar(' ');
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
59 for (j = 0; j < 13; j++)
128
a5ffec18e4cd test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
60 printf(" %d", params[n++]);
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
61 putchar('\n');
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
62 }
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 case 0xD0:
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fputs("FR", stdout);
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
66 gsm_explode(dummy_state, frame, params);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 n = 0;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 for (i = 0; i < 8; i++)
128
a5ffec18e4cd test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
69 printf(" %d", params[n++]);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 putchar('\n');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 for (i = 0; i < 4; i++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 putchar(' ');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 for (j = 0; j < 17; j++)
128
a5ffec18e4cd test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
74 printf(" %d", params[n++]);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 putchar('\n');
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 exit(0);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }