FreeCalypso > hg > freecalypso-sw
annotate rvinterf/asyncshell/usercmd.c @ 879:4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 00:19:28 +0000 |
parents | dab341e172de |
children | 1b1683cda154 |
rev | line source |
---|---|
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module implements interactive fc-shell command dispatch. |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <ctype.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <stdio.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <string.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <strings.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdlib.h> |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 extern char usercmd[]; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
14 extern void cmd_disable(); |
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
15 extern void cmd_enable(); |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
16 extern void cmd_sendat(); |
875
dab341e172de
fc-shell: sysprim sending (sp command) implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
874
diff
changeset
|
17 extern void cmd_sendsp(); |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
18 |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 void |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 cmd_exit() |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 tty_cleanup(); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 exit(0); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 } |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 static struct cmdtab { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 char *cmd; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 void (*func)(); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 } cmdtab[] = { |
874
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
30 {"disable", cmd_disable}, |
72d64c172d85
fc-shell: Rx control implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
872
diff
changeset
|
31 {"enable", cmd_enable}, |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 {"exit", cmd_exit}, |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 {"quit", cmd_exit}, |
875
dab341e172de
fc-shell: sysprim sending (sp command) implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
874
diff
changeset
|
34 {"sp", cmd_sendsp}, |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
35 {"str", cmd_sendat}, |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 {0, 0} |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 }; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 void |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 dispatch_user_cmd() |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 { |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 char *cp, *np; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 struct cmdtab *tp; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 for (cp = usercmd; isspace(*cp); cp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 ; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (!*cp || *cp == '#') |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 return; |
879
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
49 if (!strncmp(cp, "AT", 2) || !strncmp(cp, "at", 2)) { |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
50 cmd_sendat(cp); |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
51 return; |
4661b84260a0
fc-shell: AT-over-RVTMUX command sending implemented
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
875
diff
changeset
|
52 } |
872
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 for (np = cp; *cp && !isspace(*cp); cp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 ; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 if (*cp) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 *cp++ = '\0'; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 for (tp = cmdtab; tp->cmd; tp++) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 if (!strcmp(tp->cmd, np)) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 break; |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 if (tp->func) |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 tp->func(cp); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 else |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 printf("error: no such command\n"); |
5e46679bdb6a
fc-shell skeleton created
Space Falcon <falcon@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 } |