FreeCalypso > hg > freecalypso-tools
annotate tchtools/fc-tch2fr.c @ 989:a5bff8104b45
pln-ppb-test: implement program operation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:16:17 +0000 |
parents | a7ad6b39e01b |
children |
rev | line source |
---|---|
6
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
903
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
2 * This program reads TCH downlink capture files in the old format from 2016 |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
3 * (the format which fc-shell tch record will write if the firmware running |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
4 * on the Calypso GSM device is an old version that emits TCH DL bits in |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
5 * the old format from 2016), completely *disregards* all 3 status words |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
6 * including the essential word of control flags, converts the 260-bit |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
7 * payload portion of each frame into standard libgsm/RTP format, and |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
8 * writes the result into a .gsm binary file. |
6
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
903
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
10 * This program was written in 2016, at that time we (FreeCalypso team) |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
11 * did not have a proper understanding of how the complete TCH DL processing |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
12 * chain works - we particularly missed the Rx DTX handler block that MUST |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
13 * be present between the output of the GSM 05.03 channel decoder and the |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
14 * input to the GSM 06.10 speech decoder - and therefore the function |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
15 * performed by this program is a bogo-transform. |
6
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 * |
903
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
17 * This bogo-transform program is kept as part of FC host tools package |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
18 * only for backward compatibility - for actual decoding of TCH DL captures, |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
19 * please use our new gsmfr-dlcap-* and gsmefr-dlcap-* utilities that are |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
20 * maintained as part of Themyscira Wireless GSM codec libraries & utilities |
a7ad6b39e01b
tchtools/fc-tch2fr.c: update big header comment for new reality
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
21 * package. |
6
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 */ |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 #include <sys/types.h> |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 #include <ctype.h> |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 #include <stdio.h> |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 #include <stdlib.h> |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 static |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 decode_hex_digit(ch) |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (isdigit(ch)) |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return(ch - '0'); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 else if (isupper(ch)) |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(ch - 'A' + 10); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 else |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(ch - 'a' + 10); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 main(argc, argv) |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 char **argv; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 FILE *inf, *outf; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 char linebuf[128]; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int lineno; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 char *cp; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 int i, j; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 u_char tidsp_bytes[33], libgsm_bytes[33]; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (argc != 3) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(1); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 inf = fopen(argv[1], "r"); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (!inf) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 perror(argv[1]); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 exit(1); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 outf = fopen(argv[2], "w"); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!outf) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 perror(argv[2]); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 exit(1); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 /* skip DSP status words */ |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 cp = linebuf; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (i = 0; i < 3; i++) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 for (j = 0; j < 4; j++) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!isxdigit(*cp++)) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 invalid: fprintf(stderr, |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 "error: %s is not in the expected format\n", |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 argv[1]); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 exit(1); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (*cp++ != ' ') |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 goto invalid; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 /* read the frame bits */ |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 for (i = 0; i < 33; i++) { |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (!isxdigit(cp[0]) || !isxdigit(cp[1])) |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 goto invalid; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 tidsp_bytes[i] = (decode_hex_digit(cp[0]) << 4) | |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 decode_hex_digit(cp[1]); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 cp += 2; |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 fwrite(libgsm_bytes, 1, 33, outf); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 exit(0); |
d57f68d0568d
fc-tch2fr utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |