only:EPIC: Improve toolset for default tune canned tune generation #4871
This commit is contained in:
parent
be06316e80
commit
8c2ba87915
|
@ -219,17 +219,24 @@ public class IniFileModel {
|
||||||
private void handleYBins(LinkedList<String> list) {
|
private void handleYBins(LinkedList<String> list) {
|
||||||
list.removeFirst();
|
list.removeFirst();
|
||||||
currentYBins = list.removeFirst();
|
currentYBins = list.removeFirst();
|
||||||
|
addField(currentYBins);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleXBins(LinkedList<String> list) {
|
private void handleXBins(LinkedList<String> list) {
|
||||||
list.removeFirst();
|
list.removeFirst();
|
||||||
currentXBins = list.removeFirst();
|
currentXBins = list.removeFirst();
|
||||||
DialogModel.Field field = new DialogModel.Field(currentXBins, currentXBins);
|
addField(currentXBins);
|
||||||
fieldsInUiOrder.put(currentXBins, field);
|
}
|
||||||
|
|
||||||
|
private void addField(String key) {
|
||||||
|
DialogModel.Field field = new DialogModel.Field(key, key);
|
||||||
|
fieldsInUiOrder.put(key, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTable(LinkedList<String> list) {
|
private void handleTable(LinkedList<String> list) {
|
||||||
list.removeFirst();
|
list.removeFirst();
|
||||||
|
String tableName = list.removeFirst();
|
||||||
|
addField(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleFieldDefinition(LinkedList<String> list, RawIniFile.Line line) {
|
private void handleFieldDefinition(LinkedList<String> list, RawIniFile.Line line) {
|
||||||
|
|
|
@ -126,9 +126,27 @@ public class IniFileReaderTest {
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = new IniFileModel().readIniFile(lines);
|
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||||
assertEquals(2, model.allIniFields.size());
|
assertEquals(2, model.allIniFields.size());
|
||||||
assertEquals(1, model.fieldsInUiOrder.size());
|
assertEquals(2, model.fieldsInUiOrder.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTable() {
|
||||||
|
String string = "page = 1\n" +
|
||||||
|
"[Constants]\n" +
|
||||||
|
"tpsTpsAccelTable = array, F32, 19744, [8x8], \"value\", 1, 0, 0, 30000, 2\n" +
|
||||||
|
"tpsTpsAccelFromRpmBins = array, F32, 20000, [8], \"from\", 1, 0, 0, 30000, 2\n" +
|
||||||
|
"tpsTpsAccelToRpmBins = array, F32, 20032, [8], \"to\", 1, 0, 0, 25500, 2\n\n " +
|
||||||
|
"[TableEditor]\n" +
|
||||||
|
"\ttable = tpsTpsAccelTbl, tpsTpsAccelMap, \"TPS/TPS Acceleration Extra Fuel(ms)\",\t1\n" +
|
||||||
|
"\ttopicHelp = \"tpstpsHelp\"\n" +
|
||||||
|
"\t\txBins\t\t= tpsTpsAccelFromRpmBins, TPSValue\n" +
|
||||||
|
"\t\tyBins\t\t= tpsTpsAccelToRpmBins, TPSValue\n" +
|
||||||
|
"\t\tzBins\t\t= tpsTpsAccelTable";
|
||||||
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
|
IniFileModel model = new IniFileModel().readIniFile(lines);
|
||||||
|
assertEquals(3, model.allIniFields.size());
|
||||||
|
assertEquals(3, model.fieldsInUiOrder.size());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConditional() {
|
public void testConditional() {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.rusefi.tools.tune;
|
||||||
|
|
||||||
import com.opensr5.ini.IniFileModel;
|
import com.opensr5.ini.IniFileModel;
|
||||||
import com.opensr5.ini.field.ArrayIniField;
|
import com.opensr5.ini.field.ArrayIniField;
|
||||||
|
import com.opensr5.ini.field.IniField;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -37,7 +38,10 @@ public class CurveData {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static CurveData valueOf(String msqFileName, String curveName, IniFileModel model) throws IOException {
|
public static CurveData valueOf(String msqFileName, String curveName, IniFileModel model) throws IOException {
|
||||||
ArrayIniField field = (ArrayIniField) model.allIniFields.get(curveName);
|
IniField iniField = model.allIniFields.get(curveName);
|
||||||
|
if (!(iniField instanceof ArrayIniField))
|
||||||
|
return null;
|
||||||
|
ArrayIniField field = (ArrayIniField) iniField;
|
||||||
int curveSize = field.getRows();
|
int curveSize = field.getRows();
|
||||||
BufferedReader r = TS2C.readAndScroll(msqFileName, curveName + "\"");
|
BufferedReader r = TS2C.readAndScroll(msqFileName, curveName + "\"");
|
||||||
float[] curveValues = new float[curveSize];
|
float[] curveValues = new float[curveSize];
|
||||||
|
@ -93,9 +97,18 @@ public class CurveData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCsourceMethod(String reference) {
|
public String getCsourceMethod(String reference) {
|
||||||
return "static void canned" + curveName + "() {\n"
|
return "static void " + getCannedMethod() + " {\n"
|
||||||
+ "\t" + getCsourceCode() +
|
+ "\t" + getCsourceCode() +
|
||||||
"\tcopyArray(" + reference + curveName + ", " + getCannedName() + ");\n" +
|
"\tcopyArray(" + reference + curveName + ", " + getCannedName() + ");\n" +
|
||||||
"}\n\n";
|
"}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String getCannedMethod() {
|
||||||
|
return "canned" + curveName + "()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCinvokeMethod() {
|
||||||
|
return "\t" + getCannedMethod() + ";\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,13 @@ import com.devexperts.logging.Logging;
|
||||||
import com.opensr5.ini.DialogModel;
|
import com.opensr5.ini.DialogModel;
|
||||||
import com.opensr5.ini.IniFileModel;
|
import com.opensr5.ini.IniFileModel;
|
||||||
import com.rusefi.*;
|
import com.rusefi.*;
|
||||||
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.core.preferences.storage.Node;
|
import com.rusefi.core.preferences.storage.Node;
|
||||||
import com.rusefi.output.ConfigStructure;
|
import com.rusefi.output.ConfigStructure;
|
||||||
import com.rusefi.tune.xml.Constant;
|
import com.rusefi.tune.xml.Constant;
|
||||||
import com.rusefi.tune.xml.Msq;
|
import com.rusefi.tune.xml.Msq;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -37,29 +39,32 @@ public class TuneCanTool {
|
||||||
public static final String DEFAULT_TUNE = SIMULATED_PREFIX + SIMULATED_SUFFIX;
|
public static final String DEFAULT_TUNE = SIMULATED_PREFIX + SIMULATED_SUFFIX;
|
||||||
private static final String workingFolder = "downloaded_tunes";
|
private static final String workingFolder = "downloaded_tunes";
|
||||||
|
|
||||||
private static Msq simulatorDefaultTune;
|
|
||||||
private static IniFileModel ini;
|
private static IniFileModel ini;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
simulatorDefaultTune = Msq.readTune(TuneCanTool.DEFAULT_TUNE);
|
|
||||||
ini = new IniFileModel().readIniFile(INI_FILE_FOR_SIMULATOR);
|
ini = new IniFileModel().readIniFile(INI_FILE_FOR_SIMULATOR);
|
||||||
if (ini == null)
|
if (ini == null)
|
||||||
throw new IllegalStateException("Not found " + INI_FILE_FOR_SIMULATOR);
|
throw new IllegalStateException("Not found " + INI_FILE_FOR_SIMULATOR);
|
||||||
|
|
||||||
RootHolder.ROOT = "../firmware/";
|
RootHolder.ROOT = "../firmware/";
|
||||||
|
|
||||||
// handle("BK2", 1507, simulatorDefaultTune);
|
process(1507, Fields.engine_type_e_HELLEN_154_HYUNDAI_COUPE_BK2, "BK2");
|
||||||
handle("BK2-diff", 1507, Msq.readTune(SIMULATED_PREFIX + "_95" + SIMULATED_SUFFIX));
|
// process(1502, Fields.engine_type_e_HYUNDAI_PB, "PB");
|
||||||
// handle("PB", 1502);
|
// process(1490, Fields.engine_type_e_MRE_M111, "m111-alex");
|
||||||
// handle("Mitsubicha", 1258);
|
// handle("Mitsubicha", 1258);
|
||||||
// handle("Scion-1NZ-FE", 1448);
|
// handle("Scion-1NZ-FE", 1448);
|
||||||
// handle("4g93", 1425);
|
// handle("4g93", 1425);
|
||||||
// handle("BMW-mtmotorsport", 1479);
|
// handle("BMW-mtmotorsport", 1479);
|
||||||
// handle("m111-alex", 1490);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handle(String vehicleName, int tuneId, Msq currentTune) throws JAXBException, IOException {
|
private static void process(int tuneId, int engineType, String key) throws JAXBException, IOException {
|
||||||
|
handle(key, tuneId, TuneCanTool.DEFAULT_TUNE);
|
||||||
|
handle(key + "-diff", tuneId, SIMULATED_PREFIX + "_" + engineType + SIMULATED_SUFFIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handle(String vehicleName, int tuneId, String currentTuneFileName) throws JAXBException, IOException {
|
||||||
|
Msq currentTune = Msq.readTune(currentTuneFileName);
|
||||||
String localFileName = workingFolder + File.separator + tuneId + ".msq";
|
String localFileName = workingFolder + File.separator + tuneId + ".msq";
|
||||||
String url = "https://rusefi.com/online/view.php?msq=" + tuneId;
|
String url = "https://rusefi.com/online/view.php?msq=" + tuneId;
|
||||||
|
|
||||||
|
@ -69,19 +74,27 @@ public class TuneCanTool {
|
||||||
new File(reportsOutputFolder).mkdir();
|
new File(reportsOutputFolder).mkdir();
|
||||||
|
|
||||||
Msq custom = Msq.readTune(localFileName);
|
Msq custom = Msq.readTune(localFileName);
|
||||||
StringBuilder sb = TuneCanTool.getTunePatch(currentTune, custom, ini);
|
|
||||||
|
StringBuilder methods = new StringBuilder();
|
||||||
|
|
||||||
|
StringBuilder sb = TuneCanTool.getTunePatch(currentTune, custom, ini, currentTuneFileName, methods);
|
||||||
|
|
||||||
|
String fileNameMethods = reportsOutputFolder + "/" + vehicleName + "_methods.md";
|
||||||
|
try (FileWriter methodsWriter = new FileWriter(fileNameMethods)) {
|
||||||
|
methodsWriter.append(methods);
|
||||||
|
}
|
||||||
|
|
||||||
String fileName = reportsOutputFolder + "/" + vehicleName + ".md";
|
String fileName = reportsOutputFolder + "/" + vehicleName + ".md";
|
||||||
log.info("Writing to " + fileName);
|
log.info("Writing to " + fileName);
|
||||||
|
|
||||||
FileWriter w = new FileWriter(fileName);
|
try (FileWriter w = new FileWriter(fileName)) {
|
||||||
w.append("# " + vehicleName + "\n\n");
|
w.append("# " + vehicleName + "\n\n");
|
||||||
w.append("// canned tune " + url + "\n\n");
|
w.append("// canned tune " + url + "\n\n");
|
||||||
|
|
||||||
w.append("```\n");
|
w.append("```\n");
|
||||||
w.append(sb);
|
w.append(sb);
|
||||||
w.append("```\n");
|
w.append("```\n");
|
||||||
w.close();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void downloadTune(int tuneId, String localFileName) throws IOException {
|
private static void downloadTune(int tuneId, String localFileName) throws IOException {
|
||||||
|
@ -112,10 +125,12 @@ public class TuneCanTool {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static StringBuilder getTunePatch(Msq defaultTune, Msq customTune, IniFileModel ini) throws IOException {
|
public static StringBuilder getTunePatch(Msq defaultTune, Msq customTune, IniFileModel ini, String currentTuneFileName, StringBuilder methods) throws IOException {
|
||||||
List<String> options = Files.readAllLines(Paths.get(RootHolder.ROOT + "../" + ConfigDefinition.CONFIG_PATH));
|
List<String> options = Files.readAllLines(Paths.get(RootHolder.ROOT + "../" + ConfigDefinition.CONFIG_PATH));
|
||||||
String[] totalArgs = options.toArray(new String[0]);
|
String[] totalArgs = options.toArray(new String[0]);
|
||||||
|
|
||||||
|
StringBuilder invokeMethods = new StringBuilder();
|
||||||
|
|
||||||
ReaderStateImpl state = new ReaderStateImpl();
|
ReaderStateImpl state = new ReaderStateImpl();
|
||||||
ConfigDefinition.doJob(totalArgs, state);
|
ConfigDefinition.doJob(totalArgs, state);
|
||||||
|
|
||||||
|
@ -130,7 +145,7 @@ public class TuneCanTool {
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(defaultValue.getValue(), "d value");
|
Objects.requireNonNull(defaultValue.getValue(), "d value");
|
||||||
if (customValue == null) {
|
if (customValue == null) {
|
||||||
log.info("Skipping " + name + " TODO");
|
log.info("Skipping " + name + " not present in tune");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Objects.requireNonNull(customValue.getValue(), "c value");
|
Objects.requireNonNull(customValue.getValue(), "c value");
|
||||||
|
@ -148,7 +163,19 @@ public class TuneCanTool {
|
||||||
String cName = context + cf.getOriginalArrayName();
|
String cName = context + cf.getOriginalArrayName();
|
||||||
|
|
||||||
if (cf.getType().equals("boolean")) {
|
if (cf.getType().equals("boolean")) {
|
||||||
sb.append(TuneTools.getAssignmentCode(defaultValue, customValue.getName(), unquote(customValue.getValue())));
|
sb.append(TuneTools.getAssignmentCode(defaultValue, cName, unquote(customValue.getValue())));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cf.isArray()) {
|
||||||
|
|
||||||
|
CurveData data = CurveData.valueOf(currentTuneFileName, name, ini);
|
||||||
|
if (data == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
methods.append(data.getCsourceMethod("engineConfiguration"));
|
||||||
|
invokeMethods.append(data.getCinvokeMethod());
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,15 +219,22 @@ public class TuneCanTool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sb.append("\n\n").append(invokeMethods);
|
||||||
|
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigField findField(ReaderStateImpl state, String name, StringBuffer context) {
|
private static ConfigField findField(ReaderStateImpl state, String name, StringBuffer context) {
|
||||||
|
return doLook(state, name, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static ConfigField doLook(ReaderStateImpl state, String name, StringBuffer context) {
|
||||||
ConfigStructure s = state.getStructures().get("engine_configuration_s");
|
ConfigStructure s = state.getStructures().get("engine_configuration_s");
|
||||||
// log.info("We have a custom value " + name);
|
// log.info("We have a custom value " + name);
|
||||||
ConfigField cf = s.getTsFieldByName(name);
|
ConfigField cf = s.getTsFieldByName(name);
|
||||||
if (cf != null) {
|
if (cf != null) {
|
||||||
return cf; // it was easy!
|
return cf;
|
||||||
}
|
}
|
||||||
int fromIndex = 0;
|
int fromIndex = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -211,11 +245,14 @@ public class TuneCanTool {
|
||||||
}
|
}
|
||||||
String parentName = name.substring(0, fromIndex);
|
String parentName = name.substring(0, fromIndex);
|
||||||
cf = s.getTsFieldByName(parentName);
|
cf = s.getTsFieldByName(parentName);
|
||||||
|
fromIndex++; // skip underscore
|
||||||
|
if (cf == null)
|
||||||
|
continue;
|
||||||
String type = cf.getType();
|
String type = cf.getType();
|
||||||
s = state.getStructures().get(type);
|
s = state.getStructures().get(type);
|
||||||
|
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
String substring = name.substring(fromIndex + 1);
|
String substring = name.substring(fromIndex);
|
||||||
ConfigField tsFieldByName = s.getTsFieldByName(substring);
|
ConfigField tsFieldByName = s.getTsFieldByName(substring);
|
||||||
if (tsFieldByName == null) {
|
if (tsFieldByName == null) {
|
||||||
log.info("Not located " + substring + " in " + s);
|
log.info("Not located " + substring + " in " + s);
|
||||||
|
@ -225,7 +262,6 @@ public class TuneCanTool {
|
||||||
}
|
}
|
||||||
return tsFieldByName;
|
return tsFieldByName;
|
||||||
}
|
}
|
||||||
fromIndex++; // skip underscore
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class LoadOlderTuneTest {
|
||||||
|
|
||||||
RootHolder.ROOT = "../../firmware/";
|
RootHolder.ROOT = "../../firmware/";
|
||||||
|
|
||||||
StringBuilder sb = TuneCanTool.getTunePatch(lessOldDefaultTune, customOldTune, ini);
|
StringBuilder sb = TuneCanTool.getTunePatch(lessOldDefaultTune, customOldTune, ini, TuneReadWriteTest.TUNE_NAME, new StringBuilder());
|
||||||
|
|
||||||
assertEquals(" // default \"Single Coil\"\n" +
|
assertEquals(" // default \"Single Coil\"\n" +
|
||||||
" engineConfiguration->ignitionMode = IM_ONE_COIL;\n" +
|
" engineConfiguration->ignitionMode = IM_ONE_COIL;\n" +
|
||||||
|
|
Loading…
Reference in New Issue