mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 11:56:25 +01:00
Fix checksum calculation for sml (#5271)
This commit is contained in:
parent
a35122231c
commit
b566c78f00
@ -100,14 +100,14 @@ bool check_sml_data(const bytes &buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t crc_received = (buffer.at(buffer.size() - 2) << 8) | buffer.at(buffer.size() - 1);
|
uint16_t crc_received = (buffer.at(buffer.size() - 2) << 8) | buffer.at(buffer.size() - 1);
|
||||||
uint16_t crc_calculated = crc16(buffer.data(), buffer.size(), 0x6e23, 0x8408, true, true);
|
uint16_t crc_calculated = crc16(buffer.data(), buffer.size() - 2, 0x6e23, 0x8408, true, true);
|
||||||
crc_calculated = (crc_calculated >> 8) | (crc_calculated << 8);
|
crc_calculated = (crc_calculated >> 8) | (crc_calculated << 8);
|
||||||
if (crc_received == crc_calculated) {
|
if (crc_received == crc_calculated) {
|
||||||
ESP_LOGV(TAG, "Checksum verification successful with CRC16/X25.");
|
ESP_LOGV(TAG, "Checksum verification successful with CRC16/X25.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
crc_calculated = crc16(buffer.data(), buffer.size(), 0xed50, 0x8408);
|
crc_calculated = crc16(buffer.data(), buffer.size() - 2, 0xed50, 0x8408);
|
||||||
if (crc_received == crc_calculated) {
|
if (crc_received == crc_calculated) {
|
||||||
ESP_LOGV(TAG, "Checksum verification successful with CRC16/KERMIT.");
|
ESP_LOGV(TAG, "Checksum verification successful with CRC16/KERMIT.");
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user