auto-sync
This commit is contained in:
parent
eeec275bc6
commit
f317365b26
|
@ -194,6 +194,8 @@ public class BinaryProtocol {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
if (stream.isClosed())
|
||||||
|
return;
|
||||||
dropPending();
|
dropPending();
|
||||||
|
|
||||||
stream.write((SWITCH_TO_BINARY_COMMAND + "\n").getBytes());
|
stream.write((SWITCH_TO_BINARY_COMMAND + "\n").getBytes());
|
||||||
|
@ -311,10 +313,11 @@ public class BinaryProtocol {
|
||||||
putShort(packet, 3, swap16(offset));
|
putShort(packet, 3, swap16(offset));
|
||||||
putShort(packet, 5, swap16(requestSize));
|
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) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,4 +23,6 @@ public interface IoStream {
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void purge();
|
void purge();
|
||||||
|
|
||||||
|
boolean isClosed();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.io.IOException;
|
||||||
public class SerialIoStream implements IoStream {
|
public class SerialIoStream implements IoStream {
|
||||||
private final SerialPort serialPort;
|
private final SerialPort serialPort;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
private boolean isClosed;
|
||||||
|
|
||||||
public SerialIoStream(SerialPort serialPort, Logger logger) {
|
public SerialIoStream(SerialPort serialPort, Logger logger) {
|
||||||
this.serialPort = serialPort;
|
this.serialPort = serialPort;
|
||||||
|
@ -24,6 +25,7 @@ public class SerialIoStream implements IoStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
isClosed = true;
|
||||||
try {
|
try {
|
||||||
FileLog.MAIN.logLine("CLOSING PORT...");
|
FileLog.MAIN.logLine("CLOSING PORT...");
|
||||||
serialPort.closePort();
|
serialPort.closePort();
|
||||||
|
@ -60,4 +62,9 @@ public class SerialIoStream implements IoStream {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return isClosed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import java.io.OutputStream;
|
||||||
public class TcpIoStream implements IoStream {
|
public class TcpIoStream implements IoStream {
|
||||||
private final InputStream input;
|
private final InputStream input;
|
||||||
private final OutputStream output;
|
private final OutputStream output;
|
||||||
|
private boolean isClosed;
|
||||||
|
|
||||||
public TcpIoStream(InputStream input, OutputStream output) {
|
public TcpIoStream(InputStream input, OutputStream output) {
|
||||||
if (input == null)
|
if (input == null)
|
||||||
|
@ -28,7 +29,7 @@ public class TcpIoStream implements IoStream {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
|
isClosed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,4 +67,9 @@ public class TcpIoStream implements IoStream {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isClosed() {
|
||||||
|
return isClosed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue