FreeCalypso > hg > gsm-codec-lib
view 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 |
line wrap: on
line source
/* * This program reads a TW-TS-005 Annex B hexadecimal file and converts it to * ETSI TS 101 318 raw packed format (good frames only, 14 bytes per frame). */ #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "../libgsmhr1/tw_gsmhr.h" #include "../libtest/tw5reader.h" main(argc, argv) char **argv; { FILE *inf, *outf; unsigned lineno; uint8_t frame[TWTS005_MAX_FRAME], canon[GSMHR_FRAME_LEN_5993]; unsigned frame_len, ft; int rc; if (argc != 3) { fprintf(stderr, "usage: %s input.hex output.hrpf\n", argv[0]); exit(1); } inf = fopen(argv[1], "r"); if (!inf) { perror(argv[1]); exit(1); } outf = fopen(argv[2], "w"); if (!outf) { perror(argv[2]); 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", argv[1], lineno); exit(1); } if (!rc) break; rc = gsmhr_rtp_in_preen(frame, frame_len, canon); if (rc < 0) { fprintf(stderr, "%s line %u: not a valid GSM-HR frame\n", argv[1], lineno); exit(1); } ft = canon[0] >> 4; switch (ft) { case 0: break; case 2: gsmhr_ts101318_set_sid_codeword(canon + 1); break; default: fprintf(stderr, "%s line %u: frame type %u not valid for RPF\n", argv[1], lineno, ft); exit(1); } fwrite(canon + 1, 1, GSMHR_FRAME_LEN_RPF, outf); } exit(0); }