only: method prefix

This commit is contained in:
Andrey 2024-03-06 12:39:40 -05:00
parent 2020b88b09
commit 07f5dcb636
7 changed files with 44 additions and 40 deletions

View File

@ -102,20 +102,20 @@ public class CurveData implements HoHo {
}
@Override
public String getCsourceMethod(String reference) {
return "static void " + getCannedMethod() + " {\n"
public String getCsourceMethod(String reference, String methodNamePrefix) {
return "static void " + getCannedMethod(methodNamePrefix) + " {\n"
+ "\t" + getCsourceCode() +
"\tcopyArray(" + reference + curveName + ", " + getCannedName() + ");\n" +
"}\n\n";
}
@NotNull
private String getCannedMethod() {
return "canned" + curveName + "()";
private String getCannedMethod(String methodNamePrefix) {
return methodNamePrefix + "canned" + curveName + "()";
}
@Override
public String getCinvokeMethod() {
return "\t" + getCannedMethod() + ";\n";
public String getCinvokeMethod(String methodNamePrefix) {
return "\t" + getCannedMethod(methodNamePrefix) + ";\n";
}
}

View File

@ -1,7 +1,7 @@
package com.rusefi.tools.tune;
public interface HoHo {
String getCsourceMethod(String reference);
String getCsourceMethod(String reference, String methodNamePrefix);
String getCinvokeMethod();
String getCinvokeMethod(String methodNamePrefix);
}

View File

@ -90,8 +90,8 @@ public class TableData implements HoHo {
return output.toString();
}
private String getCannedMethod() {
return "canned" + tableName + "()";
private String getCannedMethod(String methodNamePrefix) {
return methodNamePrefix + "canned" + tableName + "()";
}
private String getCannedName() {
@ -107,15 +107,15 @@ public class TableData implements HoHo {
}
@Override
public String getCsourceMethod(String reference) {
return "static void " + getCannedMethod() + " {\n"
public String getCsourceMethod(String reference, String methodNamePrefix) {
return "static void " + getCannedMethod(methodNamePrefix) + " {\n"
+ "\t" + getCsourceCode() +
"\tcopyTable(" + reference + tableName + ", " + getCannedName() + ");\n" +
"}\n\n";
}
@Override
public String getCinvokeMethod() {
return "\t" + getCannedMethod() + ";\n";
public String getCinvokeMethod(String methodNamePrefix) {
return "\t" + getCannedMethod(methodNamePrefix) + ";\n";
}
}

View File

@ -48,6 +48,7 @@ public class TuneCanTool implements TuneCanToolConstants {
public static final String TUNE_FILE_SUFFIX = ".msq";
public static final String DEFAULT_TUNE = SIMULATED_PREFIX + TUNE_FILE_SUFFIX;
private static final String workingFolder = "downloaded_tunes";
public static final String MD_FIXED_FORMATTING = "```\n";
protected static IniFileModel ini;
@ -70,11 +71,12 @@ public class TuneCanTool implements TuneCanToolConstants {
/**
* @see WriteSimulatorConfiguration
*/
protected static void processREOtune(int tuneId, engine_type_e engineType, String key) throws JAXBException, IOException {
protected static void processREOtune(int tuneId, engine_type_e engineType, String key,
String methodNamePrefix) throws JAXBException, IOException {
// compare specific internet tune to total global default
handle(key + "-comparing-against-global-defaults", tuneId, TuneCanTool.DEFAULT_TUNE);
handle(key + "-comparing-against-global-defaults", tuneId, TuneCanTool.DEFAULT_TUNE, methodNamePrefix);
// compare same internet tune to default tune of specified engine type
handle(key + "-comparing-against-current-" + key + "-default", tuneId, getDefaultTuneName(engineType));
handle(key + "-comparing-against-current-" + key + "-default", tuneId, getDefaultTuneName(engineType), methodNamePrefix);
}
@NotNull
@ -82,13 +84,13 @@ public class TuneCanTool implements TuneCanToolConstants {
return SIMULATED_PREFIX + "_" + engineType.name() + TUNE_FILE_SUFFIX;
}
private static void handle(String vehicleName, int tuneId, String defaultTuneFileName) throws JAXBException, IOException {
private static void handle(String vehicleName, int tuneId, String defaultTuneFileName, String methodNamePrefix) throws JAXBException, IOException {
String customTuneFileName = workingFolder + File.separator + tuneId + ".msq";
String url = "https://rusefi.com/online/view.php?msq=" + tuneId;
downloadTune(tuneId, customTuneFileName);
writeDiffBetweenLocalTuneFileAndDefaultTune(vehicleName, defaultTuneFileName, customTuneFileName, url);
writeDiffBetweenLocalTuneFileAndDefaultTune(vehicleName, defaultTuneFileName, customTuneFileName, url, methodNamePrefix);
}
// private static void writeDiffBetweenLocalTuneFileAndDefaultTune(String localFileName) throws JAXBException, IOException {
@ -101,7 +103,7 @@ public class TuneCanTool implements TuneCanToolConstants {
// localFileName, cannedComment);
// }
private static void writeDiffBetweenLocalTuneFileAndDefaultTune(String vehicleName, String defaultTuneFileName, String customTuneFileName, String cannedComment) throws JAXBException, IOException {
private static void writeDiffBetweenLocalTuneFileAndDefaultTune(String vehicleName, String defaultTuneFileName, String customTuneFileName, String cannedComment, String methodNamePrefix) throws JAXBException, IOException {
new File(REPORTS_OUTPUT_FOLDER).mkdir();
Msq customTune = Msq.readTune(customTuneFileName);
@ -109,11 +111,13 @@ public class TuneCanTool implements TuneCanToolConstants {
StringBuilder methods = new StringBuilder();
StringBuilder sb = getTunePatch(defaultTune, customTune, ini, customTuneFileName, methods, defaultTuneFileName);
StringBuilder sb = getTunePatch(defaultTune, customTune, ini, customTuneFileName, methods, defaultTuneFileName, methodNamePrefix);
String fileNameMethods = REPORTS_OUTPUT_FOLDER + "/" + vehicleName + "_methods.md";
try (FileWriter methodsWriter = new FileWriter(fileNameMethods)) {
methodsWriter.append(MD_FIXED_FORMATTING);
methodsWriter.append(methods);
methodsWriter.append(MD_FIXED_FORMATTING);
}
String fileName = REPORTS_OUTPUT_FOLDER + "/" + vehicleName + ".md";
@ -124,9 +128,9 @@ public class TuneCanTool implements TuneCanToolConstants {
w.append("# " + vehicleName + "\n\n");
w.append("// canned tune " + cannedComment + "\n\n");
w.append("```\n");
w.append(MD_FIXED_FORMATTING);
w.append(sb);
w.append("```\n");
w.append(MD_FIXED_FORMATTING);
}
log.info("Done writing to " + outputFile.getAbsolutePath() + "!");
}
@ -159,7 +163,7 @@ public class TuneCanTool implements TuneCanToolConstants {
}
@NotNull
public static StringBuilder getTunePatch(Msq defaultTune, Msq customTune, IniFileModel ini, String customTuneFileName, StringBuilder methods, String defaultTuneFileName) throws IOException {
public static StringBuilder getTunePatch(Msq defaultTune, Msq customTune, IniFileModel ini, String customTuneFileName, StringBuilder methods, String defaultTuneFileName, String methodNamePrefix) throws IOException {
ReaderStateImpl state = MetaHelper.getReaderState();
StringBuilder invokeMethods = new StringBuilder();
@ -232,7 +236,7 @@ public class TuneCanTool implements TuneCanToolConstants {
if (defaultTuneFileName != null) {
TableData defaultTableData = TableData.readTable(defaultTuneFileName, fieldName, ini);
if (defaultTableData.getCsourceMethod(parentReference).equals(tableData.getCsourceMethod(parentReference))) {
if (defaultTableData.getCsourceMethod(parentReference, methodNamePrefix).equals(tableData.getCsourceMethod(parentReference, methodNamePrefix))) {
System.out.println("Table " + fieldName + " matches default content");
continue;
}
@ -240,8 +244,8 @@ public class TuneCanTool implements TuneCanToolConstants {
System.out.println("Custom content in table " + fieldName);
methods.append(tableData.getCsourceMethod(parentReference));
invokeMethods.append(tableData.getCinvokeMethod());
methods.append(tableData.getCsourceMethod(parentReference, methodNamePrefix));
invokeMethods.append(tableData.getCinvokeMethod(methodNamePrefix));
continue;
}
@ -251,15 +255,15 @@ public class TuneCanTool implements TuneCanToolConstants {
if (defaultTuneFileName != null) {
CurveData defaultCurveData = CurveData.valueOf(defaultTuneFileName, fieldName, ini);
if (defaultCurveData.getCinvokeMethod().equals(data.getCinvokeMethod())) {
if (defaultCurveData.getCinvokeMethod(methodNamePrefix).equals(data.getCinvokeMethod(methodNamePrefix))) {
System.out.println("Curve " + fieldName + " matches default content");
continue;
}
}
System.out.println("Custom content in curve " + fieldName);
methods.append(data.getCsourceMethod(parentReference));
invokeMethods.append(data.getCinvokeMethod());
methods.append(data.getCsourceMethod(parentReference, methodNamePrefix));
invokeMethods.append(data.getCinvokeMethod(methodNamePrefix));
continue;
}

View File

@ -21,10 +21,10 @@ public class TuneCanToolRunner extends TuneCanTool {
public static void runPopular() throws JAXBException, IOException {
// while adding a line here make sure corresponding line is at rusEfiFunctionalTest.cpp
// https://github.com/rusefi/rusefi/issues/4038
processREOtune(985, engine_type_e.MAZDA_MIATA_NB2, "MazdaMiataNB2");
processREOtune(1507, engine_type_e.HELLEN_154_HYUNDAI_COUPE_BK2, "COUPE-BK2");
processREOtune(1576, engine_type_e.HYUNDAI_PB, "PB");
processREOtune(1591, engine_type_e.BMW_M52, "M52");
processREOtune(1490, engine_type_e.MRE_M111, "m111-alex");
processREOtune(985, engine_type_e.MAZDA_MIATA_NB2, "MazdaMiataNB2", "nb2");
processREOtune(1507, engine_type_e.HELLEN_154_HYUNDAI_COUPE_BK2, "COUPE-BK2", "couple");
processREOtune(1576, engine_type_e.HYUNDAI_PB, "PB", "pb");
processREOtune(1591, engine_type_e.BMW_M52, "M52", "");
processREOtune(1490, engine_type_e.MRE_M111, "m111-alex", "");
}
}

View File

@ -27,7 +27,7 @@ public class LoadOlderTuneTest {
RootHolder.ROOT = "../../firmware/";
StringBuilder sb = TuneCanTool.getTunePatch(lessOldDefaultTune, customOldTune, ini, TuneReadWriteTest.TUNE_NAME, new StringBuilder(), null);
StringBuilder sb = TuneCanTool.getTunePatch(lessOldDefaultTune, customOldTune, ini, TuneReadWriteTest.TUNE_NAME, new StringBuilder(), null, "");
assertEquals(" // default \"Single Coil\"\n" +
" engineConfiguration->ignitionMode = IM_ONE_COIL;\n" +

View File

@ -46,11 +46,11 @@ public class TuneReadWriteTest {
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", xRpmCurve.getCsourceCode());
assertEquals("static void cannedignitionIatCorrRpmBins() {\n" +
assertEquals("static void prefixcannedignitionIatCorrRpmBins() {\n" +
"\tstatic 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" +
"\tcopyArray(config->ignitionIatCorrRpmBins, hardCodedignitionIatCorrRpmBins);\n" +
"}\n" +
"\n", xRpmCurve.getCsourceMethod("config->"));
"\n", xRpmCurve.getCsourceMethod("config->", "prefix"));
TS2C.FINGER_PRINT = "/*unittest*/\n";
String tableSource = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model);
@ -78,7 +78,7 @@ public class TuneReadWriteTest {
@Test
public void testALotTogether() throws IOException {
String expected = "static void cannedveTable() {\n" +
String expected = "static void prefixcannedveTable() {\n" +
"\tstatic const float hardCodedveRpmBins[16] = {650.0, 800.0, 1100.0, 1400.0, 1700.0, 2000.0, 2300.0, 2600.0, 2900.0, 3200.0, 3500.0, 3800.0, 4100.0, 4400.0, 4700.0, 7000.0};\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" +
"static const float hardCodedveTable[16][16] = {\n" +
@ -116,7 +116,7 @@ public class TuneReadWriteTest {
String tableSource = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model);
String completeMethod = "static void canned" + tableName + "() {\n" +
String completeMethod = "static void prefixcanned" + tableName + "() {\n" +
"\t" + xRpmCurve.getCsourceCode() +
"\t" + yLoadCurve.getCsourceCode() +
tableSource +