changeset 568:0affb05c2ce2

hrutil: new program gsmhr-dec2hex
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Feb 2025 03:29:52 +0000
parents 2fcb6b27ee9b
children 0d05892150cf
files .hgignore hrutil/Makefile hrutil/dec2hex.c
diffstat 3 files changed, 120 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Feb 12 02:32:21 2025 +0000
+++ b/.hgignore	Wed Feb 12 03:29:52 2025 +0000
@@ -81,6 +81,7 @@
 ^hrutil/gsmhr-cod2hex$
 ^hrutil/gsmhr-dec-craft$
 ^hrutil/gsmhr-dec-parse$
+^hrutil/gsmhr-dec2hex$
 ^hrutil/gsmhr-hex2dec$
 ^hrutil/gsmhr-hex2rpf$
 ^hrutil/gsmhr-rpf2hex$
--- a/hrutil/Makefile	Wed Feb 12 02:32:21 2025 +0000
+++ b/hrutil/Makefile	Wed Feb 12 03:29:52 2025 +0000
@@ -1,5 +1,5 @@
 PROGS=	gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse \
-	gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex tw5b-dump
+	gsmhr-dec2hex gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
 LIBS=	${LIBHR1} ${LIBTEST}
@@ -20,6 +20,9 @@
 gsmhr-dec-parse:	dec-parse.o print-frame.o read-dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-dec2hex:	dec2hex.o read-dec.o ${LIBS}
+	${CC} ${CFLAGS} -o $@ $^
+
 gsmhr-hex2dec:	hex2dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
--- /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);
+}