view rvinterf/etmsync/l1tmcmd.c @ 809:c30c2f6a55c2

CHANGES: fc-host-tools-r15 released
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 27 Mar 2021 18:48:36 +0000
parents dd97e75620a7
children 4694c7686ccd
line wrap: on
line source

/*
 * This module contains the user command wrappers around the functions
 * in the l1tmops.c module.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "pktmux.h"
#include "limits.h"
#include "localtypes.h"
#include "tm3.h"
#include "l1tm.h"
#include "exitcodes.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();

cmd_tms(argc, argv)
	char **argv;
{
	u16 arg;

	arg = strtoul(argv[1], 0, 0);
	return do_tms(arg);
}

static
is_num_string(argstr)
	char *argstr;
{
	char *cp = argstr;

	if (!isdigit(*cp++))
		return(0);
	while (*cp) {
		if (!isdigit(*cp++))
			return(0);
	}
	return(1);
}

struct kwtab {
	char	*kw;
	int	val;
};

static
keyword_or_num(argstr, kwtab, valp)
	char *argstr;
	struct kwtab *kwtab;
	u16 *valp;
{
	struct kwtab *tp;

	if (is_num_string(argstr)) {
		*valp = atoi(argstr);
		return(0);
	}
	for (tp = kwtab; tp->kw; tp++) {
		if (!strcmp(tp->kw, argstr)) {
			*valp = tp->val;
			return(0);
		}
	}
	printf("error: non-numeric argument not understood\n");
	return(ERROR_USAGE);
}

static struct kwtab rf_param_arg[] = {
	{"bcch-arfcn", BCCH_ARFCN},
	{"tch-arfcn", TCH_ARFCN},
	{"mon-arfcn", MON_ARFCN},
	{"pdtch-arfcn", PDTCH_ARFCN},
	{"std-band", STD_BAND_FLAG},
	{"afc-enable", AFC_ENA_FLAG},
	{"afc-dac-val", AFC_DAC_VALUE},
	{"init-afc-dac", INITIAL_AFC_DAC},
	{"multislot-class", MULTISLOT_CLASS},
	{0, 0}
};

cmd_rfpw2(argc, argv)
	char **argv;
{
	u16 index, value;

	if (keyword_or_num(argv[1], rf_param_arg, &index))
		return(ERROR_USAGE);
	value = strtol(argv[2], 0, 0);
	return do_rfpw(index, value);
}

cmd_rfpw3(argc, argv)
	char **argv;
{
	u16 index;
	u8 val1, val2;

	if (keyword_or_num(argv[1], rf_param_arg, &index))
		return(ERROR_USAGE);
	val1 = strtoul(argv[2], 0, 0);
	val2 = strtoul(argv[3], 0, 0);
	return do_rfpw(index, (val2 << 8) | val1);
}

cmd_rfpw(argc, argv)
	char **argv;
{
	switch (argc) {
	case 3:
		return cmd_rfpw2(argc, argv);
	case 4:
		return cmd_rfpw3(argc, argv);
	default:
		fprintf(stderr, "BUG: wrong argc in cmd_rfpw()\n");
		return(ERROR_BUG);
	}
}

cmd_rfpr(argc, argv)
	char **argv;
{
	u16 index, val;
	int rc;

	if (keyword_or_num(argv[1], rf_param_arg, &index))
		return(ERROR_USAGE);
	rc = do_rfpr(index, &val);
	if (rc)
		return(rc);
	if (val >= 0x8000)
		printf("read value: 0x%04X (%u or %d)\n", val, val,
			(int)val - 65536);
	else
		printf("read value: 0x%04X (%u)\n", val, val);
	return(0);
}

static struct kwtab rf_table_arg[] = {
	{"rx-agc-table", RX_AGC_TABLE},
	{"afcparams", AFC_PARAMS},
	{"rx-agc-global-params", RX_AGC_GLOBAL_PARAMS},
	{"rx-il2agc-max", RX_IL_2_AGC_MAX},
	{"rx-il2agc-pwr", RX_IL_2_AGC_PWR},
	{"rx-il2agc-av", RX_IL_2_AGC_AV},
	{"tx-levels", TX_LEVELS},
	{"tx-calchan", TX_CAL_CHAN},
	{"tx-caltemp", TX_CAL_TEMP},
	{"rx-calchan", RX_CAL_CHAN},
	{"rx-caltemp", RX_CAL_TEMP},
	{"rx-agcparams", RX_AGC_PARAMS},
	{0, 0}
};

static struct table_map {
	int	index;
	int	size;
	void	(*func)();
} table_map[] = {
	{RX_AGC_TABLE,		40,	write_agcwords_table},
	{AFC_PARAMS,		24,	write_afcparams_table},
	{RX_AGC_GLOBAL_PARAMS,	8,	write_agcglobals_table},
	{RX_IL_2_AGC_MAX,	121,	write_il2agc_table},
	{RX_IL_2_AGC_PWR,	121,	write_il2agc_table},
	{RX_IL_2_AGC_AV,	121,	write_il2agc_table},
	{TX_LEVELS,		128,	write_tx_levels_table},
	{TX_CAL_CHAN,		128,	write_tx_calchan_table},
	{TX_CAL_TEMP,		40,	write_tx_caltemp_table},
	{RX_CAL_CHAN,		40,	write_rx_calchan_table},
	{RX_CAL_TEMP,		44,	write_rx_caltemp_table},
	{RX_AGC_PARAMS,		8,	write_rx_agcparams_table},
	{0,			0,	0}
};

cmd_rftr(argc, argv)
	char **argv;
{
	u16 index;
	struct table_map *tp;
	u_char table_data[MAX_RF_TABLE_SIZE];
	int rc;
	FILE *of;

	if (keyword_or_num(argv[1], rf_table_arg, &index))
		return(ERROR_USAGE);
	for (tp = table_map; tp->index; tp++) {
		if (tp->index == index)
			break;
	}
	if (!tp->index) {
		printf("error: table index %u not supported, use fc-tmsh\n",
			index);
		return(ERROR_USAGE);
	}
	rc = do_rftr(index, table_data, tp->size);
	if (rc)
		return(rc);
	if (argv[2]) {
		of = fopen(argv[2], "w");
		if (!of) {
			perror(argv[2]);
			return(ERROR_UNIX);
		}
		tp->func(table_data, of);
		fclose(of);
	} else
		tp->func(table_data, stdout);
	return(0);
}

cmd_ttr(argc, argv)
	char **argv;
{
	unsigned index;
	u_char ramp_data[32];
	int rc;

	index = strtoul(argv[1], 0, 0);
	if (index >= 16) {
		printf("error: index out of range\n");
		return(ERROR_USAGE);
	}
	rc = do_ttr(index, ramp_data);
	if (rc)
		return(rc);
	write_tx_ramp(ramp_data, stdout);
	return(0);
}

cmd_ttr_all(argc, argv)
	char **argv;
{
	u_char table[512];
	int rc, i;
	FILE *of;

	for (i = 0; i < 16; i++) {
		rc = do_ttr(i, table + i * 32);
		if (rc)
			return(rc);
	}
	of = fopen(argv[1], "w");
	if (!of) {
		perror(argv[1]);
		return(ERROR_UNIX);
	}
	write_tx_ramps_table(table, of);
	fclose(of);
	return(0);
}