# HG changeset patch # User Mychaela Falconia # Date 1446854446 0 # Node ID bd873572ef2c497cb54aa0a8c1ac4b8fd136b7f5 # Parent 373af5f74e3945a0b4cb3a80bc633a9b8738857c fc-shell: one-shot command mode implemented diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/Makefile --- 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 diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/main.c --- 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(); diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/oneshot.c --- /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 +#include +#include +#include + +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); +} diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/poweroff.c --- 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); } diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/sendsp.c --- 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]); +} diff -r 373af5f74e39 -r bd873572ef2c rvinterf/asyncshell/usercmd.c --- 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}