changeset 609:a2b2ca082dd7 default tip

hrutil: new program gsmhr-tfo-xfrm-dc
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 24 Feb 2026 04:16:57 +0000
parents d4e42ec4a688
children
files .hgignore hrutil/Makefile hrutil/cod-out-endian.c hrutil/tfo-xfrm-dc.c
diffstat 4 files changed, 116 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Dec 05 09:01:14 2025 +0000
+++ b/.hgignore	Tue Feb 24 04:16:57 2026 +0000
@@ -95,6 +95,7 @@
 ^hrutil/gsmhr-hex2rpf$
 ^hrutil/gsmhr-rpf2hex$
 ^hrutil/gsmhr-tfo-xfrm$
+^hrutil/gsmhr-tfo-xfrm-dc$
 ^hrutil/tw5b-dump$
 
 ^libgsmhr1/dhf_packed\.c$
--- a/hrutil/Makefile	Fri Dec 05 09:01:14 2025 +0000
+++ b/hrutil/Makefile	Tue Feb 24 04:16:57 2026 +0000
@@ -1,7 +1,7 @@
 PROGS=	gsmhr-cod-craft gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft \
 	gsmhr-dec-parse gsmhr-dec2hex gsmhr-decode gsmhr-decode-r \
 	gsmhr-etsi-dec gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex \
-	gsmhr-tfo-xfrm tw5b-dump
+	gsmhr-tfo-xfrm gsmhr-tfo-xfrm-dc tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
 LIBS=	${LIBHR1} ${LIBTEST}
@@ -49,6 +49,9 @@
 gsmhr-tfo-xfrm:	tfo-xfrm.o tw5b-out-cod.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-tfo-xfrm-dc:	cod-out-endian.o read-dec.o tfo-xfrm-dc.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/cod-out-endian.c	Tue Feb 24 04:16:57 2026 +0000
@@ -0,0 +1,34 @@
+/*
+ * The helper function implemented in this module emits an encoder output
+ * array of params (*.cod format) in either BE or LE format.  This helper
+ * function will be used for gsmhr-etsi-enc and gsmhr-tfo-xfrm-dc utilities,
+ * which need to both read and write ETSI-format files that are subject to
+ * endian concerns.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+
+void
+emit_cod_to_endian(outf, params, big_endian)
+	FILE *outf;
+	int16_t *params;
+{
+	uint8_t file_bytes[GSMHR_NUM_PARAMS_ENC * 2], *dp;
+	unsigned n;
+	uint16_t val;
+
+	dp = file_bytes;
+	for (n = 0; n < GSMHR_NUM_PARAMS_ENC; n++) {
+		val = params[n];
+		if (big_endian) {
+			*dp++ = val >> 8;
+			*dp++ = val;
+		} else {
+			*dp++ = val;
+			*dp++ = val >> 8;
+		}
+	}
+	fwrite(file_bytes, 2, GSMHR_NUM_PARAMS_ENC, outf);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/tfo-xfrm-dc.c	Tue Feb 24 04:16:57 2026 +0000
@@ -0,0 +1,77 @@
+/*
+ * This program exercises our ThemWi implementation of TFO transform for
+ * GSM-HR.  The present variant reads radio leg A Rx frames from an
+ * ETSI-format *.dec file and writes the "pristine" stream intended for
+ * radio leg B Tx into an ETSI-format *.cod file.  This variant exercises
+ * libgsmhr1 TFO transform function in its most native form.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+#include "../libtest/local_endian.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	int big_endian;
+	unsigned frame_no;
+	struct gsmhr_rxfe_state *state;
+	int16_t prm_in[GSMHR_NUM_PARAMS_DEC], prm_out[GSMHR_NUM_PARAMS_ENC];
+	int opt, rc, dtxd = 0;
+	extern int optind;
+
+	big_endian = is_native_big_endian();
+	while ((opt = getopt(argc, argv, "bdl")) != EOF) {
+		switch (opt) {
+		case 'b':
+			big_endian = 1;
+			continue;
+		case 'd':
+			dtxd = 1;
+			continue;
+		case 'l':
+			big_endian = 0;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-b|-l] [-d] input.dec output.cod\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);
+	}
+	state = gsmhr_rxfe_create();
+	if (!state) {
+		fprintf(stderr, "gsmhr_rxfe_create() failed!\n");
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_dec_frame(inf, big_endian, prm_in, infname, frame_no);
+		if (!rc)
+			break;
+		gsmhr_tfo_xfrm(state, dtxd, prm_in, prm_out);
+		emit_cod_to_endian(outf, prm_out, big_endian);
+	}
+	fclose(outf);
+	exit(0);
+}