]> mj.ucw.cz Git - arexx.git/commitdiff
Wait 5ms between packets
authorMartin Mares <mj@ucw.cz>
Sun, 12 Feb 2012 17:49:57 +0000 (18:49 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 12 Feb 2012 17:49:57 +0000 (18:49 +0100)
I suspect that the occasional data loss when transmitting lots of
data points is caused by buggy firmware which drops packets sent
too quickly.

arexxd.c

index 3baaefd669ca9b168eff4dbedc82018c297204de..e82fc8426f55c20b77275b9a81d1df59648244e5 100644 (file)
--- a/arexxd.c
+++ b/arexxd.c
@@ -494,10 +494,11 @@ static void sigterm_handler(int sig __attribute__((unused)))
        want_shutdown = 1;
 }
 
-static void interruptible_sleep(int seconds)
+static void interruptible_msleep(int ms)
 {
        sigprocmask(SIG_UNBLOCK, &term_sigs, NULL);
-       sleep(seconds);
+       struct timespec ts = { .tv_sec = ms/1000, .tv_nsec = (ms%1000) * 1000000 };
+       nanosleep(&ts, NULL);
        sigprocmask(SIG_BLOCK, &term_sigs, NULL);
 }
 
@@ -586,7 +587,7 @@ int main(int argc, char **argv)
                                inited = 1;
                                log_error("Data logger not connected, waiting until it appears");
                        }
-                       interruptible_sleep(30);
+                       interruptible_msleep(30000);
                        continue;
                }
                log_info("Listening");
@@ -619,15 +620,16 @@ int main(int argc, char **argv)
                        if (err > 0 && parse_packet(reply))
                                want_sleep = 0;
                        if (want_sleep) {
-                               interruptible_sleep(4);
+                               interruptible_msleep(4000);
                                want_stats = 1;
-                       }
+                       } else
+                               interruptible_msleep(5);
                }
 
                log_info("Disconnecting data logger");
                release_device();
                inited = 0;
-               interruptible_sleep(10);
+               interruptible_msleep(10000);
        }
 
        log_info("Terminated");