view rvinterf/tmsh/bsimcmd.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents b3724fe6c581
children
line wrap: on
line source

/*
 * In this module we are going to implement FreeCalypso BSIM
 * (battery simulation mode) commands.
 */

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "limits.h"
#include "localtypes.h"
#include "etm.h"
#include "bsim_etm_cmd.h"
#include "exitcodes.h"

cmd_bsim_query(argc, argv)
	char **argv;
{
	u_char cmdpkt[4];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_QUERY;
	send_etm_cmd(cmdpkt, 2);
	return(0);
}

cmd_bsim_disch(argc, argv)
	char **argv;
{
	u_char cmdpkt[5];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_DISCHARGE;
	cmdpkt[3] = strtoul(argv[1], 0, 0);
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

cmd_bsim_start(argc, argv)
	char **argv;
{
	u_char cmdpkt[4];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_CHG_START;
	send_etm_cmd(cmdpkt, 2);
	return(0);
}

cmd_bsim_start_enable(argc, argv)
	char **argv;
{
	u_char cmdpkt[5];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_START_ENABLE;
	cmdpkt[3] = strtoul(argv[1], 0, 0);
	send_etm_cmd(cmdpkt, 3);
	return(0);
}

cmd_bsim_ci2cv(argc, argv)
	char **argv;
{
	u_char cmdpkt[4];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_CHG_CI2CV;
	send_etm_cmd(cmdpkt, 2);
	return(0);
}

cmd_bsim_complete(argc, argv)
	char **argv;
{
	u_char cmdpkt[4];

	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_CHG_COMPLETE;
	send_etm_cmd(cmdpkt, 2);
	return(0);
}

cmd_bsim_ichg(argc, argv)
	char **argv;
{
	u_char cmdpkt[6];
	unsigned ichg;

	ichg = strtoul(argv[1], 0, 0);
	cmdpkt[1] = ETM_BSIM;
	cmdpkt[2] = BSIM_CMD_SET_ICHG;
	cmdpkt[3] = ichg;
	cmdpkt[4] = ichg >> 8;
	send_etm_cmd(cmdpkt, 4);
	return(0);
}

static struct cmdtab {
	char *cmd;
	int minargs;
	int maxargs;
	int (*func)();
} bsim_cmds[] = {
	{"ci2cv", 0, 0, cmd_bsim_ci2cv},
	{"complete", 0, 0, cmd_bsim_complete},
	{"disch", 1, 1, cmd_bsim_disch},
	{"ichg", 1, 1, cmd_bsim_ichg},
	{"query", 0, 0, cmd_bsim_query},
	{"start", 0, 0, cmd_bsim_start},
	{"start-enable", 1, 1, cmd_bsim_start_enable},
	{0, 0, 0, 0}
};

cmd_bsim(argc, argv)
	char **argv;
{
	struct cmdtab *tp;
	int extargs;

	for (tp = bsim_cmds; tp->cmd; tp++)
		if (!strcmp(tp->cmd, argv[1]))
			break;
	if (!tp->func) {
		printf("error: no such bsim command\n");
		return(ERROR_USAGE);
	}
	extargs = argc - 2;
	if (extargs > tp->maxargs) {
		printf("error: too many arguments\n");
		return(ERROR_USAGE);
	}
	if (extargs < tp->minargs) {
		printf("error: too few arguments\n");
		return(ERROR_USAGE);
	}
	return tp->func(argc - 1, argv + 1);
}