changeset 816:b3724fe6c581

fc-tmsh bsim commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 May 2021 17:16:43 +0000
parents bc1e150f5bd9
children 9706832b740b
files rvinterf/tmsh/Makefile rvinterf/tmsh/bsimcmd.c rvinterf/tmsh/usercmd.c
diffstat 3 files changed, 144 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/tmsh/Makefile	Fri May 14 15:51:20 2021 +0000
+++ b/rvinterf/tmsh/Makefile	Fri May 14 17:16:43 2021 +0000
@@ -2,9 +2,9 @@
 CFLAGS=	-O2
 CPPFLAGS=-I../include
 PROG=	fc-tmsh
-OBJS=	abb.o abbtm3.o audiocmd.o audioresp.o etmbasic.o ffs2.o ffs2resp.o \
-	init.o l1cmd.o l1resp.o main.o misc.o omr.o omw.o oneshot.o pktsort.o \
-	rftablechk.o saverftab.o tmcore.o usercmd.o
+OBJS=	abb.o abbtm3.o audiocmd.o audioresp.o bsimcmd.o etmbasic.o ffs2.o \
+	ffs2resp.o init.o l1cmd.o l1resp.o main.o misc.o omr.o omw.o oneshot.o \
+	pktsort.o rftablechk.o saverftab.o tmcore.o usercmd.o
 LIBS=	../libasync/libasync.a ../libinterf/libinterf.a \
 	../../librftab/librftab.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/bsimcmd.c	Fri May 14 17:16:43 2021 +0000
@@ -0,0 +1,139 @@
+/*
+ * 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);
+}
--- a/rvinterf/tmsh/usercmd.c	Fri May 14 15:51:20 2021 +0000
+++ b/rvinterf/tmsh/usercmd.c	Fri May 14 17:16:43 2021 +0000
@@ -19,6 +19,7 @@
 extern int cmd_aus();
 extern int cmd_auw();
 extern int cmd_auw_fir();
+extern int cmd_bsim();
 extern int cmd_check_ffs1();
 extern int cmd_dieid();
 extern int cmd_ffs2();
@@ -82,6 +83,7 @@
 	{"aus", 1, 1, cmd_aus},
 	{"auw", 2, 126, cmd_auw},
 	{"auw-fir", 2, 2, cmd_auw_fir},
+	{"bsim", 1, 2, cmd_bsim},
 	{"check-ffs1", 0, 0, cmd_check_ffs1},
 	{"dieid", 0, 0, cmd_dieid},
 	{"etmpkt", 1, 253, cmd_tmpkt},