diff --git a/firmware/console/eficonsole.cpp b/firmware/console/eficonsole.cpp index 298fa2db0f..4f1d101a82 100644 --- a/firmware/console/eficonsole.cpp +++ b/firmware/console/eficonsole.cpp @@ -46,11 +46,11 @@ static void sayNothing(void) { } static void sayHello(void) { - scheduleMsg(&logger, "*** rusEFI LLC (c) 2012-2020. All rights reserved."); - scheduleMsg(&logger, "rusEFI v%d@%s", getRusEfiVersion(), VCS_VERSION); - scheduleMsg(&logger, "*** Chibios Kernel: %s", CH_KERNEL_VERSION); - scheduleMsg(&logger, "*** Compiled: " __DATE__ " - " __TIME__ ""); - scheduleMsg(&logger, "COMPILER=%s", __VERSION__); + scheduleMsg(&logger, PROTOCOL_HELLO_PREFIX " rusEFI LLC (c) 2012-2020. All rights reserved."); + scheduleMsg(&logger, PROTOCOL_HELLO_PREFIX " rusEFI v%d@%s", getRusEfiVersion(), VCS_VERSION); + scheduleMsg(&logger, PROTOCOL_HELLO_PREFIX " Chibios Kernel: %s", CH_KERNEL_VERSION); + scheduleMsg(&logger, PROTOCOL_HELLO_PREFIX " Compiled: " __DATE__ " - " __TIME__ ""); + scheduleMsg(&logger, PROTOCOL_HELLO_PREFIX " COMPILER=%s", __VERSION__); #if defined(STM32F4) || defined(STM32F7) uint32_t *uid = ((uint32_t *)UID_BASE); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index cefc9c4545..8f3e82ba16 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -717,6 +717,6 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20200525; + return 20200531; } #endif /* EFI_UNIT_TEST */ diff --git a/java_console/io/src/com/rusefi/io/LinkManager.java b/java_console/io/src/com/rusefi/io/LinkManager.java index 08845b670b..50f20b3c70 100644 --- a/java_console/io/src/com/rusefi/io/LinkManager.java +++ b/java_console/io/src/com/rusefi/io/LinkManager.java @@ -63,7 +63,7 @@ public class LinkManager { public static LinkDecoder ENCODER = new LinkDecoder() { @Override public String unpack(String packedLine) { - return LinkManager.unpack(packedLine); + return packedLine; } }; @@ -169,10 +169,6 @@ public class LinkManager { connector.restart(); } - public static String unpack(String packet) { - return connector.unpack(packet); - } - public static String unpackConfirmation(String message) { if (message.startsWith(CommandQueue.CONFIRMATION_PREFIX)) return message.substring(CommandQueue.CONFIRMATION_PREFIX.length()); diff --git a/java_console/models/src/com/rusefi/core/EngineState.java b/java_console/models/src/com/rusefi/core/EngineState.java index 79c85e957b..ecf77cfad8 100644 --- a/java_console/models/src/com/rusefi/core/EngineState.java +++ b/java_console/models/src/com/rusefi/core/EngineState.java @@ -29,10 +29,10 @@ public class EngineState { /** * text protocol key and callback associated with this key */ - private static class StringActionPair extends Pair> { + public static class StringActionPair extends Pair> { public final String prefix; - StringActionPair(String key, ValueCallback second) { + public StringActionPair(String key, ValueCallback second) { super(key, second); prefix = key.toLowerCase() + SEPARATOR; } @@ -53,6 +53,7 @@ public class EngineState { buffer = new ResponseBuffer(new ResponseBuffer.ResponseListener() { public void onResponse(String response) { if (response != null) { + // let's remove timestamp if we get content from a log file not controller int i = response.indexOf(FileLog.END_OF_TIMESTAND_TAG); if (i != -1) response = response.substring(i + FileLog.END_OF_TIMESTAND_TAG.length()); @@ -172,7 +173,16 @@ public class EngineState { return response; } - private String handleStringActionPair(String response, StringActionPair pair, EngineStateListener listener) { + public static String skipToken(String string) { + int keyEnd = string.indexOf(SEPARATOR); + if (keyEnd == -1) { + // discarding invalid line + return ""; + } + return string.substring(keyEnd + SEPARATOR.length()); + } + + public static String handleStringActionPair(String response, StringActionPair pair, EngineStateListener listener) { if (startWithIgnoreCase(response, pair.prefix)) { String key = pair.first; int beginIndex = key.length() + 1; @@ -182,7 +192,8 @@ public class EngineState { String strValue = response.substring(beginIndex, endIndex); pair.second.onUpdate(strValue); - listener.onKeyValue(key, strValue); + if (listener != null) + listener.onKeyValue(key, strValue); response = response.substring(endIndex); if (!response.isEmpty()) diff --git a/java_console/ui/src/com/rusefi/tools/ConsoleTools.java b/java_console/ui/src/com/rusefi/tools/ConsoleTools.java index 2e0ae1fd84..e86482dbfd 100644 --- a/java_console/ui/src/com/rusefi/tools/ConsoleTools.java +++ b/java_console/ui/src/com/rusefi/tools/ConsoleTools.java @@ -2,15 +2,18 @@ package com.rusefi.tools; import com.fathzer.soft.javaluator.DoubleEvaluator; import com.opensr5.ConfigurationImage; +import com.opensr5.Logger; import com.opensr5.io.ConfigurationImageFile; import com.rusefi.*; import com.rusefi.autodetect.PortDetector; +import com.rusefi.autodetect.SerialAutoChecker; import com.rusefi.binaryprotocol.BinaryProtocol; +import com.rusefi.binaryprotocol.IncomingDataBuffer; import com.rusefi.config.generated.Fields; -import com.rusefi.io.ConnectionStateListener; -import com.rusefi.io.ConnectionStatusLogic; -import com.rusefi.io.IoStream; -import com.rusefi.io.LinkManager; +import com.rusefi.core.EngineState; +import com.rusefi.core.ResponseBuffer; +import com.rusefi.io.*; +import com.rusefi.io.serial.PortHolder; import com.rusefi.io.serial.SerialIoStreamJSerialComm; import com.rusefi.maintenance.ExecHelper; import com.rusefi.tools.online.Online; @@ -27,6 +30,7 @@ import java.util.Arrays; import java.util.Map; import java.util.TreeMap; +import static com.rusefi.binaryprotocol.BinaryProtocol.sleep; import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; public class ConsoleTools { @@ -36,25 +40,27 @@ public class ConsoleTools { private static Map toolsHelp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); static { - TOOLSput("help", args -> printTools(), "Print this help."); - TOOLSput("headless", ConsoleTools::runHeadless, "Connect to rusEFI controller and start saving logs."); + registerTool("help", args -> printTools(), "Print this help."); + registerTool("headless", ConsoleTools::runHeadless, "Connect to rusEFI controller and start saving logs."); - TOOLSput("ptrace_enums", ConsoleTools::runPerfTraceTool, "NOT A USER TOOL. Development tool to process pefrormance trace enums"); - TOOLSput("firing_order", ConsoleTools::runFiringOrderTool, "NOT A USER TOOL. Development tool relating to adding new firing order into rusEFI firmware."); - TOOLSput("functional_test", ConsoleTools::runFunctionalTest, "NOT A USER TOOL. Development tool related to functional testing"); - TOOLSput("convert_binary_configuration_to_xml", ConsoleTools::convertBinaryToXml, "NOT A USER TOOL. Development tool to convert binary configuration into XML form."); + registerTool("ptrace_enums", ConsoleTools::runPerfTraceTool, "NOT A USER TOOL. Development tool to process pefrormance trace enums"); + registerTool("firing_order", ConsoleTools::runFiringOrderTool, "NOT A USER TOOL. Development tool relating to adding new firing order into rusEFI firmware."); + registerTool("functional_test", ConsoleTools::runFunctionalTest, "NOT A USER TOOL. Development tool related to functional testing"); + registerTool("convert_binary_configuration_to_xml", ConsoleTools::convertBinaryToXml, "NOT A USER TOOL. Development tool to convert binary configuration into XML form."); - TOOLSput("compile_fsio_line", ConsoleTools::invokeCompileExpressionTool, "Convert a line to RPN form."); - TOOLSput("compile_fsio_file", ConsoleTools::runCompileTool, "Convert all lines from a file to RPN form."); + registerTool("compile_fsio_line", ConsoleTools::invokeCompileExpressionTool, "Convert a line to RPN form."); + registerTool("compile_fsio_file", ConsoleTools::runCompileTool, "Convert all lines from a file to RPN form."); - TOOLSput("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token."); - TOOLSput(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token."); + registerTool("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token."); + registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token."); - TOOLSput("reboot_ecu", args -> sendCommand(Fields.CMD_REBOOT), "Sends a command to reboot rusEFI controller."); - TOOLSput(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU), "Sends a command to switch rusEFI controller into DFU mode."); + + registerTool("detect", ConsoleTools::detect, "Find attached rusEFI"); + registerTool("reboot_ecu", args -> sendCommand(Fields.CMD_REBOOT), "Sends a command to reboot rusEFI controller."); + registerTool(Fields.CMD_REBOOT_DFU, args -> sendCommand(Fields.CMD_REBOOT_DFU), "Sends a command to switch rusEFI controller into DFU mode."); } - private static void TOOLSput(String command, ConsoleTool callback, String help) { + private static void registerTool(String command, ConsoleTool callback, String help) { TOOLS.put(command, callback); toolsHelp.put(command, help); } @@ -236,6 +242,59 @@ public class ConsoleTools { } } + static void detect(String[] strings) throws IOException, InterruptedException { + String autoDetectedPort = autoDetectPort(); + if (autoDetectedPort == null) { + System.out.println("rusEFI not detected"); + return; + } + IoStream stream = SerialIoStreamJSerialComm.openPort(autoDetectedPort); + Logger logger = FileLog.LOGGER; + IncomingDataBuffer incomingData = BinaryProtocol.createDataBuffer(stream, logger); + byte[] commandBytes = BinaryProtocol.getTextCommandBytes("hello"); + stream.sendPacket(commandBytes, logger); + // skipping response + incomingData.getPacket(logger, "", true); + + sleep(300); + stream.sendPacket(new byte[]{Fields.TS_GET_TEXT}, logger); + sleep(300); + + byte[] response = incomingData.getPacket(logger, "", true); + if (response == null) { + System.out.println("No response"); + return; + } + String textResponse = new String(response, 1, response.length - 1); + + StringBuilder messages = new StringBuilder(); + + ResponseBuffer responseBuffer = new ResponseBuffer(unpack -> { + EngineState.ValueCallback callback = new EngineState.ValueCallback() { + @Override + public void onUpdate(String value) { + if (value.startsWith(Fields.PROTOCOL_HELLO_PREFIX)) + messages.append(value + "\n"); + } + }; + while (!unpack.isEmpty()) { + String original = unpack; + unpack = EngineState.handleStringActionPair(unpack, new EngineState.StringActionPair(Fields.PROTOCOL_MSG, callback), null); + if (original.length() == unpack.length()) { + // skip key + unpack = EngineState.skipToken(unpack); + // skip value + unpack = EngineState.skipToken(unpack); + } + } + }); + responseBuffer.append(textResponse + "\r\n", LinkManager.ENCODER); + + System.out.println("Signature: " + SerialAutoChecker.SIGNATURE); + System.out.println("It says " + messages); + System.exit(0); + } + interface ConsoleTool { void runTool(String args[]) throws Exception; }