REO progress

This commit is contained in:
rusefi 2020-06-14 00:01:34 -04:00
parent 4d82103f77
commit 63bf2ed595
2 changed files with 32 additions and 11 deletions

View File

@ -12,12 +12,14 @@ public class ArrayIniField extends IniField {
private final FieldType type;
private final int cols;
private final int rows;
private final double multiplier;
public ArrayIniField(String name, int offset, FieldType type, int cols, int rows) {
public ArrayIniField(String name, int offset, FieldType type, int cols, int rows, String unit, double multiplier) {
super(name, offset);
this.type = type;
this.cols = cols;
this.rows = rows;
this.multiplier = multiplier;
}
public FieldType getType() {
@ -66,7 +68,7 @@ public class ArrayIniField extends IniField {
for (int colIndex = 0; colIndex < cols; colIndex++) {
String value = values[rowIndex * cols + colIndex];
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, multiplier);
}
}
}
@ -87,6 +89,9 @@ public class ArrayIniField extends IniField {
FieldType type = FieldType.parseTs(list.get(2));
int offset = Integer.parseInt(list.get(3));
String size = list.get(4);
String unit = list.get(5);
double multiplier = Double.parseDouble(list.get(6));
size = size.replaceAll("[\\]\\[x]", " ").trim();
String dimentions[] = size.split(" ");
int cols;
@ -101,6 +106,6 @@ public class ArrayIniField extends IniField {
throw new IllegalStateException("Unexpected " + size);
}
return new ArrayIniField(name, offset, type, cols, rows);
return new ArrayIniField(name, offset, type, cols, rows, unit, multiplier);
}
}

View File

@ -13,11 +13,15 @@ import static com.rusefi.config.FieldType.*;
public class ScalarIniField extends IniField {
private final String unit;
private final FieldType type;
private final double multiplier;
public ScalarIniField(String name, int offset, String unit, FieldType type) {
public ScalarIniField(String name, int offset, String unit, FieldType type, double multiplier) {
super(name, offset);
this.unit = unit;
this.type = type;
if (multiplier == 0)
throw new IllegalArgumentException("Multiplier should not be zero");
this.multiplier = multiplier;
}
@Override
@ -48,32 +52,44 @@ 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());
setValue(wrapped, type, constant.getValue(), f.getBitOffset());
setValue(wrapped, type, constant.getValue(), f.getBitOffset(), multiplier);
}
public static void setValue(ByteBuffer wrapped, FieldType type, String value, int bitOffset) {
public static void setValue(ByteBuffer wrapped, FieldType type, String value, int bitOffset, double multiplier) {
double v = Double.parseDouble(value) / multiplier;
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(value));
wrapped.put((byte) v);
} else if (type == INT) {
wrapped.putInt((int) Double.parseDouble(value));
wrapped.putInt((int) v);
} else if (type == INT16 || type == UINT16) {
wrapped.putShort((short) Double.parseDouble(value));
wrapped.putShort((short) v);
} else {
wrapped.putFloat(Float.parseFloat(value));
wrapped.putFloat((float) v);
}
}
@Override
public String toString() {
return "ScalarIniField{" +
"name=" + getName() +
", offset=" + getOffset() +
", unit='" + unit + '\'' +
", type=" + type +
'}';
}
public static ScalarIniField parse(LinkedList<String> list) {
String name = list.get(0);
FieldType type = FieldType.parseTs(list.get(2));
int offset = Integer.parseInt(list.get(3));
String unit = list.get(4);
double multiplier = Double.parseDouble(list.get(5));
return new ScalarIniField(name, offset, unit, type);
return new ScalarIniField(name, offset, unit, type, multiplier);
}
}