annotate frtest/tfo-xfrm.c @ 546:b26df31124a4

frtest: new program gsmfr-tfo-xfrm
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 04 Oct 2024 19:07:52 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
546
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program exercises our ThemWi implementation of TFO transform for
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * GSM-FR. It reads a stream of radio leg A Rx frames from a TW-TS-005 Annex A
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * hex file and writes the "pristine" stream intended for radio leg B Tx
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * into another TW-TS-005 Annex A hex file. The output is in basic RTP format.
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libgsmfr2/tw_gsmfr.h"
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../libtest/tw5reader.h"
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../libtest/tw5writer.h"
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *infname, *outfname;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 FILE *inf, *outf;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned lineno;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 struct gsmfr_preproc_state *pp_state;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint8_t frame_in[TWTS005_MAX_FRAME], frame_out[GSMFR_RTP_FRAME_LEN];
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned frame_in_len;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int dtxd, rc;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (argc == 3 && argv[1][0] != '-') {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 dtxd = 0;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 infname = argv[1];
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 outfname = argv[2];
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 } else if (argc == 4 && !strcmp(argv[1], "-d")) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 dtxd = 1;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 infname = argv[2];
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 outfname = argv[3];
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 } else {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, "usage: %s [-d] input.hex output.hex\n",
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 argv[0]);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 inf = fopen(infname, "r");
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!inf) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 perror(infname);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 lineno = 0;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 outf = fopen(outfname, "w");
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!outf) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(outfname);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 pp_state = gsmfr_preproc_create();
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (!pp_state) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr, "gsmfr_preproc_create() failed!\n");
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 for (;;) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc = twts005_read_frame(inf, &lineno, frame_in, &frame_in_len);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (rc < 0) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr, "%s line %u: not valid TW-TS-005\n",
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 argv[1], lineno);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!rc)
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 break;
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 rc = gsmfr_tfo_xfrm_main(pp_state, frame_in, frame_in_len,
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 frame_out);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (rc < 0) {
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(stderr,
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 "%s line %u: not a valid GSM-FR frame\n",
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 argv[1], lineno);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(1);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (dtxd)
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 gsmfr_tfo_xfrm_dtxd(pp_state, frame_out);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 emit_hex_frame(outf, frame_out, GSMFR_RTP_FRAME_LEN);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 fclose(outf);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 exit(0);
b26df31124a4 frtest: new program gsmfr-tfo-xfrm
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }