From 8c3b22cfdde8fb74ec9efaecced5a02bf5e60856 Mon Sep 17 00:00:00 2001 From: Chiuaua79 <39282804+Chiuaua79@users.noreply.github.com> Date: Sat, 8 Mar 2025 23:55:33 +0100 Subject: [PATCH] [modbus][sunspec] Fix acc32 and uint32 (#18370) In 2020 the ACC32 fields were changed from unsigned int to signed, ref. #7826. This is incorrect. The acc32 is an unsigned integer. On top of that, the sunspec meter handlers had values assigned with acc32 that are uint32 according to the sunspec specification. https://sunspec.org/wp-content/uploads/2025/01/SunSpec-Device-Information-Model-Specificiation-V1-2-1-1.pdf This is the latest specification from 2024. Here it is stated that: acc32 = Unsigned 32-bit accumulator (deprecated in favor of uint32) Basically both acc32 and uint32 can have values from 0 to 4294967294 acc32 even until 4294967295, which is due to uint32 0xFFFFFFFF is specified as "not implemented". See also https://community.openhab.org/t/modbus-sunspec-showing-negative-total-exported-energy/161611/13 for the bug. Please cherrypick to 4.3.x branch as well. Signed-off-by: Cor Hoogendoorn --- .../modbus/sunspec/internal/parser/AbstractBaseParser.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/parser/AbstractBaseParser.java b/bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/parser/AbstractBaseParser.java index d38cf077a6c..bb3dc246129 100644 --- a/bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/parser/AbstractBaseParser.java +++ b/bundles/org.openhab.binding.modbus.sunspec/src/main/java/org/openhab/binding/modbus/sunspec/internal/parser/AbstractBaseParser.java @@ -79,19 +79,19 @@ public class AbstractBaseParser { } /** - * Extract an optional acc32 value + * Extract an optional acc32/uint32 value * * @param raw the register array to extract from * @param index the address of the field * @return the parsed value or empty if the field is not implemented */ protected Optional extractOptionalAcc32(ModbusRegisterArray raw, int index) { - return ModbusBitUtilities.extractStateFromRegisters(raw, index, ValueType.INT32).map(DecimalType::longValue) + return ModbusBitUtilities.extractStateFromRegisters(raw, index, ValueType.UINT32).map(DecimalType::longValue) .filter(value -> value != 0); } /** - * Extract a mandatory acc32 value + * Extract a mandatory acc32/uint32 value * * @param raw the register array to extract from * @param index the address of the field