From 5f06541757ae3885618ae07f98fb6226de6e3a06 Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 5 Apr 2017 17:28:38 -0400 Subject: [PATCH] better fatal error handling --- .../autotest/src/com/rusefi/AutoTest.java | 23 +++++++++++++++++-- .../src/com/rusefi/io/ConnectionStatus.java | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index 91d7fa57f6..83a9e37fcd 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -1,14 +1,15 @@ package com.rusefi; +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 static com.rusefi.IoUtil.changeRpm; import static com.rusefi.TestingUtils.nextChart; -import static com.rusefi.IoUtil.sendCommand; import static com.rusefi.IoUtil.sleep; import static com.rusefi.TestingUtils.*; import static com.rusefi.waves.EngineReport.isCloseEnough; @@ -24,8 +25,17 @@ import static com.rusefi.waves.EngineReport.isCloseEnough; public class AutoTest { public static final int COMPLEX_COMMAND_RETRY = 10000; static int currentEngineType; + private static String fatalError; static void mainTestBody() { + MessagesCentral.getInstance().addListener(new MessagesCentral.MessageListener() { + @Override + public void onMessage(Class clazz, String message) { + if (message.startsWith(ConnectionStatus.FATAL_MESSAGE_PREFIX)) + fatalError = message; + } + }); + sendCommand("fl 1"); // just in case it was disabled testCustomEngine(); testMazdaMiata2003(); @@ -410,6 +420,15 @@ public class AutoTest { assertWaveNull("hard limit check", chart, EngineChart.INJECTOR_1); } + private static void sendCommand(String command) { + sendCommand(command, CommandQueue.DEFAULT_TIMEOUT, Timeouts.CMD_TIMEOUT); + } + + private static void sendCommand(String command, int retryTimeoutMs, int totalTimeoutSeconds) { + assertNull("Fatal not expected", fatalError); + IoUtil.sendCommand(command, retryTimeoutMs, totalTimeoutSeconds); + } + private static void assertEquals(double expected, double actual) { assertEquals("", expected, actual); } diff --git a/java_console/io/src/com/rusefi/io/ConnectionStatus.java b/java_console/io/src/com/rusefi/io/ConnectionStatus.java index 46b5c610da..6e6c224f60 100644 --- a/java_console/io/src/com/rusefi/io/ConnectionStatus.java +++ b/java_console/io/src/com/rusefi/io/ConnectionStatus.java @@ -18,7 +18,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class ConnectionStatus { // todo: react to any message as connected? how to know if message from controller, not internal message? - private static final String FATAL_MESSAGE_PREFIX = "FATAL"; + public static final String FATAL_MESSAGE_PREFIX = "FATAL"; @NotNull private Value value = Value.NOT_CONNECTED;