Improve toolset for default tune canned tune generation #4871

This commit is contained in:
rusefillc 2023-03-28 23:37:58 -04:00
parent 91e1eb825f
commit 9536a60b31
2 changed files with 54 additions and 16 deletions

View File

@ -60,9 +60,9 @@ public class TS2C {
}
if (!tableName.equalsIgnoreCase("none")) {
StringBuilder sb = getTableCSourceCode2(msqFileName, tableName, model, loadBins, rpmBins);
String sb = getTableCSourceCode2(msqFileName, tableName, model, rpmBins, loadBins);
w.write(sb.toString());
w.write(sb);
}
@ -81,22 +81,30 @@ public class TS2C {
w.close();
}
@NotNull
public static StringBuilder getTableCSourceCode2(String msqFileName, String tableName, IniFileModel model, CurveData loadBins, CurveData rpmBins) throws IOException {
float[][] table = readTable(msqFileName, tableName, model);
public static String getTableCSourceCode2(String msqFileName, String tableName, IniFileModel model) throws IOException {
String xRpmBinsName = model.getXBin(tableName);
String yLoadBinsName = model.getYBin(tableName);
return getTableCSourceCode(tableName, loadBins, rpmBins, table);
CurveData xRpmCurve = CurveData.valueOf(msqFileName, xRpmBinsName, model);
CurveData yLoadCurve = CurveData.valueOf(msqFileName, yLoadBinsName, model);
return getTableCSourceCode2(msqFileName, tableName, model, xRpmCurve, yLoadCurve);
}
@NotNull
private static StringBuilder getTableCSourceCode(String tableName, CurveData loadBins, CurveData rpmBins, float[][] table) {
public static String getTableCSourceCode2(String msqFileName, String tableName, IniFileModel model, CurveData xRpmCurve, CurveData yLoadBins) throws IOException {
float[][] table = readTable(msqFileName, tableName, model);
return getTableCSourceCode(tableName, yLoadBins, xRpmCurve, table);
}
private static String getTableCSourceCode(String tableName, CurveData loadBins, CurveData rpmBins, float[][] table) {
StringBuilder sb = new StringBuilder();
sb.append("static const float hardCoded" + tableName + "[" + table.length + "][" + table[0].length + "] = {\n");
writeTable(loadBins, rpmBins, sb, (loadIndex, rpmIndex) -> table[loadIndex][rpmIndex]);
sb.append("};\n\n");
return sb;
return sb.toString();
}
@NotNull

View File

@ -48,16 +48,15 @@ public class TuneReadWriteTest {
assertEquals("ignitionIatCorrLoadBins", yLoadBinsName);
CurveData xRpmCurve = CurveData.valueOf(TUNE_NAME, xRpmBinsName, model);
CurveData yLoadCurve = CurveData.valueOf(TUNE_NAME, yLoadBinsName, model);
assertEquals("static const float hardCodedignitionIatCorrRpmBins[16] = " +
"{880.0, 1260.0, 1640.0, 2020.0, 2400.0, 2780.0, 3000.0, 3380.0, 3760.0, 4140.0, 4520.0, 5000.0, 5700.0, 6500.0, 7200.0, 8000.0};\n" +
"\n", xRpmCurve.getCsourceCode());
TS2C.FINGER_PRINT = "unitest\n";
String actual = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model, yLoadCurve, xRpmCurve).toString();
TS2C.FINGER_PRINT = "/*unittest*/\n";
String tableSource = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model);
assertEquals("static const float hardCodedignitionIatCorrTable[16][16] = {\n" +
"unitest\n" +
"/*unittest*/\n" +
"{/* 0 -40.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
"{/* 1 -30.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
"{/* 2 -20.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
@ -75,7 +74,7 @@ public class TuneReadWriteTest {
"{/* 14 100.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-3.900,\t/* 12 5700.0*/-3.900,\t/* 13 6500.0*/-3.900,\t/* 14 7200.0*/-3.900,\t/* 15 8000.0*/-3.900,\t},\n" +
"{/* 15 110.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-3.900,\t/* 12 5700.0*/-3.900,\t/* 13 6500.0*/-3.900,\t/* 14 7200.0*/-3.900,\t/* 15 8000.0*/-3.900,\t},\n" +
"};\n" +
"\n", actual);
"\n", tableSource);
}
@Test
@ -85,6 +84,29 @@ public class TuneReadWriteTest {
"\n" +
"\tstatic const float hardCodedveLoadBins[16] = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0};\n" +
"\n" +
"static const float hardCodedveTable[16][16] = {\n" +
"/*unittest*/\n" +
"{/* 0 10.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 1 20.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 2 30.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 3 40.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 4 50.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 5 60.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 6 70.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 7 80.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 8 90.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 9 100.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 10 110.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 11 120.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 12 130.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 13 140.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 14 150.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"{/* 15 160.000\t*//* 0 650.0*/80.000,\t/* 1 800.0*/80.000,\t/* 2 1100.0*/80.000,\t/* 3 1400.0*/80.000,\t/* 4 1700.0*/80.000,\t/* 5 2000.0*/80.000,\t/* 6 2300.0*/80.000,\t/* 7 2600.0*/80.000,\t/* 8 2900.0*/80.000,\t/* 9 3200.0*/80.000,\t/* 10 3500.0*/80.000,\t/* 11 3800.0*/80.000,\t/* 12 4100.0*/80.000,\t/* 13 4400.0*/80.000,\t/* 14 4700.0*/80.000,\t/* 15 7000.0*/80.000,\t},\n" +
"};\n" +
"\n" +
"\tcopyArray(config->veLoadBins, hardCodedveRpmBins);\n" +
"\tcopyArray(config->veRpmBins, hardCodedveLoadBins);\n" +
"\tcopyTable(config->veTable, hardCodedveTable);\n" +
"}\n";
String tableReference = "config->ve";
@ -96,20 +118,28 @@ public class TuneReadWriteTest {
CurveData xRpmCurve = CurveData.valueOf(TUNE_NAME, model.getXBin(tableName), model);
CurveData yLoadCurve = CurveData.valueOf(TUNE_NAME, model.getYBin(tableName), model);
TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model, yLoadCurve, xRpmCurve).toString();
String tableSource = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model);
String completeMethod = "static void canned" + tableName + "() {\n" +
"\t" + xRpmCurve.getCsourceCode() +
"\t" + yLoadCurve.getCsourceCode() +
"}\n"
;
tableSource +
copyMethodBody +
"}\n";
assertEquals(expected, completeMethod);
}
@Test
public void testCopyCode() {
String tableReference = "config->ve";
IniFileModel model = IniFileModel.getInstance();
String tableName = "veTable";
String copyMethodBody = TS2C.getCopyMethodBody(tableReference, model, tableName);
assertEquals("\tcopyArray(config->veLoadBins, hardCodedveRpmBins);\n" +
"\tcopyArray(config->veRpmBins, hardCodedveLoadBins);\n" +
"\tcopyTable(config->veTable, hardCodedveTable);\n", copyMethodBody);
}