mirror of https://github.com/rusefi/rusefi.git
8chan Official well known idle stepper configuration #5197
only:alphax-8chan
This commit is contained in:
parent
513bd20726
commit
f76a07360d
|
@ -16,12 +16,7 @@ import java.util.Date;
|
|||
*/
|
||||
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
|
||||
public class TS2C {
|
||||
static final String FINGER_PRINT = "/* Generated by " + TS2C.class.getSimpleName() + " on " + new Date() + "*/\r\n";
|
||||
// todo: replace with loadCount & rpmCount
|
||||
private int size;
|
||||
|
||||
private CurveData loadBins;
|
||||
private CurveData rpmBins;
|
||||
public static String FINGER_PRINT = "/* Generated by " + TS2C.class.getSimpleName() + " on " + new Date() + "*/\n";
|
||||
|
||||
/**
|
||||
* @see TS2CRunner
|
||||
|
@ -53,6 +48,9 @@ public class TS2C {
|
|||
BufferedWriter w = new BufferedWriter(new FileWriter("generated_" + methodName + ".cpp"));
|
||||
|
||||
|
||||
CurveData loadBins = null;
|
||||
CurveData rpmBins = null;
|
||||
|
||||
if (!loadSectionName.equalsIgnoreCase("none")) {
|
||||
loadBins = CurveData.processCurve(msqFileName, loadSectionName, model, w);
|
||||
}
|
||||
|
@ -62,24 +60,10 @@ public class TS2C {
|
|||
}
|
||||
|
||||
if (!tableName.equalsIgnoreCase("none")) {
|
||||
ArrayIniField field = (ArrayIniField) model.allIniFields.get(tableName);
|
||||
StringBuilder sb = getTableCSourceCode2(msqFileName, tableName, model, loadBins, rpmBins);
|
||||
|
||||
if (field.getRows() != field.getCols())
|
||||
throw new UnsupportedOperationException("Not square table not supported yet");
|
||||
size = field.getRows();
|
||||
w.write(sb.toString());
|
||||
|
||||
float[][] table = new float[size][];
|
||||
for (int i = 0; i < size; i++) {
|
||||
table[i] = new float[size];
|
||||
}
|
||||
|
||||
BufferedReader r = readAndScroll(msqFileName, tableName);
|
||||
readTable(table, r);
|
||||
|
||||
w.write("static const float hardCoded" + tableName + "[" + size + "][" + size + "] = {\n");
|
||||
|
||||
writeTable(w, (loadIndex, rpmIndex) -> table[loadIndex][rpmIndex]);
|
||||
w.write("};\n\n");
|
||||
}
|
||||
|
||||
w.write(FINGER_PRINT);
|
||||
|
@ -97,15 +81,54 @@ public class TS2C {
|
|||
w.close();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static StringBuilder getTableCSourceCode2(String msqFileName, String tableName, IniFileModel model, CurveData loadBins, CurveData rpmBins) throws IOException {
|
||||
float[][] table = readTable(msqFileName, tableName, model);
|
||||
|
||||
return getTableCSourceCode(tableName, loadBins, rpmBins, table);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static StringBuilder getTableCSourceCode(String tableName, CurveData loadBins, CurveData rpmBins, float[][] table) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("static const float hardCoded" + tableName + "[" + table.length + "][" + table[0].length + "] = {\n");
|
||||
|
||||
writeTable(loadBins, rpmBins, sb, (loadIndex, rpmIndex) -> table[loadIndex][rpmIndex]);
|
||||
sb.append("};\n\n");
|
||||
return sb;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
private void writeTable(BufferedWriter w, ValueSource valueSource) throws IOException {
|
||||
w.write(FINGER_PRINT);
|
||||
for (int loadIndex = 0; loadIndex < loadBins.getRawData().length; loadIndex++)
|
||||
writeTableLine(valueSource, w, loadIndex);
|
||||
private static void writeTable(CurveData loadBins, CurveData rpmBins, StringBuilder sb, ValueSource valueSource) {
|
||||
sb.append(FINGER_PRINT);
|
||||
for (int loadIndex = 0; loadIndex < loadBins.getRawData().length; loadIndex++) {
|
||||
String line = writeTableLine(loadBins, rpmBins, valueSource, loadIndex);
|
||||
sb.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,23 +149,23 @@ public class TS2C {
|
|||
return reader;
|
||||
}
|
||||
|
||||
private void writeTableLine(ValueSource valueSource, BufferedWriter w, int loadIndex) throws IOException {
|
||||
private static String writeTableLine(CurveData loadBins, CurveData rpmBins, ValueSource valueSource, int loadIndex) {
|
||||
StringBuilder sb = new StringBuilder("{");
|
||||
|
||||
sb.append("/* " + loadIndex + " " + String.format("%3.3f", loadBins.getRawData()[loadIndex]) + "\t*/");
|
||||
for (int rpmIndex = 0; rpmIndex < rpmBins.getRawData().length; rpmIndex++) {
|
||||
sb.append("/* " + rpmIndex + " " + rpmBins.getRawData()[rpmIndex] + "*/" + String.format("%3.3f", valueSource.getValue(loadIndex, rpmIndex)) + ",\t");
|
||||
}
|
||||
sb.append("},\r\n");
|
||||
sb.append("},\n");
|
||||
|
||||
w.write(sb.toString());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
interface ValueSource {
|
||||
float getValue(int loadIndex, int rpmIndex);
|
||||
}
|
||||
|
||||
private void readTable(float[][] table, BufferedReader r) throws IOException {
|
||||
private static void readTable(float[][] table, BufferedReader r, int size) throws IOException {
|
||||
int index = 0;
|
||||
|
||||
while (index < size) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.opensr5.ini.field.IniField;
|
|||
import com.opensr5.io.ConfigurationImageFile;
|
||||
import com.rusefi.binaryprotocol.MsqFactory;
|
||||
import com.rusefi.tools.tune.CurveData;
|
||||
import com.rusefi.tools.tune.TS2C;
|
||||
import com.rusefi.tune.xml.Constant;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import org.junit.Before;
|
||||
|
@ -40,12 +41,41 @@ public class TuneReadWriteTest {
|
|||
assertEquals("fuelRpmBins", model.getXBin("FUELTable"));
|
||||
assertEquals("fuelLoadBins", model.getYBin("fuelTable"));
|
||||
|
||||
String xBins = model.getXBin("ignitionIatCorrTable");
|
||||
String tableName = "ignitionIatCorrTable";
|
||||
String xRpmBinsName = model.getXBin(tableName);
|
||||
String yLoadBinsName = model.getYBin(tableName);
|
||||
assertEquals("ignitionIatCorrRpmBins", xRpmBinsName);
|
||||
assertEquals("ignitionIatCorrLoadBins", yLoadBinsName);
|
||||
|
||||
CurveData xRpmCurve = CurveData.valueOf(TUNE_NAME, xRpmBinsName, model);
|
||||
CurveData yLoadCurve = CurveData.valueOf(TUNE_NAME, yLoadBinsName, model);
|
||||
|
||||
CurveData curveData = CurveData.valueOf(TUNE_NAME, xBins, model);
|
||||
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" +
|
||||
"\n", curveData.getCsourceCode());
|
||||
"\n", xRpmCurve.getCsourceCode());
|
||||
|
||||
TS2C.FINGER_PRINT = "unitest\n";
|
||||
String actual = TS2C.getTableCSourceCode2(TUNE_NAME, tableName, model, yLoadCurve, xRpmCurve).toString();
|
||||
assertEquals("static const float hardCodedignitionIatCorrTable[16][16] = {\n" +
|
||||
"unitest\n" +
|
||||
"{/* 0 -40.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 1 -30.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 2 -20.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 3 -10.000\t*//* 0 880.0*/4.000,\t/* 1 1260.0*/4.000,\t/* 2 1640.0*/4.000,\t/* 3 2020.0*/4.000,\t/* 4 2400.0*/4.000,\t/* 5 2780.0*/4.000,\t/* 6 3000.0*/4.000,\t/* 7 3380.0*/4.000,\t/* 8 3760.0*/4.000,\t/* 9 4140.0*/4.000,\t/* 10 4520.0*/4.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 4 0.000\t*//* 0 880.0*/3.500,\t/* 1 1260.0*/3.500,\t/* 2 1640.0*/3.500,\t/* 3 2020.0*/3.500,\t/* 4 2400.0*/3.500,\t/* 5 2780.0*/3.500,\t/* 6 3000.0*/3.500,\t/* 7 3380.0*/3.500,\t/* 8 3760.0*/3.500,\t/* 9 4140.0*/3.500,\t/* 10 4520.0*/3.500,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 5 10.000\t*//* 0 880.0*/3.000,\t/* 1 1260.0*/3.000,\t/* 2 1640.0*/3.000,\t/* 3 2020.0*/3.000,\t/* 4 2400.0*/3.000,\t/* 5 2780.0*/3.000,\t/* 6 3000.0*/3.000,\t/* 7 3380.0*/3.000,\t/* 8 3760.0*/3.000,\t/* 9 4140.0*/3.000,\t/* 10 4520.0*/3.000,\t/* 11 5000.0*/2.000,\t/* 12 5700.0*/2.000,\t/* 13 6500.0*/2.000,\t/* 14 7200.0*/2.000,\t/* 15 8000.0*/2.000,\t},\n" +
|
||||
"{/* 6 20.000\t*//* 0 880.0*/2.000,\t/* 1 1260.0*/2.000,\t/* 2 1640.0*/2.000,\t/* 3 2020.0*/2.000,\t/* 4 2400.0*/2.000,\t/* 5 2780.0*/2.000,\t/* 6 3000.0*/2.000,\t/* 7 3380.0*/2.000,\t/* 8 3760.0*/2.000,\t/* 9 4140.0*/2.000,\t/* 10 4520.0*/2.000,\t/* 11 5000.0*/0.000,\t/* 12 5700.0*/0.000,\t/* 13 6500.0*/0.000,\t/* 14 7200.0*/0.000,\t/* 15 8000.0*/0.000,\t},\n" +
|
||||
"{/* 7 30.000\t*//* 0 880.0*/0.000,\t/* 1 1260.0*/0.000,\t/* 2 1640.0*/0.000,\t/* 3 2020.0*/0.000,\t/* 4 2400.0*/0.000,\t/* 5 2780.0*/0.000,\t/* 6 3000.0*/0.000,\t/* 7 3380.0*/0.000,\t/* 8 3760.0*/0.000,\t/* 9 4140.0*/0.000,\t/* 10 4520.0*/0.000,\t/* 11 5000.0*/0.000,\t/* 12 5700.0*/0.000,\t/* 13 6500.0*/0.000,\t/* 14 7200.0*/0.000,\t/* 15 8000.0*/0.000,\t},\n" +
|
||||
"{/* 8 40.000\t*//* 0 880.0*/0.000,\t/* 1 1260.0*/0.000,\t/* 2 1640.0*/0.000,\t/* 3 2020.0*/0.000,\t/* 4 2400.0*/0.000,\t/* 5 2780.0*/0.000,\t/* 6 3000.0*/0.000,\t/* 7 3380.0*/0.000,\t/* 8 3760.0*/0.000,\t/* 9 4140.0*/0.000,\t/* 10 4520.0*/0.000,\t/* 11 5000.0*/0.000,\t/* 12 5700.0*/0.000,\t/* 13 6500.0*/0.000,\t/* 14 7200.0*/0.000,\t/* 15 8000.0*/0.000,\t},\n" +
|
||||
"{/* 9 50.000\t*//* 0 880.0*/0.000,\t/* 1 1260.0*/0.000,\t/* 2 1640.0*/-0.900,\t/* 3 2020.0*/-0.900,\t/* 4 2400.0*/-0.900,\t/* 5 2780.0*/-0.900,\t/* 6 3000.0*/-0.900,\t/* 7 3380.0*/-0.900,\t/* 8 3760.0*/-0.900,\t/* 9 4140.0*/-0.900,\t/* 10 4520.0*/-0.900,\t/* 11 5000.0*/-0.900,\t/* 12 5700.0*/-0.900,\t/* 13 6500.0*/-0.900,\t/* 14 7200.0*/-0.900,\t/* 15 8000.0*/-0.900,\t},\n" +
|
||||
"{/* 10 60.000\t*//* 0 880.0*/-3.300,\t/* 1 1260.0*/-3.400,\t/* 2 1640.0*/-4.900,\t/* 3 2020.0*/-4.900,\t/* 4 2400.0*/-4.900,\t/* 5 2780.0*/-4.900,\t/* 6 3000.0*/-4.400,\t/* 7 3380.0*/-4.400,\t/* 8 3760.0*/-4.400,\t/* 9 4140.0*/-4.400,\t/* 10 4520.0*/-4.400,\t/* 11 5000.0*/-0.900,\t/* 12 5700.0*/-0.900,\t/* 13 6500.0*/-0.900,\t/* 14 7200.0*/-0.900,\t/* 15 8000.0*/-0.900,\t},\n" +
|
||||
"{/* 11 70.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-2.400,\t/* 12 5700.0*/-2.400,\t/* 13 6500.0*/-2.400,\t/* 14 7200.0*/-2.400,\t/* 15 8000.0*/-2.400,\t},\n" +
|
||||
"{/* 12 80.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-2.900,\t/* 12 5700.0*/-2.900,\t/* 13 6500.0*/-2.900,\t/* 14 7200.0*/-2.900,\t/* 15 8000.0*/-2.900,\t},\n" +
|
||||
"{/* 13 90.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-3.900,\t/* 12 5700.0*/-3.900,\t/* 13 6500.0*/-3.900,\t/* 14 7200.0*/-3.900,\t/* 15 8000.0*/-3.900,\t},\n" +
|
||||
"{/* 14 100.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-3.900,\t/* 12 5700.0*/-3.900,\t/* 13 6500.0*/-3.900,\t/* 14 7200.0*/-3.900,\t/* 15 8000.0*/-3.900,\t},\n" +
|
||||
"{/* 15 110.000\t*//* 0 880.0*/-4.400,\t/* 1 1260.0*/-4.900,\t/* 2 1640.0*/-5.900,\t/* 3 2020.0*/-5.900,\t/* 4 2400.0*/-5.900,\t/* 5 2780.0*/-5.900,\t/* 6 3000.0*/-4.900,\t/* 7 3380.0*/-4.900,\t/* 8 3760.0*/-4.900,\t/* 9 4140.0*/-4.900,\t/* 10 4520.0*/-4.900,\t/* 11 5000.0*/-3.900,\t/* 12 5700.0*/-3.900,\t/* 13 6500.0*/-3.900,\t/* 14 7200.0*/-3.900,\t/* 15 8000.0*/-3.900,\t},\n" +
|
||||
"};\n" +
|
||||
"\n", actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue