FreeCalypso > hg > gsm-codec-lib
view hrutil/hex2dec.c @ 566:62fe499ffc15
hrutil: new program gsmhr-hex2rpf
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Feb 2025 01:48:01 +0000 |
parents | ec146b5b9c91 |
children |
line wrap: on
line source
/* * This program reads a TW-TS-005 Annex B hexadecimal file and converts it * to ETSI *.dec GSM-HR decoder input 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/tw5reader.h" main(argc, argv) char **argv; { char *infname, *outfname; FILE *inf, *outf; int opt, rc, allow_bfi_nodata = 0; unsigned lineno; uint8_t frame[TWTS005_MAX_FRAME]; unsigned frame_len; int16_t params[GSMHR_NUM_PARAMS_DEC]; extern int optind; while ((opt = getopt(argc, argv, "f")) != EOF) { switch (opt) { case 'f': allow_bfi_nodata = 1; continue; default: usage: fprintf(stderr, "usage: %s [-f] input.hex output.dec\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); } lineno = 0; for (;;) { rc = twts005_read_frame(inf, &lineno, frame, &frame_len); if (rc < 0) { fprintf(stderr, "%s line %u: not valid TW-TS-005\n", infname, lineno); exit(1); } if (!rc) break; rc = gsmhr_rtp_in_direct(frame, frame_len, params); if (rc < 0) { fprintf(stderr, "%s line %u: not a valid GSM-HR frame\n", infname, lineno); exit(1); } if (params[18] == 2 && !allow_bfi_nodata) { fprintf(stderr, "%s line %u: BFI-no-data not allowed\n", infname, lineno); exit(1); } fwrite(params, 2, GSMHR_NUM_PARAMS_DEC, outf); } exit(0); }