toolset progress
This commit is contained in:
parent
45f61e2b88
commit
14eae026e9
|
@ -1,11 +1,11 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2CRunner" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2CRunner" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2CRunner" />
|
||||
<module name="models" />
|
||||
<option name="VM_PARAMETERS" value="-Dini_file_path=." />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="com.rusefi.*" />
|
||||
<option name="PATTERN" value="com.rusefi.tools.tune.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C fsioTable1" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq fsioTable1LoadBins fsioTable1RpmBins fsioTable1 8" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C fuelTable" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq fuelLoadBins fuelRpmBins fuelTable" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C ignitionTable" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq ignitionLoadBins ignitionRpmBins ignitionTable" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C targetAFR" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq afrLoadBins afrRpmBins afrTable" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C tps2tps" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq tpsTpsAccelFromRpmBins tpsTpsAccelToRpmBins tpsTpsAccelTable 8" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="TS2C veTable" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.TS2C" />
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.tools.tune.TS2C" />
|
||||
<module name="models" />
|
||||
<option name="PROGRAM_PARAMETERS" value="currenttune.msq veLoadBins veRpmBins veTable" />
|
||||
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
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"});
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.rusefi.tools.tune;
|
||||
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.field.ArrayIniField;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CurveData {
|
||||
private final float[] rawData;
|
||||
|
||||
public CurveData(float[] rawData) {
|
||||
this.rawData = rawData;
|
||||
|
||||
int countOfEqualElementsAtTheEnd = 0;
|
||||
float lastElement = rawData[rawData.length - 1];
|
||||
for (int i = rawData.length - 2; i >= 0; i--) {
|
||||
if (rawData[i] != lastElement)
|
||||
break;
|
||||
countOfEqualElementsAtTheEnd++;
|
||||
}
|
||||
System.out.println(countOfEqualElementsAtTheEnd + " equal elements at the end of the curve");
|
||||
}
|
||||
|
||||
static CurveData processCurve(String msqFileName, String loadSectionName, IniFileModel model, BufferedWriter w) throws IOException {
|
||||
ArrayIniField field = (ArrayIniField) model.allIniFields.get(loadSectionName);
|
||||
int curveSize = field.getRows();
|
||||
BufferedReader r = TS2C.readAndScroll(msqFileName, loadSectionName);
|
||||
float[] curve = new float[curveSize];
|
||||
readAxle(curve, r);
|
||||
|
||||
CurveData curveData = new CurveData(curve);
|
||||
|
||||
|
||||
w.write("static const float hardCoded" + loadSectionName + "[" + curveSize + "] = ");
|
||||
w.write(toString(curve));
|
||||
w.write(";\r\n\r\n");
|
||||
return curveData;
|
||||
}
|
||||
|
||||
private static String toString(float[] a) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
int iMax = a.length - 1;
|
||||
b.append('{');
|
||||
for (int i = 0; ; i++) {
|
||||
b.append(a[i]);
|
||||
if (i == iMax)
|
||||
return b.append('}').toString();
|
||||
b.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void readAxle(float[] curve, BufferedReader r) throws IOException {
|
||||
int index = 0;
|
||||
|
||||
while (index < curve.length) {
|
||||
String line = r.readLine();
|
||||
if (line == null)
|
||||
throw new IOException("End of file?");
|
||||
line = line.trim();
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
curve[index++] = Float.parseFloat(line);
|
||||
}
|
||||
|
||||
System.out.println("Got bins " + Arrays.toString(curve));
|
||||
}
|
||||
|
||||
public float[] getRawData() {
|
||||
return rawData;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.rusefi;
|
||||
package com.rusefi.tools.tune;
|
||||
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.field.ArrayIniField;
|
||||
|
@ -16,10 +16,10 @@ import java.util.Date;
|
|||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public class TS2C {
|
||||
// todo: replace with loadCount & rpmCount
|
||||
private final int size;
|
||||
private int size;
|
||||
|
||||
private float[] loadBins;
|
||||
private float[] rpmBins;
|
||||
private CurveData loadBins;
|
||||
private CurveData rpmBins;
|
||||
|
||||
/**
|
||||
* @see TS2CRunner
|
||||
|
@ -42,24 +42,31 @@ public class TS2C {
|
|||
String loadSectionName = args[1];
|
||||
String rpmSectionName = args[2];
|
||||
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"));
|
||||
String methodName = tableName.equalsIgnoreCase("none") ? loadSectionName : tableName;
|
||||
methodName = methodName.toUpperCase().substring(0, 1) + methodName.substring(1);
|
||||
|
||||
BufferedWriter w = new BufferedWriter(new FileWriter("generated_" + methodName + ".cpp"));
|
||||
|
||||
|
||||
if (!loadSectionName.equalsIgnoreCase("none")) {
|
||||
loadBins = processCurve(msqFileName, loadSectionName, model, w);
|
||||
loadBins = CurveData.processCurve(msqFileName, loadSectionName, model, w);
|
||||
}
|
||||
|
||||
if (!rpmSectionName.equalsIgnoreCase("none")) {
|
||||
rpmBins = processCurve(msqFileName, rpmSectionName, model, w);
|
||||
rpmBins = CurveData.processCurve(msqFileName, rpmSectionName, model, w);
|
||||
}
|
||||
|
||||
if (!tableName.equalsIgnoreCase("none")) {
|
||||
float[][] table;
|
||||
ArrayIniField field = (ArrayIniField) model.allIniFields.get(tableName);
|
||||
|
||||
table = new float[size][];
|
||||
if (field.getRows() != field.getCols())
|
||||
throw new UnsupportedOperationException("Not square table not supported yet");
|
||||
size = field.getRows();
|
||||
|
||||
float[][] table = new float[size][];
|
||||
for (int i = 0; i < size; i++) {
|
||||
table[i] = new float[size];
|
||||
}
|
||||
|
@ -71,7 +78,8 @@ public class TS2C {
|
|||
w.write("\r\n\r\n");
|
||||
}
|
||||
|
||||
w.write("static void set" + tableName + "() {\n");
|
||||
w.write("static void set" + methodName + "() {\n");
|
||||
w.write("\tMEMCPY(config->" + loadSectionName + ", hardCoded" + loadSectionName + ");\n");
|
||||
w.write("\tMEMCPY(config->" + rpmSectionName + ", hardCoded" + rpmSectionName + ");\n");
|
||||
|
||||
if (!tableName.equalsIgnoreCase("none")) {
|
||||
|
@ -84,34 +92,9 @@ public class TS2C {
|
|||
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) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
int iMax = a.length - 1;
|
||||
b.append('{');
|
||||
for (int i = 0; ; i++) {
|
||||
b.append(a[i]);
|
||||
if (i == iMax)
|
||||
return b.append('}').toString();
|
||||
b.append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
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 < loadBins.length; loadIndex++)
|
||||
for (int loadIndex = 0; loadIndex < loadBins.getRawData().length; loadIndex++)
|
||||
writeTableLine(valueSource, w, loadIndex);
|
||||
}
|
||||
|
||||
|
@ -120,7 +103,7 @@ public class TS2C {
|
|||
* @param magicStringKey magic string content to scroll to
|
||||
* @return Reader after the magicStringKey line
|
||||
*/
|
||||
private static BufferedReader readAndScroll(String fileName, String magicStringKey) throws IOException {
|
||||
static BufferedReader readAndScroll(String fileName, String magicStringKey) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(fileName));
|
||||
System.out.println("Reading from " + fileName + ", scrolling to " + magicStringKey);
|
||||
String line;
|
||||
|
@ -136,9 +119,9 @@ public class TS2C {
|
|||
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 < rpmBins.length; rpmIndex++) {
|
||||
sb.append("/* " + rpmIndex + " " + rpmBins[rpmIndex] + "*/" + String.format("%3.3f", valueSource.getValue(loadIndex, rpmIndex)) + ",\t");
|
||||
sb.append("/* " + loadIndex + " " + String.format("%3.3f", loadBins.getRawData()[loadIndex]) + "\t*/");
|
||||
for (int rpmIndex = 0; rpmIndex < rpmBins.getRawData().length; rpmIndex++) {
|
||||
sb.append("/* " + rpmIndex + " " + rpmBins.getRawData()[rpmIndex] + "*/" + String.format("%3.3f", valueSource.getValue(loadIndex, rpmIndex)) + ",\t");
|
||||
}
|
||||
sb.append("},\r\n");
|
||||
|
||||
|
@ -177,19 +160,4 @@ public class TS2C {
|
|||
}
|
||||
}
|
||||
|
||||
private void readAxle(float[] bins, BufferedReader r) throws IOException {
|
||||
int index = 0;
|
||||
|
||||
while (index < size) {
|
||||
String line = r.readLine();
|
||||
if (line == null)
|
||||
throw new IOException("End of file?");
|
||||
line = line.trim();
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
bins[index++] = Float.parseFloat(line);
|
||||
}
|
||||
|
||||
System.out.println("Got bins " + Arrays.toString(bins));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.rusefi.tools.tune;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class TS2CRunner {
|
||||
public static void main(String[] args) throws IOException {
|
||||
String tuneFileName = "CurrentTune.msq";
|
||||
|
||||
|
||||
|
||||
TS2C.main(new String[]{tuneFileName, "mafDecodingBins", "mafDecoding", "none"});
|
||||
|
||||
TS2C.main(new String[]{tuneFileName, "crankingCycleBins", "crankingCycleCoef", "none"});
|
||||
TS2C.main(new String[]{tuneFileName, "crankingFuelBins", "crankingFuelCoef", "none"});
|
||||
|
||||
// TS2C.main(new String[]{tuneFileName, "afrLoadBins", "afrRpmBins", "afrTable"});
|
||||
// TS2C.main(new String[]{tuneFileName, "fuelLoadBins", "fuelRpmBins", "fuelTable"});
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue