refactoring: extracting common magic constant
This commit is contained in:
parent
db724568db
commit
bfc4392dcd
|
@ -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;
|
||||
|
|
|
@ -1523,6 +1523,7 @@
|
|||
#define PROTOCOL_ANALOG_CHART "analog_chart"
|
||||
#define PROTOCOL_ENGINE_SNIFFER "wave_chart"
|
||||
#define PROTOCOL_OUTPIN "outpin"
|
||||
#define PROTOCOL_TEST_RESPONSE_TAG "ts_p_alive"
|
||||
#define PROTOCOL_VERSION_TAG "rusEfiVersion"
|
||||
#define RPM_1_BYTE_PACKING_MULT 50
|
||||
#define rpmHardLimit_offset 416
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue