changeset 965:bd873572ef2c

fc-shell: one-shot command mode implemented
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Sat, 07 Nov 2015 00:00:46 +0000
parents 373af5f74e39
children 64cddafcd939
files rvinterf/asyncshell/Makefile rvinterf/asyncshell/main.c rvinterf/asyncshell/oneshot.c rvinterf/asyncshell/poweroff.c rvinterf/asyncshell/sendsp.c rvinterf/asyncshell/usercmd.c
diffstat 6 files changed, 66 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/asyncshell/Makefile	Fri Nov 06 23:22:47 2015 +0000
+++ b/rvinterf/asyncshell/Makefile	Sat Nov 07 00:00:46 2015 +0000
@@ -1,7 +1,8 @@
 CC=	gcc
 CFLAGS=	-O2 -I../include
 PROG=	fc-shell
-OBJS=	at.o init.o main.o pktsort.o poweroff.o rxctl.o sendsp.o usercmd.o
+OBJS=	at.o init.o main.o oneshot.o pktsort.o poweroff.o rxctl.o sendsp.o \
+	usercmd.o
 LIBS=	../libasync/libasync.a ../libg23/libg23.a
 INSTBIN=/usr/local/bin
 
--- a/rvinterf/asyncshell/main.c	Fri Nov 06 23:22:47 2015 +0000
+++ b/rvinterf/asyncshell/main.c	Sat Nov 07 00:00:46 2015 +0000
@@ -69,6 +69,9 @@
 		connect_local_socket();
 	}
 
+	if (argv[optind])
+		return oneshot_command(argc - optind, argv + optind);
+
 	ttyhacks = isatty(0) && !dflag;
 	init();
 	tty_init();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/asyncshell/oneshot.c	Sat Nov 07 00:00:46 2015 +0000
@@ -0,0 +1,49 @@
+/*
+ * This module implements the one-shot command mode of fc-shell.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+extern int cmd_poweroff();
+extern int cmd_sp_oneshot();
+extern int cmd_tgtreset();
+
+static struct cmdtab {
+	char *cmd;
+	int minargs;
+	int maxargs;
+	int (*func)();
+} cmdtab[] = {
+	{"poweroff", 0, 0, cmd_poweroff},
+	{"sp", 2, 2, cmd_sp_oneshot},
+	{"tgtreset", 0, 0, cmd_tgtreset},
+	{0, 0, 0, 0}
+};
+
+oneshot_command(argc, argv)
+	char **argv;
+{
+	struct cmdtab *tp;
+
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[0]))
+			break;
+	if (!tp->func) {
+		fprintf(stderr,
+			"error: \"%s\" is not a valid one-shot command\n",
+			argv[0]);
+		exit(1);
+	}
+	if (argc - 1 > tp->maxargs) {
+		fprintf(stderr, "%s: too many arguments\n", tp->cmd);
+		exit(1);
+	}
+	if (argc - 1 < tp->minargs) {
+		fprintf(stderr, "%s: too few arguments\n", tp->cmd);
+		exit(1);
+	}
+	return tp->func(argc, argv);
+}
--- a/rvinterf/asyncshell/poweroff.c	Fri Nov 06 23:22:47 2015 +0000
+++ b/rvinterf/asyncshell/poweroff.c	Sat Nov 07 00:00:46 2015 +0000
@@ -8,7 +8,6 @@
 #include "pktmux.h"
 #include "etm.h"
 
-void
 send_etm_cmd(buf, len)
 	u_char *buf;
 {
@@ -20,9 +19,9 @@
 		c ^= buf[i];
 	buf[i] = c;
 	send_pkt_to_target(buf, len + 2);
+	return 0;
 }
 
-void
 cmd_poweroff()
 {
 	u_char cmdpkt[7];
@@ -32,15 +31,14 @@
 	cmdpkt[3] = 30;		/* VRPCDEV */
 	cmdpkt[4] = 0x01;	/* low 8 bits */
 	cmdpkt[5] = 0;		/* high 2 bits */
-	send_etm_cmd(cmdpkt, 5);
+	return send_etm_cmd(cmdpkt, 5);
 }
 
-void
 cmd_tgtreset()
 {
 	u_char cmdpkt[4];
 
 	cmdpkt[1] = ETM_CORE;
 	cmdpkt[2] = TMCORE_OPC_RESET;
-	send_etm_cmd(cmdpkt, 2);
+	return send_etm_cmd(cmdpkt, 2);
 }
--- a/rvinterf/asyncshell/sendsp.c	Fri Nov 06 23:22:47 2015 +0000
+++ b/rvinterf/asyncshell/sendsp.c	Sat Nov 07 00:00:46 2015 +0000
@@ -51,7 +51,7 @@
 }
 
 void
-cmd_sendsp(args)
+cmd_sp_interactive(args)
 	char *args;
 {
 	char *cp, *np;
@@ -74,3 +74,9 @@
 	gpf_rx_control(1);
 	send_gpf_sysprim(np, cp);
 }
+
+cmd_sp_oneshot(argc, argv)
+	char **argv;
+{
+	return send_gpf_sysprim(argv[1], argv[2]);
+}
--- a/rvinterf/asyncshell/usercmd.c	Fri Nov 06 23:22:47 2015 +0000
+++ b/rvinterf/asyncshell/usercmd.c	Sat Nov 07 00:00:46 2015 +0000
@@ -15,7 +15,7 @@
 extern void cmd_enable();
 extern void cmd_poweroff();
 extern void cmd_sendat();
-extern void cmd_sendsp();
+extern void cmd_sp_interactive();
 extern void cmd_tgtreset();
 
 void
@@ -34,7 +34,7 @@
 	{"exit", cmd_exit},
 	{"poweroff", cmd_poweroff},
 	{"quit", cmd_exit},
-	{"sp", cmd_sendsp},
+	{"sp", cmd_sp_interactive},
 	{"str", cmd_sendat},
 	{"tgtreset", cmd_tgtreset},
 	{0, 0}