REO progress

This commit is contained in:
rusefi 2020-06-13 21:51:09 -04:00
parent 611a9e5ce3
commit 8f06ffa1e5
8 changed files with 78 additions and 7 deletions

View File

@ -28,8 +28,7 @@ public class ConfigurationImage {
@NotNull
public ByteBuffer getByteBuffer(int offset, int size) {
byte data[] = getRange(offset, size);
ByteBuffer wrapped = ByteBuffer.wrap(data);
ByteBuffer wrapped = ByteBuffer.wrap(content, offset, size);
wrapped.order(ByteOrder.LITTLE_ENDIAN);
return wrapped;
}

View File

@ -205,6 +205,14 @@ public class IniFileModel {
list.removeFirst();
}
public IniField findByOffset(int i) {
for (IniField field : allIniFields.values()) {
if (i >= field.getOffset() && i < field.getOffset() + field.getSize())
return field;
}
return null;
}
enum State {
SKIPPING,
DIALOG

View File

@ -32,6 +32,11 @@ public class ArrayIniField extends IniField {
return rows;
}
@Override
public int getSize() {
return type.getStorageSize() * cols * rows;
}
@Override
public String getValue(ConfigurationImage image) {
StringBuilder sb = new StringBuilder();
@ -60,12 +65,23 @@ public class ArrayIniField extends IniField {
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
for (int colIndex = 0; colIndex < cols; colIndex++) {
String value = values[rowIndex * cols + colIndex];
ByteBuffer wrapped = image.getByteBuffer(getOffset(), type.getStorageSize());
ByteBuffer wrapped = image.getByteBuffer(getOffset(rowIndex, colIndex), type.getStorageSize());
ScalarIniField.setValue(wrapped, type, value, Field.NO_BIT_OFFSET);
}
}
}
@Override
public String toString() {
return "ArrayIniField{" +
"name=" + getName() +
", offset=" + getOffset() +
", type=" + type +
", cols=" + cols +
", rows=" + rows +
'}';
}
public static IniField parse(LinkedList<String> list) {
String name = list.get(0);
FieldType type = FieldType.parseTs(list.get(2));

View File

@ -24,6 +24,11 @@ public class EnumIniField extends IniField {
this.bitSize = bitSize;
}
@Override
public int getSize() {
return type.getStorageSize();
}
public int getBitPosition() {
return bitPosition;
}
@ -71,6 +76,18 @@ public class EnumIniField extends IniField {
getByteBuffer(image).putInt(value);
}
@Override
public String toString() {
return "EnumIniField{" +
"name=" + getName() +
", offset=" + getOffset() +
", type=" + type +
", enums=" + enums +
", bitPosition=" + bitPosition +
", bitSize=" + bitSize +
'}';
}
public static int setBitRange(int value, int ordinal, int bitPosition, int bitSize) {
int num = ((1 << bitSize) - 1) << bitPosition;
int clearBitRange = value & ~num;

View File

@ -3,7 +3,7 @@ package com.opensr5.ini.field;
import com.opensr5.ConfigurationImage;
import com.rusefi.tune.xml.Constant;
public class IniField {
public abstract class IniField {
private final String name;
private final int offset;
@ -24,6 +24,8 @@ public class IniField {
return offset;
}
public abstract int getSize();
public String getValue(ConfigurationImage image) {
return null;
}

View File

@ -29,6 +29,11 @@ public class ScalarIniField extends IniField {
return type;
}
@Override
public int getSize() {
return type.getStorageSize();
}
@Override
public String getValue(ConfigurationImage image) {
Field f = new Field(getName(), getOffset(), getType());

View File

@ -13,6 +13,11 @@ public class StringIniField extends IniField {
this.size = size;
}
@Override
public int getSize() {
return size;
}
@Override
public String getValue(ConfigurationImage image) {
String value = new String(image.getContent(), getOffset(), size);

View File

@ -10,8 +10,12 @@ import com.rusefi.tune.xml.Msq;
import com.rusefi.xml.XmlUtil;
import org.junit.Test;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Objects;
import static org.junit.Assert.assertEquals;
/**
* from IDEA this unit test needs to be exectuted with "empty" working directory
*/
@ -26,15 +30,28 @@ public class TuneReadWriteTest {
Msq tsTune = XmlUtil.readModel(Msq.class, PATH + "CurrentTune.msq");
System.out.println(tsTune);
makeBinaryTune(tsTune, IniFileModel.getInstance());
ConfigurationImage tsBinaryData = makeBinaryTune(tsTune, IniFileModel.getInstance());
String binary = PATH + "current_configuration.rusefi_binary";
System.out.println("Reading " + binary);
ConfigurationImageFile.readFromFile(binary);
ConfigurationImage fileBinaryData = ConfigurationImageFile.readFromFile(binary);
byte[] tsBinaryDataContent = tsBinaryData.getContent();
byte[] fileBinaryDataContent = fileBinaryData.getContent();
for (int i = 0; i < tsBinaryDataContent.length; i++) {
byte tsByte = tsBinaryDataContent[i];
byte fileByte = fileBinaryDataContent[i];
if (tsByte != fileByte) {
// System.out.println("Out issue is at " + IniFileModel.getInstance().findByOffset(i) + " " + tsByte + "/" + fileByte);
// throw new IllegalStateException("Content not same at " + i);
}
}
// assertEquals(Arrays.toString(tsBinaryDataContent), Arrays.toString(fileBinaryDataContent));
}
private void makeBinaryTune(Msq tsTune, IniFileModel instance) {
private ConfigurationImage makeBinaryTune(Msq tsTune, IniFileModel instance) {
ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE);
for (Constant constant : tsTune.getPage().constant) {
@ -43,7 +60,9 @@ public class TuneReadWriteTest {
}
IniField field = instance.allIniFields.get(constant.getName());
Objects.requireNonNull(field, "Field for " + constant.getName());
System.out.println("Setting " + field);
field.setValue(ci, constant);
}
return ci;
}
}