diff --git a/java_console/inifile/src/main/java/com/opensr5/ConfigurationImage.java b/java_console/inifile/src/main/java/com/opensr5/ConfigurationImage.java index efe173617d..295088c85a 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ConfigurationImage.java +++ b/java_console/inifile/src/main/java/com/opensr5/ConfigurationImage.java @@ -1,9 +1,9 @@ package com.opensr5; +import com.rusefi.shared.FileUtil; import org.jetbrains.annotations.NotNull; import java.nio.ByteBuffer; -import java.nio.ByteOrder; /** * Andrey Belomutskiy, (c) 2013-2020 @@ -28,9 +28,7 @@ public class ConfigurationImage { @NotNull public ByteBuffer getByteBuffer(int offset, int size) { - ByteBuffer wrapped = ByteBuffer.wrap(content, offset, size); - wrapped.order(ByteOrder.LITTLE_ENDIAN); - return wrapped; + return FileUtil.littleEndianWrap(content, offset, size); } public int getSize() { diff --git a/java_console/inifile/src/main/java/com/rusefi/config/Field.java b/java_console/inifile/src/main/java/com/rusefi/config/Field.java index 042e996983..ae835ddaae 100644 --- a/java_console/inifile/src/main/java/com/rusefi/config/Field.java +++ b/java_console/inifile/src/main/java/com/rusefi/config/Field.java @@ -2,12 +2,12 @@ package com.rusefi.config; import com.macfaq.io.LittleEndianOutputStream; import com.opensr5.ConfigurationImage; +import com.rusefi.shared.FileUtil; import org.jetbrains.annotations.NotNull; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.Objects; import static com.rusefi.config.FieldType.*; @@ -159,8 +159,7 @@ public class Field { } public void setValue(byte[] content, boolean value) { - ByteBuffer wrapped = ByteBuffer.wrap(content, 0, content.length); - wrapped.order(ByteOrder.LITTLE_ENDIAN); + ByteBuffer wrapped = FileUtil.littleEndianWrap(content, 0, content.length); if (bitOffset != NO_BIT_OFFSET) { int packed = wrapped.getInt(); int thisBit = (value ? 1 : 0) << bitOffset; diff --git a/java_console/models/src/main/java/com/rusefi/core/ISensorHolder.java b/java_console/models/src/main/java/com/rusefi/core/ISensorHolder.java index 3e18143201..3b21eb2541 100644 --- a/java_console/models/src/main/java/com/rusefi/core/ISensorHolder.java +++ b/java_console/models/src/main/java/com/rusefi/core/ISensorHolder.java @@ -1,8 +1,8 @@ package com.rusefi.core; -import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.ByteOrder; + +import static com.rusefi.shared.FileUtil.littleEndianWrap; public interface ISensorHolder { default void grabSensorValues(byte[] response) { @@ -17,8 +17,7 @@ public interface ISensorHolder { if (offset + size > response.length) { throw new IllegalArgumentException(sensor + String.format(" but %d+%d in %d", offset, size, response.length)); } - ByteBuffer bb = ByteBuffer.wrap(response, offset, size); - bb.order(ByteOrder.LITTLE_ENDIAN); + ByteBuffer bb = littleEndianWrap(response, offset, size); double rawValue = sensor.getValueForChannel(bb); double scaledValue = rawValue * sensor.getScale(); diff --git a/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java b/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java index cca7b6834a..0544b34bdf 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java +++ b/java_console/shared_io/src/main/java/com/rusefi/shared/FileUtil.java @@ -1,6 +1,10 @@ package com.rusefi.shared; +import org.jetbrains.annotations.NotNull; + import java.io.*; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -66,4 +70,11 @@ public class FileUtil { } } } + + @NotNull + public static ByteBuffer littleEndianWrap(byte[] array, int offset, int length) { + ByteBuffer wrapped = ByteBuffer.wrap(array, offset, length); + wrapped.order(ByteOrder.LITTLE_ENDIAN); + return wrapped; + } }