getting ready for driver install

This commit is contained in:
rusefi 2019-07-01 00:22:47 -04:00
parent 3c815f8071
commit 5c73e35474
13 changed files with 106 additions and 84 deletions

View File

@ -486,7 +486,7 @@ public class AutoTest {
e.printStackTrace(); e.printStackTrace();
failed = true; failed = true;
} finally { } finally {
ExecHelper.destroy(); SimulatorExecHelper.destroy();
} }
if (failed) if (failed)
System.exit(-1); System.exit(-1);

View File

@ -109,7 +109,7 @@ public class IoUtil {
if (startProcess) { if (startProcess) {
if (!TcpConnector.getAvailablePorts().isEmpty()) if (!TcpConnector.getAvailablePorts().isEmpty())
throw new IllegalStateException("Port already binded on startup?"); throw new IllegalStateException("Port already binded on startup?");
ExecHelper.startSimulator(); SimulatorExecHelper.startSimulator();
} }

View File

@ -10,7 +10,7 @@ import java.util.function.Consumer;
* 3/18/14 * 3/18/14
* (c) Andrey Belomutskiy * (c) Andrey Belomutskiy
*/ */
public class ExecHelper { public class SimulatorExecHelper {
// see also SimulatorHelper // see also SimulatorHelper
private static final String SIMULATOR_BINARY = "../simulator/build/rusefi_simulator.exe"; private static final String SIMULATOR_BINARY = "../simulator/build/rusefi_simulator.exe";
static Process simulatorProcess; static Process simulatorProcess;
@ -26,10 +26,10 @@ public class ExecHelper {
FileLog.MAIN.logLine("Binary size: " + new File(SIMULATOR_BINARY).length()); FileLog.MAIN.logLine("Binary size: " + new File(SIMULATOR_BINARY).length());
FileLog.MAIN.logLine("Executing " + SIMULATOR_BINARY); FileLog.MAIN.logLine("Executing " + SIMULATOR_BINARY);
ExecHelper.simulatorProcess = Runtime.getRuntime().exec(SIMULATOR_BINARY); SimulatorExecHelper.simulatorProcess = Runtime.getRuntime().exec(SIMULATOR_BINARY);
FileLog.MAIN.logLine("simulatorProcess: " + ExecHelper.simulatorProcess); FileLog.MAIN.logLine("simulatorProcess: " + SimulatorExecHelper.simulatorProcess);
dumpProcessOutput(ExecHelper.simulatorProcess); dumpProcessOutput(SimulatorExecHelper.simulatorProcess);
FileLog.MAIN.logLine("exitValue: " + simulatorProcess.exitValue()); FileLog.MAIN.logLine("exitValue: " + simulatorProcess.exitValue());

View File

@ -56,10 +56,18 @@ public enum FileLog {
} }
private static void printOsInfo() { private static void printOsInfo() {
MAIN.logLine("OS name: " + System.getProperty("os.name")); MAIN.logLine("OS name: " + getOsName());
MAIN.logLine("OS version: " + System.getProperty(OS_VERSION)); MAIN.logLine("OS version: " + System.getProperty(OS_VERSION));
} }
private static String getOsName() {
return System.getProperty("os.name");
}
public static boolean isWindows() {
return getOsName().contains("Windows");
}
private FileOutputStream openLog() throws FileNotFoundException { private FileOutputStream openLog() throws FileNotFoundException {
String date = getDate(); String date = getDate();
createFolderIfNeeded(); createFolderIfNeeded();

View File

@ -46,7 +46,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel * @see EngineSnifferPanel
*/ */
public class Launcher { public class Launcher {
public static final int CONSOLE_VERSION = 20190628; public static final int CONSOLE_VERSION = 20190630;
public static final boolean SHOW_STIMULATOR = false; public static final boolean SHOW_STIMULATOR = false;
public static final String INPUT_FILES_PATH = ".."; public static final String INPUT_FILES_PATH = "..";
private static final String TAB_INDEX = "main_tab"; private static final String TAB_INDEX = "main_tab";

View File

@ -34,7 +34,7 @@ public class SimulatorHelper {
FileLog.SIMULATOR_CONSOLE.start(); FileLog.SIMULATOR_CONSOLE.start();
process = Runtime.getRuntime().exec(BINARY); process = Runtime.getRuntime().exec(BINARY);
FileLog.MAIN.logLine("Executing " + BINARY + "=" + process); FileLog.MAIN.logLine("Executing " + BINARY + "=" + process);
ExecHelper.dumpProcessOutput(process); SimulatorExecHelper.dumpProcessOutput(process);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }

View File

@ -127,7 +127,7 @@ public class StartupFrame {
installMessage(noPortsMessage, "Check you cables. Check your drivers. Do you want to start simulator maybe?"); installMessage(noPortsMessage, "Check you cables. Check your drivers. Do you want to start simulator maybe?");
realHardwarePanel.add(new URLLabel(VCP_DRIVER_TEXT, VCP_DRIVER_URI)); realHardwarePanel.add(new URLLabel(VCP_DRIVER_TEXT, VCP_DRIVER_URI));
if (ProcessStatusWindow.isWindows()) { if (FileLog.isWindows()) {
realHardwarePanel.add(new HorizontalLine()); realHardwarePanel.add(new HorizontalLine());
// for F7 builds we just build one file at the moment // for F7 builds we just build one file at the moment
realHardwarePanel.add(new FirmwareFlasher(FirmwareFlasher.IMAGE_FILE, "Program Firmware").getButton()); realHardwarePanel.add(new FirmwareFlasher(FirmwareFlasher.IMAGE_FILE, "Program Firmware").getButton());

View File

@ -23,7 +23,7 @@ public class EraseChip extends ProcessStatusWindow {
if (dialogResult != JOptionPane.YES_OPTION) if (dialogResult != JOptionPane.YES_OPTION)
return; return;
wnd.showFrame("rusEfi Firmware Flasher"); wnd.showFrame("rusEfi Firmware Flasher");
submitAction(() -> executeCommand(getEraseCommand())); ExecHelper.submitAction(() -> executeCommand(getEraseCommand()), EraseChip.this.getClass() + " extProcessThread");
} }
}); });
} }

View File

@ -0,0 +1,77 @@
package com.rusefi.maintenance;
import com.rusefi.SimulatorExecHelper;
import com.rusefi.ui.StatusConsumer;
import org.jetbrains.annotations.NotNull;
import java.io.*;
/**
* @see SimulatorExecHelper
*/
public class ExecHelper {
private static boolean isRunning(Process p) {
try {
p.exitValue();
return false;
} catch (IllegalThreadStateException e) {
return true;
}
}
/**
* This method listens to a data stream from the process, appends messages to UI
* and accumulates output in a buffer
*/
private static void startStreamThread(final Process p, final InputStream stream, final StringBuffer buffer, final StatusConsumer wnd) {
final Thread t = new Thread(() -> {
try {
BufferedReader bis = new BufferedReader(new InputStreamReader(stream));
while (isRunning(p)) {
String line = bis.readLine();
if (line == null)
break;
wnd.appendMsg(line);
buffer.append(line);
}
} catch (IOException e) {
wnd.appendMsg("Stream " + e);
}
});
t.setDaemon(true);
t.start();
}
@NotNull
public static StringBuffer executeCommand(String workingDirPath, String command, String binaryRelativeName, StatusConsumer wnd) {
StringBuffer error = new StringBuffer();
String binaryFullName = workingDirPath + File.separator + binaryRelativeName;
if (!new File(binaryFullName).exists()) {
wnd.appendMsg(binaryFullName + " not found :(");
return error;
}
command = workingDirPath + File.separator + command;
wnd.appendMsg("Executing " + command);
StringBuffer output = new StringBuffer();
try {
File workingDir = new File(workingDirPath);
Process p = Runtime.getRuntime().exec(command, null, workingDir);
startStreamThread(p, p.getInputStream(), output, wnd);
startStreamThread(p, p.getErrorStream(), error, wnd);
p.waitFor();
} catch (IOException e) {
wnd.appendMsg("IOError: " + e);
} catch (InterruptedException e) {
wnd.appendMsg("WaitError: " + e);
}
wnd.appendMsg("Done!");
return error;
}
protected static void submitAction(Runnable runnable, String threadName) {
Thread thread = new Thread(runnable, threadName);
thread.setDaemon(true);
thread.start();
}
}

View File

@ -38,14 +38,14 @@ public class FirmwareFlasher extends ProcessStatusWindow {
wnd.showFrame("rusEfi Firmware Flasher"); wnd.showFrame("rusEfi Firmware Flasher");
submitAction(() -> doFlashFirmware()); ExecHelper.submitAction(() -> doFlashFirmware(), getClass() + " extProcessThread");
} }
}); });
} }
public static String getOpenocdCommad() { public static String getOpenocdCommad() {
String cfg = "stm32f4discovery.cfg"; String cfg = "stm32f4discovery.cfg";
return BINARY_LOCATION + File.separator + OPENOCD_EXE + " -f openocd/" + cfg; return OPENOCD_EXE + " -f openocd/" + cfg;
} }
private void doFlashFirmware() { private void doFlashFirmware() {

View File

@ -2,82 +2,13 @@ package com.rusefi.maintenance;
import com.rusefi.ui.StatusWindow; import com.rusefi.ui.StatusWindow;
import java.io.*;
/** /**
* (c) Andrey Belomutskiy 2013-2018 * (c) Andrey Belomutskiy 2013-2018
*/ */
public class ProcessStatusWindow { public class ProcessStatusWindow {
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("win");
}
protected final StatusWindow wnd = new StatusWindow(); protected final StatusWindow wnd = new StatusWindow();
protected static boolean isRunning(Process p) {
try {
p.exitValue();
return false;
} catch (IllegalThreadStateException e) {
return true;
}
}
/**
* This method listens to a data stream from the process, appends messages to UI
* and accumulates output in a buffer
*/
protected void startStreamThread(final Process p, final InputStream stream, final StringBuffer buffer) {
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
BufferedReader bis = new BufferedReader(new InputStreamReader(stream));
while (isRunning(p)) {
String line = bis.readLine();
if (line == null)
break;
wnd.appendMsg(line);
buffer.append(line);
}
} catch (IOException e) {
wnd.appendMsg("Stream " + e);
}
}
});
t.setDaemon(true);
t.start();
}
protected StringBuffer executeCommand(String command) { protected StringBuffer executeCommand(String command) {
StringBuffer error = new StringBuffer(); return ExecHelper.executeCommand(FirmwareFlasher.BINARY_LOCATION, command, FirmwareFlasher.OPENOCD_EXE, wnd);
String binaryFullName = FirmwareFlasher.BINARY_LOCATION + File.separator + FirmwareFlasher.OPENOCD_EXE;
if (!new File(binaryFullName).exists()) {
wnd.appendMsg(binaryFullName + " not found :(");
return error;
}
wnd.appendMsg("Executing " + command);
StringBuffer output = new StringBuffer();
try {
File workingDir = new File(FirmwareFlasher.BINARY_LOCATION);
Process p = Runtime.getRuntime().exec(command, null, workingDir);
startStreamThread(p, p.getInputStream(), output);
startStreamThread(p, p.getErrorStream(), error);
p.waitFor();
} catch (IOException e) {
wnd.appendMsg("IOError: " + e);
} catch (InterruptedException e) {
wnd.appendMsg("WaitError: " + e);
}
wnd.appendMsg("Done!");
return error;
}
protected void submitAction(Runnable runnable) {
Thread thread = new Thread(runnable, "console extProcessThread");
thread.setDaemon(true);
thread.start();
} }
} }

View File

@ -0,0 +1,5 @@
package com.rusefi.ui;
public interface StatusConsumer {
void appendMsg(String s);
}

View File

@ -12,7 +12,7 @@ import java.awt.*;
* (c) Andrey Belomutskiy 2013-2018 * (c) Andrey Belomutskiy 2013-2018
* 3/7/2015 * 3/7/2015
*/ */
public class StatusWindow { public class StatusWindow implements StatusConsumer {
// todo: extract driver from console bundle? find a separate driver bundle? // todo: extract driver from console bundle? find a separate driver bundle?
private static final String CONSOLE_DRIVER_URI = "http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/utility/stsw-link004.zip"; private static final String CONSOLE_DRIVER_URI = "http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/utility/stsw-link004.zip";
private final JTextArea log = new JTextArea(); private final JTextArea log = new JTextArea();
@ -53,6 +53,7 @@ public class StatusWindow {
log.setText(""); // let's remove stuff from previous invocation log.setText(""); // let's remove stuff from previous invocation
} }
@Override
public void appendMsg(final String s) { public void appendMsg(final String s) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override