mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 12:37:45 +01:00
Fix 24 bit signed integer parsing in sml parser (#5250)
This commit is contained in:
parent
afd26c6f1a
commit
ff8a73c2d1
@ -88,6 +88,11 @@ uint64_t bytes_to_uint(const bytes &buffer) {
|
|||||||
for (auto const value : buffer) {
|
for (auto const value : buffer) {
|
||||||
val = (val << 8) + value;
|
val = (val << 8) + value;
|
||||||
}
|
}
|
||||||
|
// Some smart meters send 24 bit signed integers. Sign extend to 64 bit if the
|
||||||
|
// 24 bit value is negative.
|
||||||
|
if (buffer.size() == 3 && buffer[0] & 0x80) {
|
||||||
|
val |= 0xFFFFFFFFFF000000;
|
||||||
|
}
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user