rusEFI console to compare current bundle against auto-DFU bundle #3266

smaller step forward
This commit is contained in:
rusefillc 2021-09-26 00:31:47 -04:00
parent ce87e995e8
commit 4f8cd915ae
2 changed files with 20 additions and 18 deletions

View File

@ -2,7 +2,6 @@ package com.rusefi.autodetect;
import com.devexperts.logging.Logging; import com.devexperts.logging.Logging;
import com.rusefi.NamedThreadFactory; import com.rusefi.NamedThreadFactory;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager; import com.rusefi.io.LinkManager;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -51,7 +50,7 @@ public class PortDetector {
Thread thread = AUTO_DETECT_PORT.newThread(new Runnable() { Thread thread = AUTO_DETECT_PORT.newThread(new Runnable() {
@Override @Override
public void run() { public void run() {
new SerialAutoChecker(serialPort, portFound).run(result, callback); new SerialAutoChecker(serialPort, portFound).openAndCheckResponse(result, callback);
} }
}); });
serialFinder.add(thread); serialFinder.add(thread);

View File

@ -24,30 +24,33 @@ public class SerialAutoChecker {
this.portFound = portFound; this.portFound = portFound;
} }
public void run(AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) { public String checkResponse(IoStream stream, Function<CallbackContext, Void> callback) {
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
IncomingDataBuffer incomingData = stream.getDataBuffer(); IncomingDataBuffer incomingData = stream.getDataBuffer();
boolean isPortFound = false;
String signature;
try { try {
HelloCommand.send(stream); HelloCommand.send(stream);
byte[] response = incomingData.getPacket("auto detect"); byte[] response = incomingData.getPacket("auto detect");
if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK)) if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK))
return; return null;
signature = new String(response, 1, response.length - 1); String signature = new String(response, 1, response.length - 1);
log.info("Got signature=" + signature + " from " + serialPort); if (!signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) { return null;
if (callback != null) {
callback.apply(new CallbackContext(stream, signature));
}
isPortFound = true;
} }
log.info("Got signature=" + signature + " from " + serialPort);
if (callback != null) {
callback.apply(new CallbackContext(stream, signature));
}
return signature;
} catch (IOException ignore) { } catch (IOException ignore) {
return; return null;
} finally {
stream.close();
} }
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 * propagating result after closing the port so that it could be used right away
*/ */