From 04009fd6f739f778ab925babb89864e96f163f94 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 18 Aug 2019 12:30:59 -0400 Subject: [PATCH] refactoring: extracting common magic constant --- firmware/console/binary/tunerstudio.cpp | 14 ++++++-------- firmware/integration/rusefi_config.txt | 1 + .../src/com/rusefi/config/generated/Fields.java | 3 ++- .../models/src/com/rusefi/core/EngineState.java | 11 ++++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 11207c5faa..b554c83e96 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -645,26 +645,24 @@ void handleOutputChannelsCommand(ts_channel_s *tsChannel, ts_response_format_e m sr5SendResponse(tsChannel, mode, ((const uint8_t *) &tsOutputChannels) + offset, count); } -#define TEST_RESPONSE_TAG " ts_p_alive\r\n" - void handleTestCommand(ts_channel_s *tsChannel) { tsState.testCommandCounter++; - static char testOutputBuffer[12]; + static char testOutputBuffer[24]; /** * this is NOT a standard TunerStudio command, this is my own * extension of the protocol to simplify troubleshooting */ tunerStudioDebug("got T (Test)"); sr5WriteData(tsChannel, (const uint8_t *) VCS_VERSION, sizeof(VCS_VERSION)); + chsnprintf(testOutputBuffer, sizeof(testOutputBuffer), " %d %d", engine->engineState.warnings.lastErrorCode, tsState.testCommandCounter); sr5WriteData(tsChannel, (const uint8_t *) testOutputBuffer, strlen(testOutputBuffer)); + chsnprintf(testOutputBuffer, sizeof(testOutputBuffer), " uptime=%ds", getTimeNowSeconds()); sr5WriteData(tsChannel, (const uint8_t *) testOutputBuffer, strlen(testOutputBuffer)); - /** - * Please note that this response is a magic constant used by rusEfi console for protocol detection - * @see EngineState#TS_PROTOCOL_TAG - */ - sr5WriteData(tsChannel, (const uint8_t *) TEST_RESPONSE_TAG, sizeof(TEST_RESPONSE_TAG)); + + chsnprintf(testOutputBuffer, sizeof(testOutputBuffer), " %s\r\n", PROTOCOL_TEST_RESPONSE_TAG); + sr5WriteData(tsChannel, (const uint8_t *) testOutputBuffer, strlen(testOutputBuffer)); } extern CommandHandler console_line_callback; diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 107a390cff..d9ffce36de 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1236,6 +1236,7 @@ end_struct #define PROTOCOL_ANALOG_CHART "analog_chart" #define PROTOCOL_ENGINE_SNIFFER "wave_chart" #define PROTOCOL_VERSION_TAG "rusEfiVersion" +#define PROTOCOL_TEST_RESPONSE_TAG "ts_p_alive" #define GAUGE_NAME_DWELL_DUTY "dwell: coil duty cycle" diff --git a/java_console/models/src/com/rusefi/config/generated/Fields.java b/java_console/models/src/com/rusefi/config/generated/Fields.java index 4e0adfa57b..38ba0e84fb 100644 --- a/java_console/models/src/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/com/rusefi/config/generated/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config.generated; -// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration\rusefi_config.txt Sun Aug 18 12:09:19 EDT 2019 +// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration\rusefi_config.txt Sun Aug 18 12:24:07 EDT 2019 // by class com.rusefi.output.JavaFieldsConsumer import com.rusefi.config.*; @@ -1001,6 +1001,7 @@ public class Fields { public static final String PROTOCOL_ANALOG_CHART = "analog_chart"; public static final String PROTOCOL_ENGINE_SNIFFER = "wave_chart"; public static final String PROTOCOL_OUTPIN = "outpin"; + public static final String PROTOCOL_TEST_RESPONSE_TAG = "ts_p_alive"; public static final String PROTOCOL_VERSION_TAG = "rusEfiVersion"; public static final int RPM_1_BYTE_PACKING_MULT = 50; public static final int rpmHardLimit_offset = 416; diff --git a/java_console/models/src/com/rusefi/core/EngineState.java b/java_console/models/src/com/rusefi/core/EngineState.java index 915707fc0d..65200a61f4 100644 --- a/java_console/models/src/com/rusefi/core/EngineState.java +++ b/java_console/models/src/com/rusefi/core/EngineState.java @@ -1,6 +1,7 @@ package com.rusefi.core; import com.rusefi.FileLog; +import com.rusefi.config.generated.Fields; import com.rusefi.io.LinkDecoder; import org.jetbrains.annotations.NotNull; @@ -17,10 +18,6 @@ import java.util.concurrent.CopyOnWriteArrayList; public class EngineState { public static final String SEPARATOR = ","; public static final String PACKING_DELIMITER = ":"; - /** - * If we get this tag we have probably connected to the wrong port - */ - private static final CharSequence TS_PROTOCOL_TAG = "ts_p_al"; private final Object lock = new Object(); public void replaceStringValueAction(String key, ValueCallback callback) { @@ -107,7 +104,11 @@ public class EngineState { */ public static String unpackString(String message) { String prefix = "line" + PACKING_DELIMITER; - if (message.contains(TS_PROTOCOL_TAG)) { + /** + * If we get this tag we have probably connected to the wrong port + * todo: as of 2019 this logic maybe makes no sense any more since pure text protocol was reduce/removed? + */ + if (message.contains(Fields.PROTOCOL_TEST_RESPONSE_TAG)) { JOptionPane.showMessageDialog(null, "Are you sure you are not connected to TS port?"); return null; }