changeset 484:68c7e4edc4da

fc-bin2rftab utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 Mar 2019 05:47:06 +0000
parents e76cb6994508
children 944e26b2f314
files .hgignore ffstools/caltools/Makefile ffstools/caltools/fc-bin2rftab.c
diffstat 3 files changed, 113 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Mar 07 01:42:18 2019 +0000
+++ b/.hgignore	Fri Mar 15 05:47:06 2019 +0000
@@ -7,6 +7,7 @@
 
 ^ffstools/cal2text/fc-cal2text$
 ^ffstools/caltools/c1xx-calextr$
+^ffstools/caltools/fc-bin2rftab$
 ^ffstools/caltools/fc-cal2bin$
 ^ffstools/caltools/fc-rftab2c$
 ^ffstools/newcomp/compile-fc-batt$
--- a/ffstools/caltools/Makefile	Thu Mar 07 01:42:18 2019 +0000
+++ b/ffstools/caltools/Makefile	Fri Mar 15 05:47:06 2019 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	c1xx-calextr fc-cal2bin fc-rftab2c
+PROGS=	c1xx-calextr fc-bin2rftab fc-cal2bin fc-rftab2c
 
 INSTALL_PREFIX=	/opt/freecalypso
 
@@ -10,12 +10,17 @@
 
 LIBRFTAB=	../../librftab/librftab.a
 
+BIN2RFTAB_OBJS=	fc-bin2rftab.o ${LIBRFTAB}
+
 CAL2BIN_OBJS=	fc-cal2bin.o ${LIBRFTAB}
 
 CALEXTR_OBJS=	c1xx-calextr.o mkdir.o ${LIBRFTAB}
 
 RFTAB2C_OBJS=	fc-rftab2c.o ${LIBRFTAB}
 
+fc-bin2rftab:	${BIN2RFTAB_OBJS}
+	${CC} ${CFLAGS} -o $@ ${BIN2RFTAB_OBJS}
+
 fc-cal2bin:	${CAL2BIN_OBJS}
 	${CC} ${CFLAGS} -o $@ ${CAL2BIN_OBJS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/caltools/fc-bin2rftab.c	Fri Mar 15 05:47:06 2019 +0000
@@ -0,0 +1,106 @@
+/*
+ * This utility reads a binary RF table or extracts it out of some larger
+ * binary file such as an alien fw image (the user must specify the offset
+ * in the binary file and the expected RF table type), and emits it in our
+ * FreeCalypso ASCII format.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+
+extern void write_afcparams_table();
+extern void write_agcwords_table();
+extern void write_agcglobals_table();
+extern void write_il2agc_table();
+extern void write_tx_ramps_table();
+extern void write_tx_levels_table();
+extern void write_tx_calchan_table();
+extern void write_tx_caltemp_table();
+extern void write_rx_calchan_table();
+extern void write_rx_caltemp_table();
+extern void write_rx_agcparams_table();
+
+static struct table_map {
+	char	*type;
+	int	size;
+	void	(*func)();
+} table_map[] = {
+	{"afcparams",		24,	write_afcparams_table},
+	{"agc-table",		40,	write_agcwords_table},
+	{"agc-global-params",	8,	write_agcglobals_table},
+	{"il2agc",		121,	write_il2agc_table},
+	{"tx-ramps",		512,	write_tx_ramps_table},
+	{"tx-levels",		128,	write_tx_levels_table},
+	{"tx-calchan",		128,	write_tx_calchan_table},
+	{"tx-caltemp",		40,	write_tx_caltemp_table},
+	{"rx-calchan",		40,	write_rx_calchan_table},
+	{"rx-caltemp",		44,	write_rx_caltemp_table},
+	{"rx-agc-params",	8,	write_rx_agcparams_table},
+	{0,			0,	0}
+};
+
+main(argc, argv)
+	char **argv;
+{
+	struct table_map *tp;
+	u_char buf[512];
+	int ifd, cc;
+	u_long offset;
+	char *endp;
+	FILE *outf;
+
+	if (argc < 4 || argc > 5) {
+		fprintf(stderr, "usage: %s binfile offset type [outfile]\n",
+			argv[0]);
+		exit(1);
+	}
+	ifd = open(argv[1], O_RDONLY);
+	if (ifd < 0) {
+		perror(argv[1]);
+		exit(1);
+	}
+	if (!isdigit(argv[2][0])) {
+inv_offset:	fprintf(stderr, "error: specified offset \"%s\" is invalid\n",
+			argv[2]);
+		exit(1);
+	}
+	offset = strtoul(argv[2], &endp, 0);
+	if (*endp)
+		goto inv_offset;
+	lseek(ifd, offset, SEEK_SET);
+	for (tp = table_map; tp->type; tp++)
+		if (!strcmp(tp->type, argv[3]))
+			break;
+	if (!tp->type) {
+		fprintf(stderr, "error: RF table type \"%s\" not known\n",
+			argv[3]);
+		exit(1);
+	}
+	cc = read(ifd, buf, tp->size);
+	if (cc < 0) {
+		perror("error reading from file");
+		exit(1);
+	}
+	if (cc != tp->size) {
+		fprintf(stderr, "error: short read\n");
+		exit(1);
+	}
+	close(ifd);
+	if (argc >= 5) {
+		outf = fopen(argv[4], "w");
+		if (!outf) {
+			perror(argv[4]);
+			exit(1);
+		}
+		tp->func(buf, outf);
+		fclose(outf);
+	} else
+		tp->func(buf, stdout);
+	exit(0);
+}