comparison 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
comparison
equal deleted inserted replaced
31:5b4e345095c4 32:ea061975c883
1 /*
2 * ETM audio commands
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdlib.h>
10 #include "limits.h"
11 #include "localtypes.h"
12 #include "etm.h"
13
14 void
15 cmd_audio_load(argc, argv)
16 char **argv;
17 {
18 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
19 int slen;
20
21 slen = strlen(argv[1]);
22 if (slen > 9) {
23 printf("error: audio config name is limited to 9 chars\n");
24 return;
25 }
26 dp = cmdpkt + 1;
27 *dp++ = ETM_AUDIO;
28 *dp++ = 'L';
29 strcpy(dp, argv[1]);
30 dp += slen + 1;
31 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
32 }
33
34 void
35 cmd_audio_save(argc, argv)
36 char **argv;
37 {
38 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
39 int slen;
40
41 slen = strlen(argv[1]);
42 if (slen > 9) {
43 printf("error: audio config name is limited to 9 chars\n");
44 return;
45 }
46 dp = cmdpkt + 1;
47 *dp++ = ETM_AUDIO;
48 *dp++ = 'S';
49 strcpy(dp, argv[1]);
50 dp += slen + 1;
51 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
52 }
53
54 static struct cmdtab {
55 char *cmd;
56 int minargs;
57 int maxargs;
58 void (*func)();
59 } audio_cmds[] = {
60 {"load", 1, 1, cmd_audio_load},
61 {"save", 1, 1, cmd_audio_save},
62 {0, 0, 0, 0}
63 };
64
65 void
66 cmd_audio(argc, argv)
67 char **argv;
68 {
69 struct cmdtab *tp;
70 int extargs;
71
72 for (tp = audio_cmds; tp->cmd; tp++)
73 if (!strcmp(tp->cmd, argv[1]))
74 break;
75 if (!tp->func) {
76 printf("error: no such audio command\n");
77 return;
78 }
79 extargs = argc - 2;
80 if (extargs > tp->maxargs) {
81 printf("error: too many arguments\n");
82 return;
83 }
84 if (extargs < tp->minargs) {
85 printf("error: too few arguments\n");
86 return;
87 }
88 tp->func(argc - 1, argv + 1);
89 }