diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index 2c3110bc79..a3bcae3bd8 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -9,13 +9,11 @@ import com.rusefi.core.MessagesCentral; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.io.CommandQueue; -import com.rusefi.io.ConnectionStatus; import com.rusefi.waves.EngineChart; import com.rusefi.waves.EngineReport; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Function; import static com.rusefi.IoUtil.*; import static com.rusefi.IoUtil.getEnableCommand; @@ -72,12 +70,21 @@ public class AutoTest { testFordFiesta(); } + private static Function FAIL = new Function() { + @Override + public Object apply(String errorCode) { + if (errorCode != null) + throw new IllegalStateException("Failed " + errorCode); + return null; + } + }; + private static void testVW_60_2() { setEngineType(32); changeRpm(900); // TODO: we shall get this RPM higher! // first let's get to expected RPM - assertRpmDoesNotJump(2000); + assertRpmDoesNotJump(2000, 4, 30, FAIL); } private static void testV12() { @@ -85,25 +92,24 @@ public class AutoTest { changeRpm(700); // TODO: we shall get this RPM higher! // first let's get to expected RPM - assertRpmDoesNotJump(1200); + assertRpmDoesNotJump(1200, 4, 30, FAIL); } - private static void assertRpmDoesNotJump(int rpm) { + public static void assertRpmDoesNotJump(int rpm, int settleTime, int testDuration, Function callback) { changeRpm(rpm); - sleep(4); - AtomicReference failure = new AtomicReference(); + sleep(settleTime); + AtomicReference result = new AtomicReference<>(); SensorCentral.SensorListener listener = new SensorCentral.SensorListener() { @Override public void onSensorUpdate(double value) { double actualRpm = SensorCentral.getInstance().getValue(Sensor.RPM); if (!isCloseEnough(rpm, actualRpm)) - failure.set("Got " + actualRpm + " while trying to stay at " + rpm); + result.set("Got " + actualRpm + " while trying to stay at " + rpm); } }; SensorCentral.getInstance().addListener(Sensor.RPM, listener); - sleep(30); - if (failure.get() != null) - throw new IllegalStateException("Failed " + failure.get()); + sleep(testDuration); + callback.apply(result.get()); SensorCentral.getInstance().removeListener(Sensor.RPM, listener); } diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index c8c8120d36..aecddee738 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -49,7 +49,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see EngineSnifferPanel */ public class Launcher { - public static final int CONSOLE_VERSION = 20200422; + public static final int CONSOLE_VERSION = 20200424; public static final String INI_FILE_PATH = System.getProperty("ini_file_path", ".."); public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", ".."); public static final String TOOLS_PATH = System.getProperty("tools_path", "."); diff --git a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java index 3609866c09..55078e4108 100644 --- a/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java +++ b/java_console/ui/src/com/rusefi/ui/widgets/AnyCommand.java @@ -1,6 +1,7 @@ package com.rusefi.ui.widgets; import com.fathzer.soft.javaluator.DoubleEvaluator; +import com.rusefi.AutoTest; import com.rusefi.FileLog; import com.rusefi.InfixConverter; import com.rusefi.core.MessagesCentral; @@ -19,6 +20,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; /** * Date: 3/20/13 @@ -113,7 +115,7 @@ public class AnyCommand { if (cmd == null) { /** * {@link #DECODE_RPN} for example does not send out anything - */ + */ return; } if (listener != null) @@ -128,6 +130,9 @@ public class AnyCommand { try { if (rawCommand.startsWith("eval" + " ")) { return prepareEvalCommand(rawCommand); + } else if (rawCommand.toLowerCase().startsWith("stim_check" + " ")) { + handleStimulationSelfCheck(rawCommand); + return null; } else if (rawCommand.toLowerCase().startsWith(DECODE_RPN + " ")) { handleDecodeRpn(rawCommand); return null; @@ -142,6 +147,33 @@ public class AnyCommand { } } + private static void handleStimulationSelfCheck(String rawCommand) { + String[] parts = rawCommand.split(" ", 4); + if (parts.length != 3) + return; // let's ignore invalid command + int rpm = Integer.parseInt(parts[1]); + int settleTime = Integer.parseInt(parts[2]); + int durationTime = Integer.parseInt(parts[3]); + new Thread(new Runnable() { + @Override + public void run() { + MessagesCentral.getInstance().postMessage(AnyCommand.class, "Will test with RPM" + rpm + ", settle time" + settleTime + "s and duration" + durationTime + "s"); + Function callback = new Function() { + @Override + public Object apply(String status) { + if (status == null) { + MessagesCentral.getInstance().postMessage(AnyCommand.class, rpm + " worked!"); + } else { + MessagesCentral.getInstance().postMessage(AnyCommand.class, rpm + " failed " + status); + } + return null; + } + }; + AutoTest.assertRpmDoesNotJump(rpm, settleTime, durationTime, callback); + } + }).start(); + } + private static String prepareSetFsioCommand(String rawCommand) { String[] parts = rawCommand.split(" ", 3); if (parts.length != 3)