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

This commit is contained in:
Andrey 2023-11-25 19:02:56 -05:00
parent 2e797ae525
commit ddbedd213c
2 changed files with 21 additions and 8 deletions

View File

@ -28,7 +28,9 @@ import static com.rusefi.tools.tune.WriteSimulatorConfiguration.INI_FILE_FOR_SIM
public class TuneCanTool {
public static final String SRC_TEST_RESOURCES = "src/test/resources/";
private static final String FOLDER = "generated";
public static final String DEFAULT_TUNE = FOLDER + File.separator + "simulator_tune.xml";
public static final String SIMULATED_PREFIX = FOLDER + File.separator + "simulator_tune";
public static final String SIMULATED_SUFFIX = ".xml";
public static final String DEFAULT_TUNE = SIMULATED_PREFIX + SIMULATED_SUFFIX;
private static final String workingFolder = "downloaded_tunes";
private static Msq simulatorDefaultTune;

View File

@ -1,5 +1,6 @@
package com.rusefi.tools.tune;
import com.devexperts.logging.Logging;
import com.opensr5.ConfigurationImage;
import com.opensr5.ini.IniFileModel;
import com.rusefi.binaryprotocol.MsqFactory;
@ -12,24 +13,34 @@ import java.io.IOException;
import java.nio.file.Files;
import java.util.Objects;
import static com.devexperts.logging.Logging.getLogging;
public class WriteSimulatorConfiguration {
private static final Logging log = getLogging(WriteSimulatorConfiguration.class);
// f407-discovery is historically the most inclusive .ini file
public static final String INI_FILE_FOR_SIMULATOR = "../firmware/tunerstudio/generated/rusefi_f407-discovery.ini";
public static String ROOT_FOLDER = System.getProperty("ROOT_FOLDER", "");
public static void main(String[] args) throws IOException, InterruptedException, JAXBException {
System.out.printf("ROOT_FOLDER=" + ROOT_FOLDER);
try {
writeTune();
writeTune(Fields.SIMULATOR_TUNE_BIN_FILE_NAME, TuneCanTool.DEFAULT_TUNE);
String engine = "_" + 95;
writeTune(Fields.SIMULATOR_TUNE_BIN_FILE_NAME_PREFIX + engine + Fields.SIMULATOR_TUNE_BIN_FILE_NAME_SUFFIX,
TuneCanTool.SIMULATED_PREFIX + engine + TuneCanTool.SIMULATED_SUFFIX);
} catch (Throwable e) {
System.err.println("Unfortunately " + e);
log.error("Unfortunately", e);
System.exit(-1);
} finally {
// No way to set Process.exec to be a daemon, we need explicit exit
System.exit(0);
}
}
private static void writeTune() throws JAXBException, IOException {
byte[] fileContent = Files.readAllBytes(new File(Fields.SIMULATOR_TUNE_BIN_FILE_NAME).toPath());
System.out.println("Got " + fileContent.length + " from " + Fields.SIMULATOR_TUNE_BIN_FILE_NAME + " while expecting " + Fields.TOTAL_CONFIG_SIZE);
private static void writeTune(String tuneBinFileName, String outputXmlFileName) throws JAXBException, IOException {
byte[] fileContent = Files.readAllBytes(new File(ROOT_FOLDER + tuneBinFileName).toPath());
System.out.println("Got " + fileContent.length + " from " + tuneBinFileName + " while expecting " + Fields.TOTAL_CONFIG_SIZE);
if (fileContent.length != Fields.TOTAL_CONFIG_SIZE)
throw new IllegalStateException("Unexpected image size " + fileContent.length);
ConfigurationImage configuration = new ConfigurationImage(fileContent);
@ -38,9 +49,9 @@ public class WriteSimulatorConfiguration {
if (ini == null)
throw new IllegalStateException("Not found " + INI_FILE_FOR_SIMULATOR);
Msq m = MsqFactory.valueOf(configuration, ini);
m.writeXmlFile(TuneCanTool.DEFAULT_TUNE);
m.writeXmlFile(ROOT_FOLDER + outputXmlFileName);
Msq newTuneJustToValidate = Msq.readTune(TuneCanTool.DEFAULT_TUNE);
Msq newTuneJustToValidate = Msq.readTune(ROOT_FOLDER + outputXmlFileName);
System.out.println("Looks valid " + newTuneJustToValidate);
}
}