diff --git a/firmware/config/engines/mazda_miata_1_6.cpp b/firmware/config/engines/mazda_miata_1_6.cpp index b341e14a1c..8fa8f4e551 100644 --- a/firmware/config/engines/mazda_miata_1_6.cpp +++ b/firmware/config/engines/mazda_miata_1_6.cpp @@ -19,10 +19,6 @@ EXTERN_CONFIG; -// todo: -// extern const float ve16RpmBins[FUEL_RPM_COUNT]; - - static const float ve16RpmBins[FUEL_RPM_COUNT] = { 650.0,1100.0,1550.0,2000.0, 2450.0,2900.0,3350.0,3800.0, diff --git a/java_console/.gitignore b/java_console/.gitignore index a909b99a5a..b4bc2f58fd 100644 --- a/java_console/.gitignore +++ b/java_console/.gitignore @@ -2,7 +2,7 @@ autoupdate_build rusefi_autoupdate.jar logs/ rusefi_console_properties.xml -output.c +generated*.cpp currenttune.msq output.msq rusefi.ini diff --git a/java_console/.idea/runConfigurations/TS2CRunner.xml b/java_console/.idea/runConfigurations/TS2CRunner.xml new file mode 100644 index 0000000000..51ee590e21 --- /dev/null +++ b/java_console/.idea/runConfigurations/TS2CRunner.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java index b256ac0362..c52ca7c8e4 100644 --- a/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java +++ b/java_console/inifile/src/main/java/com/opensr5/ini/IniFileModel.java @@ -227,11 +227,6 @@ public class IniFileModel { return null; } - enum State { - SKIPPING, - DIALOG - } - public static synchronized IniFileModel getInstance() { if (INSTANCE == null) { INSTANCE = new IniFileModel(); diff --git a/java_console/models/src/main/java/com/rusefi/TS2C.java b/java_console/models/src/main/java/com/rusefi/TS2C.java index adc139bc31..a1db88d286 100644 --- a/java_console/models/src/main/java/com/rusefi/TS2C.java +++ b/java_console/models/src/main/java/com/rusefi/TS2C.java @@ -1,12 +1,15 @@ package com.rusefi; +import com.opensr5.ini.IniFileModel; +import com.opensr5.ini.field.ArrayIniField; + import java.io.*; import java.util.Arrays; import java.util.Date; /** * tuner studio project to C data structure converter command line utility - * + *

* 12/27/2014 * Andrey Belomutskiy, (c) 2012-2016 */ @@ -15,13 +18,12 @@ public class TS2C { // todo: replace with loadCount & rpmCount private final int size; - private int rpmCount; - private int loadCount; - - private float loadBins[]; - private float rpmBins[]; - private float table[][]; + private float[] loadBins; + private float[] rpmBins; + /** + * @see TS2CRunner + */ public static void main(String[] args) throws IOException { new TS2C(args); } @@ -42,46 +44,57 @@ public class TS2C { String tableName = args[3]; size = Integer.parseInt(args.length > 4 ? args[4] : "16"); + IniFileModel model = IniFileModel.getInstance(); + + BufferedWriter w = new BufferedWriter(new FileWriter("generated_" + tableName + ".cpp")); + if (!loadSectionName.equalsIgnoreCase("none")) { - BufferedReader r = readAndScroll(msqFileName, loadSectionName); - - loadCount = size; - loadBins = new float[loadCount]; - readAxle(loadBins, r); + loadBins = processCurve(msqFileName, loadSectionName, model, w); } + if (!rpmSectionName.equalsIgnoreCase("none")) { - BufferedReader r = readAndScroll(msqFileName, rpmSectionName); - rpmCount = size; - rpmBins = new float[rpmCount]; - readAxle(rpmBins, r); + rpmBins = processCurve(msqFileName, rpmSectionName, model, w); } - table = new float[size][]; - for (int i = 0; i < size; i++) { - table[i] = new float[size]; - } + if (!tableName.equalsIgnoreCase("none")) { + float[][] table; - BufferedReader r = readAndScroll(msqFileName, tableName); - readTable(table, r); - - BufferedWriter w = new BufferedWriter(new FileWriter("output.c")); - writeTable(w, new ValueSource() { - @Override - public float getValue(int loadIndex, int rpmIndex) { - return table[loadIndex][rpmIndex]; + table = new float[size][]; + for (int i = 0; i < size; i++) { + table[i] = new float[size]; } - }, "TS2C"); + + BufferedReader r = readAndScroll(msqFileName, tableName); + readTable(table, r); + + writeTable(w, (loadIndex, rpmIndex) -> table[loadIndex][rpmIndex], "TS2C"); + w.write("\r\n\r\n"); + } + + w.write("static void set" + tableName + "() {\n"); + w.write("\tMEMCPY(config->" + rpmSectionName + ", hardCoded" + rpmSectionName + ");\n"); + + if (!tableName.equalsIgnoreCase("none")) { + + } - w.write("\r\n\r\n/* rpm bins */\r\n\r\n"); - w.write(toString(rpmBins)); - - w.write("\r\n\r\n/* load bins */\r\n\r\n"); - w.write(toString(loadBins)); - w.write("\r\n\r\n"); + w.write("}\n"); w.close(); + } + private float[] processCurve(String msqFileName, String loadSectionName, IniFileModel model, BufferedWriter w) throws IOException { + ArrayIniField field = (ArrayIniField) model.allIniFields.get(loadSectionName); + int curveSize = field.getRows(); + BufferedReader r = readAndScroll(msqFileName, loadSectionName); + float[] curve = new float[curveSize]; + readAxle(curve, r); + + w.write("static const float hardCoded" + loadSectionName + "[" + curveSize + "] = "); + w.write(toString(curve)); + w.write(";\r\n\r\n"); + return curve; } private String toString(float[] a) { @@ -98,12 +111,12 @@ public class TS2C { private void writeTable(BufferedWriter w, ValueSource valueSource, String toolName) throws IOException { w.write("/* Generated by " + toolName + " on " + new Date() + "*/\r\n"); - for (int loadIndex = 0; loadIndex < loadCount; loadIndex++) - writeLine(valueSource, w, loadIndex); + for (int loadIndex = 0; loadIndex < loadBins.length; loadIndex++) + writeTableLine(valueSource, w, loadIndex); } /** - * @param fileName text file to open + * @param fileName text file to open * @param magicStringKey magic string content to scroll to * @return Reader after the magicStringKey line */ @@ -120,11 +133,11 @@ public class TS2C { return reader; } - private void writeLine(ValueSource valueSource, BufferedWriter w, int loadIndex) throws IOException { + private void writeTableLine(ValueSource valueSource, BufferedWriter w, int loadIndex) throws IOException { StringBuilder sb = new StringBuilder("{"); sb.append("/* " + loadIndex + " " + String.format("%3.3f", loadBins[loadIndex]) + "\t*/"); - for (int rpmIndex = 0; rpmIndex < rpmCount; rpmIndex++) { + for (int rpmIndex = 0; rpmIndex < rpmBins.length; rpmIndex++) { sb.append("/* " + rpmIndex + " " + rpmBins[rpmIndex] + "*/" + String.format("%3.3f", valueSource.getValue(loadIndex, rpmIndex)) + ",\t"); } sb.append("},\r\n"); diff --git a/java_console/models/src/main/java/com/rusefi/TS2CRunner.java b/java_console/models/src/main/java/com/rusefi/TS2CRunner.java new file mode 100644 index 0000000000..621f62bc27 --- /dev/null +++ b/java_console/models/src/main/java/com/rusefi/TS2CRunner.java @@ -0,0 +1,13 @@ +package com.rusefi; + +import java.io.IOException; + +public class TS2CRunner { + public static void main(String[] args) throws IOException { + String tuneFileName = "CurrentTune.msq"; + + TS2C.main(new String[]{tuneFileName, "afrLoadBins", "afrRpmBins", "afrTable"}); + TS2C.main(new String[]{tuneFileName, "fuelLoadBins", "fuelRpmBins", "fuelTable"}); + + } +}