mirror of https://github.com/FOME-Tech/fome-fw.git
GCC 13 simulator build, console->simulator on Linux (#378)
* engine: variable engine is: constexpr Engine * can: rename CanRead::start to not hide * console: support launching simulator on Linux * console: fully encapsulate simulator binary name * console: simplify simulator binary wrangling * console: cleaner java code-style
This commit is contained in:
parent
f4186c1e79
commit
bfb8cf1f89
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue