From ac3abdc9b31313dd17aa5de1d7911b0a4832c30b Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 14 Nov 2021 18:26:54 -0500 Subject: [PATCH] I bet device manager has command line interface #3547 --- .../main/java/com/rusefi/rusEFIVersion.java | 2 +- .../com/rusefi/maintenance/DfuFlasher.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/java_console/shared_io/src/main/java/com/rusefi/rusEFIVersion.java b/java_console/shared_io/src/main/java/com/rusefi/rusEFIVersion.java index f78c3886c1..1a1feeed4c 100644 --- a/java_console/shared_io/src/main/java/com/rusefi/rusEFIVersion.java +++ b/java_console/shared_io/src/main/java/com/rusefi/rusEFIVersion.java @@ -6,7 +6,7 @@ import java.net.URL; import java.util.concurrent.atomic.AtomicReference; public class rusEFIVersion { - public static final int CONSOLE_VERSION = 20211112; + public static final int CONSOLE_VERSION = 20211114; public static AtomicReference firmwareVersion = new AtomicReference<>("N/A"); public static long classBuildTimeMillis() { 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 6a9d455f25..844f93d033 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 @@ -10,9 +10,16 @@ import com.rusefi.io.DfuHelper; import com.rusefi.io.IoStream; import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.ui.StatusWindow; +import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.io.BufferedReader; import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -107,14 +114,21 @@ public class DfuFlasher { wnd.appendMsg("ERROR: Device not connected or STM32 Bootloader driver not installed?"); wnd.appendMsg("ERROR: Please try installing drivers using 'Install Drivers' button on rusEFI splash screen"); wnd.appendMsg("ERROR: Alternatively please install drivers using Device Manager pointing at 'drivers/silent_st_drivers/DFU_Driver' folder"); + appendDeviceReport(wnd); wnd.setErrorState(true); } else { wnd.appendMsg(stdout.length() + " / " + errorResponse.length()); wnd.appendMsg("ERROR: does not look like DFU has worked!"); + appendDeviceReport(wnd); wnd.setErrorState(true); } } + private static void appendDeviceReport(StatusWindow wnd) { + for (String line : getDevicesReport()) + wnd.appendMsg("Devices: " + line); + } + private static void timeForDfuSwitch(StatusWindow wnd) { wnd.appendMsg("Giving time for USB enumeration..."); try { @@ -133,4 +147,29 @@ public class DfuFlasher { return DFU_BINARY_LOCATION + "/" + DFU_BINARY + " -c port=usb1 -w " + absolutePath + " -v -s"; } + + @NotNull + static List getDevicesReport() { + // todo: assert windows 10, explicit message if not + List report = new ArrayList<>(); + + try { + Process powerShellProcess = Runtime.getRuntime().exec("powershell \"Get-PnpDevice -PresentOnly\""); + // Getting the results + powerShellProcess.getOutputStream().close(); + + String line; + BufferedReader stdout = new BufferedReader(new InputStreamReader(powerShellProcess.getInputStream())); + while ((line = stdout.readLine()) != null) { + String lowerCase = line.toLowerCase(); + if (!lowerCase.contains("stm32") && !lowerCase.contains("dfu") && !lowerCase.contains("rusefi")) + continue; + report.add(line); + } + stdout.close(); + return report; + } catch (IOException e) { + return Collections.emptyList(); + } + } }