annotate calypso/tpinterf.c @ 86:de23872796cb

fc-uicc-tool: update-rec-imm and update-rec-fill ported over from fc-simtool
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 11 Apr 2021 03:19:22 +0000
parents b25d4dfe5798
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This code is based on loadtools/tpinterf.c from FC host tools,
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * modified for our different application of interfacing between
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * simagent below and fc-simtool above.
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/time.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/errno.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int errno;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int target_fd;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 /* definition matches target-utils/libcommon/cmdentry.c */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define MAXCMD 527
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /*
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 * static buffer between tpinterf_make_cmd and tpinterf_send_cmd
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 *
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 * We store the command with an ending \r\n so we can use it for
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 * matching the received echo as well, hence the sizing of the
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 * buffer.
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 static char cmdbuf[MAXCMD+2];
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 static int cmdlen;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 static int
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 arg_chars_valid(arg)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 char *arg;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char *cp;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 for (cp = arg; *cp; cp++)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (*cp < ' ' || *cp > '~')
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(0);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 /*
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 * This function takes a command for the target in argv form and
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 * converts it to a space-separated continuous string which can be
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 * passed as tty "keyboard" input to the target, enforcing length
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * and character validity limits in the process. The output is
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 * stored in an internal static buffer for subsequent
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 * tpinterf_send_cmd().
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 *
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 * Return value: 0 if everything OK, or -1 if some constraint is
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 * violated.
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 tpinterf_make_cmd(argv)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 char **argv;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 int arglen;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 char **ap, *dp;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 dp = cmdbuf;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 cmdlen = 0;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 for (ap = argv; *ap; ap++) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 arglen = strlen(*ap);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (ap != argv)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 arglen++; /* separating space */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (arglen > MAXCMD - cmdlen)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!arg_chars_valid(*ap))
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (ap != argv)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 *dp++ = ' ';
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 strcpy(dp, *ap);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 dp += strlen(*ap);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 cmdlen += arglen;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 *dp++ = '\r';
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 *dp = '\n';
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(0);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /*
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 * This function sends the previously-constructed command to the target,
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 * and collects the expected echo.
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 *
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 * Return value: 0 if successful, -1 on errors (timeout or wrong response)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 tpinterf_send_cmd()
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 char echobuf[MAXCMD+2];
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 fd_set fds;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 struct timeval tv;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 int rcvd, cc;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 write(target_fd, cmdbuf, cmdlen + 1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 for (rcvd = 0; rcvd < cmdlen + 2; ) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 FD_ZERO(&fds);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 FD_SET(target_fd, &fds);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 tv.tv_sec = 1;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 tv.tv_usec = 0;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (cc < 0) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (errno == EINTR)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 continue;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 printf("back end error: failed select\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (cc < 1) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 printf(
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 "back end error: timeout waiting for command echo\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 cc = read(target_fd, echobuf + rcvd, cmdlen + 2 - rcvd);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (cc <= 0) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 printf(
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 "back end error: failed read after successful select\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 rcvd += cc;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (bcmp(echobuf, cmdbuf, cmdlen + 2)) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 printf("back end error: command echo mismatch\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 } else
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return(0);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 /*
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 * This functions reads the serial output from the target until a
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 * '=' prompt is received. All intermediate output is passed to
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 * stdout, with some hacks specific to this SIM interface back end.
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 */
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 tpinterf_pass_output(timeout)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 char buf[1024], *cp;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 fd_set fds;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 struct timeval tv;
7
b25d4dfe5798 fcsim-calypso-be actually works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
139 int cc, newline = 1, termflag = 0, finish = 0;
4
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 unsigned goodchar;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
7
b25d4dfe5798 fcsim-calypso-be actually works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
142 for (goodchar = 0; !finish; ) {
4
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 FD_ZERO(&fds);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 FD_SET(target_fd, &fds);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 tv.tv_sec = timeout;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 tv.tv_usec = 0;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 if (cc < 0) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (errno == EINTR)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 continue;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 printf("back end error: failed select\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 if (cc < 1) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 printf(
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 "back end error: timeout waiting for simagent response\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 cc = read(target_fd, buf + goodchar, sizeof(buf) - goodchar);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 if (cc <= 0) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 printf(
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 "back end error: failed read after successful select\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 for (cp = buf + goodchar; cc; cp++) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 cc--;
7
b25d4dfe5798 fcsim-calypso-be actually works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
167 if (*cp == '=' && newline && !cc) {
b25d4dfe5798 fcsim-calypso-be actually works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
168 finish = 1;
4
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 break;
7
b25d4dfe5798 fcsim-calypso-be actually works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
170 }
4
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (*cp == '\n') {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 newline = 1;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 termflag = 1;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 continue;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 newline = 0;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (*cp == '\r')
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 termflag = 1;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (!termflag)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 goodchar++;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (goodchar >= 516)
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 termflag = 1;
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 if (!goodchar) {
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 printf("back end error: empty output from simagent\n");
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 return(-1);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 }
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 buf[goodchar] = '\0';
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 puts(buf);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 return(0);
deeeef558279 fcsim-calypso-be put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 }