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