auto-sync

This commit is contained in:
rusEfi 2016-02-06 22:01:40 -05:00
parent eeec275bc6
commit f317365b26
4 changed files with 21 additions and 3 deletions

View File

@ -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;
}

View File

@ -23,4 +23,6 @@ public interface IoStream {
void close();
void purge();
boolean isClosed();
}

View File

@ -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;
}
}

View File

@ -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;
}
}