FreeCalypso > hg > freecalypso-tools
comparison rvinterf/asyncshell/at.c @ 75:bbc41034f14c
fc-shell: added support for AT commands in one-shot mode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 27 Oct 2016 02:13:38 +0000 |
parents | d43d82cbfb85 |
children | dd0247097097 |
comparison
equal
deleted
inserted
replaced
74:84920d3d97c6 | 75:bbc41034f14c |
---|---|
1 /* | 1 /* |
2 * Functions for the AT-over-RVTMUX interface | 2 * Functions for the AT-over-RVTMUX interface |
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <sys/errno.h> | |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 #include <ctype.h> | 8 #include <ctype.h> |
8 #include <string.h> | 9 #include <string.h> |
9 #include <strings.h> | 10 #include <strings.h> |
10 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <unistd.h> | |
11 #include "pktmux.h" | 13 #include "pktmux.h" |
12 #include "limits.h" | 14 #include "limits.h" |
13 #include "exitcodes.h" | 15 #include "exitcodes.h" |
16 | |
17 extern u_char rvi_msg[]; | |
18 extern int rvi_msg_len; | |
19 extern int oneshot_nowait; | |
20 extern int sock; | |
14 | 21 |
15 send_string_to_ati(str) | 22 send_string_to_ati(str) |
16 char *str; | 23 char *str; |
17 { | 24 { |
18 unsigned len; | 25 unsigned len; |
42 return; | 49 return; |
43 } | 50 } |
44 ati_rx_control(1); | 51 ati_rx_control(1); |
45 send_string_to_ati(arg); | 52 send_string_to_ati(arg); |
46 } | 53 } |
54 | |
55 oneshot_at_command(cmd) | |
56 char *cmd; | |
57 { | |
58 fd_set fds; | |
59 int rc; | |
60 | |
61 if (!oneshot_nowait) { | |
62 init(); /* to catch the response properly */ | |
63 ati_rx_control(1); | |
64 } | |
65 rc = send_string_to_ati(cmd); | |
66 if (rc) | |
67 exit(rc); | |
68 if (oneshot_nowait) | |
69 exit(0); | |
70 /* wait for response */ | |
71 for (;;) { | |
72 FD_ZERO(&fds); | |
73 FD_SET(sock, &fds); | |
74 rc = select(sock+1, &fds, 0, 0, 0); | |
75 if (rc < 0) { | |
76 if (errno == EINTR) | |
77 continue; | |
78 perror("select"); | |
79 exit(ERROR_UNIX); | |
80 } | |
81 if (FD_ISSET(sock, &fds)) | |
82 handle_rvinterf_input(); | |
83 } | |
84 } | |
85 | |
86 cmd_str_oneshot(argc, argv) | |
87 char **argv; | |
88 { | |
89 return oneshot_at_command(argv[1]); | |
90 } | |
91 | |
92 void | |
93 oneshot_at_check_response() | |
94 { | |
95 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "OK", 2)) | |
96 exit(0); | |
97 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "> ", 2)) | |
98 exit(0); | |
99 if (rvi_msg_len == 7 && !strncmp(rvi_msg + 2, "ERROR", 5)) | |
100 exit(ERROR_TARGET); | |
101 if (rvi_msg_len == 6 && !strncmp(rvi_msg + 2, "BUSY", 4)) | |
102 exit(ERROR_TARGET); | |
103 if (rvi_msg_len == 12 && !strncmp(rvi_msg + 2, "NO CARRIER", 10)) | |
104 exit(ERROR_TARGET); | |
105 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CME ERROR", 10)) | |
106 exit(ERROR_TARGET); | |
107 if (rvi_msg_len >= 12 && !strncmp(rvi_msg + 2, "+CMS ERROR", 10)) | |
108 exit(ERROR_TARGET); | |
109 } |