]> git.itanic.dy.fi Git - glucose/commitdiff
Have extra 20ms delay after every 16th read entry master
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 23 Jul 2012 15:07:19 +0000 (18:07 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Mon, 23 Jul 2012 15:13:08 +0000 (18:13 +0300)
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 <timo.t.kokkonen@iki.fi>
contour-protocol.c
contour-protocol.h
main.c

index 99fda48096ac1db5b89dedb4afc7a134578ce737..bc87a0a2133f770ad06aec1079f985946e7cc5da 100644 (file)
@@ -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);
 }
index 3bb2edbeea397bbe39d439888925f0704d1d987d..b6ab99c0a360871ac35a7fdd38c7ed45287dbdd2 100644 (file)
@@ -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 f0faa447d5bf6b8d0fd96c77387e667b36cffd5f..442154b17022a31cbbada5ee10d2865d7174e64f 100644 (file)
--- 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);