FreeCalypso > hg > gsm-codec-lib
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrutil/dec2hex.c Wed Feb 12 03:29:52 2025 +0000 @@ -0,0 +1,115 @@ +/* + * This program reads an HRv1 *.dec file in ETSI test sequence format + * (decoder input format) and converts it into TW-TS-005 Annex B + * hexadecimal format. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "../libgsmhr1/tw_gsmhr.h" +#include "../libtest/tw5writer.h" +#include "../libtest/local_endian.h" + +static int +convert_ft(bfi, sid) +{ + switch (sid) { + case 0: + switch (bfi) { + case 0: + return 0; + case 1: + return 6; + case 2: + return 7; + } + break; + case 1: + return 1; + case 2: + switch (bfi) { + case 0: + return 2; + case 1: + case 2: + return 1; + } + } + abort(); +} + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + int opt, rc, big_endian, ft; + unsigned frame_no; + int16_t params[GSMHR_NUM_PARAMS_DEC]; + uint8_t frame_out[GSMHR_FRAME_LEN_5993]; + extern int optind; + + big_endian = is_native_big_endian(); + while ((opt = getopt(argc, argv, "bl")) != EOF) { + switch (opt) { + case 'b': + big_endian = 1; + continue; + case 'l': + big_endian = 0; + continue; + default: + usage: + fprintf(stderr, + "usage: %s [-b|-l] input.dec output.hex\n", + argv[0]); + exit(1); + } + } + if (argc != optind + 2) + goto usage; + infname = argv[optind]; + outfname = argv[optind+1]; + + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + + for (frame_no = 0; ; frame_no++) { + rc = read_dec_frame(inf, big_endian, params, infname, frame_no); + if (!rc) + break; + ft = convert_ft(params[18], params[20]); + frame_out[0] = ft << 4; + if (params[19]) + frame_out[0] |= 0x02; + if (params[21]) + frame_out[0] |= 0x01; + switch (ft) { + case 0: + case 2: + case 6: + gsmhr_pack_ts101318(params, frame_out + 1); + emit_hex_frame(outf, frame_out, GSMHR_FRAME_LEN_5993); + break; + case 1: + case 7: + emit_hex_frame(outf, frame_out, 1); + break; + default: + abort(); + } + } + exit(0); +}