visomat-data-downloader: document why code is 4 bytes in decode_datetime()
authorAntonio Ospite <ao2@ao2.it>
Wed, 14 Sep 2016 11:32:02 +0000 (13:32 +0200)
committerAntonio Ospite <ao2@ao2.it>
Wed, 14 Sep 2016 11:32:02 +0000 (13:32 +0200)
src/visomat-data-downloader.c

index a3282ba..1cbe6f5 100644 (file)
@@ -234,7 +234,7 @@ static int decode_eeprom(uint8_t *buffer,
 static int decode_datetime(uint8_t *buffer, unsigned int len)
 {
        int ret;
 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;
 
        struct datetime d;
        uint8_t *pbuffer = buffer;
 
@@ -245,7 +245,7 @@ static int decode_datetime(uint8_t *buffer, unsigned int len)
        code[1] = buffer[2];
        code[2] = buffer[3];
 
        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;
 
        if (ret < 0)
                return ret;