REO progress
This commit is contained in:
parent
152fa17990
commit
683402f176
|
@ -3,8 +3,10 @@ package com.opensr5.ini.field;
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
import com.rusefi.config.FieldType;
|
import com.rusefi.config.FieldType;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -40,7 +42,7 @@ public class EnumIniField extends IniField {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
int ordinal = image.getByteBuffer(getOffset(), type.getStorageSize()).get();
|
int ordinal = getByteBuffer(image).getInt();
|
||||||
ordinal = getBitRange(ordinal, bitPosition, bitSize);
|
ordinal = getBitRange(ordinal, bitPosition, bitSize);
|
||||||
|
|
||||||
if (ordinal >= enums.size())
|
if (ordinal >= enums.size())
|
||||||
|
@ -48,6 +50,11 @@ public class EnumIniField extends IniField {
|
||||||
return enums.get(ordinal);
|
return enums.get(ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private ByteBuffer getByteBuffer(ConfigurationImage image) {
|
||||||
|
return image.getByteBuffer(getOffset(), 4);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isQuoted(String q) {
|
private static boolean isQuoted(String q) {
|
||||||
final int len = q.length();
|
final int len = q.length();
|
||||||
return (len >= 2 && q.charAt(0) == '"' && q.charAt(len - 1) == '"');
|
return (len >= 2 && q.charAt(0) == '"' && q.charAt(len - 1) == '"');
|
||||||
|
@ -59,6 +66,15 @@ public class EnumIniField extends IniField {
|
||||||
int ordinal = enums.indexOf(isQuoted(v) ? ObjectName.unquote(v) : v);
|
int ordinal = enums.indexOf(isQuoted(v) ? ObjectName.unquote(v) : v);
|
||||||
if (ordinal == -1)
|
if (ordinal == -1)
|
||||||
throw new IllegalArgumentException("Not found " + v);
|
throw new IllegalArgumentException("Not found " + v);
|
||||||
|
int value = getByteBuffer(image).getInt();
|
||||||
|
value = setBitRange(value, ordinal, bitPosition, bitSize);
|
||||||
|
getByteBuffer(image).putInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int setBitRange(int value, int ordinal, int bitPosition, int bitSize) {
|
||||||
|
int num = ((1 << bitSize) - 1) << bitPosition;
|
||||||
|
int clearBitRange = value & ~num;
|
||||||
|
return (byte) (clearBitRange + (ordinal << bitPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBit(int ordinal, int bitPosition) {
|
public static boolean getBit(int ordinal, int bitPosition) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.junit.Test;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
|
@ -101,6 +102,17 @@ public class IniFileReaderTest {
|
||||||
assertEquals(2, model.allIniFields.size());
|
assertEquals(2, model.allIniFields.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetBits() {
|
||||||
|
assertEquals((byte) 0xFE, EnumIniField.setBitRange((byte) 0xFF, 0, 0, 1));
|
||||||
|
assertEquals((byte) 0xF0, EnumIniField.setBitRange((byte) 0xFF, 0, 0, 4));
|
||||||
|
assertEquals((byte) 0x0F, EnumIniField.setBitRange((byte) 0xFF, 0, 4, 4));
|
||||||
|
|
||||||
|
assertEquals((byte) 1, EnumIniField.setBitRange((byte) 0xFF, 3, 0, 1));
|
||||||
|
assertEquals((byte) -13, EnumIniField.setBitRange((byte) 0xFF, 3, 0, 4));
|
||||||
|
assertEquals((byte) 0x3F, EnumIniField.setBitRange((byte) 0xFF, 3, 4, 4));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBitLogic() {
|
public void testBitLogic() {
|
||||||
assertEquals(4, EnumIniField.getBitRange(4, 0, 7));
|
assertEquals(4, EnumIniField.getBitRange(4, 0, 7));
|
||||||
|
|
Loading…
Reference in New Issue