FreeCalypso > hg > freecalypso-tools
annotate uptools/atcmd/atinterf.c @ 978:a400bb4a1620
fc-loadtool flash lock-state: no global bits in second bank
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 01 Dec 2023 08:05:31 +0000 |
parents | f0e9bb28b4d6 |
children |
rev | line source |
---|---|
348
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the interface functions to the AT command phone or |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * modem to be used by the rest of the FreeCalypso User Phone tools suite. |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <unistd.h> |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../../rvinterf/include/exitcodes.h" |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static char atinterf_pathname[] = "/opt/freecalypso/bin/fcup-atinterf"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static char rvtat_pathname[] = "/opt/freecalypso/bin/fcup-rvtat"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static char shell_pathname[] = "/bin/sh"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *target_ttyport, *target_baud, *external_prog; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rvtat_mode, no_target_mode; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static char *backend_prog, *backend_argv[6]; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 FILE *cpipeF, *rpipeF; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char at_response[514]; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 atinterf_cmdline_opt(opt) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 extern char *optarg; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 switch (opt) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 case 'B': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 target_baud = optarg; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 case 'n': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 no_target_mode = 1; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 case 'p': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 target_ttyport = optarg; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case 'R': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rvtat_mode = 1; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 return(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 case 'X': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 external_prog = optarg; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return(0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 static void |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 preen_port_baud_config() |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!target_ttyport && target_baud) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "error: -B option invalid without -p\n"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(ERROR_USAGE); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (rvtat_mode) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!target_ttyport) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 target_ttyport = getenv("FC_GSM_DEVICE"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!target_ttyport) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 "error: no FC GSM device target specified\n"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 exit(ERROR_USAGE); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!target_baud) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 target_baud = "115200"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 static void |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 setup_be_native_at() |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 backend_prog = atinterf_pathname; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 backend_argv[0] = "fcup-atinterf"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 backend_argv[1] = target_ttyport; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 backend_argv[2] = target_baud; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 backend_argv[3] = 0; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 static void |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 setup_be_rvtat() |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 char **ap; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 backend_prog = rvtat_pathname; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 ap = backend_argv; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 *ap++ = "fcup-rvtat"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (target_ttyport) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 *ap++ = "-p"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *ap++ = target_ttyport; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (target_baud) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 *ap++ = "-B"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 *ap++ = target_baud; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 *ap = 0; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 static void |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 setup_be_external() |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 backend_prog = shell_pathname; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 backend_argv[0] = "sh"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 backend_argv[1] = "-c"; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 backend_argv[2] = external_prog; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 backend_argv[3] = 0; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 atinterf_init() |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 int cpipe[2], rpipe[2], rc; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
350
9ffaeb6fea1a
uptools/atcmd/atinterf.c: logic inversion error
Mychaela Falconia <falcon@freecalypso.org>
parents:
348
diff
changeset
|
113 if (no_target_mode) |
348
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 return(0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (external_prog) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 setup_be_external(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 else { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 preen_port_baud_config(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 if (rvtat_mode) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 setup_be_rvtat(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 else |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 setup_be_native_at(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 if (pipe(cpipe) < 0 || pipe(rpipe) < 0) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 perror("pipe"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 exit(ERROR_UNIX); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 rc = vfork(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 if (rc < 0) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 perror("vfork for launching back end"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 exit(ERROR_UNIX); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if (!rc) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 /* we are in the child - prepare to exec the BE */ |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 dup2(cpipe[0], 0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 dup2(rpipe[1], 1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 close(cpipe[0]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 close(cpipe[1]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 close(rpipe[0]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 close(rpipe[1]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 /* do the exec */ |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 execv(backend_prog, backend_argv); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 perror(backend_prog); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 _exit(1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 close(cpipe[0]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 close(rpipe[1]); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 cpipeF = fdopen(cpipe[1], "w"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 if (!cpipeF) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 perror("fdopen"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 exit(ERROR_UNIX); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 rpipeF = fdopen(rpipe[0], "r"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 if (!rpipeF) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 perror("fdopen"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 exit(ERROR_UNIX); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 return(0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 atinterf_exec_cmd(command, message, callback) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 char *command, *message; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 void (*callback)(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 char *nl; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
351
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
167 if (no_target_mode) { |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
168 puts(command); |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
169 if (message) |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
170 puts(message); |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
171 strcpy(at_response, "FOK"); |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
172 return(0); |
f0e9bb28b4d6
uptools/atcmd/atinterf.c: no target debug mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
350
diff
changeset
|
173 } |
348
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 if (message) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 fputs("c+m\n", cpipeF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 fprintf(cpipeF, "%s\n", command); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 fprintf(cpipeF, "%s\n", message); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } else |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 fprintf(cpipeF, "%s\n", command); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 fflush(cpipeF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 for (;;) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 if (!fgets(at_response, sizeof at_response, rpipeF)) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 fprintf(stderr, |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 "error reading AT response from back end\n"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 exit(ERROR_RVINTERF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 nl = index(at_response, '\n'); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 if (!nl) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 fprintf(stderr, |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 "error: back end response is too long or unterminated\n"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 exit(ERROR_RVINTERF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 *nl = '\0'; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 switch (at_response[0]) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 case 'E': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 fprintf(stderr, "error from back end: %s\n", |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 at_response + 1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 exit(ERROR_RVINTERF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 case 'F': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 return(0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 case 'I': |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 if (callback) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 callback(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 continue; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 fprintf(stderr, "error: invalid response from back end\n"); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 exit(ERROR_RVINTERF); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 atinterf_exec_cmd_needok(command, message, callback) |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 char *command, *message; |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 void (*callback)(); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 atinterf_exec_cmd(command, message, callback); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 if (strcmp(at_response+1, "OK")) { |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 fprintf(stderr, "AT error: %s\n", at_response+1); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 exit(ERROR_TARGET); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 } |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 return(0); |
64dcbabd48ca
uptools/atcmd framework started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 } |