view rvinterf/tmsh/bsimcmd.c @ 995:74024eb17e04

fc-loadtool help: improve language regarding 16 MiB flash chips In FC project history, 16 MiB flash originally meant Pirelli DP-L10. Then we got FCDEV3B with the same flash (our own design), but now we are discovering more Calypso devices that used such large flash, both late Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to migrate to more generic or neutral language in associated documentation, without giving elevated status to specific examples that drove our early project history.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 21:11:12 +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);
}