rusEFI console to compare current bundle against auto-DFU bundle #3266
smaller step forward
This commit is contained in:
parent
42088bfe67
commit
cbe5d93119
|
@ -29,7 +29,7 @@ public class PortDetector {
|
|||
* @return port name on which rusEFI was detected or null if none
|
||||
*/
|
||||
@Nullable
|
||||
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<IoStream, Void> callback) {
|
||||
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<SerialAutoChecker.CallbackContext, Void> callback) {
|
||||
String rusEfiAddress = System.getProperty("rusefi.address");
|
||||
if (rusEfiAddress != null) {
|
||||
return getSignatureFromPorts(callback, new String[] {rusEfiAddress});
|
||||
|
@ -43,7 +43,7 @@ public class PortDetector {
|
|||
return getSignatureFromPorts(callback, serialPorts);
|
||||
}
|
||||
|
||||
private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<IoStream, Void> callback, String[] serialPorts) {
|
||||
private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<SerialAutoChecker.CallbackContext, Void> callback, String[] serialPorts) {
|
||||
List<Thread> serialFinder = new ArrayList<>();
|
||||
CountDownLatch portFound = new CountDownLatch(1);
|
||||
AtomicReference<SerialAutoChecker.AutoDetectResult> result = new AtomicReference<>();
|
||||
|
|
|
@ -21,9 +21,9 @@ public class SerialAutoChecker implements Runnable {
|
|||
private final CountDownLatch portFound;
|
||||
private final AtomicReference<AutoDetectResult> result;
|
||||
@Nullable
|
||||
private final Function<IoStream, Void> callback;
|
||||
private final Function<CallbackContext, Void> callback;
|
||||
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result, Function<IoStream, Void> callback) {
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) {
|
||||
this.serialPort = serialPort;
|
||||
this.portFound = portFound;
|
||||
this.result = result;
|
||||
|
@ -49,7 +49,7 @@ public class SerialAutoChecker implements Runnable {
|
|||
log.info("Got signature=" + signature + " from " + serialPort);
|
||||
if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
|
||||
if (callback != null) {
|
||||
callback.apply(stream);
|
||||
callback.apply(new CallbackContext(stream, signature));
|
||||
}
|
||||
isPortFound = true;
|
||||
}
|
||||
|
@ -67,6 +67,24 @@ public class SerialAutoChecker implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
public static class CallbackContext {
|
||||
private final IoStream stream;
|
||||
private final String signature;
|
||||
|
||||
public CallbackContext(IoStream stream, String signature) {
|
||||
this.stream = stream;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public IoStream getStream() {
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AutoDetectResult {
|
||||
|
||||
private final String serialPort;
|
||||
|
|
|
@ -59,8 +59,8 @@ public class DfuFlasher {
|
|||
messages.append("Auto-detecting port...\n");
|
||||
// instead of opening the just-detected port we execute the command using the same stream we used to discover port
|
||||
// it's more reliable this way
|
||||
port = PortDetector.autoDetectSerial(stream -> {
|
||||
DfuHelper.sendDfuRebootCommand(stream, messages);
|
||||
port = PortDetector.autoDetectSerial(callbackContext -> {
|
||||
DfuHelper.sendDfuRebootCommand(callbackContext.getStream(), messages);
|
||||
return null;
|
||||
}).getSerialPort();
|
||||
if (port == null) {
|
||||
|
|
Loading…
Reference in New Issue