}
int send_line(FILE *comm, resp_type_t response_type, char *line) {
- char s[160];
+ char s[160], *p;
int sel, resp;
+ size_t size;
/* send command */
/*
if (response_type == NO_RESPONSE)
return 0;
- /* check response, 1s timeout */
- if ((sel = poll_input(comm, 1, 0)) < 1) {
- if (sel == 0)
- fprintf(stderr, "send_line: \"%s\" command response timeout\n", line);
- else
- perror("send_line: select");
- return(1);
- }
- fgets(s, sizeof(s), comm);
+ p=s;
+ /* read with timout for every character (necessary for go command) */
+ do {
+ /* check response, 1s timeout */
+ if ((sel = poll_input(comm, 1, 0)) < 1) {
+ *p = '\0';
+ /*DEBUG*/printf(">%s", s);
+ fflush(stdout);
+ if (sel == 0) {
+ fprintf(stderr, "send_line: \"%s\" command response timeout\n", line);
+ }
+ else
+ perror("send_line: select");
+ return(1);
+ }
+ /* read one character */
+ size = fread(p, 1, 1, comm);
+ p++;
+ } while (*(p-1) != '\n');
+
+ *p = '\0';
/*DEBUG*/printf(">%s", s);
+
if (response_type == OK_RESPONSE) {
/* textual response -- expecting "OK" */
resp = (strncmp(s, "OK", 2) != 0);
FILE *comm;
int comm_dev, line;
+ /* TODO: Open the serial line the same way as lpc21isp. It seems
+ * that loading works even if there is terminal emulator attached to
+ * the same port. */
if ((comm = fopen(device, "r+")) == NULL) {
perror("open_comm: fopen");
return(NULL);