FreeCalypso > hg > gsm-codec-lib
comparison hrutil/hex2rpf.c @ 566:62fe499ffc15
hrutil: new program gsmhr-hex2rpf
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Feb 2025 01:48:01 +0000 |
parents | hrutil/hex2dec.c@ec146b5b9c91 |
children |
comparison
equal
deleted
inserted
replaced
565:ec146b5b9c91 | 566:62fe499ffc15 |
---|---|
1 /* | |
2 * This program reads a TW-TS-005 Annex B hexadecimal file and converts it to | |
3 * ETSI TS 101 318 raw packed format (good frames only, 14 bytes per frame). | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "../libgsmhr1/tw_gsmhr.h" | |
12 #include "../libtest/tw5reader.h" | |
13 | |
14 main(argc, argv) | |
15 char **argv; | |
16 { | |
17 FILE *inf, *outf; | |
18 unsigned lineno; | |
19 uint8_t frame[TWTS005_MAX_FRAME], canon[GSMHR_FRAME_LEN_5993]; | |
20 unsigned frame_len, ft; | |
21 int rc; | |
22 | |
23 if (argc != 3) { | |
24 fprintf(stderr, "usage: %s input.hex output.hrpf\n", argv[0]); | |
25 exit(1); | |
26 } | |
27 inf = fopen(argv[1], "r"); | |
28 if (!inf) { | |
29 perror(argv[1]); | |
30 exit(1); | |
31 } | |
32 outf = fopen(argv[2], "w"); | |
33 if (!outf) { | |
34 perror(argv[2]); | |
35 exit(1); | |
36 } | |
37 | |
38 lineno = 0; | |
39 for (;;) { | |
40 rc = twts005_read_frame(inf, &lineno, frame, &frame_len); | |
41 if (rc < 0) { | |
42 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
43 argv[1], lineno); | |
44 exit(1); | |
45 } | |
46 if (!rc) | |
47 break; | |
48 rc = gsmhr_rtp_in_preen(frame, frame_len, canon); | |
49 if (rc < 0) { | |
50 fprintf(stderr, | |
51 "%s line %u: not a valid GSM-HR frame\n", | |
52 argv[1], lineno); | |
53 exit(1); | |
54 } | |
55 ft = canon[0] >> 4; | |
56 switch (ft) { | |
57 case 0: | |
58 break; | |
59 case 2: | |
60 gsmhr_ts101318_set_sid_codeword(canon + 1); | |
61 break; | |
62 default: | |
63 fprintf(stderr, | |
64 "%s line %u: frame type %u not valid for RPF\n", | |
65 argv[1], lineno, ft); | |
66 exit(1); | |
67 } | |
68 fwrite(canon + 1, 1, GSMHR_FRAME_LEN_RPF, outf); | |
69 } | |
70 exit(0); | |
71 } |