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

This reverts commit 40610783
This commit is contained in:
rusefillc 2021-09-25 23:21:27 -04:00
parent a9afae7977
commit 42088bfe67
3 changed files with 13 additions and 48 deletions

View File

@ -29,7 +29,7 @@ public class PortDetector {
* @return port name on which rusEFI was detected or null if none * @return port name on which rusEFI was detected or null if none
*/ */
@Nullable @Nullable
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<SerialAutoChecker.CallbackContext, Void> callback) { public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<IoStream, Void> callback) {
String rusEfiAddress = System.getProperty("rusefi.address"); String rusEfiAddress = System.getProperty("rusefi.address");
if (rusEfiAddress != null) { if (rusEfiAddress != null) {
return getSignatureFromPorts(callback, new String[] {rusEfiAddress}); return getSignatureFromPorts(callback, new String[] {rusEfiAddress});
@ -43,16 +43,12 @@ public class PortDetector {
return getSignatureFromPorts(callback, serialPorts); return getSignatureFromPorts(callback, serialPorts);
} }
public static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<SerialAutoChecker.CallbackContext, Void> callback, String[] serialPorts) { private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<IoStream, Void> callback, String[] serialPorts) {
List<Thread> serialFinder = new ArrayList<>(); List<Thread> serialFinder = new ArrayList<>();
CountDownLatch portFound = new CountDownLatch(1); CountDownLatch portFound = new CountDownLatch(1);
AtomicReference<SerialAutoChecker.AutoDetectResult> result = new AtomicReference<>(); AtomicReference<SerialAutoChecker.AutoDetectResult> result = new AtomicReference<>();
for (String serialPort : serialPorts) { for (String serialPort : serialPorts) {
Thread thread = AUTO_DETECT_PORT.newThread( Thread thread = AUTO_DETECT_PORT.newThread(new SerialAutoChecker(serialPort, portFound, result, callback));
() -> {
SerialAutoChecker checker = new SerialAutoChecker(serialPort, portFound, result, callback);
checker.openAndRunLogic();
});
serialFinder.add(thread); serialFinder.add(thread);
thread.start(); thread.start();
} }

View File

@ -15,15 +15,15 @@ import java.util.function.Function;
import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode; import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
public class SerialAutoChecker { public class SerialAutoChecker implements Runnable {
private final static Logging log = Logging.getLogging(SerialAutoChecker.class); private final static Logging log = Logging.getLogging(SerialAutoChecker.class);
private final String serialPort; private final String serialPort;
private final CountDownLatch portFound; private final CountDownLatch portFound;
private final AtomicReference<AutoDetectResult> result; private final AtomicReference<AutoDetectResult> result;
@Nullable @Nullable
private final Function<CallbackContext, Void> callback; private final Function<IoStream, Void> callback;
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result, Function<CallbackContext, Void> callback) { public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result, Function<IoStream, Void> callback) {
this.serialPort = serialPort; this.serialPort = serialPort;
this.portFound = portFound; this.portFound = portFound;
this.result = result; this.result = result;
@ -34,16 +34,9 @@ public class SerialAutoChecker {
this(serialPort, portFound, result, null); this(serialPort, portFound, result, null);
} }
public void openAndRunLogic() { @Override
public void run() {
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort); IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
try {
runLogic(stream);
} finally {
stream.close();
}
}
public void runLogic(IoStream stream) {
IncomingDataBuffer incomingData = stream.getDataBuffer(); IncomingDataBuffer incomingData = stream.getDataBuffer();
boolean isPortFound = false; boolean isPortFound = false;
String signature; String signature;
@ -56,12 +49,14 @@ public class SerialAutoChecker {
log.info("Got signature=" + signature + " from " + serialPort); log.info("Got signature=" + signature + " from " + serialPort);
if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) { if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
if (callback != null) { if (callback != null) {
callback.apply(new CallbackContext(stream, signature)); callback.apply(stream);
} }
isPortFound = true; isPortFound = true;
} }
} catch (IOException ignore) { } catch (IOException ignore) {
return; return;
} finally {
stream.close();
} }
if (isPortFound) { if (isPortFound) {
/** /**
@ -72,24 +67,6 @@ public class SerialAutoChecker {
} }
} }
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 { public static class AutoDetectResult {
private final String serialPort; private final String serialPort;

View File

@ -5,7 +5,6 @@ import com.rusefi.ConsoleUI;
import com.rusefi.Launcher; import com.rusefi.Launcher;
import com.rusefi.Timeouts; import com.rusefi.Timeouts;
import com.rusefi.autodetect.PortDetector; import com.rusefi.autodetect.PortDetector;
import com.rusefi.autodetect.SerialAutoChecker;
import com.rusefi.io.DfuHelper; import com.rusefi.io.DfuHelper;
import com.rusefi.io.IoStream; import com.rusefi.io.IoStream;
import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.io.serial.SerialIoStreamJSerialComm;
@ -17,10 +16,7 @@ import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File; import java.io.File;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import static com.rusefi.StartupFrame.appendBundleName; import static com.rusefi.StartupFrame.appendBundleName;
@ -57,18 +53,14 @@ public class DfuFlasher {
if (!PortDetector.isAutoPort(port)) { if (!PortDetector.isAutoPort(port)) {
messages.append("Using selected " + port + "\n"); messages.append("Using selected " + port + "\n");
Function<SerialAutoChecker.CallbackContext, Void> callback = null; // todo
AtomicReference<SerialAutoChecker.AutoDetectResult> result = new AtomicReference<>();
SerialAutoChecker checker = new SerialAutoChecker(port, new CountDownLatch(1), result, callback);
IoStream stream = SerialIoStreamJSerialComm.openPort(port); IoStream stream = SerialIoStreamJSerialComm.openPort(port);
checker.runLogic(stream);
DfuHelper.sendDfuRebootCommand(stream, messages); DfuHelper.sendDfuRebootCommand(stream, messages);
} else { } else {
messages.append("Auto-detecting port...\n"); 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 // 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 // it's more reliable this way
port = PortDetector.autoDetectSerial(callbackContext -> { port = PortDetector.autoDetectSerial(stream -> {
DfuHelper.sendDfuRebootCommand(callbackContext.getStream(), messages); DfuHelper.sendDfuRebootCommand(stream, messages);
return null; return null;
}).getSerialPort(); }).getSerialPort();
if (port == null) { if (port == null) {