From ddbedd213c4414d27bcd33e521158dc0d3ba744d Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 25 Nov 2023 19:02:56 -0500 Subject: [PATCH] only:EPIC: Improve toolset for default tune canned tune generation #4871 --- .../com/rusefi/tools/tune/TuneCanTool.java | 4 ++- .../tune/WriteSimulatorConfiguration.java | 25 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) 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 929327aa74..d339f8a2d5 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 @@ -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; diff --git a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/WriteSimulatorConfiguration.java b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/WriteSimulatorConfiguration.java index 9bbe94d812..af0ca9cf27 100644 --- a/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/WriteSimulatorConfiguration.java +++ b/java_tools/tune-tools/src/main/java/com/rusefi/tools/tune/WriteSimulatorConfiguration.java @@ -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); } }