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>
-int communicate(int fd, int uc)
+int contour_initialize(int fd, int uc)
- trace(0, "Initializing..\n");
read_msgs(fd);
SET_FIRST_BYTE(0x01);
read_msgs(fd);
SET_FIRST_BYTE(0x01);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
send_msg_with_proggress_note(&msg, fd, uc);
read_msgs(fd);
- trace(0, "\nGlucose readings:\n");
- do {
- send_msg(&msg, fd, uc);
- read_and_verify(&in, fd);
- print_ascii(in.data, datalen(in.data));
- } while (datalen(in.data) > 45);
+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;
int wait_for_device(int vendor, int product, int *usage_code)
{
int fd;
-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);
int wait_for_device(int vendor, int product, int *usage_code);
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
+ int fd, usage_code, ret;
struct user_options opts;
struct user_options opts;
read_args(argc, argv, &opts);
trace_level = opts.trace_level;
read_args(argc, argv, &opts);
trace_level = opts.trace_level;
- 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;
+ }