annotate rvinterf/tmsh/audiocmd.c @ 34:5ae8f6e55371

ringtools/examples: so-far-unsuccessful Melody E1 experiments
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 25 Oct 2016 08:17:07 +0000
parents ea061975c883
children 2159f260ed13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * ETM audio commands
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "limits.h"
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "localtypes.h"
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "etm.h"
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 void
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 cmd_audio_load(argc, argv)
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int slen;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 slen = strlen(argv[1]);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (slen > 9) {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 printf("error: audio config name is limited to 9 chars\n");
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 dp = cmdpkt + 1;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 *dp++ = ETM_AUDIO;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *dp++ = 'L';
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 strcpy(dp, argv[1]);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 dp += slen + 1;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 void
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cmd_audio_save(argc, argv)
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 char **argv;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 int slen;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 slen = strlen(argv[1]);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (slen > 9) {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 printf("error: audio config name is limited to 9 chars\n");
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 dp = cmdpkt + 1;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 *dp++ = ETM_AUDIO;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *dp++ = 'S';
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 strcpy(dp, argv[1]);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 dp += slen + 1;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 static struct cmdtab {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 char *cmd;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 int minargs;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 int maxargs;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 void (*func)();
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 } audio_cmds[] = {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 {"load", 1, 1, cmd_audio_load},
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {"save", 1, 1, cmd_audio_save},
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 {0, 0, 0, 0}
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 };
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 void
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 cmd_audio(argc, argv)
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 char **argv;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 struct cmdtab *tp;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 int extargs;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 for (tp = audio_cmds; tp->cmd; tp++)
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (!strcmp(tp->cmd, argv[1]))
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 break;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (!tp->func) {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 printf("error: no such audio command\n");
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 extargs = argc - 2;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (extargs > tp->maxargs) {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 printf("error: too many arguments\n");
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (extargs < tp->minargs) {
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 printf("error: too few arguments\n");
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 return;
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 tp->func(argc - 1, argv + 1);
ea061975c883 fc-tmsh: implemented sending of ETM audio load and save commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }