rusEFI console to compare current bundle against auto-DFU bundle #3266
smaller step forward
This commit is contained in:
parent
ce87e995e8
commit
4f8cd915ae
|
@ -2,7 +2,6 @@ package com.rusefi.autodetect;
|
|||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -51,7 +50,7 @@ public class PortDetector {
|
|||
Thread thread = AUTO_DETECT_PORT.newThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new SerialAutoChecker(serialPort, portFound).run(result, callback);
|
||||
new SerialAutoChecker(serialPort, portFound).openAndCheckResponse(result, callback);
|
||||
}
|
||||
});
|
||||
serialFinder.add(thread);
|
||||
|
|
|
@ -24,30 +24,33 @@ public class SerialAutoChecker {
|
|||
this.portFound = portFound;
|
||||
}
|
||||
|
||||
public void run(AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) {
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
|
||||
public String checkResponse(IoStream stream, Function<CallbackContext, Void> callback) {
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
boolean isPortFound = false;
|
||||
String signature;
|
||||
try {
|
||||
HelloCommand.send(stream);
|
||||
byte[] response = incomingData.getPacket("auto detect");
|
||||
if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK))
|
||||
return;
|
||||
signature = new String(response, 1, response.length - 1);
|
||||
log.info("Got signature=" + signature + " from " + serialPort);
|
||||
if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
|
||||
if (callback != null) {
|
||||
callback.apply(new CallbackContext(stream, signature));
|
||||
}
|
||||
isPortFound = true;
|
||||
return null;
|
||||
String signature = new String(response, 1, response.length - 1);
|
||||
if (!signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
|
||||
return null;
|
||||
}
|
||||
log.info("Got signature=" + signature + " from " + serialPort);
|
||||
if (callback != null) {
|
||||
callback.apply(new CallbackContext(stream, signature));
|
||||
}
|
||||
return signature;
|
||||
} catch (IOException ignore) {
|
||||
return;
|
||||
} finally {
|
||||
stream.close();
|
||||
return null;
|
||||
}
|
||||
if (isPortFound) {
|
||||
}
|
||||
|
||||
public void openAndCheckResponse(AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) {
|
||||
String signature;
|
||||
try (IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort)) {
|
||||
signature = checkResponse(stream, callback);
|
||||
}
|
||||
if (signature != null) {
|
||||
/**
|
||||
* propagating result after closing the port so that it could be used right away
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue