mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Modbus QWORD fix (#3856)
This commit is contained in:
parent
98171c9f49
commit
71387be72e
1 changed files with 7 additions and 15 deletions
|
@ -571,24 +571,16 @@ int64_t payload_to_number(const std::vector<uint8_t> &data, SensorValueType sens
|
||||||
static_cast<int32_t>(((value & 0x7FFF) << 16 | (value & 0xFFFF0000) >> 16) | sign_bit), bitmask);
|
static_cast<int32_t>(((value & 0x7FFF) << 16 | (value & 0xFFFF0000) >> 16) | sign_bit), bitmask);
|
||||||
} break;
|
} break;
|
||||||
case SensorValueType::U_QWORD:
|
case SensorValueType::U_QWORD:
|
||||||
// Ignore bitmask for U_QWORD
|
|
||||||
value = get_data<uint64_t>(data, offset);
|
|
||||||
break;
|
|
||||||
case SensorValueType::S_QWORD:
|
case SensorValueType::S_QWORD:
|
||||||
// Ignore bitmask for S_QWORD
|
// Ignore bitmask for QWORD
|
||||||
value = get_data<int64_t>(data, offset);
|
value = get_data<uint64_t>(data, offset);
|
||||||
break;
|
break;
|
||||||
case SensorValueType::U_QWORD_R:
|
case SensorValueType::U_QWORD_R:
|
||||||
// Ignore bitmask for U_QWORD
|
case SensorValueType::S_QWORD_R: {
|
||||||
value = get_data<uint64_t>(data, offset);
|
// Ignore bitmask for QWORD
|
||||||
value = static_cast<uint64_t>(value & 0xFFFF) << 48 | (value & 0xFFFF000000000000) >> 48 |
|
uint64_t tmp = get_data<uint64_t>(data, offset);
|
||||||
static_cast<uint64_t>(value & 0xFFFF0000) << 32 | (value & 0x0000FFFF00000000) >> 32 |
|
value = (tmp << 48) | (tmp >> 48) | ((tmp & 0xFFFF0000) << 16) | ((tmp >> 16) & 0xFFFF0000);
|
||||||
static_cast<uint64_t>(value & 0xFFFF00000000) << 16 | (value & 0x00000000FFFF0000) >> 16;
|
} break;
|
||||||
break;
|
|
||||||
case SensorValueType::S_QWORD_R:
|
|
||||||
// Ignore bitmask for S_QWORD
|
|
||||||
value = get_data<int64_t>(data, offset);
|
|
||||||
break;
|
|
||||||
case SensorValueType::RAW:
|
case SensorValueType::RAW:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue