view rvinterf/asyncshell/usercmd.c @ 992:a7b0b426f9ca

target-utils: boot ROM UART autodetection revamped The new implementation should work with both the familiar Calypso C035 boot ROM version found in our regular targets as well as the older Calypso F741979B version found on the vintage D-Sample board.
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Wed, 30 Dec 2015 21:28:41 +0000
parents bd873572ef2c
children 6eee1e547778
line wrap: on
line source

/*
 * This module implements interactive fc-shell command dispatch.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>

extern char usercmd[];

extern void cmd_disable();
extern void cmd_enable();
extern void cmd_poweroff();
extern void cmd_sendat();
extern void cmd_sp_interactive();
extern void cmd_tgtreset();

void
cmd_exit()
{
	tty_cleanup();
	exit(0);
}

static struct cmdtab {
	char *cmd;
	void (*func)();
} cmdtab[] = {
	{"disable", cmd_disable},
	{"enable", cmd_enable},
	{"exit", cmd_exit},
	{"poweroff", cmd_poweroff},
	{"quit", cmd_exit},
	{"sp", cmd_sp_interactive},
	{"str", cmd_sendat},
	{"tgtreset", cmd_tgtreset},
	{0, 0}
};

void
dispatch_user_cmd()
{
	char *cp, *np;
	struct cmdtab *tp;

	for (cp = usercmd; isspace(*cp); cp++)
		;
	if (!*cp || *cp == '#')
		return;
	if (!strncmp(cp, "AT", 2) || !strncmp(cp, "at", 2)) {
		cmd_sendat(cp);
		return;
	}
	for (np = cp; *cp && !isspace(*cp); cp++)
		;
	if (*cp)
		*cp++ = '\0';
	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, np))
			break;
	if (tp->func)
		tp->func(cp);
	else
		printf("error: no such command\n");
}