Add a way to filter measurements by user ids
authorAntonio Ospite <ospite@studenti.unina.it>
Wed, 13 Mar 2013 14:26:07 +0000 (15:26 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Wed, 13 Mar 2013 14:26:07 +0000 (15:26 +0100)
src/visomat-data-downloader.c

index d925388..a91ee43 100644 (file)
@@ -118,7 +118,9 @@ static void print_record_csv_compat(struct datetime *d, struct pressure *p)
 }
 
 /* TODO separate better decoding data from printing it */
-static int decode_eeprom(unsigned char *buffer, unsigned int len)
+static int decode_eeprom(unsigned char *buffer,
+                        unsigned int len,
+                        unsigned int user_mask)
 {
        int ret;
        unsigned int n;
@@ -144,7 +146,6 @@ static int decode_eeprom(unsigned char *buffer, unsigned int len)
                        /* i tracks the bytes consumed */
                        i += 1;
 
-
                        ret = sscanf((char *)(buffer + i), "%1u%02u",
                                     &user_id, &num_records);
                        if (ret != 2)
@@ -153,8 +154,6 @@ static int decode_eeprom(unsigned char *buffer, unsigned int len)
                        /* user_id and num_records take 3 bytes */
                        i += 3;
 
-                       printf("# User: %d\n", user_id);
-
                        for (j = 0; j < num_records; j++) {
                                ret = extract_datetime(buffer + i, &d);
                                if (ret < 0)
@@ -175,7 +174,12 @@ static int decode_eeprom(unsigned char *buffer, unsigned int len)
                                /* pressure data is 10 bytes */
                                i += 10;
 
-                               print_record_csv_compat(&d, &p);
+                               /* TODO: split out the printing part */
+                               if (user_id & user_mask) {
+                                       if (j == 0)
+                                               printf("# User: %d\n", user_id);
+                                       print_record_csv_compat(&d, &p);
+                               }
                        }
                }
        }
@@ -266,7 +270,7 @@ static int get_response(libusb_device_handle *dev,
 
 /* Candidates for a future public API, if a shared library will ever be made */
 #define visomat_device libusb_device_handle
-static int visomat_dump_eeprom(visomat_device *dev)
+static int visomat_dump_eeprom(visomat_device *dev, unsigned int user_mask)
 {
        /* Assuming an EEPROM of 1 KiB  */
        unsigned char buffer[1024] = { 0 };
@@ -280,7 +284,7 @@ static int visomat_dump_eeprom(visomat_device *dev)
        if (ret < 0)
                return ret;
 
-       ret = decode_eeprom(buffer, ret);
+       ret = decode_eeprom(buffer, ret, user_mask);
        if (ret < 0)
                return ret;
 
@@ -330,7 +334,7 @@ int main(void)
        if (ret < 0)
                goto out;
 
-       ret = visomat_dump_eeprom(dev);
+       ret = visomat_dump_eeprom(dev, 0x01 | 0x02);
 
 out:
        libusb_close(dev);