refactoring: extracting utility method
This commit is contained in:
parent
6c8f130ff9
commit
d88a049c9e
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue