REO progress
This commit is contained in:
parent
4c86d84e0f
commit
b5a637c939
|
@ -2,7 +2,9 @@ package com.opensr5.ini.field;
|
|||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.config.FieldType;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -46,13 +48,26 @@ public class EnumIniField extends IniField {
|
|||
return enums.get(ordinal);
|
||||
}
|
||||
|
||||
private static boolean isQuoted(String q) {
|
||||
final int len = q.length();
|
||||
return (len >= 2 && q.charAt(0) == '"' && q.charAt(len - 1) == '"');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(ConfigurationImage image, Constant constant) {
|
||||
String v = constant.getValue();
|
||||
int ordinal = enums.indexOf(isQuoted(v) ? ObjectName.unquote(v) : v);
|
||||
if (ordinal == -1)
|
||||
throw new IllegalArgumentException("Not found " + v);
|
||||
}
|
||||
|
||||
public static boolean getBit(int ordinal, int bitPosition) {
|
||||
return getBitRange(ordinal, bitPosition, 0) == 1;
|
||||
}
|
||||
|
||||
public static int getBitRange(int ordinal, int bitPosition, int bitSize) {
|
||||
ordinal = ordinal >> bitPosition;
|
||||
ordinal = ordinal & ((1 << (bitSize + 1)) - 1);
|
||||
ordinal = ordinal & ((1 << (bitSize + 1)) - 1);
|
||||
return ordinal;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.opensr5.ini.field;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
|
||||
public class IniField {
|
||||
private final String name;
|
||||
|
@ -26,4 +27,8 @@ public class IniField {
|
|||
public String getValue(ConfigurationImage image) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValue(ConfigurationImage image, Constant constant) {
|
||||
// throw new UnsupportedOperationException("On " + getClass());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,4 +33,13 @@ public class XmlUtil {
|
|||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
return (T) jaxbUnmarshaller.unmarshal(xmlFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://stackoverflow.com/questions/25644023/error-unmarshalling-xml-in-java-8-secure-processing-org-xml-sax-saxnotrecognize
|
||||
*/
|
||||
public static void setParserImpl() {
|
||||
System.setProperty("org.xml.sax.driver", "com.sun.org.apache.xerces.internal.parsers.SAXParser");
|
||||
System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
|
||||
System.setProperty("javax.xml.parsers.SAXParserFactory","com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.rusefi.ui;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.opensr5.io.ConfigurationImageFile;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import com.rusefi.xml.XmlUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* from IDEA this unit test needs to be exectuted with "empty" working directory
|
||||
|
@ -16,13 +20,30 @@ public class TuneReadWriteTest {
|
|||
|
||||
@Test
|
||||
public void testReadTsTune() throws Exception {
|
||||
XmlUtil.setParserImpl();
|
||||
|
||||
IniFileModel.getInstance().readIniFile(PATH + "mainController.ini");
|
||||
// Msq tsTune = XmlUtil.readModel(Msq.class, PATH + "CurrentTune.msq");
|
||||
// System.out.println(tsTune);
|
||||
Msq tsTune = XmlUtil.readModel(Msq.class, PATH + "CurrentTune.msq");
|
||||
System.out.println(tsTune);
|
||||
|
||||
makeBinaryTune(tsTune, IniFileModel.getInstance());
|
||||
|
||||
|
||||
String binary = PATH + "current_configuration.rusefi_binary";
|
||||
System.out.println("Reading " + binary);
|
||||
ConfigurationImageFile.readFromFile(binary);
|
||||
}
|
||||
|
||||
private void makeBinaryTune(Msq tsTune, IniFileModel instance) {
|
||||
ConfigurationImage ci = new ConfigurationImage(Fields.TOTAL_CONFIG_SIZE);
|
||||
|
||||
for (Constant constant : tsTune.getPage().constant) {
|
||||
if (constant.getName().startsWith("UNALLOCATED_SPACE")) {
|
||||
continue;
|
||||
}
|
||||
IniField field = instance.allIniFields.get(constant.getName());
|
||||
Objects.requireNonNull(field, "Field for " + constant.getName());
|
||||
field.setValue(ci, constant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue