FreeCalypso > hg > gsm-codec-lib
comparison hrutil/dec2hex.c @ 568:0affb05c2ce2
hrutil: new program gsmhr-dec2hex
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 12 Feb 2025 03:29:52 +0000 |
| parents | hrutil/cod2hex.c@cf62fe9fac3a |
| children |
comparison
equal
deleted
inserted
replaced
| 567:2fcb6b27ee9b | 568:0affb05c2ce2 |
|---|---|
| 1 /* | |
| 2 * This program reads an HRv1 *.dec file in ETSI test sequence format | |
| 3 * (decoder input format) and converts it into TW-TS-005 Annex B | |
| 4 * hexadecimal format. | |
| 5 */ | |
| 6 | |
| 7 #include <stdio.h> | |
| 8 #include <stdint.h> | |
| 9 #include <stdlib.h> | |
| 10 #include <string.h> | |
| 11 #include <strings.h> | |
| 12 #include <unistd.h> | |
| 13 #include "../libgsmhr1/tw_gsmhr.h" | |
| 14 #include "../libtest/tw5writer.h" | |
| 15 #include "../libtest/local_endian.h" | |
| 16 | |
| 17 static int | |
| 18 convert_ft(bfi, sid) | |
| 19 { | |
| 20 switch (sid) { | |
| 21 case 0: | |
| 22 switch (bfi) { | |
| 23 case 0: | |
| 24 return 0; | |
| 25 case 1: | |
| 26 return 6; | |
| 27 case 2: | |
| 28 return 7; | |
| 29 } | |
| 30 break; | |
| 31 case 1: | |
| 32 return 1; | |
| 33 case 2: | |
| 34 switch (bfi) { | |
| 35 case 0: | |
| 36 return 2; | |
| 37 case 1: | |
| 38 case 2: | |
| 39 return 1; | |
| 40 } | |
| 41 } | |
| 42 abort(); | |
| 43 } | |
| 44 | |
| 45 main(argc, argv) | |
| 46 char **argv; | |
| 47 { | |
| 48 char *infname, *outfname; | |
| 49 FILE *inf, *outf; | |
| 50 int opt, rc, big_endian, ft; | |
| 51 unsigned frame_no; | |
| 52 int16_t params[GSMHR_NUM_PARAMS_DEC]; | |
| 53 uint8_t frame_out[GSMHR_FRAME_LEN_5993]; | |
| 54 extern int optind; | |
| 55 | |
| 56 big_endian = is_native_big_endian(); | |
| 57 while ((opt = getopt(argc, argv, "bl")) != EOF) { | |
| 58 switch (opt) { | |
| 59 case 'b': | |
| 60 big_endian = 1; | |
| 61 continue; | |
| 62 case 'l': | |
| 63 big_endian = 0; | |
| 64 continue; | |
| 65 default: | |
| 66 usage: | |
| 67 fprintf(stderr, | |
| 68 "usage: %s [-b|-l] input.dec output.hex\n", | |
| 69 argv[0]); | |
| 70 exit(1); | |
| 71 } | |
| 72 } | |
| 73 if (argc != optind + 2) | |
| 74 goto usage; | |
| 75 infname = argv[optind]; | |
| 76 outfname = argv[optind+1]; | |
| 77 | |
| 78 inf = fopen(infname, "r"); | |
| 79 if (!inf) { | |
| 80 perror(infname); | |
| 81 exit(1); | |
| 82 } | |
| 83 outf = fopen(outfname, "w"); | |
| 84 if (!outf) { | |
| 85 perror(outfname); | |
| 86 exit(1); | |
| 87 } | |
| 88 | |
| 89 for (frame_no = 0; ; frame_no++) { | |
| 90 rc = read_dec_frame(inf, big_endian, params, infname, frame_no); | |
| 91 if (!rc) | |
| 92 break; | |
| 93 ft = convert_ft(params[18], params[20]); | |
| 94 frame_out[0] = ft << 4; | |
| 95 if (params[19]) | |
| 96 frame_out[0] |= 0x02; | |
| 97 if (params[21]) | |
| 98 frame_out[0] |= 0x01; | |
| 99 switch (ft) { | |
| 100 case 0: | |
| 101 case 2: | |
| 102 case 6: | |
| 103 gsmhr_pack_ts101318(params, frame_out + 1); | |
| 104 emit_hex_frame(outf, frame_out, GSMHR_FRAME_LEN_5993); | |
| 105 break; | |
| 106 case 1: | |
| 107 case 7: | |
| 108 emit_hex_frame(outf, frame_out, 1); | |
| 109 break; | |
| 110 default: | |
| 111 abort(); | |
| 112 } | |
| 113 } | |
| 114 exit(0); | |
| 115 } |
