FreeCalypso > hg > freecalypso-sw
annotate rvinterf/asyncshell/oneshot.c @ 1022:24440bc7cee8
gsm-fw/configs: gtamodem-gsmtch-{ext,int} configurations added
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Tue, 03 May 2016 13:43:31 +0000 |
parents | 0511507bf6e7 |
children |
rev | line source |
---|---|
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements the one-shot command mode of fc-shell. |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <stdio.h> |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <string.h> |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <strings.h> |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <stdlib.h> |
1012
93f4fc26b204
fc-shell: arbitrary send command implemented in one-shot mode
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
965
diff
changeset
|
9 #include "limits.h" |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 extern int cmd_poweroff(); |
1012
93f4fc26b204
fc-shell: arbitrary send command implemented in one-shot mode
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
965
diff
changeset
|
12 extern int cmd_send_oneshot(); |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 extern int cmd_sp_oneshot(); |
1014
0511507bf6e7
fc-shell: tch-dl control command implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
1012
diff
changeset
|
14 extern int cmd_tchdl_oneshot(); |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern int cmd_tgtreset(); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 static struct cmdtab { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 char *cmd; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 int minargs; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 int maxargs; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 int (*func)(); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 } cmdtab[] = { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 {"poweroff", 0, 0, cmd_poweroff}, |
1012
93f4fc26b204
fc-shell: arbitrary send command implemented in one-shot mode
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
965
diff
changeset
|
24 {"send", 1, MAX_PKT_TO_TARGET, cmd_send_oneshot}, |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 {"sp", 2, 2, cmd_sp_oneshot}, |
1014
0511507bf6e7
fc-shell: tch-dl control command implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
1012
diff
changeset
|
26 {"tch-dl", 1, 1, cmd_tchdl_oneshot}, |
965
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 {"tgtreset", 0, 0, cmd_tgtreset}, |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 {0, 0, 0, 0} |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 }; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 oneshot_command(argc, argv) |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 char **argv; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 struct cmdtab *tp; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 for (tp = cmdtab; tp->cmd; tp++) |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 if (!strcmp(tp->cmd, argv[0])) |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 break; |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 if (!tp->func) { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 fprintf(stderr, |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 "error: \"%s\" is not a valid one-shot command\n", |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 argv[0]); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 exit(1); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 } |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 if (argc - 1 > tp->maxargs) { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 fprintf(stderr, "%s: too many arguments\n", tp->cmd); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 exit(1); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 if (argc - 1 < tp->minargs) { |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 fprintf(stderr, "%s: too few arguments\n", tp->cmd); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 exit(1); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 } |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 return tp->func(argc, argv); |
bd873572ef2c
fc-shell: one-shot command mode implemented
Mychaela Falconia <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |