From fc8fdedf34e70001fe9ab170bd32b516bd295f5c Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 8 Apr 2021 16:42:52 -0400 Subject: [PATCH] console usability: better handling of 12340005 fix #2531 --- .../com/rusefi/maintenance/DfuFlasher.java | 20 +++++++++++++++---- .../com/rusefi/maintenance/ExecHelper.java | 3 ++- 2 files changed, 18 insertions(+), 5 deletions(-) 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 67fae1e8ae..cbbb50ae8c 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 @@ -8,6 +8,7 @@ import com.rusefi.autodetect.PortDetector; import com.rusefi.io.DfuHelper; import com.rusefi.io.IoStream; import com.rusefi.io.serial.SerialIoStreamJSerialComm; +import com.rusefi.ui.StatusConsumer; import com.rusefi.ui.StatusWindow; import com.rusefi.ui.util.URLLabel; @@ -16,6 +17,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; /** * @see FirmwareFlasher @@ -80,13 +82,23 @@ public class DfuFlasher { } catch (InterruptedException e) { throw new IllegalStateException(e); } + AtomicBoolean errorReported = new AtomicBoolean(); StringBuffer stdout = new StringBuffer(); String errorResponse = ExecHelper.executeCommand(FirmwareFlasher.BINARY_LOCATION, FirmwareFlasher.BINARY_LOCATION + File.separator + getDfuCommand(), - DFU_BINARY, wnd, stdout); - if (stdout.toString().contains("0x12340005")) { - wnd.appendMsg("Driver issue? Maybe driver conflict with STM32Cube? rusEFI currently uses older incompatible driver"); - } else if (stdout.toString().contains("Verify successful") || stdout.toString().contains("Upgrade successful")) { + DFU_BINARY, s -> { + if (s.contains("0x12340005") && errorReported.compareAndSet(false, true)) { + wnd.appendMsg(" ***************"); + wnd.appendMsg(" ***************"); + wnd.appendMsg("ERROR: Maybe DFU device not attached? Please check Device Manager."); + wnd.appendMsg("ERROR: Maybe ST DFU Driver is missing?"); + wnd.appendMsg("ERROR: Maybe driver conflict with STM32Cube?"); + wnd.appendMsg(" ***************"); + wnd.appendMsg(" ***************"); + } + wnd.appendMsg(s); + }, stdout); + if (stdout.toString().contains("Verify successful") || stdout.toString().contains("Upgrade successful")) { // looks like sometimes we are not catching the last line of the response? 'Upgrade' happens before 'Verify' wnd.appendMsg("SUCCESS!"); } else { diff --git a/java_console/ui/src/main/java/com/rusefi/maintenance/ExecHelper.java b/java_console/ui/src/main/java/com/rusefi/maintenance/ExecHelper.java index 7abe861df1..b5150150e2 100644 --- a/java_console/ui/src/main/java/com/rusefi/maintenance/ExecHelper.java +++ b/java_console/ui/src/main/java/com/rusefi/maintenance/ExecHelper.java @@ -5,6 +5,7 @@ import com.rusefi.ui.StatusConsumer; import org.jetbrains.annotations.NotNull; import java.io.*; +import java.util.concurrent.TimeUnit; /** * @see SimulatorExecHelper @@ -66,7 +67,7 @@ public class ExecHelper { Process p = Runtime.getRuntime().exec(command, null, workingDir); startStreamThread(p, p.getInputStream(), output, wnd); startStreamThread(p, p.getErrorStream(), error, wnd); - p.waitFor(); + p.waitFor(3, TimeUnit.MINUTES); } catch (IOException e) { wnd.appendMsg("IOError: " + e); } catch (InterruptedException e) {