changeset 303:7de38a7e1fa5

c1xx-calextr: Rx calchan conversion implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 Nov 2017 06:10:54 +0000
parents e05563f0dfcf
children 9c1444923495
files ffstools/caltools/c1xx-calextr.c
diffstat 1 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ffstools/caltools/c1xx-calextr.c	Sun Nov 19 23:10:07 2017 +0000
+++ b/ffstools/caltools/c1xx-calextr.c	Mon Nov 20 06:10:54 2017 +0000
@@ -164,6 +164,42 @@
 	close(fd);
 }
 
+write_rx_calchan_ascii(band, table)
+	struct band *band;
+	u_char *table;
+{
+	char pathname[MAXPATHLEN];
+	FILE *of;
+
+	sprintf(pathname, "%s/rx-calchan.%s", ascii_output_dir, band->name);
+	of = fopen(pathname, "w");
+	if (!of) {
+		perror(pathname);
+		exit(1);
+	}
+	write_rx_calchan_table(table, of);
+	fclose(of);
+}
+
+write_rx_calchan_bin(band, table)
+	struct band *band;
+	u_char *table;
+{
+	char pathname[MAXPATHLEN];
+	int fd;
+
+	sprintf(pathname, "%s/rx", bin_output_dir);
+	mkdir_existok(pathname);
+	sprintf(pathname, "%s/rx/calchan.%s", bin_output_dir, band->name);
+	fd = open(pathname, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+	if (fd < 0) {
+		perror(pathname);
+		exit(1);
+	}
+	write(fd, table, 40);
+	close(fd);
+}
+
 write_tx_levels_ascii(band, table)
 	struct band *band;
 	u_char *table;
@@ -220,6 +256,33 @@
 		write_rx_agcparams_bin(band, rx_agcparams_table);
 }
 
+do_rx_calchan(band, compal_data)
+	struct band *band;
+	signed char *compal_data;
+{
+	u_char rx_calchan_table[40], *dp;
+	struct rx_calchan_map *map;
+	unsigned i, j;
+	int accum, average;
+
+	dp = rx_calchan_table;
+	for (i = 0; i < RF_RX_CAL_CHAN_SIZE; i++) {
+		map = band->rx_calchan_map + i;
+		*dp++ = map->upper_bound;
+		*dp++ = map->upper_bound >> 8;
+		accum = 0;
+		for (j = 0; j < map->compal_num; j++)
+			accum += compal_data[map->compal_start + j];
+		average = accum / (int)map->compal_num;
+		*dp++ = average;
+		*dp++ = average >> 8;
+	}
+	if (ascii_output_dir)
+		write_rx_calchan_ascii(band, rx_calchan_table);
+	if (bin_output_dir)
+		write_rx_calchan_bin(band, rx_calchan_table);
+}
+
 do_tx_levels(band, compal_data)
 	struct band *band;
 	u_char *compal_data;
@@ -263,6 +326,7 @@
 		return(-1);
 	}
 	do_rx_agcparams(band, record + 4);
+	do_rx_calchan(band, record + 6);
 	do_tx_levels(band, record + band->magic2_offset + 12);
 	return(0);
 }