README: mention that the Prevention DS-2200PV uses the same protocol
[visomat-utils.git] / src / visomat-data-downloader.c
index bc9ec90..1cbe6f5 100644 (file)
@@ -63,6 +63,7 @@ static void debug_dump_buffer(const char *filename, uint8_t *buffer, unsigned in
 #define STX 0x02
 #define ETX 0x03
 
+#define DATETIME_PACKET_SIZE 15
 #define BASE_YEAR 2000
 
 typedef enum {
@@ -233,18 +234,18 @@ static int decode_eeprom(uint8_t *buffer,
 static int decode_datetime(uint8_t *buffer, unsigned int len)
 {
        int ret;
-       uint8_t code[4] = { 0 };
+       uint8_t code[4] = { 0 }; /* the initial STX + 3 bytes command code */
        struct datetime d;
        uint8_t *pbuffer = buffer;
 
-       if (len != 15)
+       if (len != DATETIME_PACKET_SIZE)
                return -EINVAL;
 
        code[0] = buffer[1];
        code[1] = buffer[2];
        code[2] = buffer[3];
 
-       ret = extract_datetime(pbuffer + 4, &d);
+       ret = extract_datetime(pbuffer + sizeof(code), &d);
        if (ret < 0)
                return ret;