annotate uptools/atinterf/fcup-atinterf.c @ 408:f0e6dd5971f2

CHANGES: fcup-* minor fixes documented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Aug 2018 22:36:26 +0000
parents cc207d81c05f
children 7eddc2578fdb
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>
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
2 #include <sys/time.h>
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdio.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <string.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <strings.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <unistd.h>
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 extern int target_fd;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 FILE *target_rd;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char response[515];
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char command[513], message[513];
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int cmd_with_msg;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 read_command_input(buf)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *buf;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char *nl;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (!fgets(buf, 513, stdin))
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(0);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 nl = index(buf, '\n');
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (!nl) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 printf("Ecommand or message is too long\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 *nl = '\0';
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
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 send_to_target(cmd, term)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *cmd;
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 char *endp;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 int len, cc;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 endp = index(cmd, '\0');
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 *endp = term;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 len = endp - cmd + 1;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 cc = write(target_fd, cmd, len);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 *endp = '\0';
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (cc != len) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 printf("Etarget write error\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
50 single_char_to_target(ch)
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
51 {
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
52 char buf = ch;
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
53 int cc;
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
54
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
55 cc = write(target_fd, &buf, 1);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
56 if (cc != 1) {
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
57 printf("Etarget write error\n");
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
58 exit(1);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
59 }
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
60 }
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
61
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 collect_target_response()
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 char *nl;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!fgets(response, 515, target_rd)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 printf("Etarget read error\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 nl = index(response, '\n');
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (!nl) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 printf("Etarget response is too long\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 while (nl > response && nl[-1] == '\r')
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 nl--;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 *nl = '\0';
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 execute_command()
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 int c;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 send_to_target(command, '\r');
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 collect_target_response();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (strcmp(command, response)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 printf("Efailed to get echo of command\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (cmd_with_msg) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if ((c = getc(target_rd)) != '>') {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 ungetc(c, target_rd);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 collect_target_response();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 printf("F%s\n", response);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 return;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if ((c = getc(target_rd)) != ' ') {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 ungetc(c, target_rd);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 collect_target_response();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 printf("F%s\n", response);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
344
e0260c2982b6 fcup-atinterf: brown paper bag
Mychaela Falconia <falcon@freecalypso.org>
parents: 341
diff changeset
103 send_to_target(message, '\032');
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 collect_target_response();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (strcmp(message, response)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 printf("Efailed to get echo of message\n");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 for (;;) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 collect_target_response();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (!strcmp(response, "OK") || !strcmp(response, "ERROR") ||
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 !strcmp(response, "BUSY") ||
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 !strcmp(response, "NO CARRIER") ||
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 !strncmp(response, "+CME ERROR", 10) ||
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 !strncmp(response, "+CMS ERROR", 10)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 printf("F%s\n", response);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 printf("I%s\n", response);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
124 wakeup_at()
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
125 {
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
126 single_char_to_target('A');
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
127 usleep(50000);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
128 single_char_to_target('T');
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
129 usleep(50000);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
130 single_char_to_target('\r');
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
131 collect_target_response();
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
132 if (response[0] && strcmp(response, "AT")) {
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
133 badresp: printf("Ebad response to wakeup AT command\n");
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
134 exit(1);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
135 }
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
136 collect_target_response();
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
137 if (strcmp(response, "OK"))
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
138 goto badresp;
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
139 }
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
140
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 main(argc, argv)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 char **argv;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 {
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
144 int wakeup_after_sec = 7;
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
145 struct timeval curtime, last_time, timediff;
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
146
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 if (argc < 3 || argc > 4) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 fprintf(stderr,
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 "usage: %s ttyport baudrate [wakeup-after-sec]\n",
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 argv[0]);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 open_serial_port(argv[1]);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 set_fixed_baudrate(argv[2]);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 if (argc > 3)
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 wakeup_after_sec = strtoul(argv[3], 0, 0);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
158 set_serial_nonblock(0);
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 target_rd = fdopen(target_fd, "r");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 if (!target_rd) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 perror("fdopen");
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 exit(1);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 }
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
164 bzero(&last_time, sizeof(struct timeval));
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 while (read_command_input(command)) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 if (!strcasecmp(command, "c+m")) {
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 cmd_with_msg = 1;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 if (!read_command_input(command))
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 break;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (!read_command_input(message))
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 break;
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 } else
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 cmd_with_msg = 0;
345
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
175 if (wakeup_after_sec) {
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
176 gettimeofday(&curtime, 0);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
177 timersub(&curtime, &last_time, &timediff);
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
178 if (timediff.tv_sec >= wakeup_after_sec)
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
179 wakeup_at();
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
180 bcopy(&curtime, &last_time, sizeof(struct timeval));
cc207d81c05f fcup-atinterf: implemented wakeup of sleeping targets
Mychaela Falconia <falcon@freecalypso.org>
parents: 344
diff changeset
181 }
341
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 execute_command();
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 fflush(stdout);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 exit(0);
692dbc4c2f07 fcup-atinterf program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 }