]> rtime.felk.cvut.cz Git - sysless.git/blobdiff - arch/arm/mach-lpc21xx/tools/tolpc/tolpc_fn.c
cmdproc: Make backspace work even in sterm
[sysless.git] / arch / arm / mach-lpc21xx / tools / tolpc / tolpc_fn.c
index 8b104d978d6c33c46ec3a481bc877450e30c079b..c421178d84c9af1f0768d9a4d0fa14ad1192dcfb 100644 (file)
@@ -162,8 +162,9 @@ int poll_input(FILE *stream, long tv_sec, long tv_usec) {
 }
 
 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 */
   /*
@@ -194,16 +195,29 @@ int send_line(FILE *comm, resp_type_t response_type, char *line) {
   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);
@@ -311,6 +325,9 @@ FILE *open_comm(char *device, int baudrate, int flowc) {
   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);