From f317365b26df0bf0778e60709fe45405eefac97b Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 6 Feb 2016 22:01:40 -0500 Subject: [PATCH] auto-sync --- .../io/src/com/rusefi/binaryprotocol/BinaryProtocol.java | 7 +++++-- java_console/io/src/com/rusefi/io/IoStream.java | 2 ++ .../io/src/com/rusefi/io/serial/SerialIoStream.java | 7 +++++++ java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java | 8 +++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java index a0cb92ee74..2ce9df93d3 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -194,6 +194,8 @@ public class BinaryProtocol { while (true) { try { + if (stream.isClosed()) + return; dropPending(); stream.write((SWITCH_TO_BINARY_COMMAND + "\n").getBytes()); @@ -311,10 +313,11 @@ public class BinaryProtocol { putShort(packet, 3, swap16(offset)); putShort(packet, 5, swap16(requestSize)); - byte[] response = executeCommand(packet, "load image", false); + byte[] response = executeCommand(packet, "load image offset=" + offset, false); if (!checkResponseCode(response, RESPONSE_OK) || response.length != requestSize + 1) { - logger.error("readImage: Something is wrong, retrying..."); + String info = response == null ? "null" : ("code " + response[0] + " size " + response.length); + logger.error("readImage: Something is wrong, retrying... " + info); continue; } diff --git a/java_console/io/src/com/rusefi/io/IoStream.java b/java_console/io/src/com/rusefi/io/IoStream.java index 69ae901e89..b485727398 100644 --- a/java_console/io/src/com/rusefi/io/IoStream.java +++ b/java_console/io/src/com/rusefi/io/IoStream.java @@ -23,4 +23,6 @@ public interface IoStream { void close(); void purge(); + + boolean isClosed(); } diff --git a/java_console/io/src/com/rusefi/io/serial/SerialIoStream.java b/java_console/io/src/com/rusefi/io/serial/SerialIoStream.java index 515fdbfaa2..52167784c5 100644 --- a/java_console/io/src/com/rusefi/io/serial/SerialIoStream.java +++ b/java_console/io/src/com/rusefi/io/serial/SerialIoStream.java @@ -16,6 +16,7 @@ import java.io.IOException; public class SerialIoStream implements IoStream { private final SerialPort serialPort; private final Logger logger; + private boolean isClosed; public SerialIoStream(SerialPort serialPort, Logger logger) { this.serialPort = serialPort; @@ -24,6 +25,7 @@ public class SerialIoStream implements IoStream { @Override public void close() { + isClosed = true; try { FileLog.MAIN.logLine("CLOSING PORT..."); serialPort.closePort(); @@ -60,4 +62,9 @@ public class SerialIoStream implements IoStream { throw new IllegalStateException(e); } } + + @Override + public boolean isClosed() { + return isClosed; + } } diff --git a/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java b/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java index 63dcb0a7ea..fd2c5b7864 100644 --- a/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java +++ b/java_console/io/src/com/rusefi/io/tcp/TcpIoStream.java @@ -16,6 +16,7 @@ import java.io.OutputStream; public class TcpIoStream implements IoStream { private final InputStream input; private final OutputStream output; + private boolean isClosed; public TcpIoStream(InputStream input, OutputStream output) { if (input == null) @@ -28,7 +29,7 @@ public class TcpIoStream implements IoStream { @Override public void close() { - + isClosed = true; } @Override @@ -66,4 +67,9 @@ public class TcpIoStream implements IoStream { }); } + + @Override + public boolean isClosed() { + return isClosed; + } }