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

This commit is contained in:
rusefillc 2021-09-26 01:21:40 -04:00
parent 29342581d4
commit 8e60a0216b
3 changed files with 46 additions and 5 deletions

View File

@ -1,13 +1,17 @@
package com.rusefi.io;
import com.rusefi.RusEfiSignature;
import com.rusefi.SignatureHelper;
import com.rusefi.autoupdate.Autoupdate;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import javax.swing.*;
import java.io.IOException;
public class DfuHelper {
public static void sendDfuRebootCommand(IoStream stream, StringBuilder messages) {
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
try {
stream.sendPacket(command);
stream.close();
@ -16,4 +20,22 @@ public class DfuHelper {
messages.append("Error " + e);
}
}
public static boolean sendDfuRebootCommand(JComponent parent, String signature, IoStream stream, StringBuilder messages) {
RusEfiSignature s = SignatureHelper.parse(signature);
String bundleName = Autoupdate.readBundleFullName();
if (bundleName != null && s != null) {
if (!bundleName.equalsIgnoreCase(s.getBundle())) {
JOptionPane.showMessageDialog(parent, String.format("You have \"%s\" controller does not look right to program it with \"%s\"", s.getBundle(), bundleName));
// in case of mismatched bundle type we are supposed do close connection
// and properly handle the case of user hitting "Update Firmware" again
// closing connection is a mess on Windows so it's simpler to just exit
System.exit(-5);
return false;
}
}
sendDfuRebootCommand(stream, messages);
return true;
}
}

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20210920;
public static final int CONSOLE_VERSION = 20210925;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -5,6 +5,7 @@ import com.rusefi.ConsoleUI;
import com.rusefi.Launcher;
import com.rusefi.Timeouts;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.autodetect.SerialAutoChecker;
import com.rusefi.io.DfuHelper;
import com.rusefi.io.IoStream;
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
@ -16,7 +17,10 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import static com.rusefi.StartupFrame.appendBundleName;
@ -51,16 +55,27 @@ public class DfuFlasher {
String port = selectedItem.toString();
StringBuilder messages = new StringBuilder();
AtomicBoolean isSignatureValidated = new AtomicBoolean(true);
if (!PortDetector.isAutoPort(port)) {
messages.append("Using selected " + port + "\n");
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
DfuHelper.sendDfuRebootCommand(stream, messages);
AtomicReference<String> result = new AtomicReference<>();
new SerialAutoChecker(port, new CountDownLatch(1)).checkResponse(stream, new Function<SerialAutoChecker.CallbackContext, Void>() {
@Override
public Void apply(SerialAutoChecker.CallbackContext callbackContext) {
result.set(callbackContext.getSignature());
return null;
}
});
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, result.get(), stream, messages);
isSignatureValidated.set(isSignatureValidatedLocal);
} else {
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(callbackContext -> {
DfuHelper.sendDfuRebootCommand(callbackContext.getStream(), messages);
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, callbackContext.getSignature(), callbackContext.getStream(), messages);
isSignatureValidated.set(isSignatureValidatedLocal);
return null;
}).getSerialPort();
if (port == null) {
@ -73,7 +88,11 @@ public class DfuFlasher {
StatusWindow wnd = new StatusWindow();
wnd.showFrame(appendBundleName("DFU status " + Launcher.CONSOLE_VERSION));
wnd.appendMsg(messages.toString());
ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread");
if (isSignatureValidated.get()) {
ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread");
} else {
wnd.appendMsg("Please use manual DFU to change bundle type.");
}
}
public static void runDfuProgramming() {