diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 08a70cf499..5aaabddd4b 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -353,7 +353,7 @@ void unlockEcu(int password); // These externs aren't needed for unit tests - everything is injected instead #if !EFI_UNIT_TEST extern Engine ___engine; -static Engine * const engine = &___engine; +static constexpr Engine * const engine = &___engine; #else // EFI_UNIT_TEST extern Engine *engine; #endif // EFI_UNIT_TEST diff --git a/firmware/hw_layer/drivers/can/can_hw.cpp b/firmware/hw_layer/drivers/can/can_hw.cpp index 2cd51392c8..e0f489cff9 100644 --- a/firmware/hw_layer/drivers/can/can_hw.cpp +++ b/firmware/hw_layer/drivers/can/can_hw.cpp @@ -32,7 +32,7 @@ public: { } - void start(CANDriver* device) { + void tryStart(CANDriver *device) { m_device = device; if (device) { @@ -192,8 +192,8 @@ void initCan() { } if (engineConfiguration->canReadEnabled) { - canRead1.start(device1); - canRead2.start(device2); + canRead1.tryStart(device1); + canRead2.tryStart(device2); } isCanEnabled = true; diff --git a/java_console/io/src/main/java/com/rusefi/SimulatorExecHelper.java b/java_console/io/src/main/java/com/rusefi/SimulatorExecHelper.java index a833962b60..c9147a2a1f 100644 --- a/java_console/io/src/main/java/com/rusefi/SimulatorExecHelper.java +++ b/java_console/io/src/main/java/com/rusefi/SimulatorExecHelper.java @@ -13,22 +13,22 @@ import java.util.function.Consumer; public class SimulatorExecHelper { private final static NamedThreadFactory THREAD_FACTORY = new NamedThreadFactory("SimulatorExecHelper", true); - // see also SimulatorHelper - private static final String SIMULATOR_BINARY = "../simulator/build/fome_simulator.exe"; + private static final String SIMULATOR_BINARY_NAME = "fome_simulator"; + private static final String SIMULATOR_BINARY_PATH = "../simulator/build"; static Process simulatorProcess; /** * 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 { - FileLog.MAIN.logLine("Binary size: " + new File(SIMULATOR_BINARY).length()); + FileLog.MAIN.logLine("Binary size: " + binary.length()); - FileLog.MAIN.logLine("Executing " + SIMULATOR_BINARY); - SimulatorExecHelper.simulatorProcess = Runtime.getRuntime().exec(SIMULATOR_BINARY); + FileLog.MAIN.logLine("Executing " + binary.getPath()); + SimulatorExecHelper.simulatorProcess = Runtime.getRuntime().exec(binary.getPath()); FileLog.MAIN.logLine("simulatorProcess: " + SimulatorExecHelper.simulatorProcess); dumpProcessOutput(SimulatorExecHelper.simulatorProcess); @@ -93,9 +93,22 @@ public class SimulatorExecHelper { } public static void startSimulator() { - if (!new File(SIMULATOR_BINARY).exists()) - throw new IllegalStateException(SIMULATOR_BINARY + " not found"); 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) { + File binary = new File(binaryPath + SIMULATOR_BINARY_NAME); + + if (!binary.exists()) { // try also for Windows/PE executable + binary = new File(binaryPath + ".exe"); + } + + if (!binary.exists() || binary.isDirectory() || !binary.canExecute()) { + throw new IllegalStateException("FOME Simulator program not found"); + } + + return binary; } } diff --git a/java_console/ui/src/main/java/com/rusefi/SimulatorHelper.java b/java_console/ui/src/main/java/com/rusefi/SimulatorHelper.java index bd5cd37352..a1ac249a22 100644 --- a/java_console/ui/src/main/java/com/rusefi/SimulatorHelper.java +++ b/java_console/ui/src/main/java/com/rusefi/SimulatorHelper.java @@ -14,28 +14,24 @@ import static com.rusefi.ui.util.UiUtils.setToolTip; public class SimulatorHelper { private final static ThreadFactory THREAD_FACTORY = new NamedThreadFactory("SimulatorHelper"); - public static final String BINARY = "fome_simulator.exe"; + private static final String SIMULATOR_BINARY_PATH = "./"; private static Process process; - public static boolean isBinaryHere() { - return new File(BINARY).exists(); - } - /** * 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; - FileLog.MAIN.logLine("Executing " + BINARY); + FileLog.MAIN.logLine("Executing " + binary.getPath()); THREAD_FACTORY.newThread(new Runnable() { @Override public void run() { try { FileLog.SIMULATOR_CONSOLE.start(); - process = Runtime.getRuntime().exec(BINARY); - FileLog.MAIN.logLine("Executing " + BINARY + "=" + process); + process = Runtime.getRuntime().exec(binary.getPath()); + FileLog.MAIN.logLine("Executing " + binary.getPath() + "=" + process); SimulatorExecHelper.dumpProcessOutput(process); } catch (IOException e) { throw new IllegalStateException(e); @@ -62,18 +58,23 @@ public class SimulatorHelper { } public static JComponent createSimulatorComponent(final StartupFrame portSelector) { - if (!SimulatorHelper.isBinaryHere()) - return new JLabel(SimulatorHelper.BINARY + " not found"); + File simulatorBinary; + try { + simulatorBinary = SimulatorExecHelper.getSimulatorBinary(SIMULATOR_BINARY_PATH); + } catch (IllegalStateException e) { + return new JLabel(e.getMessage()); + } - if (TcpConnector.isTcpPortOpened()) + if (TcpConnector.isTcpPortOpened()) { return new JLabel("Port " + TcpConnector.DEFAULT_PORT + " already busy. Simulator running?"); + } JButton simulatorButton = new JButton("Start Virtual Simulator"); simulatorButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { portSelector.disposeFrameAndProceed(); - startSimulator(); + startSimulator(simulatorBinary); } }); setToolTip(simulatorButton, "Connect to totally virtual simulator", @@ -87,4 +88,4 @@ public class SimulatorHelper { if (process != null) process.destroy(); } -} \ No newline at end of file +}