diff --git a/java_console/inifile/src/com/opensr5/ini/field/ArrayIniField.java b/java_console/inifile/src/com/opensr5/ini/field/ArrayIniField.java index 95237da29c..132fe65dec 100644 --- a/java_console/inifile/src/com/opensr5/ini/field/ArrayIniField.java +++ b/java_console/inifile/src/com/opensr5/ini/field/ArrayIniField.java @@ -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 list) { String name = list.get(0); FieldType type = FieldType.parseTs(list.get(2)); diff --git a/java_console/inifile/src/com/opensr5/ini/field/ScalarIniField.java b/java_console/inifile/src/com/opensr5/ini/field/ScalarIniField.java index 90e7d36431..4e65586e9d 100644 --- a/java_console/inifile/src/com/opensr5/ini/field/ScalarIniField.java +++ b/java_console/inifile/src/com/opensr5/ini/field/ScalarIniField.java @@ -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 list) { diff --git a/java_console/inifile/src/com/rusefi/config/Field.java b/java_console/inifile/src/com/rusefi/config/Field.java index 115f34398a..5131e58974 100644 --- a/java_console/inifile/src/com/rusefi/config/Field.java +++ b/java_console/inifile/src/com/rusefi/config/Field.java @@ -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)