FreeCalypso > hg > gsm-codec-lib
annotate hrutil/dec2hex.c @ 585:3c6bf0d26ee7 default tip
TW-TS-005 reader: fix maximum line length bug
TW-TS-005 section 4.1 states:
The maximum allowed length of each line is 80 characters, not
including the OS-specific newline encoding.
The implementation of this line length limit in the TW-TS-005 hex file
reader function in the present suite was wrong, such that lines of
the full maximum length could not be read. Fix it.
Note that this bug affects comment lines too, not just actual RTP
payloads. Neither Annex A nor Annex B features an RTP payload format
that goes to the maximum of 40 bytes, but if a comment line goes to
the maximum allowed length of 80 characters not including the
terminating newline, the bug will be triggered, necessitating
the present fix.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 25 Feb 2025 07:49:28 +0000 |
parents | 0affb05c2ce2 |
children |
rev | line source |
---|---|
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
2 * This program reads an HRv1 *.dec file in ETSI test sequence format |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
3 * (decoder input format) and converts it into TW-TS-005 Annex B |
557
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" |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
14 #include "../libtest/tw5writer.h" |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
15 #include "../libtest/local_endian.h" |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
17 static int |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
18 convert_ft(bfi, sid) |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
19 { |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
20 switch (sid) { |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
21 case 0: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
22 switch (bfi) { |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
23 case 0: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
24 return 0; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
25 case 1: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
26 return 6; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
27 case 2: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
28 return 7; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
29 } |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
30 break; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
31 case 1: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
32 return 1; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
33 case 2: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
34 switch (bfi) { |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
35 case 0: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
36 return 2; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
37 case 1: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
38 case 2: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
39 return 1; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
40 } |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
41 } |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
42 abort(); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
43 } |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
44 |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 main(argc, argv) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 char **argv; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 char *infname, *outfname; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 FILE *inf, *outf; |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
50 int opt, rc, big_endian, ft; |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 unsigned frame_no; |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
52 int16_t params[GSMHR_NUM_PARAMS_DEC]; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
53 uint8_t frame_out[GSMHR_FRAME_LEN_5993]; |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 extern int optind; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
56 big_endian = is_native_big_endian(); |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
57 while ((opt = getopt(argc, argv, "bl")) != EOF) { |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 switch (opt) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 case 'b': |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 big_endian = 1; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 continue; |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
62 case 'l': |
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
63 big_endian = 0; |
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
64 continue; |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 default: |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 usage: |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
68 "usage: %s [-b|-l] input.dec output.hex\n", |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 argv[0]); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (argc != optind + 2) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 goto usage; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 infname = argv[optind]; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 outfname = argv[optind+1]; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 inf = fopen(infname, "r"); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (!inf) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 perror(infname); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 outf = fopen(outfname, "w"); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (!outf) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 perror(outfname); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 for (frame_no = 0; ; frame_no++) { |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
90 rc = read_dec_frame(inf, big_endian, params, infname, frame_no); |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (!rc) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 break; |
568
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
93 ft = convert_ft(params[18], params[20]); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
94 frame_out[0] = ft << 4; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
95 if (params[19]) |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
96 frame_out[0] |= 0x02; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
97 if (params[21]) |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
98 frame_out[0] |= 0x01; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
99 switch (ft) { |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
100 case 0: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
101 case 2: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
102 case 6: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
103 gsmhr_pack_ts101318(params, frame_out + 1); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
104 emit_hex_frame(outf, frame_out, GSMHR_FRAME_LEN_5993); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
105 break; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
106 case 1: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
107 case 7: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
108 emit_hex_frame(outf, frame_out, 1); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
109 break; |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
110 default: |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
111 abort(); |
0affb05c2ce2
hrutil: new program gsmhr-dec2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
561
diff
changeset
|
112 } |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 exit(0); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |