diff autocal/gmagicstand.c @ 73:c9bd1f75029f

autocal: C main modules for standalone programs renamed more sensibly
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 15 Jul 2017 18:14:49 +0000
parents autocal/gmagicmain.c@fe39aac56cde
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/autocal/gmagicstand.c	Sat Jul 15 18:14:49 2017 +0000
@@ -0,0 +1,89 @@
+/*
+ * fc-rfcal-gmagic is a debug utility implementing just one part
+ * of the fc-rfcal-rxband process in a standalone manner;
+ * this module contains the main() function for this standalone utlity.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <rvinterf/l1tm.h>
+#include <rvinterf/exitcodes.h>
+#include "rxcaldefs.h"
+#include "stdband.h"
+
+static struct band {
+	char		*name;
+	unsigned	rfpw_std_band;
+	unsigned	default_arfcn;
+} bands[] = {
+	{"850",  RFPW_STD_BAND_850,  189},
+	{"900",  RFPW_STD_BAND_900,   37},
+	{"1800", RFPW_STD_BAND_1800, 698},
+	{"1900", RFPW_STD_BAND_1900, 661},
+	{0,	 0,		     0}
+};
+static struct band *selected_band;
+static unsigned arfcn;
+
+finish_cmdline(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	struct band *band;
+
+	if (argc - optind < 1 || argc - optind > 2) {
+		fprintf(stderr, "usage: %s band [arfcn]\n", argv[0]);
+		exit(ERROR_USAGE);
+	}
+	for (band = bands; band->name; band++)
+		if (!strcmp(band->name, argv[optind]))
+			break;
+	if (!band->name) {
+		fprintf(stderr, "error: \"%s\" is not a known band\n",
+			argv[optind]);
+		exit(ERROR_USAGE);
+	}
+	selected_band = band;
+	if (argv[optind+1])
+		arfcn = atoi(argv[optind+1]);
+	else
+		arfcn = band->default_arfcn;
+	return(0);
+}
+
+prepare_rf_test_system()
+{
+	char cmd[80];
+
+	printf("Preparing RF test system for %s MHz Rx calibration\n",
+		selected_band->name);
+	sprintf(cmd, "signal-gen-setup %s\n", selected_band->name);
+	tsid_command(cmd);
+	return(0);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	int pm, Gmagic;
+	char Gmagic_db[64];
+
+	socket_pathname_options(argc, argv);
+	finish_cmdline(argc, argv);
+	connect_rvinterf_socket();
+	connect_tsid_socket();
+	setlinebuf(stdout);	/* to allow logging with tee */
+	prepare_rf_test_system();
+
+	printf("Putting the DUT into Test Mode\n");
+	do_tms(1);
+	do_rfpw(STD_BAND_FLAG, selected_band->rfpw_std_band);
+	l1tm_setup_for_rxcal();
+	pm = rx_measure(arfcn);
+	Gmagic = pm - RXCAL_SIGGEN_LEVEL - RXCAL_AGC_DB * 2;
+	halfdb_to_string(Gmagic, Gmagic_db);
+	printf("GMagic=%d (%s dB)\n", Gmagic, Gmagic_db);
+	exit(0);
+}