From 97e60b02662c15528324f1a611a1e7406500f4c7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 25 Dec 2023 20:13:08 -0500 Subject: [PATCH] only:EPIC: Improve toolset for default tune canned tune generation #4871 --- .../java/com/rusefi/tools/tune/CurveData.java | 4 +- .../main/java/com/rusefi/tools/tune/TS2C.java | 55 +------------------ .../com/rusefi/tools/tune/TuneCanTool.java | 5 ++ 3 files changed, 11 insertions(+), 53 deletions(-) diff --git a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/CurveData.java b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/CurveData.java index dbf76f3937..71f15f6109 100644 --- a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/CurveData.java +++ b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/CurveData.java @@ -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"; } diff --git a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TS2C.java b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TS2C.java index 27cd86d77a..7323561dba 100644 --- a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TS2C.java +++ b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TS2C.java @@ -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++; - } - } - } diff --git a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TuneCanTool.java b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TuneCanTool.java index 7ffa44d702..cb310e7ddf 100644 --- a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TuneCanTool.java +++ b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/TuneCanTool.java @@ -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)