XML tune export progress
This commit is contained in:
parent
db62eb21d3
commit
91ce61ab3e
|
@ -1,6 +1,6 @@
|
|||
package com.opensr5.ini;
|
||||
|
||||
import com.opensr5.ini.field.BitIniField;
|
||||
import com.opensr5.ini.field.EnumIniField;
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.opensr5.ini.field.ScalarIniField;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -143,7 +143,7 @@ public class IniFileModel {
|
|||
} else if (list.get(1).equals(FIELD_TYPE_STRING)) {
|
||||
} else if (list.get(1).equals(FIELD_TYPE_ARRAY)) {
|
||||
} else if (list.get(1).equals(FIELD_TYPE_BITS)) {
|
||||
BitIniField field = BitIniField.parse(list);
|
||||
EnumIniField field = EnumIniField.parse(list);
|
||||
registerField(field);
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected " + list);
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package com.opensr5.ini.field;
|
||||
|
||||
import com.rusefi.config.FieldType;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class BitIniField extends IniField {
|
||||
private final FieldType type;
|
||||
private final List<String> enums;
|
||||
|
||||
public BitIniField(String name, int offset, FieldType type, List<String> enums) {
|
||||
super(name, offset);
|
||||
this.type = type;
|
||||
this.enums = enums;
|
||||
}
|
||||
|
||||
public FieldType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public List<String> getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
public static BitIniField parse(LinkedList<String> list) {
|
||||
String name = list.get(0);
|
||||
FieldType type = FieldType.parseTs(list.get(2));
|
||||
int offset = Integer.parseInt(list.get(3));
|
||||
|
||||
List<String> enums = list.subList(5, list.size() - 1);
|
||||
|
||||
return new BitIniField(name, offset, type, enums);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
package com.opensr5.ini.field;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.config.FieldType;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnumIniField extends IniField {
|
||||
private final FieldType type;
|
||||
private final List<String> enums;
|
||||
private final int bitPosition;
|
||||
private final int bitSize;
|
||||
|
||||
public EnumIniField(String name, int offset, FieldType type, List<String> enums, int bitPosition, int bitSize) {
|
||||
super(name, offset);
|
||||
this.type = type;
|
||||
this.enums = enums;
|
||||
this.bitPosition = bitPosition;
|
||||
this.bitSize = bitSize;
|
||||
}
|
||||
|
||||
public int getBitPosition() {
|
||||
return bitPosition;
|
||||
}
|
||||
|
||||
public int getBitSize() {
|
||||
return bitSize;
|
||||
}
|
||||
|
||||
public List<String> getEnums() {
|
||||
return enums;
|
||||
}
|
||||
|
||||
public FieldType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(ConfigurationImage image) {
|
||||
int ordinal = image.getByteBuffer(getOffset(), type.getStorageSize()).get();
|
||||
ordinal = getBitRange(ordinal, bitPosition, bitSize);
|
||||
|
||||
if (ordinal >= enums.size())
|
||||
throw new IllegalStateException(ordinal + " in " + getName());
|
||||
return enums.get(ordinal);
|
||||
}
|
||||
|
||||
public static int getBitRange(int ordinal, int bitPosition, int bitSize) {
|
||||
ordinal = ordinal >> bitPosition;
|
||||
ordinal = ordinal & (1 << bitSize);
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
public static EnumIniField parse(LinkedList<String> list) {
|
||||
String name = list.get(0);
|
||||
FieldType type = FieldType.parseTs(list.get(2));
|
||||
int offset = Integer.parseInt(list.get(3));
|
||||
|
||||
String bitRange = list.get(4);
|
||||
bitRange = bitRange.replaceAll("[\\]\\[:]", " ").trim();
|
||||
String bitPositions[] = bitRange.split(" ");
|
||||
if (bitPositions.length != 2)
|
||||
throw new IllegalStateException("Bit position " + bitRange);
|
||||
int bitPosition = Integer.parseInt(bitPositions[0]);
|
||||
int bitSize = Integer.parseInt(bitPositions[1]) - bitPosition;
|
||||
|
||||
List<String> enums = list.subList(5, list.size());
|
||||
|
||||
return new EnumIniField(name, offset, type, enums, bitPosition, bitSize);
|
||||
}
|
||||
}
|
|
@ -28,7 +28,11 @@ public class ScalarIniField extends IniField {
|
|||
@Override
|
||||
public String getValue(ConfigurationImage image) {
|
||||
Field f = new Field(getName(), getOffset(), getType());
|
||||
return f.getValue(image).toString();
|
||||
try {
|
||||
return f.getValue(image).toString();
|
||||
} catch (Throwable e) {
|
||||
throw new IllegalStateException("While getting " + getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ScalarIniField parse(LinkedList<String> list) {
|
||||
|
|
|
@ -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.EnumIniField;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -99,6 +100,29 @@ public class IniFileReaderTest {
|
|||
assertEquals(2, model.allIniFields.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitLogic() {
|
||||
assertEquals(1, EnumIniField.getBitRange(0xff, 0, 0));
|
||||
|
||||
assertEquals(1, EnumIniField.getBitRange(0xf0, 4, 0));
|
||||
assertEquals(2, EnumIniField.getBitRange(0xf0, 3, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBitField() {
|
||||
String string = "page = 1\n" +
|
||||
"\tname\t= bits, U32, \t744, [3:5], \"false\", \"true\"";
|
||||
|
||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||
|
||||
assertEquals(1, model.allIniFields.size());
|
||||
|
||||
EnumIniField field = (EnumIniField) model.allIniFields.get("name");
|
||||
assertEquals(3, field.getBitPosition());
|
||||
assertEquals(2, field.getBitSize());
|
||||
assertEquals(2, field.getEnums().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurveField() {
|
||||
|
|
|
@ -148,9 +148,11 @@ public class Field {
|
|||
if (bitOffset != NO_BIT_OFFSET) {
|
||||
int packed = wrapped.getInt();
|
||||
value = (packed >> bitOffset) & 1;
|
||||
} else if (type == INT8 || type == UINT8) {
|
||||
value = wrapped.get();
|
||||
} else if (type == INT) {
|
||||
value = wrapped.getInt();
|
||||
} else if (type == INT16) {
|
||||
} else if (type == INT16 || type == UINT16) {
|
||||
value = wrapped.getShort();
|
||||
} else {
|
||||
value = wrapped.getFloat();
|
||||
|
|
|
@ -214,18 +214,18 @@ public class ConsoleTools {
|
|||
|
||||
IniFileModel ini = IniFileModel.getInstance(Launcher.INI_FILE_PATH);
|
||||
|
||||
handle(tune, ini, "tpsMin", image);
|
||||
handle(tune, ini, "tpsMax", image);
|
||||
handle(tune, ini, "primingSquirtDurationMs", image);
|
||||
for (String key : ini.allIniFields.keySet())
|
||||
handle(tune, ini, key, image);
|
||||
|
||||
// handle(tune, ini, "injector_battLagCorrBins");
|
||||
|
||||
|
||||
XmlUtil.writeXml(tune, Msq.class, "a.xml");
|
||||
XmlUtil.writeXml(tune, Msq.class, "a.msq");
|
||||
}
|
||||
|
||||
private static void handle(Msq tune, IniFileModel ini, String key, ConfigurationImage image) {
|
||||
IniField field = ini.allIniFields.get(key);
|
||||
tune.getPage().constants.add(prepareConstant(field, image));
|
||||
tune.getPage().constant.add(prepareConstant(field, image));
|
||||
}
|
||||
|
||||
private static Constant prepareConstant(IniField field, ConfigurationImage image) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class Page {
|
||||
public final List<Constant> constants = new ArrayList<>();
|
||||
public final List<Constant> constant = new ArrayList<>();
|
||||
|
||||
@XmlAttribute
|
||||
public int getNumber() {
|
||||
|
|
Loading…
Reference in New Issue