annotate hrutil/cod2hex.c @ 557:129c895a0564

hrutil: new program gsmhr-cod2hex
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 06 Feb 2025 08:38:27 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
557
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads an HRv1 *.cod file in ETSI test sequence format
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * (encoder output format) and converts it into TW-TS-005 Annex B
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * hexadecimal format.
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <unistd.h>
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "../libgsmhr1/tw_gsmhr.h"
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *infname, *outfname;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 FILE *inf, *outf;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int opt, rc, big_endian = 0, emit_5993 = 0;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned frame_no;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int16_t params[GSMHR_NUM_PARAMS_ENC];
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int optind;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 while ((opt = getopt(argc, argv, "bx")) != EOF) {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 switch (opt) {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 case 'b':
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 big_endian = 1;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 continue;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 case 'x':
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 emit_5993 = 1;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 continue;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 default:
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 usage:
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr,
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 "usage: %s [-b] [-x] input.cod output.hex\n",
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 argv[0]);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (argc != optind + 2)
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 goto usage;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 infname = argv[optind];
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 outfname = argv[optind+1];
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 inf = fopen(infname, "r");
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!inf) {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 perror(infname);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 outf = fopen(outfname, "w");
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!outf) {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 perror(outfname);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 for (frame_no = 0; ; frame_no++) {
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 rc = read_cod_frame(inf, big_endian, params, infname, frame_no);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!rc)
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 break;
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 emit_cod_to_tw5b(outf, params, emit_5993);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(0);
129c895a0564 hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }