mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Allow sloppy datapoint message length (#1982)
This allows datapoint update messages to be handled even if the overall message is longer than required (likely that it contains trailing empty bytes). The specific type handling will read only the expected data lengths so we only need to hard bail if we have too little data not too much.
This commit is contained in:
parent
b20760c93c
commit
e32722db70
1 changed files with 4 additions and 2 deletions
|
@ -241,8 +241,10 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) {
|
||||||
size_t data_size = (buffer[2] << 8) + buffer[3];
|
size_t data_size = (buffer[2] << 8) + buffer[3];
|
||||||
const uint8_t *data = buffer + 4;
|
const uint8_t *data = buffer + 4;
|
||||||
size_t data_len = len - 4;
|
size_t data_len = len - 4;
|
||||||
if (data_size != data_len) {
|
if (data_size > data_len) {
|
||||||
ESP_LOGW(TAG, "Datapoint %u is not expected size (%zu != %zu)", datapoint.id, data_size, data_len);
|
ESP_LOGW(TAG, "Datapoint %u has extra bytes that will be ignored (%zu > %zu)", datapoint.id, data_size, data_len);
|
||||||
|
} else if (data_size < data_len) {
|
||||||
|
ESP_LOGW(TAG, "Datapoint %u is truncated and cannot be parsed (%zu < %zu)", datapoint.id, data_size, data_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
datapoint.len = data_len;
|
datapoint.len = data_len;
|
||||||
|
|
Loading…
Reference in a new issue