|
@@ -6,7 +6,8 @@
|
|
|
#include <string.h>
|
|
|
#include "config.h"
|
|
|
|
|
|
-uint8_t xorBytes(const uint8_t * const start, const uint16_t length);
|
|
|
+uint8_t sumBytes(const uint8_t * const start, const uint16_t length);
|
|
|
+extern uint8_t bitReverse(uint8_t b);
|
|
|
|
|
|
/**
|
|
|
* @Analys of Toshiba IR Rx:
|
|
@@ -43,6 +44,14 @@ uint8_t xorBytes(const uint8_t * const start, const uint16_t length);
|
|
|
* 21 deg 4004072000125461 C560007007000091 000018 0101 0100 - 01010 A 10
|
|
|
* 16 deg 4004072000120461 C560007007000091 000070 0000 0100 - 00000 0 00
|
|
|
* 0220E00400482086 A306000EE0000089 00000E 0010 0010 17 grader
|
|
|
+ *
|
|
|
+ * Me: 4004072000000060 0220E00400483286 6306000EE00000890000E0
|
|
|
+ * Forum: 0220E00400000006 0220E00400492880 A40D000EE000000100069D
|
|
|
+ * Code has a checksum in the last byte (9D) calculated as follows:
|
|
|
+ * f4 + 02 + 20 + ... + 00 + 06 (= 9D in the case above).
|
|
|
+ * Summing all but the last byte to f4.
|
|
|
+ * Forum: https://www.varmepumpsforum.com/vpforum/index.php?topic=13580.0
|
|
|
+ * For me, the chksum needs to add 0x06 to make it work.
|
|
|
*
|
|
|
*
|
|
|
* Fan in byte ([8] >> 4)
|
|
@@ -56,6 +65,11 @@ uint8_t xorBytes(const uint8_t * const start, const uint16_t length);
|
|
|
* Power in data->raw[5]&0x01
|
|
|
* 0 = OFF
|
|
|
* 1 = ON
|
|
|
+ *
|
|
|
+ * Checksum
|
|
|
+ * Byte #19 of frame 2 is the checksum for frame 2. It allows the AC unit to know whether the command sent
|
|
|
+ * is valid or not.
|
|
|
+ * The checksum is the sum (addition) of the previous 18 bytes modulo 256 (frame 2 only).
|
|
|
*/
|
|
|
|
|
|
|
|
@@ -217,16 +231,23 @@ uint8_t* nextPulseToshiba_ir(uint32_t width)
|
|
|
break;
|
|
|
case 1:
|
|
|
rx_state = DONE;
|
|
|
+ // Panasonic has LSB8 format so we need to bit-reverse each byte
|
|
|
+ for( uint8_t i=0; i<kPanasonicNumberOfBytes; i++ ) data[i] = bitReverse(data[i]);
|
|
|
// Check checksum
|
|
|
- //if( xorBytes(data,8) == data[8] ) {
|
|
|
+ uint8_t chkSum = sumBytes(data,18) - 6;
|
|
|
+ ESP_LOGI("TOSHIBA","Chksum:0x%02X B18:0x%02X Diff:0x%02X", chkSum,data[18],(uint8_t)(chkSum-data[18]));
|
|
|
+
|
|
|
+ if( chkSum == data[18] ) {
|
|
|
+ ESP_LOGI("TOSHIBA", "CORRECT CHKSUM");
|
|
|
memcpy(dataTransfer,data,kPanasonicNumberOfBytes);
|
|
|
Toshiba_ir_ResetDecoder();
|
|
|
retVal = dataTransfer;
|
|
|
- /*}
|
|
|
+ }
|
|
|
else {
|
|
|
ESP_LOGE("TOSHIBA", "WRONG CHKSUM");
|
|
|
+ ESP_LOGE("TOSHIBA","Chksum:0x%02X B18:0x%02X Diff:0x%02X", chkSum,data[18],(uint8_t)(chkSum-data[18]));
|
|
|
Toshiba_ir_ResetDecoder();
|
|
|
- }*/
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -235,14 +256,12 @@ uint8_t* nextPulseToshiba_ir(uint32_t width)
|
|
|
return retVal;
|
|
|
}
|
|
|
|
|
|
-/// Calculate a rolling XOR of all the bytes of an array.
|
|
|
-/// @param[in] start A ptr to the start of the byte array to calculate over.
|
|
|
-/// @param[in] length How many bytes to use in the calculation.
|
|
|
-/// @return The 8-bit calculated result of all the bytes and init value.
|
|
|
-/// Copied from: https://github.com/crankyoldgit/IRremoteESP8266/blob/master/src/IRutils.cpp
|
|
|
-uint8_t xorBytes(const uint8_t * const start, const uint16_t length) {
|
|
|
+uint8_t sumBytes(const uint8_t * const start, const uint16_t length) {
|
|
|
uint8_t checksum = 0;
|
|
|
const uint8_t *ptr;
|
|
|
- for (ptr = start; ptr - start < length; ptr++) checksum ^= *ptr;
|
|
|
- return checksum;
|
|
|
+ for (ptr = start; ptr - start < length; ptr++) {
|
|
|
+ checksum += (*ptr);
|
|
|
+ //ESP_LOGI("CS","Byte:0x%02X",(*ptr));
|
|
|
+ }
|
|
|
+ return (uint8_t) (checksum);
|
|
|
}
|