From d0bb16d42f840f8fbe509b3af98e6a9b766151fc Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 16 Jun 2023 21:22:40 -0400 Subject: [PATCH] only:Improve toolset for default tune canned tune generation #4871 --- .github/workflows/build-simulator.yaml | 48 +++++++++---------- firmware/integration/rusefi_config.txt | 2 + .../java/com/rusefi/SimulatorExecHelper.java | 2 +- .../tools/WriteSimulatorConfiguration.java | 18 +++---- simulator/simulator/rusEfiFunctionalTest.cpp | 8 ++++ 5 files changed, 44 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-simulator.yaml b/.github/workflows/build-simulator.yaml index eaf831cc87..a22f8dd3c2 100644 --- a/.github/workflows/build-simulator.yaml +++ b/.github/workflows/build-simulator.yaml @@ -50,30 +50,30 @@ jobs: working-directory: ./simulator/ run: ./build/rusefi_simulator 10 -# - name: Load Default Tune from Linux Simulator -# working-directory: ./simulator/ -# run: ./write_tune.sh -# -# - name: Commit fresh generated default simulator tune -# env: -# ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' -# run: | -# git config --local user.email "action@github.com" -# git config --local user.name "GitHub gen-default-tune Action" -# git add simulator/generated -# git status -# OUT=$(git commit -am "Auto-generated default tune" 2>&1) || echo "commit failed, finding out why" -# if echo "$OUT" | grep 'nothing to commit'; then -# echo "default tune: looks like nothing to commit" -# echo "::set-env name=NOCOMMIT::true" -# exit 0 -# elif echo "$OUT" | grep 'changed'; then -# echo "default tune: looks like something has changed" -# exit 0 -# else -# echo "default tune: looks like something unexpected" -# exit 1 -# fi + - name: Load Default Tune from Linux Simulator + working-directory: ./simulator/ + run: ./write_tune.sh + + - name: Commit fresh generated default simulator tune + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub gen-default-tune Action" + git add 'simulator/generated/*xml' + git status + OUT=$(git commit -am "Auto-generated default tune" 2>&1) || echo "commit failed, finding out why" + if echo "$OUT" | grep 'nothing to commit'; then + echo "default tune: looks like nothing to commit" + echo "::set-env name=NOCOMMIT::true" + exit 0 + elif echo "$OUT" | grep 'changed'; then + echo "default tune: looks like something has changed" + exit 0 + else + echo "default tune: looks like something unexpected" + exit 1 + fi - name: Upload Linux built simulator uses: actions/upload-artifact@v3 diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index ce2f8d6edc..ce82199238 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -2132,6 +2132,8 @@ end_struct #define PROTOCOL_COIL1_SHORT_NAME "c1" #define PROTOCOL_INJ1_SHORT_NAME "i1" +#define SIMULATOR_TUNE_BIN_FILE_NAME "generated/simulator_tune_image.bin" + ! some board files override this value using prepend file #define ts_show_hip9011 false #define ts_show_tps_sent false diff --git a/java_console/autotest/src/main/java/com/rusefi/SimulatorExecHelper.java b/java_console/autotest/src/main/java/com/rusefi/SimulatorExecHelper.java index 27d5c15112..e4279a1639 100644 --- a/java_console/autotest/src/main/java/com/rusefi/SimulatorExecHelper.java +++ b/java_console/autotest/src/main/java/com/rusefi/SimulatorExecHelper.java @@ -78,7 +78,7 @@ public class SimulatorExecHelper { BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream())); try { - String prefix = "from console: "; + String prefix = "ERROR from console: "; Consumer PRINT_AND_LOG = string -> { System.out.println(prefix + string); FileLog.SIMULATOR_CONSOLE.logLine(string); diff --git a/java_console/ui/src/main/java/com/rusefi/tools/WriteSimulatorConfiguration.java b/java_console/ui/src/main/java/com/rusefi/tools/WriteSimulatorConfiguration.java index 0f8711013c..d1a5037155 100644 --- a/java_console/ui/src/main/java/com/rusefi/tools/WriteSimulatorConfiguration.java +++ b/java_console/ui/src/main/java/com/rusefi/tools/WriteSimulatorConfiguration.java @@ -2,15 +2,14 @@ package com.rusefi.tools; import com.opensr5.ConfigurationImage; import com.opensr5.ini.IniFileModel; -import com.rusefi.IoUtil; -import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.MsqFactory; -import com.rusefi.io.LinkManager; +import com.rusefi.config.generated.Fields; import com.rusefi.tune.xml.Msq; import javax.xml.bind.JAXBException; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.Objects; public class WriteSimulatorConfiguration { @@ -27,17 +26,18 @@ public class WriteSimulatorConfiguration { } } - private static void writeTune() throws InterruptedException, JAXBException, IOException { - LinkManager linkManager = new LinkManager(); - IoUtil.connectToSimulator(linkManager, true); - BinaryProtocol bp = Objects.requireNonNull(linkManager.getBinaryProtocol(), "getBinaryProtocol"); - ConfigurationImage configuration = bp.getControllerConfiguration(); + private static void writeTune() throws JAXBException, IOException { + String s = "generated/simulator_tune_image.bin"; + byte[] fileContent = Files.readAllBytes(new File(s).toPath()); + System.out.println("Got " + fileContent.length + " from " + s + " 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); System.out.println("Got " + Objects.requireNonNull(configuration, "configuration")); IniFileModel ini = new IniFileModel().readIniFile(INI_FILE_FOR_SIMULATOR); if (ini == null) throw new IllegalStateException("Not found " + INI_FILE_FOR_SIMULATOR); Msq m = MsqFactory.valueOf(configuration, ini); - new File(FOLDER).mkdirs(); m.writeXmlFile(FOLDER + File.separator + "simulator_tune.xml"); } } diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index dd2f8a0008..f33d51b1b4 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -86,6 +86,12 @@ static void runChprintfTest() { static void runCanGpioTest() { } +static void writeSimulatorTune() { + FILE *ptr = fopen("generated/simulator_tune_image.bin", "wb"); + fwrite(&persistentState.persistentConfiguration, 1, sizeof(persistentState.persistentConfiguration), ptr); + fclose(ptr); +} + void rusEfiFunctionalTest(void) { printToConsole("Running rusEFI simulator version:"); static char versionBuffer[20]; @@ -112,6 +118,8 @@ void rusEfiFunctionalTest(void) { initStatusLoop(); + writeSimulatorTune(); + /** * !!!! TESTS ! */