visomat-data-downloader: don't use a magic value for the datetime packet size
[visomat-utils.git] / src / visomat-data-downloader.c
index 574bb13..a3282ba 100644 (file)
@@ -58,10 +58,12 @@ static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned in
 #define VISOMAT_INTERFACE     1
 #define VISOMAT_EP_IN         0x82
 #define VISOMAT_EP_OUT        0x03
+#define VISOMAT_PACKET_SIZE   64
 
 #define STX 0x02
 #define ETX 0x03
 
+#define DATETIME_PACKET_SIZE 15
 #define BASE_YEAR 2000
 
 typedef enum {
@@ -236,7 +238,7 @@ static int decode_datetime(uint8_t *buffer, unsigned int len)
        struct datetime d;
        uint8_t *pbuffer = buffer;
 
-       if (len != 15)
+       if (len != DATETIME_PACKET_SIZE)
                return -EINVAL;
 
        code[0] = buffer[1];
@@ -281,7 +283,7 @@ static int get_response(libusb_device_handle *dev,
 {
        int ret;
        int transferred;
-       uint8_t response[64] = { 0 };
+       uint8_t response[VISOMAT_PACKET_SIZE] = { 0 };
        unsigned int i;
 
        i = 0;
@@ -303,7 +305,7 @@ static int get_response(libusb_device_handle *dev,
 
        } while (buffer[i - 1] != ETX && i < len);
 
-       /* Check the buffer is a valid response packet */
+       /* Check if the buffer contains a valid response packet */
        if (buffer[0] != STX || buffer[i - 1] != ETX)
                return -EINVAL;
 
@@ -314,8 +316,8 @@ static int get_response(libusb_device_handle *dev,
 #define visomat_device libusb_device_handle
 static int visomat_dump_eeprom(visomat_device *dev, unsigned int user_mask)
 {
-       /* Assuming an EEPROM of 1 KiB  */
-       uint8_t buffer[1024] = { 0 };
+       /* Assuming an EEPROM of 4 KiB  */
+       uint8_t buffer[4096] = { 0 };
        int ret;
 
        ret = send_command(dev, VISOMAT_CMD_DUMP_EEPROM);