REO progress
This commit is contained in:
parent
611a9e5ce3
commit
8f06ffa1e5
|
@ -28,8 +28,7 @@ public class ConfigurationImage {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ByteBuffer getByteBuffer(int offset, int size) {
|
public ByteBuffer getByteBuffer(int offset, int size) {
|
||||||
byte data[] = getRange(offset, size);
|
ByteBuffer wrapped = ByteBuffer.wrap(content, offset, size);
|
||||||
ByteBuffer wrapped = ByteBuffer.wrap(data);
|
|
||||||
wrapped.order(ByteOrder.LITTLE_ENDIAN);
|
wrapped.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,6 +205,14 @@ public class IniFileModel {
|
||||||
list.removeFirst();
|
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 {
|
enum State {
|
||||||
SKIPPING,
|
SKIPPING,
|
||||||
DIALOG
|
DIALOG
|
||||||
|
|
|
@ -32,6 +32,11 @@ public class ArrayIniField extends IniField {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return type.getStorageSize() * cols * rows;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -60,12 +65,23 @@ public class ArrayIniField extends IniField {
|
||||||
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
||||||
for (int colIndex = 0; colIndex < cols; colIndex++) {
|
for (int colIndex = 0; colIndex < cols; colIndex++) {
|
||||||
String value = values[rowIndex * 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);
|
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) {
|
public static IniField parse(LinkedList<String> list) {
|
||||||
String name = list.get(0);
|
String name = list.get(0);
|
||||||
FieldType type = FieldType.parseTs(list.get(2));
|
FieldType type = FieldType.parseTs(list.get(2));
|
||||||
|
|
|
@ -24,6 +24,11 @@ public class EnumIniField extends IniField {
|
||||||
this.bitSize = bitSize;
|
this.bitSize = bitSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return type.getStorageSize();
|
||||||
|
}
|
||||||
|
|
||||||
public int getBitPosition() {
|
public int getBitPosition() {
|
||||||
return bitPosition;
|
return bitPosition;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +76,18 @@ public class EnumIniField extends IniField {
|
||||||
getByteBuffer(image).putInt(value);
|
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) {
|
public static int setBitRange(int value, int ordinal, int bitPosition, int bitSize) {
|
||||||
int num = ((1 << bitSize) - 1) << bitPosition;
|
int num = ((1 << bitSize) - 1) << bitPosition;
|
||||||
int clearBitRange = value & ~num;
|
int clearBitRange = value & ~num;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package com.opensr5.ini.field;
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
|
|
||||||
public class IniField {
|
public abstract class IniField {
|
||||||
private final String name;
|
private final String name;
|
||||||
private final int offset;
|
private final int offset;
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ public class IniField {
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract int getSize();
|
||||||
|
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ public class ScalarIniField extends IniField {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return type.getStorageSize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
Field f = new Field(getName(), getOffset(), getType());
|
Field f = new Field(getName(), getOffset(), getType());
|
||||||
|
|
|
@ -13,6 +13,11 @@ public class StringIniField extends IniField {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
String value = new String(image.getContent(), getOffset(), size);
|
String value = new String(image.getContent(), getOffset(), size);
|
||||||
|
|
|
@ -10,8 +10,12 @@ import com.rusefi.tune.xml.Msq;
|
||||||
import com.rusefi.xml.XmlUtil;
|
import com.rusefi.xml.XmlUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* from IDEA this unit test needs to be exectuted with "empty" working directory
|
* 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");
|
Msq tsTune = XmlUtil.readModel(Msq.class, PATH + "CurrentTune.msq");
|
||||||
System.out.println(tsTune);
|
System.out.println(tsTune);
|
||||||
|
|
||||||
makeBinaryTune(tsTune, IniFileModel.getInstance());
|
ConfigurationImage tsBinaryData = makeBinaryTune(tsTune, IniFileModel.getInstance());
|
||||||
|
|
||||||
|
|
||||||
String binary = PATH + "current_configuration.rusefi_binary";
|
String binary = PATH + "current_configuration.rusefi_binary";
|
||||||
System.out.println("Reading " + 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);
|
ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE);
|
||||||
|
|
||||||
for (Constant constant : tsTune.getPage().constant) {
|
for (Constant constant : tsTune.getPage().constant) {
|
||||||
|
@ -43,7 +60,9 @@ public class TuneReadWriteTest {
|
||||||
}
|
}
|
||||||
IniField field = instance.allIniFields.get(constant.getName());
|
IniField field = instance.allIniFields.get(constant.getName());
|
||||||
Objects.requireNonNull(field, "Field for " + constant.getName());
|
Objects.requireNonNull(field, "Field for " + constant.getName());
|
||||||
|
System.out.println("Setting " + field);
|
||||||
field.setValue(ci, constant);
|
field.setValue(ci, constant);
|
||||||
}
|
}
|
||||||
|
return ci;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue