XML tune export progress

This commit is contained in:
rusefi 2020-05-17 01:25:05 -04:00
parent 91ce61ab3e
commit b5b2f7178f
3 changed files with 63 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.opensr5.ini;
import com.opensr5.ini.field.ArrayIniField;
import com.opensr5.ini.field.EnumIniField;
import com.opensr5.ini.field.IniField;
import com.opensr5.ini.field.ScalarIniField;
@ -138,17 +139,15 @@ public class IniFileModel {
private void handleFieldDefinition(LinkedList<String> list) {
if (list.get(1).equals(FIELD_TYPE_SCALAR)) {
ScalarIniField field = ScalarIniField.parse(list);
registerField(field);
registerField(ScalarIniField.parse(list));
} else if (list.get(1).equals(FIELD_TYPE_STRING)) {
} else if (list.get(1).equals(FIELD_TYPE_ARRAY)) {
registerField(ArrayIniField.parse(list));
} else if (list.get(1).equals(FIELD_TYPE_BITS)) {
EnumIniField field = EnumIniField.parse(list);
registerField(field);
registerField(EnumIniField.parse(list));
} else {
throw new IllegalStateException("Unexpected " + list);
}
}
private void registerField(IniField field) {

View File

@ -0,0 +1,52 @@
package com.opensr5.ini.field;
import com.rusefi.config.FieldType;
import java.util.LinkedList;
public class ArrayIniField extends IniField {
private final FieldType type;
private final int cols;
private final int rows;
public ArrayIniField(String name, int offset, FieldType type, int cols, int rows) {
super(name, offset);
this.type = type;
this.cols = cols;
this.rows = rows;
}
public FieldType getType() {
return type;
}
public int getCols() {
return cols;
}
public int getRows() {
return rows;
}
public static IniField parse(LinkedList<String> list) {
String name = list.get(0);
FieldType type = FieldType.parseTs(list.get(2));
int offset = Integer.parseInt(list.get(3));
String size = list.get(4);
size = size.replaceAll("[\\]\\[x]", " ").trim();
String dimentions[] = size.split(" ");
int cols;
int rows;
if (dimentions.length == 1) {
cols = 1;
rows = Integer.parseInt(dimentions[0]);
} else if (dimentions.length == 2) {
cols = Integer.parseInt(dimentions[0]);
rows = Integer.parseInt(dimentions[1]);
} else {
throw new IllegalStateException("Unexpected " + size);
}
return new ArrayIniField(name, offset, type, cols, rows);
}
}

View File

@ -4,6 +4,7 @@ import com.opensr5.ini.IniFileMetaInfo;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.IniFileReader;
import com.opensr5.ini.RawIniFile;
import com.opensr5.ini.field.ArrayIniField;
import com.opensr5.ini.field.EnumIniField;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
@ -126,12 +127,15 @@ public class IniFileReaderTest {
@Test
public void testCurveField() {
String string =
" \tmap_samplingAngleBins\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
String string = "page = 1\n" +
" \tname\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
IniFileModel model = new IniFileModel().readIniFile(lines);
assertEquals(0, model.getAllFields().size());
assertEquals(1, model.allIniFields.size());
ArrayIniField field = (ArrayIniField) model.allIniFields.get("name");
assertEquals(1, field.getCols());
assertEquals(8, field.getRows());
}
}