steps towards Android

This commit is contained in:
rusefi 2020-07-05 13:34:38 -04:00
parent 015293ee43
commit 882ed55611
2 changed files with 23 additions and 16 deletions

View File

@ -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);
}
}
}

View File

@ -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);