view rvinterf/etmsync/l1tmcmd.c @ 888:b8ecdf54a957

fc-imyplay script
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Apr 2022 04:28:44 +0000
parents aec320fe2653
children
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);
}

static struct kwtab misc_param_arg[] = {
	{"adc-interval", ADC_INTERVAL},
	{"adc-enable", ADC_ENA_FLAG},
	{"converted-adc0", CONVERTED_ADC0},
	{"converted-adc1", CONVERTED_ADC1},
	{"converted-adc2", CONVERTED_ADC2},
	{"converted-adc3", CONVERTED_ADC3},
	{"converted-adc4", CONVERTED_ADC4},
	{"converted-adc5", CONVERTED_ADC5},
	{"converted-adc6", CONVERTED_ADC6},
	{"converted-adc7", CONVERTED_ADC7},
	{"converted-adc8", CONVERTED_ADC8},
	{"raw-adc0", RAW_ADC0},
	{"raw-adc1", RAW_ADC1},
	{"raw-adc2", RAW_ADC2},
	{"raw-adc3", RAW_ADC3},
	{"raw-adc4", RAW_ADC4},
	{"raw-adc5", RAW_ADC5},
	{"raw-adc6", RAW_ADC6},
	{"raw-adc7", RAW_ADC7},
	{"raw-adc8", RAW_ADC8},
	{"adc0-coeff-a", ADC0_COEFF_A},
	{"adc1-coeff-a", ADC1_COEFF_A},
	{"adc2-coeff-a", ADC2_COEFF_A},
	{"adc3-coeff-a", ADC3_COEFF_A},
	{"adc4-coeff-a", ADC4_COEFF_A},
	{"adc5-coeff-a", ADC5_COEFF_A},
	{"adc6-coeff-a", ADC6_COEFF_A},
	{"adc7-coeff-a", ADC7_COEFF_A},
	{"adc8-coeff-a", ADC8_COEFF_A},
	{"adc0-coeff-b", ADC0_COEFF_B},
	{"adc1-coeff-b", ADC1_COEFF_B},
	{"adc2-coeff-b", ADC2_COEFF_B},
	{"adc3-coeff-b", ADC3_COEFF_B},
	{"adc4-coeff-b", ADC4_COEFF_B},
	{"adc5-coeff-b", ADC5_COEFF_B},
	{"adc6-coeff-b", ADC6_COEFF_B},
	{"adc7-coeff-b", ADC7_COEFF_B},
	{"adc8-coeff-b", ADC8_COEFF_B},
	{"sleep-mode", SLEEP_MODE},
	{"current-tm-mode", CURRENT_TM_MODE},
	{0, 0}
};

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

	if (keyword_or_num(argv[1], misc_param_arg, &index))
		return(ERROR_USAGE);
	rc = do_mpr(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);
}

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

	rc = do_mpr(CONVERTED_ADC0, &val);
	if (rc)
		return(rc);
	printf("VBAT=%u\n", val);
	rc = do_mpr(CONVERTED_ADC1, &val);
	if (rc)
		return(rc);
	printf("VCHG=%u\n", val);
	rc = do_mpr(RAW_ADC2, &val);
	if (rc)
		return(rc);
	printf("ICHG=%u\n", val);
	rc = do_mpr(CONVERTED_ADC3, &val);
	if (rc)
		return(rc);
	printf("VBACKUP=%u\n", val);
	rc = do_mpr(RAW_ADC4, &val);
	if (rc)
		return(rc);
	printf("ADIN1=0x%04X\n", val);
	rc = do_mpr(RAW_ADC5, &val);
	if (rc)
		return(rc);
	printf("ADIN2=0x%04X\n", val);
	rc = do_mpr(RAW_ADC6, &val);
	if (rc)
		return(rc);
	printf("ADIN3=0x%04X\n", val);
	rc = do_mpr(RAW_ADC7, &val);
	if (rc)
		return(rc);
	printf("ADIN4=0x%04X\n", val);
	return(0);
}