From cbe5d5b80e5cc6bcb6a63ab08aac423667e97cdf Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 12 Feb 2012 18:49:57 +0100 Subject: [PATCH] Wait 5ms between packets 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 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/arexxd.c b/arexxd.c index 3baaefd..e82fc84 100644 --- 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"); -- 2.39.2