only:EPIC: Improve toolset for default tune canned tune generation #4871

This commit is contained in:
Andrey 2023-12-25 20:13:08 -05:00
parent 4b0f0a4f0f
commit 97e60b0266
3 changed files with 11 additions and 53 deletions

View File

@ -10,7 +10,7 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Arrays;
public class CurveData {
public class CurveData implements HoHo {
private final String curveName;
private final float[] rawData;
@ -96,6 +96,7 @@ public class CurveData {
return rawData;
}
@Override
public String getCsourceMethod(String reference) {
return "static void " + getCannedMethod() + " {\n"
+ "\t" + getCsourceCode() +
@ -108,6 +109,7 @@ public class CurveData {
return "canned" + curveName + "()";
}
@Override
public String getCinvokeMethod() {
return "\t" + getCannedMethod() + ";\n";
}

View File

@ -1,11 +1,9 @@
package com.rusefi.tools.tune;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.field.ArrayIniField;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.Arrays;
import java.util.Date;
/**
@ -92,7 +90,7 @@ public class TS2C {
@NotNull
public static String getTableCSourceCode2(String msqFileName, String tableName, IniFileModel model, CurveData xRpmCurve, CurveData yLoadBins) throws IOException {
float[][] table = readTable(msqFileName, tableName, model);
float[][] table = TableData.readTable(msqFileName, tableName, model);
return getTableCSourceCode(tableName, yLoadBins, xRpmCurve, table);
}
@ -107,25 +105,6 @@ public class TS2C {
return sb.toString();
}
@NotNull
private static float[][] readTable(String msqFileName, String tableName, IniFileModel model) throws IOException {
ArrayIniField field = (ArrayIniField) model.allIniFields.get(tableName);
if (field.getRows() != field.getCols())
throw new UnsupportedOperationException("Not square table not supported yet");
// todo: replace with loadCount & rpmCount
int size = field.getRows();
float[][] table = new float[size][];
for (int i = 0; i < size; i++) {
table[i] = new float[size];
}
BufferedReader reader = readAndScroll(msqFileName, tableName);
readTable(table, reader, size);
return table;
}
@NotNull
private static String getMethodName(String methodName) {
return methodName.toUpperCase().charAt(0) + methodName.substring(1);
@ -175,8 +154,8 @@ public class TS2C {
String yLoadBinsName = model.getYBin(tableName);
String x = "\tcopyArray(" + tableReference + "LoadBins, hardCoded" + xRpmBinsName + ");\n" +
"\tcopyArray(" + tableReference + "RpmBins, hardCoded" + yLoadBinsName + ");\n" +
"\tcopyTable(" + tableReference + "Table, hardCoded" + tableName + ");\n";
"\tcopyArray(" + tableReference + "RpmBins, hardCoded" + yLoadBinsName + ");\n" +
"\tcopyTable(" + tableReference + "Table, hardCoded" + tableName + ");\n";
return x;
}
@ -184,32 +163,4 @@ public class TS2C {
float getValue(int loadIndex, int rpmIndex);
}
private static void readTable(float[][] table, BufferedReader r, int size) 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;
String[] values = line.split("\\s");
if (values.length != size)
throw new IllegalStateException("Expected " + size + " but got " + Arrays.toString(values) + ". Unexpected line: " + line);
for (int i = 0; i < size; i++) {
String str = values[i];
try {
table[index][i] = Float.parseFloat(str);
} catch (NumberFormatException e) {
throw new IllegalStateException("While reading " + str, e);
}
}
System.out.println("Got line " + index + ": " + Arrays.toString(table[index]));
index++;
}
}
}

View File

@ -176,6 +176,11 @@ public class TuneCanTool {
}
if (cf.isArray()) {
if (cf.getArraySizes().length == 2) {
//float[][] tableData = TableData.readTable(currentTuneFileName, name, ini);
//System.out.printf(" " + name);
continue;
}
CurveData data = CurveData.valueOf(currentTuneFileName, name, ini);
if (data == null)