}
/* 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;
/* i tracks the bytes consumed */
i += 1;
-
ret = sscanf((char *)(buffer + i), "%1u%02u",
&user_id, &num_records);
if (ret != 2)
/* 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)
/* 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);
+ }
}
}
}
/* 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 };
if (ret < 0)
return ret;
- ret = decode_eeprom(buffer, ret);
+ ret = decode_eeprom(buffer, ret, user_mask);
if (ret < 0)
return ret;
if (ret < 0)
goto out;
- ret = visomat_dump_eeprom(dev);
+ ret = visomat_dump_eeprom(dev, 0x01 | 0x02);
out:
libusb_close(dev);