FreeCalypso > hg > gsm-codec-lib
annotate frtest/dlcap-parse.c @ 462:bada654a859b
CHANGES: document rm of gsmfr-hand-test and gsmfr-max-out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 May 2024 19:48:56 +0000 |
parents | 251aed72925e |
children |
rev | line source |
---|---|
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
2 * This program reads a TCH/FS downlink capture produced with FreeCalypso tools |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
3 * (fw version with TCH downlink sniffing feature and fc-shell tch record), |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
4 * parses the frame bits according to our current understanding, and dumps |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
5 * everything in human-readable form for further analysis. |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <ctype.h> |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
10 #include <stdint.h> |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
12 #include <string.h> |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
13 #include <strings.h> |
286
251aed72925e
gsmfr-dlcap-parse: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
178
diff
changeset
|
14 #include "../libgsmfr2/tw_gsmfr.h" |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
15 |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
16 static void |
286
251aed72925e
gsmfr-dlcap-parse: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
178
diff
changeset
|
17 process_record(lineno, fn_mod_104, status_words, tidsp_bytes) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
18 int lineno; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
19 unsigned fn_mod_104; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
20 uint16_t *status_words; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
21 uint8_t *tidsp_bytes; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
22 { |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
23 uint8_t libgsm_bytes[33]; |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
24 int16_t params[76]; |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
25 int i, j, n; |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
26 |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
27 printf("#%d: fn=%u DSP %04X %04X %04X\n", lineno, fn_mod_104, |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
28 status_words[0], status_words[1], status_words[2]); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
29 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
30 fputs(" bits ", stdout); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
31 for (i = 0; i < 33; i++) |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
32 printf("%02X", tidsp_bytes[i]); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
33 printf(" SID=%d\n", gsmfr_preproc_sid_classify(libgsm_bytes)); |
286
251aed72925e
gsmfr-dlcap-parse: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
178
diff
changeset
|
34 gsmfr_unpack_to_array(libgsm_bytes, params); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
35 fputs(" FR", stdout); |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
36 n = 0; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
37 for (i = 0; i < 8; i++) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
38 printf(" %d", params[n++]); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
39 putchar('\n'); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
40 for (i = 0; i < 4; i++) { |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
41 putchar(' '); |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
42 for (j = 0; j < 17; j++) |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
43 printf(" %d", params[n++]); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
44 putchar('\n'); |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
45 } |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
46 } |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 main(argc, argv) |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 char **argv; |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 { |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
51 FILE *inf; |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 char linebuf[128]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
53 int lineno, rc; |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
54 uint16_t status_words[3]; |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
55 uint8_t tidsp_bytes[33]; |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
56 unsigned fn_mod_104; |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
162
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
58 if (argc != 2) { |
b98aebd94d1f
gsmefr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
59 fprintf(stderr, "usage: %s dlcap-file\n", argv[0]); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 inf = fopen(argv[1], "r"); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (!inf) { |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 perror(argv[1]); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
68 /* support both old and new formats */ |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
69 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
70 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { |
178
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
71 /* also support parsing output from fc-vm2hex */ |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
72 if (linebuf[4] == '\n') { |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
73 printf("#%d: fn=0 DSP %.4s\n", lineno, linebuf); |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
74 continue; |
5fe0b3eb35c1
gsmfr-dlcap-parse: also parse hex output from fc-vm2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
167
diff
changeset
|
75 } |
139
be57e06bed84
factor out common part of gsmfr-cvt-dlcap, in prep for EFR
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
76 rc = parse_dlcap_common(linebuf, status_words, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
77 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
78 if (rc < 0) { |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 invalid: fprintf(stderr, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
80 "error: %s is not in the expected format\n", |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
81 argv[1]); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 exit(1); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
84 fn_mod_104 = 0; /* won't have TAF */ |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
85 } else if (!strncmp(linebuf, "FR ", 3)) { |
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
86 rc = parse_dlcap_common(linebuf + 3, status_words, |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
87 tidsp_bytes); |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
88 if (rc < 0) |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
89 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
90 if (linebuf[84] != ' ') |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
91 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
92 if (!isdigit(linebuf[85])) |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 goto invalid; |
167
80c93ef82a51
gsmfr-dlcap-parse utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
162
diff
changeset
|
94 fn_mod_104 = strtoul(linebuf + 85, 0, 10); |
137
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
95 } else |
b7ea278390eb
gsmfr-cvt-dlcap: support new FC TCH DL recording format
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
96 goto invalid; |
286
251aed72925e
gsmfr-dlcap-parse: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
178
diff
changeset
|
97 process_record(lineno, fn_mod_104, status_words, tidsp_bytes); |
19
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 exit(0); |
7960744ba19c
frtest: gsmfr-cvt-dlcap program based on fc-tch2fr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |