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>
-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)
msg.direction = OUT;
set_first_msg_byte(&msg, &j, 0x01);
set_msg_byte(&msg, &j, 1, 0x06);
msg.direction = OUT;
set_first_msg_byte(&msg, &j, 0x01);
set_msg_byte(&msg, &j, 1, 0x06);
+ usleep(extra_delay * 1000);
read_and_verify(in, fd);
return datalen(in->data);
}
read_and_verify(in, fd);
return datalen(in->data);
}
};
int contour_initialize(int fd, int uc);
};
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);
int wait_for_device(int vendor, int product, int *usage_code);
struct msg msg;
int ret;
int entries = 0;
struct msg msg;
int ret;
int entries = 0;
trace(0, "Reading data ...\n");
if (opts->output_format == CSV)
trace(0, "Reading data ...\n");
if (opts->output_format == CSV)
"Activity,\"Control test\"\n");
while (1) {
"Activity,\"Control test\"\n");
while (1) {
- ret = contour_read_entry(fd, usage_code, &msg);
+ ret = contour_read_entry(fd, usage_code, &msg, extra_delay);
+ /*
+ * 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);
if ((opts->outf != stdout) || !isatty(fileno(stdout))) {
trace(0, "\r%d entries", entries);
fflush(stdout);