Explorar o código

Don't wait for an echo where it is unneeded

Waiting for an echo at the synchronization caused it to work improperly.
Mateusz Bugdalski %!s(int64=13) %!d(string=hai) anos
pai
achega
085ff429f4
Modificáronse 3 ficheiros con 3 adicións e 8 borrados
  1. 3 4
      lpc.c
  2. 0 3
      serial.c
  3. 0 1
      serial.h

+ 3 - 4
lpc.c

@@ -68,8 +68,7 @@ struct lpc_device *lpc_setup(struct serial_device *port) {
 void lpc_init(struct lpc_device *dev) {
   char buf[4096];
   
-  lpc_printf(dev, "?");
-  serial_drain(dev->port);
+  serial_write(dev->port, "?");
   
   if(lpc_await_reply(dev, "Synchronized", NULL)==1) {
       sprog_info("Synchronization successful\n");
@@ -80,7 +79,7 @@ void lpc_init(struct lpc_device *dev) {
     if(lpc_await_reply(dev, "OK", NULL)!=1)
       sprog_error("Expected OK, received '%s'\n", buf);
   } else {
-    lpc_printf(dev, "\r\n");
+    serial_write(dev->port, "\r\n");
     if(lpc_await_reply(dev, "?", NULL)==1)
       sprog_info("The device appears to be already synchronized\n");
     else
@@ -234,7 +233,7 @@ int lpc_await_reply(struct lpc_device *dev, ...) {
   
 
 int lpc_getline(struct lpc_device *dev, char *buf) {
-  if(sprog_waitdata(dev->port, 500)==0)
+  if(sprog_waitdata(dev->port, 5000)==0)
     return 0;
   fgets(buf, 4096, dev->port->f);
   return 1;

+ 0 - 3
serial.c

@@ -177,6 +177,3 @@ int serial_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds
   return res;
 }
 
-void serial_drain(struct serial_device *port) {
-  tcdrain(port->fd);
-}

+ 0 - 1
serial.h

@@ -32,6 +32,5 @@ int serial_setbaud(struct serial_device *port, int baud);
 void serial_setline(struct serial_device *port, int line, int state);
 int serial_read(struct serial_device *port, char *buf, int len, int timeout);
 void serial_write(struct serial_device *port, const char *text);
-void serial_drain(struct serial_device *port);
 
 #endif