changeset 557:129c895a0564

hrutil: new program gsmhr-cod2hex
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 06 Feb 2025 08:38:27 +0000
parents 18aca50d68df
children a81ce3cd38a7
files .hgignore hrutil/Makefile hrutil/cod2hex.c hrutil/tw5b-out-cod.c
diffstat 4 files changed, 95 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Oct 11 01:54:00 2024 +0000
+++ b/.hgignore	Thu Feb 06 08:38:27 2025 +0000
@@ -78,6 +78,7 @@
 ^frtest/gsmfr-tfo-xfrm$
 
 ^hrutil/gsmhr-cod-parse$
+^hrutil/gsmhr-cod2hex$
 ^hrutil/gsmhr-dec-craft$
 ^hrutil/gsmhr-dec-parse$
 
--- a/hrutil/Makefile	Fri Oct 11 01:54:00 2024 +0000
+++ b/hrutil/Makefile	Thu Feb 06 08:38:27 2025 +0000
@@ -1,5 +1,6 @@
-PROGS=	gsmhr-cod-parse gsmhr-dec-craft gsmhr-dec-parse
+PROGS=	gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft gsmhr-dec-parse
 LIBHR1=	../libgsmhr1/libgsmhr1.a
+LIBTEST=../libtest/libtest.a
 
 include ../config.defs
 
@@ -8,6 +9,9 @@
 gsmhr-cod-parse:	cod-parse.o print-frame.o read-cod.o ${LIBHR1}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-cod2hex:	cod2hex.o read-cod.o tw5b-out-cod.o ${LIBHR1} ${LIBTEST}
+	${CC} ${CFLAGS} -o $@ $^
+
 gsmhr-dec-craft:	dec-craft.o ${LIBHR1}
 	${CC} ${CFLAGS} -o $@ $^
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/cod2hex.c	Thu Feb 06 08:38:27 2025 +0000
@@ -0,0 +1,64 @@
+/*
+ * This program reads an HRv1 *.cod file in ETSI test sequence format
+ * (encoder output 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"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	int opt, rc, big_endian = 0, emit_5993 = 0;
+	unsigned frame_no;
+	int16_t params[GSMHR_NUM_PARAMS_ENC];
+	extern int optind;
+
+	while ((opt = getopt(argc, argv, "bx")) != EOF) {
+		switch (opt) {
+		case 'b':
+			big_endian = 1;
+			continue;
+		case 'x':
+			emit_5993 = 1;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-b] [-x] input.cod 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_cod_frame(inf, big_endian, params, infname, frame_no);
+		if (!rc)
+			break;
+		emit_cod_to_tw5b(outf, params, emit_5993);
+	}
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/tw5b-out-cod.c	Thu Feb 06 08:38:27 2025 +0000
@@ -0,0 +1,25 @@
+/*
+ * The helper function implemented in this module emits TW-TS-005 Annex B
+ * hex output based on an encoder output array, i.e., a cod-style frame.
+ * This helper function will be used for gsmhr-cod2hex, gsmhr-encode[-r]
+ * and gsmhr-tfo-xfrm utilities.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+#include "../libtest/tw5writer.h"
+
+void
+emit_cod_to_tw5b(outf, params, emit_5993)
+	FILE *outf;
+	int16_t *params;
+{
+	uint8_t frame[GSMHR_FRAME_LEN_5993];
+
+	gsmhr_encoder_twts002_out(params, frame);
+	if (emit_5993)
+		emit_hex_frame(outf, frame, GSMHR_FRAME_LEN_5993);
+	else
+		emit_hex_frame(outf, frame + 1, GSMHR_FRAME_LEN_RPF);
+}