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

This commit is contained in:
rusefillc 2023-12-25 19:57:57 -05:00
parent 664607fb4b
commit ff196ebf8b
4 changed files with 69 additions and 1 deletions

View File

@ -198,6 +198,7 @@ public class IniFileModel {
private void handleZBins(LinkedList<String> list) {
list.removeFirst();
String zBins = list.removeFirst();
addField(zBins);
if (currentXBins == null || currentYBins == null)
throw new IllegalStateException("X or Y missing for " + zBins);
xBinsByZBins.put(zBins, currentXBins);
@ -236,7 +237,6 @@ public class IniFileModel {
private void handleTable(LinkedList<String> list) {
list.removeFirst();
String tableName = list.removeFirst();
addField(tableName);
}
private void handleFieldDefinition(LinkedList<String> list, RawIniFile.Line line) {

View File

@ -146,6 +146,9 @@ public class IniFileReaderTest {
IniFileModel model = new IniFileModel().readIniFile(lines);
assertEquals(3, model.allIniFields.size());
assertEquals(3, model.fieldsInUiOrder.size());
assertTrue(model.fieldsInUiOrder.containsKey("tpsTpsAccelToRpmBins"));
assertFalse(model.fieldsInUiOrder.containsKey("tpsTpsAccelTbl"));
assertTrue(model.fieldsInUiOrder.containsKey("tpsTpsAccelTable"));
}
@Test

View File

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

View File

@ -0,0 +1,58 @@
package com.rusefi.tools.tune;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.field.ArrayIniField;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
public class TableData {
@NotNull
public 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 = TS2C.readAndScroll(msqFileName, tableName);
readTable(table, reader, size);
return table;
}
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++;
}
}
}