]> git.itanic.dy.fi Git - glucose/commitdiff
Separate initialization and data reading into a separate steps
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 1 May 2011 14:12:39 +0000 (17:12 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 1 May 2011 14:12:39 +0000 (17:12 +0300)
This makes it possible in future to do something useful with the data
instead of just dumping it out to stdout.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
contour-protocol.c
contour-protocol.h
main.c

index 06375553d1dfadd0a8ebdf55f54fc59ee751dcde..1a86c96b887cf07bff9f7fa93380edbd530df840 100644 (file)
@@ -136,12 +136,11 @@ static int send_pattern(int fd, int uc, unsigned char byte1, unsigned char byte2
        return 0;
 }
 
-int communicate(int fd, int uc)
+int contour_initialize(int fd, int uc)
 {
        int i, j;
-       struct msg msg, in;
+       struct msg msg;
        msg.direction = OUT;
-       trace(0, "Initializing..\n");
 
        read_msgs(fd);
        SET_FIRST_BYTE(0x01);
@@ -265,17 +264,27 @@ int communicate(int fd, int uc)
        send_msg_with_proggress_note(&msg, fd, uc);
        read_msgs(fd);
 
-       trace(0, "\nGlucose readings:\n");
        usleep(100 * 1000);
-       do {
-               send_msg(&msg, fd, uc);
-               read_and_verify(&in, fd);
-               print_ascii(in.data, datalen(in.data));
-       } while (datalen(in.data) > 45);
 
+       trace(0, "\n");
        return 0;
 }
 
+int contour_read_entry(int fd, int uc, struct msg *in)
+{
+       struct msg msg;
+       int j;
+
+       msg.direction = OUT;
+       SET_FIRST_BYTE(0x01);
+       SET_BYTE(1, 0x06);
+
+       send_msg(&msg, fd, uc);
+       read_and_verify(in, fd);
+
+       return datalen(in->data);
+}
+
 int wait_for_device(int vendor, int product, int *usage_code)
 {
        int fd;
index 049ccc995a4d40c0031616bc2d92d8e5654c9349..f1774ce1795836ddade4fa5a3a66ca50d1436fe2 100644 (file)
@@ -14,7 +14,8 @@ enum direction {
        OUT,
 };
 
-int communicate(int fd, int uc);
+int contour_initialize(int fd, int uc);
+int contour_read_entry(int fd, int uc, struct msg *in);
 int wait_for_device(int vendor, int product, int *usage_code);
 
 
diff --git a/main.c b/main.c
index 76b32d734bffb9f9d665480344af48efeba6699e..79dc67dc8c6d58fdddec31fbf7c3d234ad41d905 100644 (file)
--- a/main.c
+++ b/main.c
@@ -11,8 +11,9 @@
 
 int main(int argc, char *argv[])
 {
-       int fd, usage_code;
+       int fd, usage_code, ret;
        struct user_options opts;
+       struct msg msg;
 
        read_args(argc, argv, &opts);
        trace_level = opts.trace_level;
@@ -25,7 +26,17 @@ int main(int argc, char *argv[])
        if (fd < 0)
                return 1;
 
-       communicate(fd, usage_code);
+       trace(0, "Initializing\n");
+       contour_initialize(fd, usage_code);
+
+       trace(0, "Done! Reading data\n");
+       while (1) {
+               ret = contour_read_entry(fd, usage_code, &msg);
+               print_ascii(msg.data, ret);
+
+               if (ret < 45)
+                       break;
+       }
 
        return 0;
 }