diff --git a/java_console/io/src/main/java/com/rusefi/io/DfuHelper.java b/java_console/io/src/main/java/com/rusefi/io/DfuHelper.java new file mode 100644 index 0000000000..d8e7b0d7ba --- /dev/null +++ b/java_console/io/src/main/java/com/rusefi/io/DfuHelper.java @@ -0,0 +1,20 @@ +package com.rusefi.io; + +import com.opensr5.Logger; +import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.config.generated.Fields; + +import java.io.IOException; + +public class DfuHelper { + public static void sendDfuRebootCommand(IoStream stream, StringBuilder messages, Logger logger) { + byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU); + try { + stream.sendPacket(command, logger); + stream.close(); + messages.append("Reboot command sent!\n"); + } catch (IOException e) { + messages.append("Error " + e); + } + } +} diff --git a/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java b/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java index 9252aad3e1..03ab5a0c3a 100644 --- a/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java +++ b/java_console/ui/src/main/java/com/rusefi/maintenance/DfuFlasher.java @@ -6,8 +6,7 @@ import com.rusefi.FileLog; import com.rusefi.Launcher; import com.rusefi.Timeouts; import com.rusefi.autodetect.PortDetector; -import com.rusefi.binaryprotocol.BinaryProtocol; -import com.rusefi.config.generated.Fields; +import com.rusefi.io.DfuHelper; import com.rusefi.io.IoStream; import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.ui.StatusWindow; @@ -18,7 +17,6 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; -import java.io.IOException; /** * @see FirmwareFlasher @@ -48,13 +46,13 @@ public class DfuFlasher { if (!PortDetector.isAutoPort(port)) { messages.append("Using selected " + port + "\n"); IoStream stream = SerialIoStreamJSerialComm.openPort(port, FileLog.LOGGER); - sendDfuRebootCommand(stream, messages); + DfuHelper.sendDfuRebootCommand(stream, messages, FileLog.LOGGER); } 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(stream -> { - sendDfuRebootCommand(stream, messages); + DfuHelper.sendDfuRebootCommand(stream, messages, FileLog.LOGGER); return null; }); if (port == null) { @@ -70,17 +68,6 @@ public class DfuFlasher { ExecHelper.submitAction(() -> executeDFU(wnd), DfuFlasher.class + " thread"); } - private static void sendDfuRebootCommand(IoStream stream, StringBuilder messages) { - byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU); - try { - stream.sendPacket(command, FileLog.LOGGER); - stream.close(); - messages.append("Reboot command sent!\n"); - } catch (IOException e) { - messages.append("Error " + e); - } - } - public static void runDfuProgramming() { StatusWindow wnd = new StatusWindow(); wnd.showFrame("DFU status " + Launcher.CONSOLE_VERSION);