only:EPIC: Improve toolset for default tune canned tune generation #4871
This commit is contained in:
parent
701066064b
commit
24828840a4
|
@ -43,7 +43,7 @@ public class CurveData implements HoHo {
|
||||||
return null;
|
return null;
|
||||||
ArrayIniField field = (ArrayIniField) iniField;
|
ArrayIniField field = (ArrayIniField) iniField;
|
||||||
int curveSize = field.getRows();
|
int curveSize = field.getRows();
|
||||||
BufferedReader r = TS2C.readAndScroll(msqFileName, curveName + "\"");
|
BufferedReader r = TS2C.readAndScroll(msqFileName, curveName + "\"", TS2C.fileFactory);
|
||||||
float[] curveValues = new float[curveSize];
|
float[] curveValues = new float[curveSize];
|
||||||
readAxle(curveValues, r);
|
readAxle(curveValues, r);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tuner studio project to C data structure converter command line utility
|
* tuner studio project to C data structure converter command line utility
|
||||||
|
@ -14,6 +15,18 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||||
public class TS2C {
|
public class TS2C {
|
||||||
|
public static final Function<String, Reader> fileFactory = new Function<String, Reader>() {
|
||||||
|
@Override
|
||||||
|
public Reader apply(String fileName) {
|
||||||
|
try {
|
||||||
|
return new FileReader(fileName);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public static String FINGER_PRINT = "/* Generated by " + TS2C.class.getSimpleName() + " on " + new Date() + "*/\n";
|
public static String FINGER_PRINT = "/* Generated by " + TS2C.class.getSimpleName() + " on " + new Date() + "*/\n";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,19 +134,22 @@ public class TS2C {
|
||||||
/**
|
/**
|
||||||
* @param fileName text file to open
|
* @param fileName text file to open
|
||||||
* @param magicStringKey magic string content to scroll to
|
* @param magicStringKey magic string content to scroll to
|
||||||
|
* @param factory
|
||||||
* @return Reader after the magicStringKey line
|
* @return Reader after the magicStringKey line
|
||||||
*/
|
*/
|
||||||
static BufferedReader readAndScroll(String fileName, String magicStringKey) throws IOException {
|
static BufferedReader readAndScroll(String fileName, String magicStringKey, Function<String, Reader> factory) throws IOException {
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(fileName));
|
|
||||||
|
Reader reader = factory.apply(fileName);
|
||||||
|
BufferedReader br = new BufferedReader(reader);
|
||||||
System.out.println("Reading from " + fileName + ", scrolling to " + magicStringKey);
|
System.out.println("Reading from " + fileName + ", scrolling to " + magicStringKey);
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
if (line.contains(magicStringKey)) {
|
if (line.contains(magicStringKey)) {
|
||||||
System.out.println("Found " + line);
|
System.out.println("Found " + line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reader;
|
return br;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String writeTableLine(CurveData loadBins, CurveData rpmBins, ValueSource valueSource, int loadIndex) {
|
private static String writeTableLine(CurveData loadBins, CurveData rpmBins, ValueSource valueSource, int loadIndex) {
|
||||||
|
|
|
@ -6,7 +6,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class TableData {
|
public class TableData {
|
||||||
@NotNull
|
@NotNull
|
||||||
|
@ -16,22 +18,27 @@ public class TableData {
|
||||||
if (field.getRows() != field.getCols())
|
if (field.getRows() != field.getCols())
|
||||||
throw new UnsupportedOperationException("Not square table not supported yet");
|
throw new UnsupportedOperationException("Not square table not supported yet");
|
||||||
// todo: replace with loadCount & rpmCount
|
// todo: replace with loadCount & rpmCount
|
||||||
int size = field.getRows();
|
int rows = field.getRows();
|
||||||
|
|
||||||
float[][] table = new float[size][];
|
return readTable(msqFileName, tableName, rows, TS2C.fileFactory, field.getCols());
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
table[i] = new float[size];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferedReader reader = TS2C.readAndScroll(msqFileName, tableName);
|
@NotNull
|
||||||
readTable(table, reader, size);
|
public static float[][] readTable(String msqFileName, String tableName, int rows, Function<String, Reader> factory, int columns) throws IOException {
|
||||||
|
float[][] table = new float[rows][];
|
||||||
|
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
||||||
|
table[rowIndex] = new float[columns];
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader reader = TS2C.readAndScroll(msqFileName, tableName, factory);
|
||||||
|
readTable(table, reader, rows, columns);
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void readTable(float[][] table, BufferedReader r, int size) throws IOException {
|
private static void readTable(float[][] table, BufferedReader r, int rows, int columns) throws IOException {
|
||||||
int index = 0;
|
int rowIndex = 0;
|
||||||
|
|
||||||
while (index < size) {
|
while (rowIndex < rows) {
|
||||||
String line = r.readLine();
|
String line = r.readLine();
|
||||||
if (line == null)
|
if (line == null)
|
||||||
throw new IOException("End of file?");
|
throw new IOException("End of file?");
|
||||||
|
@ -40,19 +47,19 @@ public class TableData {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
String[] values = line.split("\\s");
|
String[] values = line.split("\\s");
|
||||||
if (values.length != size)
|
if (values.length != columns)
|
||||||
throw new IllegalStateException("Expected " + size + " but got " + Arrays.toString(values) + ". Unexpected line: " + line);
|
throw new IllegalStateException("Expected " + columns + " but got " + values.length + " content = " + Arrays.toString(values) + ". Unexpected line: " + line);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int column = 0; column < columns; column++) {
|
||||||
String str = values[i];
|
String str = values[column];
|
||||||
try {
|
try {
|
||||||
table[index][i] = Float.parseFloat(str);
|
table[rowIndex][column] = Float.parseFloat(str);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new IllegalStateException("While reading " + str, e);
|
throw new IllegalStateException("While reading " + str, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Got line " + index + ": " + Arrays.toString(table[index]));
|
System.out.println("Got line " + rowIndex + ": " + Arrays.toString(table[rowIndex]));
|
||||||
index++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,11 @@ public class TuneCanTool {
|
||||||
|
|
||||||
RootHolder.ROOT = "../firmware/";
|
RootHolder.ROOT = "../firmware/";
|
||||||
|
|
||||||
processREOtune(1507, Fields.engine_type_e_HELLEN_154_HYUNDAI_COUPE_BK2, "BK2");
|
writeDiffBetweenLocalTuneFileAndDefaultTune("x", TuneCanTool.DEFAULT_TUNE,
|
||||||
|
"C:\\stuff\\i\\canam-2022-short\\canam-progress-nov-26.msq", "x");
|
||||||
|
|
||||||
|
|
||||||
|
// processREOtune(1507, Fields.engine_type_e_HELLEN_154_HYUNDAI_COUPE_BK2, "BK2");
|
||||||
// processREOtune(1502, Fields.engine_type_e_HYUNDAI_PB, "PB");
|
// processREOtune(1502, Fields.engine_type_e_HYUNDAI_PB, "PB");
|
||||||
// processREOtune(1490, Fields.engine_type_e_MRE_M111, "m111-alex");
|
// processREOtune(1490, Fields.engine_type_e_MRE_M111, "m111-alex");
|
||||||
// handle("Mitsubicha", 1258);
|
// handle("Mitsubicha", 1258);
|
||||||
|
@ -76,7 +80,7 @@ public class TuneCanTool {
|
||||||
|
|
||||||
writeDiffBetweenLocalTuneFileAndDefaultTune(vehicleName, currentTuneFileName, localFileName, url);
|
writeDiffBetweenLocalTuneFileAndDefaultTune(vehicleName, currentTuneFileName, localFileName, url);
|
||||||
}
|
}
|
||||||
private static void writeDiffBetweenLocalTuneFileAndDefaultTune(String vehicleName, String currentTuneFileName, String localFileName, String cannedComment) throws JAXBException, IOException {
|
private static void writeDiffBetweenLocalTuneFileAndDefaultTune(String vehicleName, String defaultTuneFileName, String localFileName, String cannedComment) throws JAXBException, IOException {
|
||||||
String reportsOutputFolder = "tune_reports";
|
String reportsOutputFolder = "tune_reports";
|
||||||
new File(reportsOutputFolder).mkdir();
|
new File(reportsOutputFolder).mkdir();
|
||||||
|
|
||||||
|
@ -84,8 +88,8 @@ public class TuneCanTool {
|
||||||
|
|
||||||
StringBuilder methods = new StringBuilder();
|
StringBuilder methods = new StringBuilder();
|
||||||
|
|
||||||
Msq currentTune = Msq.readTune(currentTuneFileName);
|
Msq defaultTune = Msq.readTune(defaultTuneFileName);
|
||||||
StringBuilder sb = TuneCanTool.getTunePatch(currentTune, custom, ini, currentTuneFileName, methods);
|
StringBuilder sb = TuneCanTool.getTunePatch(defaultTune, custom, ini, defaultTuneFileName, methods);
|
||||||
|
|
||||||
String fileNameMethods = reportsOutputFolder + "/" + vehicleName + "_methods.md";
|
String fileNameMethods = reportsOutputFolder + "/" + vehicleName + "_methods.md";
|
||||||
try (FileWriter methodsWriter = new FileWriter(fileNameMethods)) {
|
try (FileWriter methodsWriter = new FileWriter(fileNameMethods)) {
|
||||||
|
@ -177,8 +181,8 @@ public class TuneCanTool {
|
||||||
|
|
||||||
if (cf.isArray()) {
|
if (cf.isArray()) {
|
||||||
if (cf.getArraySizes().length == 2) {
|
if (cf.getArraySizes().length == 2) {
|
||||||
//float[][] tableData = TableData.readTable(currentTuneFileName, name, ini);
|
float[][] tableData = TableData.readTable(currentTuneFileName, name, ini);
|
||||||
//System.out.printf(" " + name);
|
System.out.printf(" " + name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.rusefi.tools.tune.TuneTools;
|
||||||
import com.rusefi.tune.xml.Msq;
|
import com.rusefi.tune.xml.Msq;
|
||||||
import com.rusefi.tune.xml.Page;
|
import com.rusefi.tune.xml.Page;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.function.ThrowingRunnable;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.rusefi.tune;
|
||||||
|
|
||||||
|
import com.rusefi.tools.tune.TableData;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class TableDataTest {
|
||||||
|
@Test
|
||||||
|
public void read() throws IOException {
|
||||||
|
|
||||||
|
String s = "<constant cols=\"10\" digits=\"0\" name=\"scriptTable4\" rows=\"8\" units=\"value\">\n" +
|
||||||
|
" 0.0 0.0 0.0 333 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 444 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n" +
|
||||||
|
" </constant>\n";
|
||||||
|
|
||||||
|
Reader r = new StringReader(s);
|
||||||
|
float[][] data = TableData.readTable("x", "scriptTable4", 8, s1 -> r, 10);
|
||||||
|
|
||||||
|
assertEquals(333, (int)data[0][3]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue