FreeCalypso > hg > gsm-codec-lib
changeset 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 | 2fcb6b27ee9b |
files | .hgignore hrutil/Makefile hrutil/hex2rpf.c |
diffstat | 3 files changed, 76 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed Feb 12 01:12:22 2025 +0000 +++ b/.hgignore Wed Feb 12 01:48:01 2025 +0000 @@ -82,6 +82,7 @@ ^hrutil/gsmhr-dec-craft$ ^hrutil/gsmhr-dec-parse$ ^hrutil/gsmhr-hex2dec$ +^hrutil/gsmhr-hex2rpf$ ^hrutil/tw5b-dump$ ^libgsmhr1/dhf_packed\.c$
--- a/hrutil/Makefile Wed Feb 12 01:12:22 2025 +0000 +++ b/hrutil/Makefile Wed Feb 12 01:48:01 2025 +0000 @@ -1,5 +1,5 @@ PROGS= gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse \ - gsmhr-hex2dec tw5b-dump + gsmhr-hex2dec gsmhr-hex2rpf tw5b-dump LIBHR1= ../libgsmhr1/libgsmhr1.a LIBTEST=../libtest/libtest.a LIBS= ${LIBHR1} ${LIBTEST} @@ -23,6 +23,9 @@ gsmhr-hex2dec: hex2dec.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^ +gsmhr-hex2rpf: hex2rpf.o ${LIBS} + ${CC} ${CFLAGS} -o $@ $^ + tw5b-dump: print-frame.o tw5b-dump.o ${LIBS} ${CC} ${CFLAGS} -o $@ $^
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hrutil/hex2rpf.c Wed Feb 12 01:48:01 2025 +0000 @@ -0,0 +1,71 @@ +/* + * 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); +}