annotate rvinterf/rvtat/main.c @ 425:7eddc2578fdb

fcup-atinterf: added 20 ms serial flush
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 28 Oct 2018 20:03:06 +0000
parents e40bb5a6c6b9
children 261c1b6d936e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <string.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <strings.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <unistd.h>
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
7 #include "pktmux.h"
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
8 #include "limits.h"
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
9 #include "localtypes.h"
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
10 #include "exitcodes.h"
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
12 extern char *socket_pathname;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
13 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
15 extern u_char rvi_msg[];
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
16 extern int rvi_msg_len;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
17
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
18 char command[256], message[256];
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int cmd_with_msg;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 read_command_input(buf)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char *buf;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 char *nl;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
26 if (!fgets(buf, 256, stdin))
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(0);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 nl = index(buf, '\n');
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (!nl) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 printf("Ecommand or message is too long\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *nl = '\0';
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
37 send_to_target(str)
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
38 char *str;
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
40 unsigned len;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
41 u_char sendpkt[MAX_PKT_TO_TARGET+1];
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
42
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
43 len = strlen(str);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
44 /* fill out the packet */
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
45 sendpkt[0] = RVT_AT_HEADER;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
46 strcpy(sendpkt + 1, str);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
47 /* send it! */
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
48 send_pkt_to_target(sendpkt, len + 1);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
49 return(0);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 execute_command()
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 {
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
54 send_to_target(command);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (cmd_with_msg) {
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
56 collect_pkt_from_target();
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
57 if (rvi_msg_len != 4 || rvi_msg[2] != '>' || rvi_msg[3] != ' '){
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
58 printf("F%.*s\n", rvi_msg_len - 2, rvi_msg + 2);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
61 send_to_target(message);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 for (;;) {
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
64 collect_pkt_from_target();
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
65 if (rvi_msg_len == 4 && !strncmp(rvi_msg + 2, "OK", 2) ||
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
66 rvi_msg_len == 7 && !strncmp(rvi_msg + 2, "ERROR", 5) ||
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
67 rvi_msg_len == 6 && !strncmp(rvi_msg + 2, "BUSY", 4) ||
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
68 rvi_msg_len == 12 &&
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
69 !strncmp(rvi_msg + 2, "NO CARRIER", 10) ||
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
70 rvi_msg_len >= 12 &&
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
71 !strncmp(rvi_msg + 2, "+CME ERROR", 10) ||
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
72 rvi_msg_len >= 12 &&
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
73 !strncmp(rvi_msg + 2, "+CMS ERROR", 10)) {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
74 printf("F%.*s\n", rvi_msg_len - 2, rvi_msg + 2);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
77 printf("I%.*s\n", rvi_msg_len - 2, rvi_msg + 2);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 main(argc, argv)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 char **argv;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 {
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
84 extern int optind;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
85 extern char *optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
86 int c, sopt = 0;
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
87
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
88 while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF)
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
89 switch (c) {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
90 case 'B':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
91 rvinterf_Bopt = optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
92 continue;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
93 case 'l':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
94 rvinterf_lopt = optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
95 continue;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
96 case 'p':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
97 rvinterf_ttyport = optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
98 continue;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
99 case 's':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
100 socket_pathname = optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
101 sopt++;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
102 continue;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
103 case 'w':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
104 rvinterf_wopt = optarg;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
105 continue;
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
106 case '?':
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
107 default:
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
108 /* error msg already printed */
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
109 exit(ERROR_USAGE);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
110 }
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
111 if (rvinterf_ttyport) {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
112 if (sopt) {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
113 fprintf(stderr,
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
114 "%s error: -p and -s options are mutually exclusive\n",
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
115 argv[0]);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
116 exit(ERROR_USAGE);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
117 }
423
e40bb5a6c6b9 rvinterf clients: implemented 30 ms delay for batch ops with -p
Mychaela Falconia <falcon@freecalypso.org>
parents: 346
diff changeset
118 launch_rvinterf(1);
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
119 } else {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
120 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
121 fprintf(stderr,
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
122 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
123 argv[0]);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
124 exit(ERROR_USAGE);
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
125 }
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
126 connect_local_socket();
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 while (read_command_input(command)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 if (!strcasecmp(command, "c+m")) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 cmd_with_msg = 1;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (!read_command_input(command))
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 break;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (!read_command_input(message))
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 break;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 } else
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 cmd_with_msg = 0;
346
99471c57155a fcup-rvtat program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents: 345
diff changeset
138 rx_control(1);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 execute_command();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 fflush(stdout);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 exit(0);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 }