FreeCalypso > hg > freecalypso-tools
annotate rvinterf/asyncshell/oneshot.c @ 776:fac3176de18d
simagent: bare Tx implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Mar 2021 23:36:46 +0000 |
parents | b55a81ce7497 |
children |
rev | line source |
---|---|
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the one-shot command mode of fc-shell. |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <string.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <strings.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "limits.h" |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
10 #include "exitcodes.h" |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
748
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
451
diff
changeset
|
12 extern int cmd_batt_oneshot(); |
398
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
13 extern int cmd_key_oneshot(); |
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
14 extern int cmd_keydown_oneshot(); |
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
15 extern int cmd_keyup_oneshot(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int cmd_poweroff(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int cmd_send_oneshot(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int cmd_sp_oneshot(); |
75
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
19 extern int cmd_str_oneshot(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 extern int cmd_tchdl_oneshot(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern int cmd_tgtreset(); |
451
10f4062e049b
fc-shell: unterm command implemented in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
398
diff
changeset
|
22 extern int cmd_unterm_oneshot(); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 static struct cmdtab { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 char *cmd; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 int minargs; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 int maxargs; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int (*func)(); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } cmdtab[] = { |
748
b55a81ce7497
fc-shell: implement MMI_BATTERY_IND sending
Mychaela Falconia <falcon@freecalypso.org>
parents:
451
diff
changeset
|
30 {"batt", 2, 2, cmd_batt_oneshot}, |
398
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
31 {"key", 1, 1, cmd_key_oneshot}, |
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
32 {"keydown", 1, 1, cmd_keydown_oneshot}, |
8c7e86bc137e
fc-shell: added key commands for sending keystrokes via MMI CONFIG sysprims
Mychaela Falconia <falcon@freecalypso.org>
parents:
75
diff
changeset
|
33 {"keyup", 1, 1, cmd_keyup_oneshot}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 {"poweroff", 0, 0, cmd_poweroff}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 {"send", 1, MAX_PKT_TO_TARGET, cmd_send_oneshot}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 {"sp", 2, 2, cmd_sp_oneshot}, |
75
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
37 {"str", 1, 1, cmd_str_oneshot}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 {"tch-dl", 1, 1, cmd_tchdl_oneshot}, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 {"tgtreset", 0, 0, cmd_tgtreset}, |
451
10f4062e049b
fc-shell: unterm command implemented in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
398
diff
changeset
|
40 {"unterm", 1, 1, cmd_unterm_oneshot}, |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 {0, 0, 0, 0} |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 }; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 oneshot_command(argc, argv) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 char **argv; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 struct cmdtab *tp; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
75
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
49 if (!strncmp(argv[0], "AT", 2) || !strncmp(argv[0], "at", 2)) { |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
50 if (argc != 1) { |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
51 fprintf(stderr, |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
52 "error: AT command must be a single argument\n"); |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
53 exit(ERROR_USAGE); |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
54 } |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
55 return oneshot_at_command(argv[0]); |
bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
64
diff
changeset
|
56 } |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 for (tp = cmdtab; tp->cmd; tp++) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!strcmp(tp->cmd, argv[0])) |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 break; |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!tp->func) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 "error: \"%s\" is not a valid one-shot command\n", |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 argv[0]); |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
64 exit(ERROR_USAGE); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (argc - 1 > tp->maxargs) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 fprintf(stderr, "%s: too many arguments\n", tp->cmd); |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
68 exit(ERROR_USAGE); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (argc - 1 < tp->minargs) { |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 fprintf(stderr, "%s: too few arguments\n", tp->cmd); |
64
d43d82cbfb85
fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
72 exit(ERROR_USAGE); |
0
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 return tp->func(argc, argv); |
e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |