FreeCalypso > hg > freecalypso-tools
diff rvinterf/tmsh/audiocmd.c @ 32:ea061975c883
fc-tmsh: implemented sending of ETM audio load and save commands
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Oct 2016 21:52:29 +0000 |
parents | |
children | 2159f260ed13 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/tmsh/audiocmd.c Sun Oct 23 21:52:29 2016 +0000 @@ -0,0 +1,89 @@ +/* + * ETM audio 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" + +void +cmd_audio_load(argc, argv) + char **argv; +{ + u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; + int slen; + + slen = strlen(argv[1]); + if (slen > 9) { + printf("error: audio config name is limited to 9 chars\n"); + return; + } + dp = cmdpkt + 1; + *dp++ = ETM_AUDIO; + *dp++ = 'L'; + strcpy(dp, argv[1]); + dp += slen + 1; + send_etm_cmd(cmdpkt, dp - cmdpkt - 1); +} + +void +cmd_audio_save(argc, argv) + char **argv; +{ + u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; + int slen; + + slen = strlen(argv[1]); + if (slen > 9) { + printf("error: audio config name is limited to 9 chars\n"); + return; + } + dp = cmdpkt + 1; + *dp++ = ETM_AUDIO; + *dp++ = 'S'; + strcpy(dp, argv[1]); + dp += slen + 1; + send_etm_cmd(cmdpkt, dp - cmdpkt - 1); +} + +static struct cmdtab { + char *cmd; + int minargs; + int maxargs; + void (*func)(); +} audio_cmds[] = { + {"load", 1, 1, cmd_audio_load}, + {"save", 1, 1, cmd_audio_save}, + {0, 0, 0, 0} +}; + +void +cmd_audio(argc, argv) + char **argv; +{ + struct cmdtab *tp; + int extargs; + + for (tp = audio_cmds; tp->cmd; tp++) + if (!strcmp(tp->cmd, argv[1])) + break; + if (!tp->func) { + printf("error: no such audio command\n"); + return; + } + extargs = argc - 2; + if (extargs > tp->maxargs) { + printf("error: too many arguments\n"); + return; + } + if (extargs < tp->minargs) { + printf("error: too few arguments\n"); + return; + } + tp->func(argc - 1, argv + 1); +}