From: Timo Kokkonen Date: Mon, 23 Jul 2012 15:07:19 +0000 (+0300) Subject: Have extra 20ms delay after every 16th read entry X-Git-Url: http://git.itanic.dy.fi/?p=glucose;a=commitdiff_plain Have extra 20ms delay after every 16th read entry Some times the meter refuses to return all entries as expected, and just returns some crap instead. This becomes especially notcieable once the meter has reached the limit of 2000 glucose readings. Having an extra 20ms delay between readings once every 16th reads appears to help ensuring all data is read reliably out of the device. Signed-off-by: Timo Kokkonen --- diff --git a/contour-protocol.c b/contour-protocol.c index 99fda48..bc87a0a 100644 --- a/contour-protocol.c +++ b/contour-protocol.c @@ -289,7 +289,7 @@ int contour_initialize(int fd, int uc) return 0; } -int contour_read_entry(int fd, int uc, struct msg *in) +int contour_read_entry(int fd, int uc, struct msg *in, int extra_delay) { struct msg msg; int j; @@ -297,8 +297,10 @@ int contour_read_entry(int fd, int uc, struct msg *in) msg.direction = OUT; set_first_msg_byte(&msg, &j, 0x01); set_msg_byte(&msg, &j, 1, 0x06); + usleep(extra_delay * 1000); send_msg(&msg, fd, uc); + read_and_verify(in, fd); return datalen(in->data); } diff --git a/contour-protocol.h b/contour-protocol.h index 3bb2edb..b6ab99c 100644 --- a/contour-protocol.h +++ b/contour-protocol.h @@ -34,7 +34,7 @@ enum direction { }; int contour_initialize(int fd, int uc); -int contour_read_entry(int fd, int uc, struct msg *in); +int contour_read_entry(int fd, int uc, struct msg *in, int extra_delay); int wait_for_device(int vendor, int product, int *usage_code); diff --git a/main.c b/main.c index f0faa44..442154b 100644 --- a/main.c +++ b/main.c @@ -107,6 +107,7 @@ static int dump_entries(struct user_options *opts, int fd, int usage_code) struct msg msg; int ret; int entries = 0; + int extra_delay = 0; trace(0, "Reading data ...\n"); if (opts->output_format == CSV) @@ -115,7 +116,7 @@ static int dump_entries(struct user_options *opts, int fd, int usage_code) "Activity,\"Control test\"\n"); while (1) { - ret = contour_read_entry(fd, usage_code, &msg); + ret = contour_read_entry(fd, usage_code, &msg, extra_delay); if (ret < 45) break; @@ -125,6 +126,18 @@ static int dump_entries(struct user_options *opts, int fd, int usage_code) entries++; + /* + * Add 20ms magic sleep. This is needed especially for + * meters that have reached the internal limit of 2000 + * glucose readings. We don't want to delay any other + * reads as it appears to be needed only for every + * 16th read. + */ + if (!(entries % 16)) + extra_delay = 20; + else + extra_delay = 0; + if ((opts->outf != stdout) || !isatty(fileno(stdout))) { trace(0, "\r%d entries", entries); fflush(stdout);