6.1.1.5 - Fix Pow R2 and S31

Fix some Pow R2 and S31 checksum errors using optimized re-sync
This commit is contained in:
Theo Arends 2018-08-12 16:15:03 +02:00
parent 3efb84fb93
commit ee9b26ecfa
3 changed files with 31 additions and 28 deletions

View File

@ -1,6 +1,9 @@
/* 6.1.1.4
/* 6.1.1.5
* Fix some Pow R2 and S31 checksum errors using optimized re-sync
*
* 6.1.1.4
* Change version representation from 1.1.1a to 1.1.1.1 for better change reference
*
*
* 6.1.1c
* Add iFan02 Fanspeed + and Fanspeed - command options (#3415)
* Fix some Pow R2 and S31 checksum errors (#3425)

View File

@ -20,6 +20,6 @@
#ifndef _SONOFF_VERSION_H_
#define _SONOFF_VERSION_H_
#define VERSION 0x06010104
#define VERSION 0x06010105
#endif // _SONOFF_VERSION_H_

View File

@ -307,7 +307,6 @@ void CseReceived()
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// 55 5A 02 F7 60 00 03 AB 00 40 10 02 60 5D 51 A6 58 03 E9 EF 71 0B 7A 36
// Hd Id VCal---- Voltage- ICal---- Current- PCal---- Power--- Ad CF--- Ck
AddLogSerial(LOG_LEVEL_DEBUG_MORE);
uint8_t header = serial_in_buffer[0];
if ((header & 0xFC) == 0xFC) {
@ -315,14 +314,6 @@ void CseReceived()
return;
}
// Calculate checksum
uint8_t checksum = 0;
for (byte i = 2; i < 23; i++) checksum += serial_in_buffer[i];
if (checksum != serial_in_buffer[23]) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: " D_CHECKSUM_FAILURE));
return;
}
// Get chip calibration data (coefficients) and use as initial defaults
if (HLW_UREF_PULSE == Settings.energy_voltage_calibration) {
long voltage_coefficient = 191200; // uSec
@ -392,24 +383,33 @@ bool CseSerialInput()
if (cse_receive_flag) {
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
if (24 == serial_in_byte_counter) {
CseReceived();
cse_receive_flag = 0;
return 1;
AddLogSerial(LOG_LEVEL_DEBUG_MORE);
uint8_t checksum = 0;
for (byte i = 2; i < 23; i++) { checksum += serial_in_buffer[i]; }
if (checksum == serial_in_buffer[23]) {
CseReceived();
cse_receive_flag = 0;
return 1;
} else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: " D_CHECKSUM_FAILURE));
do { // Sync buffer with data (issue #1907 and #3425)
memmove(serial_in_buffer, serial_in_buffer +1, 24);
serial_in_byte_counter--;
} while ((serial_in_byte_counter > 1) && (0x5A != serial_in_buffer[1]));
if (0x5A == serial_in_buffer[1]) {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: Fixed out-of-sync"));
serial_in_byte_counter++;
} else {
cse_receive_flag = 0;
serial_in_byte_counter = 0;
}
}
}
} else {
if ((0x5A == serial_in_byte) && (serial_in_byte_counter)) { // 0x5A - Packet header 2
if ((0x55 == serial_in_buffer[serial_in_byte_counter -1]) ||
(0xAA == serial_in_buffer[serial_in_byte_counter -1]) ||
(serial_in_buffer[serial_in_byte_counter -1] > 0xF0)) {
if (serial_in_byte_counter > 1) { // Sync buffer with data (issue #1907 and #3425)
serial_in_buffer[0] = serial_in_buffer[--serial_in_byte_counter];
serial_in_byte_counter = 1;
AddLog_P(LOG_LEVEL_DEBUG, PSTR("CSE: Fixed out-of-sync"));
}
cse_receive_flag = 1;
} else {
serial_in_byte_counter = 0;
}
if ((0x5A == serial_in_byte) && (1 == serial_in_byte_counter)) { // 0x5A - Packet header 2
cse_receive_flag = 1;
} else {
serial_in_byte_counter = 0;
}
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
}