diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 10326cd328..a82e1b7ff0 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -799,6 +799,8 @@ static void setSpiMode(int index, bool mode) { static void enableOrDisable(const char *param, bool isEnabled) { if (strEqualCaseInsensitive(param, "fastadc")) { boardConfiguration->isFastAdcEnabled = isEnabled; + } else if (strEqualCaseInsensitive(param, "serial")) { + boardConfiguration->useSerialPort = isEnabled; } else if (strEqualCaseInsensitive(param, "stepperidle")) { boardConfiguration->useStepperIdle = isEnabled; } else if (strEqualCaseInsensitive(param, "trigger_only_front")) { diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index b91b8b131d..8b1e74b0ee 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -290,5 +290,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20150503; + return 20150504; } diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index bbacc28cff..715a167385 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -11,6 +11,7 @@ import com.rusefi.ui.logview.LogViewer; import com.rusefi.ui.storage.Node; import com.rusefi.ui.util.DefaultExceptionHandler; import com.rusefi.ui.util.FrameHelper; +import com.rusefi.ui.util.JustOneInstance; import jssc.SerialPortList; import javax.swing.*; @@ -31,7 +32,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; * @see com.rusefi.StartupFrame */ public class Launcher { - public static final int CONSOLE_VERSION = 20150503; + public static final int CONSOLE_VERSION = 20150504; public static final boolean SHOW_STIMULATOR = false; private static final String TAB_INDEX = "main_tab"; protected static final String PORT_KEY = "port"; @@ -174,8 +175,14 @@ public class Launcher { } private static void awtCode(String[] args) { + if (JustOneInstance.isAlreadyRunning()) { + int result = JOptionPane.showConfirmDialog(null, "Looks like another instance is already running. Do you really want to start another instance?", + "rusEfi", JOptionPane.YES_NO_OPTION); + if (result == JOptionPane.NO_OPTION) + System.exit(-1); + } + JustOneInstance.onStart(); try { - boolean isPortDefined = args.length > 0; if (isPortDefined) { new Launcher(args[0]); diff --git a/java_console/ui/src/com/rusefi/ui/util/JustOneInstance.java b/java_console/ui/src/com/rusefi/ui/util/JustOneInstance.java new file mode 100644 index 0000000000..e27ef896e1 --- /dev/null +++ b/java_console/ui/src/com/rusefi/ui/util/JustOneInstance.java @@ -0,0 +1,44 @@ +package com.rusefi.ui.util; + +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * (c) Andrey Belomutskiy + * 5/4/2015 + */ +public class JustOneInstance { + private static final int PORT = 29212; + + public static boolean isAlreadyRunning() { + try { + Socket clientSocket = new Socket("localhost", PORT); + System.out.println("*** Already running!"); + return true; + } catch (IOException e) { + return false; + } + } + + public static void onStart() { + Runnable runnable = new Runnable() { + @Override + public void run() { + ServerSocket serverSocket; + try { + serverSocket = new ServerSocket(PORT, 1); + + while (true) { + // Wait for a connection + Socket clientSocket = serverSocket.accept(); + // System.out.println("*** Got a connection! "); + clientSocket.close(); + } + } catch (IOException e) { + } + } + }; + new Thread(runnable).start(); + } +}