Skip to content

Commit

Permalink
console: simplify simulator binary wrangling
Browse files Browse the repository at this point in the history
  • Loading branch information
nmschulte committed Mar 9, 2024
1 parent 326548c commit ff413f3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ public class SimulatorExecHelper {
/**
* This is currently used by auto-tests only. Todo: reuse same code for UI-launched simulator?
*/
private static void runSimulator() {
private static void runSimulator(File binary) {
Thread.currentThread().setName("Main simulation");
FileLog.MAIN.logLine("runSimulator...");

try {
File binary = getSimulatorBinary(SIMULATOR_BINARY_PATH);
FileLog.MAIN.logLine("Binary size: " + binary.length());

FileLog.MAIN.logLine("Executing " + binary.getPath());
Expand Down Expand Up @@ -94,10 +93,9 @@ static void destroy() {
}

public static void startSimulator() {
getSimulatorBinary(SIMULATOR_BINARY_PATH);

FileLog.MAIN.logLine("startSimulator...");
new Thread(SimulatorExecHelper::runSimulator, "simulator process").start();
File simulatorBinary = getSimulatorBinary(SIMULATOR_BINARY_PATH);
new Thread(() -> SimulatorExecHelper.runSimulator(simulatorBinary), "simulator process").start();
}

public static File getSimulatorBinary(String binaryPath) {
Expand Down
9 changes: 4 additions & 5 deletions java_console/ui/src/main/java/com/rusefi/SimulatorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ public class SimulatorHelper {
* this code start sumulator for UI console
* todo: unify with the code which starts simulator for auto tests?
*/
private static void startSimulator() {
private static void startSimulator(File binary) {
LinkManager.isSimulationMode = true;

File binary = SimulatorExecHelper.getSimulatorBinary(SIMULATOR_BINARY_PATH);

FileLog.MAIN.logLine("Executing " + binary.getPath());
THREAD_FACTORY.newThread(new Runnable() {
@Override
Expand Down Expand Up @@ -60,8 +58,9 @@ public void run() {
}

public static JComponent createSimulatorComponent(final StartupFrame portSelector) {
File simulatorBinary;
try {
SimulatorExecHelper.getSimulatorBinary(SIMULATOR_BINARY_PATH);
simulatorBinary = SimulatorExecHelper.getSimulatorBinary(SIMULATOR_BINARY_PATH);
} catch (IllegalStateException e) {
return new JLabel(e.getMessage());
}
Expand All @@ -74,7 +73,7 @@ public static JComponent createSimulatorComponent(final StartupFrame portSelecto
@Override
public void actionPerformed(ActionEvent event) {
portSelector.disposeFrameAndProceed();
startSimulator();
startSimulator(simulatorBinary);
}
});
setToolTip(simulatorButton, "Connect to totally virtual simulator",
Expand Down

0 comments on commit ff413f3

Please sign in to comment.