view rvinterf/tmsh/l1cmd.c @ 123:bc23c1cd30ae

fc-tmsh: rftw format consistency check implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 19 Feb 2017 09:07:52 +0000
parents cad9129d0f03
children 8e37317f5de0
line wrap: on
line source

/*
 * In this module we are going to implement commands which send
 * TM3 command packets to the L1TM firmware component: RF calibration
 * and test modes.
 */

#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"

cmd_tminit(argc, argv)
	char **argv;
{
	u_char cmdpkt[3];

	cmdpkt[1] = TM_INIT;
	send_etm_cmd(cmdpkt, 1);
	return(0);
}

cmd_tms(argc, argv)
	char **argv;
{
	u16 arg;
	u_char cmdpkt[5];

	arg = strtoul(argv[1], 0, 0);
	cmdpkt[1] = TM_MODE_SET;
	cmdpkt[2] = arg;
	cmdpkt[3] = arg >> 8;
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

cmd_tm3ver(argc, argv)
	char **argv;
{
	u16 arg;
	u_char cmdpkt[5];

	arg = strtoul(argv[1], 0, 16);
	cmdpkt[1] = VERSION_GET;
	cmdpkt[2] = arg;
	cmdpkt[3] = arg >> 8;
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

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 rfe_arg[] = {
	{"stop-all", STOP_ALL},
	{"rx-tch", RX_TCH},
	{"tx-tch", TX_TCH},
	{"rx-tx-tch", RX_TX_TCH},
	{"rx-tx-pdtch", RX_TX_PDTCH},
	{"rx-tch-cont", RX_TCH_CONT},
	{"tx-tch-cont", TX_TCH_CONT},
	{"bcch-loop", BCCH_LOOP},
	{"sb-loop", SB_LOOP},
	{"fb1-loop", FB1_LOOP},
	{"fb0-loop", FB0_LOOP},
	{"single-pm", SINGLE_PM},
	{"rx-tx-pdtch-mon", RX_TX_PDTCH_MON},
	{"rx-tx-mon-tch", RX_TX_MON_TCH},
	{"rx-tx-mon", RX_TX_MON},
	{0, 0}
};

cmd_rfe(argc, argv)
	char **argv;
{
	u16 arg;
	u_char cmdpkt[5];

	if (keyword_or_num(argv[1], rfe_arg, &arg))
		return(ERROR_USAGE);
	cmdpkt[1] = RF_ENABLE;
	cmdpkt[2] = arg;
	cmdpkt[3] = arg >> 8;
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

static struct kwtab stats_config_arg[] = {
	{"loops", LOOPS},
	{"auto-result-loops", AUTO_RESULT_LOOPS},
	{"auto-reset-loops", AUTO_RESET_LOOPS},
	{"stat-gprs-slots", STAT_GPRS_SLOTS},
	{"stat-type", STAT_TYPE},
	{"stat-bitmask", STAT_BITMASK},
	{0, 0}
};

cmd_scw(argc, argv)
	char **argv;
{
	u16 index, value;
	u_char cmdpkt[7];

	if (keyword_or_num(argv[1], stats_config_arg, &index))
		return(ERROR_USAGE);
	value = strtoul(argv[2], 0, 0);
	cmdpkt[1] = STATS_CONFIG_WRITE;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	cmdpkt[4] = value;
	cmdpkt[5] = value >> 8;
	send_etm_cmd(cmdpkt, 5);
	return(0);
}

cmd_scr(argc, argv)
	char **argv;
{
	u16 index;
	u_char cmdpkt[5];

	if (keyword_or_num(argv[1], stats_config_arg, &index))
		return(ERROR_USAGE);
	cmdpkt[1] = STATS_CONFIG_READ;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

static struct kwtab stats_read_arg[] = {
	{"accum", ACCUMULATED_RX_STATS},
	{"most-recent", MOST_RECENT_RX_STATS},
	{0, 0}
};

cmd_sr(argc, argv)
	char **argv;
{
	u16 type, bitmask;
	u_char cmdpkt[7];

	if (keyword_or_num(argv[1], stats_read_arg, &type))
		return(ERROR_USAGE);
	bitmask = strtoul(argv[2], 0, 16);
	cmdpkt[1] = STATS_READ;
	cmdpkt[2] = type;
	cmdpkt[3] = type >> 8;
	cmdpkt[4] = bitmask;
	cmdpkt[5] = bitmask >> 8;
	send_etm_cmd(cmdpkt, 5);
	return(0);
}

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;
	u_char cmdpkt[7];

	if (keyword_or_num(argv[1], rf_param_arg, &index))
		return(ERROR_USAGE);
	value = strtol(argv[2], 0, 0);
	cmdpkt[1] = RF_PARAM_WRITE;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	cmdpkt[4] = value;
	cmdpkt[5] = value >> 8;
	send_etm_cmd(cmdpkt, 5);
	return(0);
}

cmd_rfpw3(argc, argv)
	char **argv;
{
	u16 index;
	u8 val1, val2;
	u_char cmdpkt[7];

	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);
	cmdpkt[1] = RF_PARAM_WRITE;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	cmdpkt[4] = val1;
	cmdpkt[5] = val2;
	send_etm_cmd(cmdpkt, 5);
	return(0);
}

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;
	u_char cmdpkt[5];

	if (keyword_or_num(argv[1], rf_param_arg, &index))
		return(ERROR_USAGE);
	cmdpkt[1] = RF_PARAM_READ;
	cmdpkt[2] = index;
	cmdpkt[3] = index >> 8;
	send_etm_cmd(cmdpkt, 3);
	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},
	{"tx-cal-extreme", TX_CAL_EXTREME},
	{"rx-calchan", RX_CAL_CHAN},
	{"rx-caltemp", RX_CAL_TEMP},
	{"rx-cal-level", RX_CAL_LEVEL},
	{"rx-agcparams", RX_AGC_PARAMS},
	{"rx-agcparams-pcs", RX_AGC_PARAMS_PCS},
	{"tx-data-buffer", TX_DATA_BUFFER},
	{"rlc-tx-buffer-cs1", RLC_TX_BUFFER_CS1},
	{"rlc-tx-buffer-cs2", RLC_TX_BUFFER_CS2},
	{"rlc-tx-buffer-cs3", RLC_TX_BUFFER_CS3},
	{"rlc-tx-buffer-cs4", RLC_TX_BUFFER_CS4},
	{0, 0}
};

cmd_rftw(argc, argv)
	char **argv;
{
	u16 index;
	u_char cmdpkt[MAX_RF_TABLE_SIZE + 4];
	int rc;
	char *format;
	unsigned size;

	if (keyword_or_num(argv[1], rf_table_arg, &index))
		return(ERROR_USAGE);
	cmdpkt[1] = RF_TABLE_WRITE;
	cmdpkt[2] = index;
	rc = read_rf_table(argv[2], cmdpkt + 3, &format, &size);
	if (rc)
		return(rc);
	if (argc > 3) {
		if (strcmp(argv[3], "force")) {
			printf("error: unexpected 3rd argument\n");
			return(ERROR_USAGE);
		}
	} else {
		rc = rftw_index_format_check(index, format);
		if (rc)
			return(rc);
	}
	send_etm_cmd(cmdpkt, size + 2);
	return(0);
}