diff --git a/java_console/io/src/com/rusefi/Timeouts.java b/java_console/io/src/com/rusefi/Timeouts.java index ffc83bd426..ab2ba59231 100644 --- a/java_console/io/src/com/rusefi/Timeouts.java +++ b/java_console/io/src/com/rusefi/Timeouts.java @@ -6,10 +6,11 @@ package com.rusefi; public interface Timeouts { int SECOND = 1000; int COMMAND_TIMEOUT_SEC = 10; // seconds - int CONNECTION_RESTART_DELAY = 20 * SECOND; int BINARY_IO_TIMEOUT = 5 * SECOND; int CMD_TIMEOUT = 20; int READ_IMAGE_TIMEOUT = 60 * SECOND; + + int CONNECTION_RESTART_DELAY = 20 * SECOND; int CS_TIMEOUT = 3000; } diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java index f30133045c..e4a95d0580 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -2,12 +2,10 @@ package com.rusefi.binaryprotocol; import com.rusefi.*; import com.rusefi.config.FieldType; -import com.rusefi.core.MessagesCentral; import com.rusefi.core.Pair; import com.rusefi.core.Sensor; import com.rusefi.core.SensorCentral; import com.rusefi.io.*; -import com.rusefi.io.serial.PortHolder; import com.rusefi.io.serial.SerialIoStream; import jssc.SerialPort; import jssc.SerialPortException; @@ -102,7 +100,7 @@ public class BinaryProtocol { public void doSend(final String command, boolean fireEvent) throws InterruptedException { FileLog.MAIN.logLine("Sending [" + command + "]"); - if (fireEvent) { + if (fireEvent && LinkManager.LOG_LEVEL.isDebugEnabled()) { CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(BinaryProtocol.class, "Sending [" + command + "]"); } @@ -129,7 +127,7 @@ public class BinaryProtocol { /** * this here to make CommandQueue happy */ - MessagesCentral.getInstance().postMessage(PortHolder.class, CommandQueue.CONFIRMATION_PREFIX + command); + CommandQueue.getInstance().handleConfirmationMessage(CommandQueue.CONFIRMATION_PREFIX + command); } /** diff --git a/java_console/io/src/com/rusefi/io/CommandQueue.java b/java_console/io/src/com/rusefi/io/CommandQueue.java index 4bb45cd6eb..46b654a3ce 100644 --- a/java_console/io/src/com/rusefi/io/CommandQueue.java +++ b/java_console/io/src/com/rusefi/io/CommandQueue.java @@ -9,7 +9,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; /** - * This class keeps re-sending a command till a proper confirmation is received + * This singleton keeps re-sending commands till a proper confirmation is received + * *

* Date: 1/7/13 * (c) Andrey Belomutskiy @@ -115,27 +116,23 @@ public class CommandQueue { Thread thread = new Thread(runnable, "Commands Queue"); thread.setDaemon(true); thread.start(); - final MessagesCentral mc = MessagesCentral.getInstance(); - mc.addListener(new MessagesCentral.MessageListener() { - @Override - public void onMessage(Class clazz, String message) { - if (message.startsWith(CONFIRMATION_PREFIX)) - handleConfirmationMessage(message, mc); - } - }); } /** * this method handles command confirmations packed as * TODO: add example, todo: refactor method and add unit test */ - private void handleConfirmationMessage(final String message, MessagesCentral mc) { + public void handleConfirmationMessage(final String message) { + MessagesCentral mc = MessagesCentral.getInstance(); String confirmation = LinkManager.unpackConfirmation(message); if (confirmation == null) mc.postMessage(CommandQueue.class, "Broken confirmation length: " + message); pendingConfirmations.add(confirmation); - mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size()); + if (LinkManager.LOG_LEVEL.isDebugEnabled()) + mc.postMessage(CommandQueue.class, "got valid conf! " + confirmation + ", still pending: " + pendingCommands.size()); + // FileLog.MAIN.logLine("templog got valid conf " + confirmation + " " + System.currentTimeMillis() + " " + new Date()); + synchronized (lock) { lock.notifyAll(); } diff --git a/java_console/io/src/com/rusefi/io/ConnectionStatus.java b/java_console/io/src/com/rusefi/io/ConnectionStatus.java index f0f92290a7..46b5c610da 100644 --- a/java_console/io/src/com/rusefi/io/ConnectionStatus.java +++ b/java_console/io/src/com/rusefi/io/ConnectionStatus.java @@ -34,7 +34,7 @@ public class ConnectionStatus { private final Timer timer = new Timer(Timeouts.CS_TIMEOUT, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - setValue(Value.NOT_CONNECTED); +// setValue(Value.NOT_CONNECTED); } }); diff --git a/java_console/io/src/com/rusefi/io/ConnectionWatchdog.java b/java_console/io/src/com/rusefi/io/ConnectionWatchdog.java index 5559a5beb9..c15cf5e254 100644 --- a/java_console/io/src/com/rusefi/io/ConnectionWatchdog.java +++ b/java_console/io/src/com/rusefi/io/ConnectionWatchdog.java @@ -15,7 +15,7 @@ public class ConnectionWatchdog { public void actionPerformed(ActionEvent e) { FileLog.MAIN.logLine("ConnectionWatchdog.reconnectTimer restarting"); LinkManager.restart(); - reconnectTimer.restart(); + onDataArrived(); } }); @@ -23,20 +23,20 @@ public class ConnectionWatchdog { } public static void start() { - reconnectTimer.restart(); + onDataArrived(); LinkManager.engineState.timeListeners.add(new EngineTimeListener() { @Override public void onTime(double time) { - /** - * this timer will reconnect - */ - reconnectTimer.restart(); + onDataArrived(); } }); } public static void onDataArrived() { + /** + * this timer will reconnect + */ reconnectTimer.restart(); } } \ No newline at end of file diff --git a/java_console/io/src/com/rusefi/io/LinkManager.java b/java_console/io/src/com/rusefi/io/LinkManager.java index e2315a10c8..a5d41f50e1 100644 --- a/java_console/io/src/com/rusefi/io/LinkManager.java +++ b/java_console/io/src/com/rusefi/io/LinkManager.java @@ -13,6 +13,19 @@ import java.util.concurrent.*; * 3/3/14 */ public class LinkManager { + public enum LogLevel { + INFO, + DEBUG, + TRACE; + + public boolean isDebugEnabled() { + return this == DEBUG || this == TRACE; + } + } + + @NotNull + public static LogLevel LOG_LEVEL = LogLevel.INFO; + public static LinkDecoder ENCODER = new LinkDecoder() { @Override public String unpack(String packedLine) { @@ -96,6 +109,7 @@ public class LinkManager { } public static void restart() { + ConnectionStatus.INSTANCE.setValue(ConnectionStatus.Value.NOT_CONNECTED); connector.restart(); } diff --git a/java_console/models/src/com/rusefi/core/MessagesCentral.java b/java_console/models/src/com/rusefi/core/MessagesCentral.java index d987459190..07e1a20ef6 100644 --- a/java_console/models/src/com/rusefi/core/MessagesCentral.java +++ b/java_console/models/src/com/rusefi/core/MessagesCentral.java @@ -5,6 +5,7 @@ import com.rusefi.io.CommunicationLoggingHolder; import com.rusefi.io.CommunicationLoggingListener; import javax.swing.*; +import java.util.LinkedHashMap; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index 9cc096098a..6cd86982c3 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -36,7 +36,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see EngineSnifferPanel */ public class Launcher { - public static final int CONSOLE_VERSION = 20160321; + public static final int CONSOLE_VERSION = 20160402; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; @@ -236,6 +236,9 @@ public class Launcher { JustOneInstance.onStart(); try { boolean isPortDefined = args.length > 0; + boolean isBaudRateDefined = args.length > 1; + if (isBaudRateDefined) + PortHolder.BAUD_RATE = Integer.parseInt(args[1]); if (isPortDefined) { new Launcher(args[0]); } else {