rusEFI console to has "Erase via DFU" button #2250

This commit is contained in:
rusefillc 2021-11-23 16:48:11 -05:00
parent 25d175b47a
commit 9d7792f453
8 changed files with 35 additions and 38 deletions

View File

@ -57,6 +57,7 @@ import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.StreamConnector; import com.rusefi.io.serial.StreamConnector;
import com.rusefi.proxy.NetworkConnector; import com.rusefi.proxy.NetworkConnector;
import com.rusefi.proxy.NetworkConnectorContext; import com.rusefi.proxy.NetworkConnectorContext;
import com.rusefi.ui.StatusConsumer;
import java.util.Date; import java.util.Date;
@ -212,7 +213,7 @@ public class rusEFI extends Activity {
} }
mResultView.append("Switching to DFU\n"); mResultView.append("Switching to DFU\n");
DfuHelper.sendDfuRebootCommand(serial, new StringBuilder()); DfuHelper.sendDfuRebootCommand(serial, StatusConsumer.VOID);
} }
private void dfuUpdate(UsbDevice dfuDevice) { private void dfuUpdate(UsbDevice dfuDevice) {

View File

@ -1,7 +1,8 @@
package com.rusefi.ui; package com.rusefi.ui;
public interface StatusConsumer { public interface StatusConsumer {
void appendMsg(String s); StatusConsumer VOID = s -> {
};
void append(String s); void append(String s);
} }

View File

@ -104,7 +104,7 @@ public class UploadChanges {
@Override @Override
public void run() { public void run() {
// System.out.println(msg); // System.out.println(msg);
// wnd.appendMsg(msg); // wnd.append(msg);
} }
}); });
} }
@ -115,7 +115,7 @@ public class UploadChanges {
@Override @Override
public void run() { public void run() {
System.out.println(msg); System.out.println(msg);
wnd.appendMsg(msg); wnd.append(msg);
} }
}); });
} }
@ -126,7 +126,7 @@ public class UploadChanges {
@Override @Override
public void run() { public void run() {
System.out.println(msg); System.out.println(msg);
wnd.appendMsg(msg); wnd.append(msg);
} }
}); });
} }

View File

@ -48,8 +48,8 @@ public class DfuFlasher {
if (isSignatureValidated == null) return; if (isSignatureValidated == null) return;
if (isSignatureValidated.get()) { if (isSignatureValidated.get()) {
if (!ProgramSelector.IS_WIN) { if (!ProgramSelector.IS_WIN) {
wnd.appendMsg("Switched to DFU mode!"); wnd.append("Switched to DFU mode!");
wnd.appendMsg("rusEFI console can only program on Windows"); wnd.append("rusEFI console can only program on Windows");
return; return;
} }
submitAction(() -> { submitAction(() -> {
@ -57,7 +57,7 @@ public class DfuFlasher {
executeDFU(wnd); executeDFU(wnd);
}); });
} else { } else {
wnd.appendMsg("Please use manual DFU to change bundle type."); wnd.append("Please use manual DFU to change bundle type.");
} }
} }
@ -131,17 +131,17 @@ public class DfuFlasher {
DFU_BINARY, wnd, stdout); DFU_BINARY, wnd, stdout);
if (stdout.toString().contains("Download verified successfully")) { if (stdout.toString().contains("Download verified successfully")) {
// looks like sometimes we are not catching the last line of the response? 'Upgrade' happens before 'Verify' // looks like sometimes we are not catching the last line of the response? 'Upgrade' happens before 'Verify'
wnd.appendMsg("SUCCESS!"); wnd.append("SUCCESS!");
wnd.appendMsg("Please power cycle device to exit DFU mode"); wnd.append("Please power cycle device to exit DFU mode");
} else if (stdout.toString().contains("Target device not found")) { } else if (stdout.toString().contains("Target device not found")) {
wnd.appendMsg("ERROR: Device not connected or STM32 Bootloader driver not installed?"); wnd.append("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.append("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"); wnd.append("ERROR: Alternatively please install drivers using Device Manager pointing at 'drivers/silent_st_drivers/DFU_Driver' folder");
appendDeviceReport(wnd); appendDeviceReport(wnd);
wnd.setErrorState(true); wnd.setErrorState(true);
} else { } else {
wnd.appendMsg(stdout.length() + " / " + errorResponse.length()); wnd.append(stdout.length() + " / " + errorResponse.length());
wnd.appendMsg("ERROR: does not look like DFU has worked!"); wnd.append("ERROR: does not look like DFU has worked!");
appendDeviceReport(wnd); appendDeviceReport(wnd);
wnd.setErrorState(true); wnd.setErrorState(true);
} }
@ -150,16 +150,16 @@ public class DfuFlasher {
private static void appendDeviceReport(StatusWindow wnd) { private static void appendDeviceReport(StatusWindow wnd) {
for (String line : getDevicesReport()) { for (String line : getDevicesReport()) {
if (line.contains("STM Device in DFU Mode")) { if (line.contains("STM Device in DFU Mode")) {
wnd.appendMsg(" ******************************************************************"); wnd.append(" ******************************************************************");
wnd.appendMsg(" ************* YOU NEED TO REMOVE LEGACY DFU DRIVER ***************"); wnd.append(" ************* YOU NEED TO REMOVE LEGACY DFU DRIVER ***************");
wnd.appendMsg(" ******************************************************************"); wnd.append(" ******************************************************************");
} }
wnd.appendMsg("Devices: " + line); wnd.append("Devices: " + line);
} }
} }
private static void timeForDfuSwitch(StatusWindow wnd) { private static void timeForDfuSwitch(StatusWindow wnd) {
wnd.appendMsg("Giving time for USB enumeration..."); wnd.append("Giving time for USB enumeration...");
try { try {
// two seconds not enough on my Windows 10 // two seconds not enough on my Windows 10
Thread.sleep(3 * Timeouts.SECOND); Thread.sleep(3 * Timeouts.SECOND);

View File

@ -48,7 +48,7 @@ public class DriverInstall {
FileLog.MAIN.logLine("IsWindows=" + FileLog.isWindows()); FileLog.MAIN.logLine("IsWindows=" + FileLog.isWindows());
if (!new File(FOLDER).exists()) { if (!new File(FOLDER).exists()) {
String message = FOLDER + " not found"; String message = FOLDER + " not found";
wnd.appendMsg(message); wnd.append(message);
FileLog.MAIN.logLine(message); FileLog.MAIN.logLine(message);
return; return;
} }

View File

@ -39,12 +39,12 @@ public class ExecHelper {
String line = bis.readLine(); String line = bis.readLine();
if (line == null) if (line == null)
break; break;
wnd.appendMsg(line); wnd.append(line);
buffer.append(line); buffer.append(line);
wasRunningTime = System.currentTimeMillis(); wasRunningTime = System.currentTimeMillis();
} }
} catch (IOException e) { } catch (IOException e) {
wnd.appendMsg("Stream " + e); wnd.append("Stream " + e);
} }
}); });
t.setDaemon(true); t.setDaemon(true);
@ -65,11 +65,11 @@ public class ExecHelper {
StringBuffer error = new StringBuffer(); StringBuffer error = new StringBuffer();
String binaryFullName = workingDirPath + File.separator + binaryRelativeName; String binaryFullName = workingDirPath + File.separator + binaryRelativeName;
if (!new File(binaryFullName).exists()) { if (!new File(binaryFullName).exists()) {
wnd.appendMsg(binaryFullName + " not found :("); wnd.append(binaryFullName + " not found :(");
return error.toString(); return error.toString();
} }
wnd.appendMsg("Executing " + command); wnd.append("Executing " + command);
try { try {
File workingDir = new File(workingDirPath); File workingDir = new File(workingDirPath);
Process p = Runtime.getRuntime().exec(command, null, workingDir); Process p = Runtime.getRuntime().exec(command, null, workingDir);
@ -77,11 +77,11 @@ public class ExecHelper {
startStreamThread(p, p.getErrorStream(), error, wnd); startStreamThread(p, p.getErrorStream(), error, wnd);
p.waitFor(3, TimeUnit.MINUTES); p.waitFor(3, TimeUnit.MINUTES);
} catch (IOException e) { } catch (IOException e) {
wnd.appendMsg("IOError: " + e); wnd.append("IOError: " + e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
wnd.appendMsg("WaitError: " + e); wnd.append("WaitError: " + e);
} }
wnd.appendMsg("Done!"); wnd.append("Done!");
return error.toString(); return error.toString();
} }

View File

@ -65,7 +65,7 @@ public class FirmwareFlasher {
private static void doFlashFirmware(StatusWindow wnd, String fileName) { private static void doFlashFirmware(StatusWindow wnd, String fileName) {
if (!new File(fileName).exists()) { if (!new File(fileName).exists()) {
wnd.appendMsg(fileName + " not found, cannot proceed !!!"); wnd.append(fileName + " not found, cannot proceed !!!");
wnd.setStatus("ERROR"); wnd.setStatus("ERROR");
return; return;
} }
@ -74,13 +74,13 @@ public class FirmwareFlasher {
fileName + fileName +
" verify reset exit 0x08000000\"", wnd); " verify reset exit 0x08000000\"", wnd);
if (error.contains(NO_DRIVER_MESSAGE_TAG)) { if (error.contains(NO_DRIVER_MESSAGE_TAG)) {
wnd.appendMsg(" !!! ERROR: looks like stm32 driver is not installed? The link is above !!!"); wnd.append(" !!! ERROR: looks like stm32 driver is not installed? The link is above !!!");
} else if (error.contains(SUCCESS_MESSAGE_TAG) && !error.toLowerCase().contains(FAILED_MESSAGE_TAG)) { } else if (error.contains(SUCCESS_MESSAGE_TAG) && !error.toLowerCase().contains(FAILED_MESSAGE_TAG)) {
wnd.appendMsg("Flashing looks good!"); wnd.append("Flashing looks good!");
sa.stop(); sa.stop();
wnd.setStatus(DONE); wnd.setStatus(DONE);
} else { } else {
wnd.appendMsg("!!! FIRMWARE FLASH: DOES NOT LOOK RIGHT !!!"); wnd.append("!!! FIRMWARE FLASH: DOES NOT LOOK RIGHT !!!");
} }
} }

View File

@ -63,7 +63,7 @@ public class StatusWindow implements StatusConsumer {
} }
@Override @Override
public void appendMsg(final String string) { public void append(final String string) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
String s = string.replaceAll(Character.toString((char) 219), ""); String s = string.replaceAll(Character.toString((char) 219), "");
FileLog.MAIN.logLine(s); FileLog.MAIN.logLine(s);
@ -72,11 +72,6 @@ public class StatusWindow implements StatusConsumer {
}); });
} }
@Override
public void append(String s) {
appendMsg(s);
}
public void setStatus(String status) { public void setStatus(String status) {
bottomStatusLabel.setText(status); bottomStatusLabel.setText(status);
} }