allow sending a command other than DFU (openblt)

This commit is contained in:
Matthew Kennedy 2023-10-18 02:05:44 -07:00
parent eede4d75fb
commit a6536ee037
3 changed files with 11 additions and 11 deletions

View File

@ -5,7 +5,6 @@ import com.rusefi.core.RusEfiSignature;
import com.rusefi.core.SignatureHelper;
import com.rusefi.core.io.BundleUtil;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields;
import com.rusefi.ui.StatusConsumer;
import javax.swing.*;
@ -19,18 +18,18 @@ public class DfuHelper {
private static final Logging log = getLogging(DfuHelper.class);
private static final String PREFIX = "rusefi_bundle";
public static void sendDfuRebootCommand(IoStream stream, StatusConsumer messages) {
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
public static void sendDfuRebootCommand(IoStream stream, StatusConsumer messages, String cmd) {
byte[] command = BinaryProtocol.getTextCommandBytes(cmd);
try {
stream.sendPacket(command);
stream.close();
messages.append(String.format("Reboot command [%s] sent into %s!\n", Fields.CMD_REBOOT_DFU, stream));
messages.append(String.format("Reboot command [%s] sent into %s!\n", cmd, stream));
} catch (IOException e) {
messages.append("Error " + e);
}
}
public static boolean sendDfuRebootCommand(JComponent parent, String signature, IoStream stream, StatusConsumer messages) {
public static boolean sendDfuRebootCommand(JComponent parent, String signature, IoStream stream, StatusConsumer messages, String command) {
RusEfiSignature controllerSignature = SignatureHelper.parse(signature);
String fileSystemBundleTarget = BundleUtil.getBundleTarget();
if (fileSystemBundleTarget != null && controllerSignature != null) {
@ -56,7 +55,7 @@ public class DfuHelper {
}
}
sendDfuRebootCommand(stream, messages);
sendDfuRebootCommand(stream, messages, command);
return true;
}
}

View File

@ -6,6 +6,7 @@ import com.rusefi.Timeouts;
import com.rusefi.autodetect.PortDetector;
import com.rusefi.autodetect.SerialAutoChecker;
import com.rusefi.core.io.BundleUtil;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.DfuHelper;
import com.rusefi.io.IoStream;
import com.rusefi.io.serial.BufferedSerialIoStream;
@ -57,7 +58,7 @@ public class DfuFlasher {
needsEraseFirst = true;
}
AtomicBoolean isSignatureValidated = rebootToDfu(parent, port, wnd);
AtomicBoolean isSignatureValidated = rebootToDfu(parent, port, wnd, Fields.CMD_REBOOT_DFU);
if (isSignatureValidated == null)
return;
if (isSignatureValidated.get()) {
@ -82,7 +83,7 @@ public class DfuFlasher {
}
@Nullable
public static AtomicBoolean rebootToDfu(JComponent parent, String port, StatusWindow wnd) {
public static AtomicBoolean rebootToDfu(JComponent parent, String port, StatusWindow wnd, String command) {
AtomicBoolean isSignatureValidated = new AtomicBoolean(true);
if (!PortDetector.isAutoPort(port)) {
wnd.append("Using selected " + port + "\n");
@ -101,7 +102,7 @@ public class DfuFlasher {
wnd.setErrorState();
return null;
}
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, signature.get(), stream, wnd);
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, signature.get(), stream, wnd, command);
isSignatureValidated.set(isSignatureValidatedLocal);
} else {
wnd.append("Auto-detecting port...\n");
@ -109,7 +110,7 @@ public class DfuFlasher {
// it's more reliable this way
// ISSUE: that's blocking stuff on UI thread at the moment, TODO smarter threading!
port = PortDetector.autoDetectSerial(callbackContext -> {
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, callbackContext.getSignature(), callbackContext.getStream(), wnd);
boolean isSignatureValidatedLocal = DfuHelper.sendDfuRebootCommand(parent, callbackContext.getSignature(), callbackContext.getStream(), wnd, command);
isSignatureValidated.set(isSignatureValidatedLocal);
return null;
}).getSerialPort();

View File

@ -73,7 +73,7 @@ public class ProgramSelector {
StatusWindow wnd = DfuFlasher.createStatusWindow();
Object selected = comboPorts.getSelectedItem();
String port = selected == null ? PortDetector.AUTO : selected.toString();
DfuFlasher.rebootToDfu(comboPorts, port, wnd);
DfuFlasher.rebootToDfu(comboPorts, port, wnd, Fields.CMD_REBOOT_DFU);
break;
case OPENBLT_CAN:
flashOpenBltCan();