From a0028d3483f49874c6d80cd81c798ffb71a0a7ba Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 22 Mar 2015 20:05:14 -0500 Subject: [PATCH] auto-sync --- java_console/autotest/src/com/rusefi/AutoTest.java | 12 +++++++++++- .../autotest/src/com/rusefi/EnduranceTest.java | 4 ++-- java_console/autotest/src/com/rusefi/IoUtil.java | 9 +++++++++ java_console/io/src/com/rusefi/FileLog.java | 5 +++++ java_console/io/src/com/rusefi/io/CommandQueue.java | 7 +++---- .../io/src/com/rusefi/io/serial/PortHolder.java | 2 ++ 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index 6a136ef342..b519f4a6ac 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -45,6 +45,8 @@ public class AutoTest { private static void testMitsu() { setEngineType(16); String msg = "Mitsubishi"; + IoUtil.changeRpm(200); + IoUtil.changeRpm(1200); // todo: add more content } @@ -58,7 +60,7 @@ public class AutoTest { static void setEngineType(int type) { currentEngineType = type; - sendCommand("set_engine_type " + type, COMPLEX_COMMAND_RETRY, 600); + sendCommand("set_engine_type " + type, COMPLEX_COMMAND_RETRY, 30); sleep(10); sendCommand("enable self_stimulation"); } @@ -326,6 +328,14 @@ public class AutoTest { } public static void main(String[] args) throws InterruptedException { + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + e.printStackTrace(); + System.exit(-1); + } + }); + long start = System.currentTimeMillis(); FileLog.SIMULATOR_CONSOLE.start(); FileLog.MAIN.start(); diff --git a/java_console/autotest/src/com/rusefi/EnduranceTest.java b/java_console/autotest/src/com/rusefi/EnduranceTest.java index 538b397811..28e6e17e61 100644 --- a/java_console/autotest/src/com/rusefi/EnduranceTest.java +++ b/java_console/autotest/src/com/rusefi/EnduranceTest.java @@ -24,12 +24,12 @@ public class EnduranceTest { IoUtil.realHardwareConnect(port); for (int i = 0; i < count; i++) { AutoTest.currentEngineType = 3; - sendCommand("set_engine_type " + 3, AutoTest.COMPLEX_COMMAND_RETRY, 600); + sendCommand("set_engine_type " + 3, AutoTest.COMPLEX_COMMAND_RETRY, 60); sleep(2); sendCommand("enable self_stimulation"); // IoUtil.changeRpm(1200); AutoTest.currentEngineType = 28; - sendCommand("set_engine_type " + 28, AutoTest.COMPLEX_COMMAND_RETRY, 600); + sendCommand("set_engine_type " + 28, AutoTest.COMPLEX_COMMAND_RETRY, 60); sleep(2); FileLog.MAIN.logLine("++++++++++++++++++++++++++++++++++++ " + i + " +++++++++++++++"); } diff --git a/java_console/autotest/src/com/rusefi/IoUtil.java b/java_console/autotest/src/com/rusefi/IoUtil.java index 11dcddbd7c..b67cdd0d1c 100644 --- a/java_console/autotest/src/com/rusefi/IoUtil.java +++ b/java_console/autotest/src/com/rusefi/IoUtil.java @@ -163,6 +163,7 @@ public class IoUtil { static void realHardwareConnect(String port) { LinkManager.start(port); + final CountDownLatch connected = new CountDownLatch(1); LinkManager.open(new LinkManager.LinkStateListener() { @Override public void onConnectionFailed() { @@ -172,10 +173,18 @@ public class IoUtil { @Override public void onConnectionEstablished() { + connected.countDown(); } }); LinkManager.engineState.registerStringValueAction(EngineState.RUS_EFI_VERSION_TAG, (EngineState.ValueCallback) EngineState.ValueCallback.VOID); LinkManager.engineState.registerStringValueAction(EngineState.OUTPIN_TAG, (EngineState.ValueCallback) EngineState.ValueCallback.VOID); LinkManager.engineState.registerStringValueAction(AverageAnglesUtil.KEY, (EngineState.ValueCallback) EngineState.ValueCallback.VOID); + try { + connected.await(60, TimeUnit.SECONDS); + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + if (connected.getCount() > 0) + throw new IllegalStateException("Not connected in time"); } } diff --git a/java_console/io/src/com/rusefi/FileLog.java b/java_console/io/src/com/rusefi/FileLog.java index c6ec6c14c2..9e9014278b 100644 --- a/java_console/io/src/com/rusefi/FileLog.java +++ b/java_console/io/src/com/rusefi/FileLog.java @@ -105,4 +105,9 @@ public enum FileLog { OutputStreamWriter os = new OutputStreamWriter(fileLog); exception.printStackTrace(new PrintWriter(os)); } + + public void logException(String msg, Throwable e) { + logLine(msg + e); + e.printStackTrace(); + } } \ No newline at end of file diff --git a/java_console/io/src/com/rusefi/io/CommandQueue.java b/java_console/io/src/com/rusefi/io/CommandQueue.java index 6ffcac5a70..bf5220516c 100644 --- a/java_console/io/src/com/rusefi/io/CommandQueue.java +++ b/java_console/io/src/com/rusefi/io/CommandQueue.java @@ -36,10 +36,9 @@ public class CommandQueue { while (true) { try { sendPendingCommand(); - } catch (InterruptedException e) { - FileLog.MAIN.logLine("CommandQueue error"); - e.printStackTrace(); - throw new IllegalStateException(e); + } catch (Throwable e) { + FileLog.MAIN.logException("CommandQueue error", e); + System.exit(-2); } } } diff --git a/java_console/io/src/com/rusefi/io/serial/PortHolder.java b/java_console/io/src/com/rusefi/io/serial/PortHolder.java index 55d9295769..c7dee3b7fd 100644 --- a/java_console/io/src/com/rusefi/io/serial/PortHolder.java +++ b/java_console/io/src/com/rusefi/io/serial/PortHolder.java @@ -164,6 +164,8 @@ public class PortHolder { Future f = LinkManager.COMMUNICATION_EXECUTOR.submit(new Runnable() { @Override public void run() { + if (bp == null) + throw new NullPointerException("bp"); bp.sendTextCommand(command); }