diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index 895ce16eee..a5bd503d6b 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -55,20 +55,20 @@ public class Launcher { protected static final String PORT_KEY = "port"; protected static final String SPEED_KEY = "speed"; - private static final String TOOL_NAME_COMPILE_FSIO_FILE = "compile_fsio_file"; - private static final String TOOL_NAME_REBOOT_ECU = "reboot_ecu"; - private static final String TOOL_NAME_FIRING_ORDER = "firing_order"; - private static final String TOOL_NAME_FUNCTIONAL_TEST = "functional_test"; - private static final String TOOL_NAME_PERF_ENUMS = "ptrace_enums"; - // todo: rename to something more FSIO-specific? would need to update documentation somewhere - private static final String TOOL_NAME_COMPILE = "compile"; private static final int DEFAULT_TAB_INDEX = 0; private static Map TOOLS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); static { - TOOLS.put("help", args -> printToolsAndExit()); + TOOLS.put("help", args -> printTools()); TOOLS.put("headless", args -> runHeadless()); + TOOLS.put("compile", args -> invokeCompileExpressionTool(args)); + TOOLS.put("ptrace_enums", args -> runPerfTraceTool(args)); + TOOLS.put("functional_test", args -> runFunctionalTest(args)); + TOOLS.put("compile_fsio_file", args -> runCompileTool(args)); + TOOLS.put("firing_order", args -> runFiringOrderTool(args)); + TOOLS.put("reboot_ecu", args -> sendCommand(Fields.CMD_REBOOT)); + TOOLS.put(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU)); } public static String port; @@ -203,58 +203,20 @@ public class Launcher { public static void main(final String[] args) throws Exception { String toolName = args.length == 0 ? null : args[0]; - ConsoleTool consoleTool = TOOLS.get(toolName); - if (consoleTool != null) { - consoleTool.runTool(args); - return; - } - - if (TOOL_NAME_FUNCTIONAL_TEST.equals(toolName)) { - // passing port argument if it was specified - String[] toolArgs = args.length == 1 ? new String[0] : new String[]{args[1]}; - RealHwTest.main(toolArgs); - return; - } - - if (TOOL_NAME_COMPILE_FSIO_FILE.equalsIgnoreCase(toolName)) { - int returnCode = invokeCompileFileTool(args); - System.exit(returnCode); - } - - if (TOOL_NAME_COMPILE.equals(toolName)) { - invokeCompileExpressionTool(args); - System.exit(0); - } - - if (TOOL_NAME_FIRING_ORDER.equals(toolName)) { - FiringOrderTSLogic.invoke(args[1]); - System.exit(0); - } - - if (TOOL_NAME_PERF_ENUMS.equals(toolName)) { - PerfTraceTool.readPerfTrace(args[1], args[2], args[3], args[4]); - System.exit(0); + if (args.length > 0) { + ConsoleTool consoleTool = TOOLS.get(toolName); + if (consoleTool != null) { + consoleTool.runTool(args); + return; + } } printTools(); - System.out.println("Optional tools: " + Arrays.asList(TOOL_NAME_COMPILE_FSIO_FILE, - TOOL_NAME_COMPILE, - TOOL_NAME_REBOOT_ECU, - TOOL_NAME_FIRING_ORDER)); System.out.println("Starting rusEfi UI console " + CONSOLE_VERSION); FileLog.MAIN.start(); - if (TOOL_NAME_REBOOT_ECU.equalsIgnoreCase(toolName)) { - sendCommand(Fields.CMD_REBOOT); - return; - } - if (Fields.CMD_REBOOT_DFU.equalsIgnoreCase(toolName)) { - sendCommand(Fields.CMD_REBOOT_DFU); - return; - } - getConfig().load(); FileLog.suspendLogging = getConfig().getRoot().getBoolProperty(GaugesPanel.DISABLE_LOGS); @@ -267,6 +229,25 @@ public class Launcher { }); } + private static void runPerfTraceTool(String[] args) throws IOException { + PerfTraceTool.readPerfTrace(args[1], args[2], args[3], args[4]); + } + + private static void runFiringOrderTool(String[] args) throws IOException { + FiringOrderTSLogic.invoke(args[1]); + } + + private static void runCompileTool(String[] args) throws IOException { + int returnCode = invokeCompileFileTool(args); + System.exit(returnCode); + } + + private static void runFunctionalTest(String[] args) throws InterruptedException { + // passing port argument if it was specified + String[] toolArgs = args.length == 1 ? new String[0] : new String[]{args[1]}; + RealHwTest.main(toolArgs); + } + private static void runHeadless() { String autoDetectedPort = PortDetector.autoDetectSerial(); if (autoDetectedPort == null) { @@ -382,11 +363,6 @@ public class Launcher { return staticFrame; } - private static void printToolsAndExit() { - printTools(); - System.exit(0); - } - private static void printTools() { for (String key : TOOLS.keySet()) { System.out.println("Tool available: " + key); @@ -394,6 +370,6 @@ public class Launcher { } interface ConsoleTool { - void runTool(String args[]); + void runTool(String args[]) throws Exception; } }