Skip to content

Commit

Permalink
fix emsesp#820, 4byte-values
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Dec 22, 2022
1 parent d6de0f6 commit ab1924d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,9 @@ void EMSdevice::generate_values_web(JsonObject & output) {
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
obj["v"] = Helpers::transformNumFloat(*(uint16_t *)(dv.value_p), dv.numeric_operator, fahrenheit);
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
obj["v"] = Helpers::transformNumFloat(*(uint32_t *)(dv.value_p), dv.numeric_operator);
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator); // ULONG always have positive num_op
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
obj["v"] = Helpers::transformNumFloat(*(uint32_t *)(dv.value_p), dv.numeric_operator);
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
} else {
obj["v"] = ""; // must have a value for sorting to work
}
Expand Down Expand Up @@ -912,9 +912,9 @@ void EMSdevice::generate_values_web_customization(JsonArray & output) {
} else if (dv.type == DeviceValueType::USHORT) {
obj["v"] = Helpers::transformNumFloat(*(uint16_t *)(dv.value_p), dv.numeric_operator, fahrenheit);
} else if (dv.type == DeviceValueType::ULONG) {
obj["v"] = Helpers::transformNumFloat(*(uint32_t *)(dv.value_p), dv.numeric_operator);
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
} else if (dv.type == DeviceValueType::TIME) {
obj["v"] = Helpers::transformNumFloat(*(uint32_t *)(dv.value_p), dv.numeric_operator);
obj["v"] = (*(uint32_t *)(dv.value_p) / dv.numeric_operator);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ bool Helpers::hasValue(const uint16_t & value) {
}

bool Helpers::hasValue(const uint32_t & value) {
return (value < EMS_VALUE_ULONG_NOTSET);
return (value != EMS_VALUE_ULONG_NOTSET && value != EMS_VALUE_ULLONG_NOTSET);
}

// checks if we can convert a char string to an int value
Expand Down
4 changes: 2 additions & 2 deletions src/telegram.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static constexpr uint8_t EMS_VALUE_UINT_NOTSET = 0xFF; // for 8-bit uns
static constexpr int8_t EMS_VALUE_INT_NOTSET = 0x7F; // for signed 8-bit ints/bytes
static constexpr uint16_t EMS_VALUE_USHORT_NOTSET = 0x7D00; // 32000: for 2-byte unsigned shorts
static constexpr int16_t EMS_VALUE_SHORT_NOTSET = 0x7D00; // 32000: for 2-byte signed shorts
static constexpr uint32_t EMS_VALUE_ULONG_NOTSET = 0x00FFFFFF; // for 3-byte and 4-byte longs
// 4 byte value is 21474836 (0x147AE14), we use only the lower one, see https://github.com/emsesp/EMS-ESP32/issues/820
static constexpr uint32_t EMS_VALUE_ULONG_NOTSET = 0x00FFFFFF; // for 3-byte longs
static constexpr uint32_t EMS_VALUE_ULLONG_NOTSET = 0xFFFFFFFF; // for 4-byte longs

static constexpr uint8_t EMS_MAX_TELEGRAM_LENGTH = 32; // max length of a complete EMS telegram
static constexpr uint8_t EMS_MAX_TELEGRAM_MESSAGE_LENGTH = 27; // max length of message block, assuming EMS1.0
Expand Down

0 comments on commit ab1924d

Please sign in to comment.