annotate rvinterf/asyncshell/at.c @ 430:06442f27b144

doc/RVTMUX: added note at the beginning about paradigm changes
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 04 Nov 2018 01:55:35 +0000
parents dd0247097097
children e13f60d4f8dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 * Functions for the AT-over-RVTMUX interface
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 <sys/types.h>
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
6 #include <sys/errno.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <ctype.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
12 #include <unistd.h>
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "pktmux.h"
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "limits.h"
64
d43d82cbfb85 fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
15 #include "exitcodes.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
424
dd0247097097 fc-shell: implemented 30 ms delay for batch mode AT commands with -p
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
17 extern char *rvinterf_ttyport;
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
18 extern u_char rvi_msg[];
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
19 extern int rvi_msg_len;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
20 extern int oneshot_nowait;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
21 extern int sock;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
22
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 send_string_to_ati(str)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char *str;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned len;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 u_char sendpkt[MAX_PKT_TO_TARGET+1];
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 len = strlen(str);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (len + 1 > MAX_PKT_TO_TARGET) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 printf("error: max pkt to target limit exceeded\n");
64
d43d82cbfb85 fc-shell: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
32 return(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 /* fill out the packet */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 sendpkt[0] = RVT_AT_HEADER;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 strcpy(sendpkt + 1, str);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /* send it! */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 send_pkt_to_target(sendpkt, len + 1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 cmd_sendat(arg)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 char *arg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 while (isspace(*arg))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 arg++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!*arg) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 printf("error: missing string argument\n");
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 ati_rx_control(1);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 send_string_to_ati(arg);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
55
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
56 oneshot_at_command(cmd)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
57 char *cmd;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
58 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
59 fd_set fds;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
60 int rc;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
61
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
62 if (!oneshot_nowait) {
424
dd0247097097 fc-shell: implemented 30 ms delay for batch mode AT commands with -p
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
63 if (rvinterf_ttyport)
dd0247097097 fc-shell: implemented 30 ms delay for batch mode AT commands with -p
Mychaela Falconia <falcon@freecalypso.org>
parents: 75
diff changeset
64 usleep(30000);
75
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
65 init(); /* to catch the response properly */
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
66 ati_rx_control(1);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
67 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
68 rc = send_string_to_ati(cmd);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
69 if (rc)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
70 exit(rc);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
71 if (oneshot_nowait)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
72 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
73 /* wait for response */
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
74 for (;;) {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
75 FD_ZERO(&fds);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
76 FD_SET(sock, &fds);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
77 rc = select(sock+1, &fds, 0, 0, 0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
78 if (rc < 0) {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
79 if (errno == EINTR)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
80 continue;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
81 perror("select");
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
82 exit(ERROR_UNIX);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
83 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
84 if (FD_ISSET(sock, &fds))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
85 handle_rvinterf_input();
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
86 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
87 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
88
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
89 cmd_str_oneshot(argc, argv)
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
90 char **argv;
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
91 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
92 return oneshot_at_command(argv[1]);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
93 }
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
94
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
95 void
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
96 oneshot_at_check_response()
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
97 {
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
98 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "OK", 2))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
99 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
100 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "> ", 2))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
101 exit(0);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
102 if (rvi_msg_len == 7 && !strncmp(rvi_msg + 2, "ERROR", 5))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
103 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
104 if (rvi_msg_len == 6 && !strncmp(rvi_msg + 2, "BUSY", 4))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
105 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
106 if (rvi_msg_len == 12 && !strncmp(rvi_msg + 2, "NO CARRIER", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
107 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
108 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CME ERROR", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
109 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
110 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CMS ERROR", 10))
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
111 exit(ERROR_TARGET);
bbc41034f14c fc-shell: added support for AT commands in one-shot mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 64
diff changeset
112 }