annotate uptools/atinterf/fcup-atinterf.c @ 951:297c7d5b57a2

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