From: Antonio Ospite Date: Wed, 13 Mar 2013 14:26:07 +0000 (+0100) Subject: Add a way to filter measurements by user ids X-Git-Url: https://git.ao2.it/visomat-utils.git/commitdiff_plain/91d0c4148bdb1fca33062b80b669e3c9e00c8030 Add a way to filter measurements by user ids --- diff --git a/src/visomat-data-downloader.c b/src/visomat-data-downloader.c index d925388..a91ee43 100644 --- a/src/visomat-data-downloader.c +++ b/src/visomat-data-downloader.c @@ -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);