REO progress

This commit is contained in:
rusefi 2020-06-13 21:12:33 -04:00
parent 1b1e9595f0
commit ea8b5df4cd
3 changed files with 33 additions and 8 deletions

View File

@ -3,7 +3,9 @@ package com.opensr5.ini.field;
import com.opensr5.ConfigurationImage;
import com.rusefi.config.Field;
import com.rusefi.config.FieldType;
import com.rusefi.tune.xml.Constant;
import java.nio.ByteBuffer;
import java.util.LinkedList;
public class ArrayIniField extends IniField {
@ -36,7 +38,7 @@ public class ArrayIniField extends IniField {
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
sb.append("\n\t");
for (int colIndex = 0; colIndex < cols; colIndex++) {
Field f = new Field("", getOffset() + rowIndex * getType().getStorageSize(), getType());
Field f = new Field("", getOffset(rowIndex, colIndex), getType());
sb.append(' ');
sb.append(f.getAnyValue(image));
}
@ -45,6 +47,25 @@ public class ArrayIniField extends IniField {
return sb.toString();
}
private int getOffset(int rowIndex, int colIndex) {
return getOffset() + (rowIndex * cols + colIndex) * getType().getStorageSize();
}
@Override
public void setValue(ConfigurationImage image, Constant constant) {
String[] values = constant.getValue().trim().split("\\s+");
if (values.length != getRows() * getCols())
throw new IllegalStateException(values.length + " values while expecting " + getRows() + " by " + getCols() + " total " + getRows() * getCols());
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());
ScalarIniField.setValue(wrapped, type, value, Field.NO_BIT_OFFSET);
}
}
}
public static IniField parse(LinkedList<String> list) {
String name = list.get(0);
FieldType type = FieldType.parseTs(list.get(2));

View File

@ -43,20 +43,23 @@ public class ScalarIniField extends IniField {
public void setValue(ConfigurationImage image, Constant constant) {
Field f = new Field(getName(), getOffset(), getType());
ByteBuffer wrapped = image.getByteBuffer(getOffset(), type.getStorageSize());
if (f.getBitOffset() != Field.NO_BIT_OFFSET) {
throw new UnsupportedOperationException("For " + constant);
setValue(wrapped, type, constant.getValue(), f.getBitOffset());
}
public static void setValue(ByteBuffer wrapped, FieldType type, String value, int bitOffset) {
if (bitOffset != Field.NO_BIT_OFFSET) {
throw new UnsupportedOperationException("For " + value);
// int packed = wrapped.getInt();
// value = (packed >> bitOffset) & 1;
} else if (type == INT8 || type == UINT8) {
wrapped.put((byte) Double.parseDouble(constant.getValue()));
wrapped.put((byte) Double.parseDouble(value));
} else if (type == INT) {
wrapped.putInt((int) Double.parseDouble(constant.getValue()));
wrapped.putInt((int) Double.parseDouble(value));
} else if (type == INT16 || type == UINT16) {
wrapped.putShort((short) Double.parseDouble(constant.getValue()));
wrapped.putShort((short) Double.parseDouble(value));
} else {
wrapped.putFloat(Float.parseFloat(constant.getValue()));
wrapped.putFloat(Float.parseFloat(value));
}
super.setValue(image, constant);
}
public static ScalarIniField parse(LinkedList<String> list) {

View File

@ -131,6 +131,7 @@ public class Field {
public Object getAnyValue(ConfigurationImage ci) {
if (options == null) {
// we are here for non-enum types
return niceToString(getValue(ci));
}
if (type != INT8)