changeset 565:ec146b5b9c91

hrutil: new program gsmhr-hex2dec
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Feb 2025 01:12:22 +0000
parents 30c57cf6e87d
children 62fe499ffc15
files .hgignore hrutil/Makefile hrutil/hex2dec.c
diffstat 3 files changed, 86 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Feb 12 00:33:32 2025 +0000
+++ b/.hgignore	Wed Feb 12 01:12:22 2025 +0000
@@ -81,6 +81,7 @@
 ^hrutil/gsmhr-cod2hex$
 ^hrutil/gsmhr-dec-craft$
 ^hrutil/gsmhr-dec-parse$
+^hrutil/gsmhr-hex2dec$
 ^hrutil/tw5b-dump$
 
 ^libgsmhr1/dhf_packed\.c$
--- a/hrutil/Makefile	Wed Feb 12 00:33:32 2025 +0000
+++ b/hrutil/Makefile	Wed Feb 12 01:12:22 2025 +0000
@@ -1,4 +1,5 @@
-PROGS=	gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse tw5b-dump
+PROGS=	gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse \
+	gsmhr-hex2dec tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
 LIBS=	${LIBHR1} ${LIBTEST}
@@ -19,6 +20,9 @@
 gsmhr-dec-parse:	dec-parse.o print-frame.o read-dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-hex2dec:	hex2dec.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/hex2dec.c	Wed Feb 12 01:12:22 2025 +0000
@@ -0,0 +1,80 @@
+/*
+ * 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);
+}