TPS Live Documentation

This commit is contained in:
rusefi 2019-06-17 21:37:11 -04:00
parent e91e3f9690
commit 717af8a681
23 changed files with 181 additions and 40 deletions

View File

@ -290,6 +290,8 @@ static void handleGetStructContent(ts_channel_s *tsChannel, int structId, int si
addr = static_cast<thermistor_state_s*>(&engine->engineState.cltCurve);
} else if (structId == LDS_IAT_INDEX) {
addr = static_cast<thermistor_state_s*>(&engine->engineState.iatCurve);
} else if (structId == LDS_ENGINE_STATE_INDEX) {
addr = static_cast<engine_state2_s*>(&engine->engineState);
}
if (addr == NULL) {
// todo: add warning code - unexpected structId

View File

@ -34,6 +34,8 @@
#define DISPLAY_CONFIG(x) x
#define DISPLAY_FIELD(x) x
// we use this 'DISPLAY' macro if value is not used by C++ in current context
#define DISPLAY(x)
#define DISPLAY_TEXT(x)
#define DISPLAY_SENSOR(x) {}

View File

@ -810,6 +810,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0)
return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20190616;
return 20190617;
}
#endif /* EFI_UNIT_TEST */

View File

@ -1,4 +1,4 @@
// this section was generated automatically by ConfigDefinition.jar based on integration/engine_state.txt Sun Jun 16 23:32:38 EDT 2019
// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on integration/engine_state.txt Mon Jun 17 20:32:33 EDT 2019
// begin
#ifndef CONTROLLERS_GENERATED_ENGINE_STATE_GENERATED_H
#define CONTROLLERS_GENERATED_ENGINE_STATE_GENERATED_H
@ -29,11 +29,23 @@ struct engine_state2_s {
* offset 20
*/
float minRpmKcurrentTPS = 0;
/** total size 24*/
/**
* offset 24
*/
int currentTpsAdc = 0;
/**
* offset 28
*/
float tpsVoltageMCU = 0;
/**
* offset 32
*/
float tpsVoltageBoard = 0;
/** total size 36*/
};
typedef struct engine_state2_s engine_state2_s;
#endif
// end
// this section was generated automatically by ConfigDefinition.jar based on integration/engine_state.txt Sun Jun 16 23:32:38 EDT 2019
// this section was generated automatically by rusEfi tool ConfigDefinition.jar based on integration/engine_state.txt Mon Jun 17 20:32:33 EDT 2019

View File

@ -1313,6 +1313,7 @@
#define lcdThreadPeriodMs_offset 720
#define lcdThreadPeriodMs_offset_hex 2d0
#define LDS_CLT_INDEX 0
#define LDS_ENGINE_STATE_INDEX 3
#define LDS_IAT_INDEX 1
#define LDS_SPEED_DENSITY_INDEX 2
#define LE_COMMAND_LENGTH 200

View File

@ -84,12 +84,12 @@ float getTemperatureC(ThermistorConf *cfg, ThermistorMath *tm, bool useLinear DE
tm->DISPLAY_FIELD(voltageMCU) = DISPLAY_TEXT(from_pin) getVoltage("term", cfg->DISPLAY_CONFIG(adcChannel));
DISPLAY_TEXT(EOL);
DISPLAY_TEXT(Analog_ECU_read);
DISPLAY_TEXT(Analog_ECU_reads);
#if EFI_UNIT_TEST
// todo: get rid of this branch, unify unit test with real firmware. maybe analogInputDividerCoefficient needs to be set?
tm->voltageBoard = getVoltageDivided("term", cfg->adcChannel);
// CONFIG(analogInputDividerCoefficient) = 1;
// tm->DISPLAY_FIELD(voltageBoard) = DISPLAY_TEXT(Rdivider) tm->voltageMCU * CONFIG(DISPLAY_CONFIG(analogInputDividerCoefficient));
// tm-> ISPLAY_FIELD(voltageBoard) = ISPLAY_TEXT(Rdivider) tm->voltageMCU * CONFIG( ISPLAY_CONFIG(analogInputDividerCoefficient));
#else
tm->DISPLAY_FIELD(voltageBoard) = DISPLAY_TEXT(Rdivider) tm->voltageMCU * CONFIG(DISPLAY_CONFIG(analogInputDividerCoefficient));
#endif /* EFI_UNIT_TEST */

View File

@ -78,11 +78,33 @@ float getTpsRateOfChange(void) {
*
* */
percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX) {
DISPLAY_TEXT(Analog_MCU_reads);
engine->engineState.currentTpsAdc = adc;
#if !EFI_UNIT_TEST
engine->engineState.DISPLAY_FIELD(tpsVoltageMCU) = adcToVolts(adc);
#endif
DISPLAY_TEXT(Volts);inte
DISPLAY_TEXT(from_pin) DISPLAY(DISPLAY_CONFIG(tps1_1AdcChannel))
DISPLAY_TEXT(EOL);
DISPLAY_TEXT(Analog_ECU_reads);
engine->engineState.DISPLAY_FIELD(tpsVoltageBoard) =
DISPLAY_TEXT(Rdivider) engine->engineState.tpsVoltageMCU * CONFIG(DISPLAY_CONFIG(analogInputDividerCoefficient));
DISPLAY_TEXT(EOL);
if (engineConfiguration->tpsMin == engineConfiguration->tpsMax) {
warning(CUSTOM_INVALID_TPS_SETTING, "Invalid TPS configuration: same value %d", engineConfiguration->tpsMin);
return NAN;
}
float result = interpolateMsg("TPS", TPS_TS_CONVERSION * engineConfiguration->tpsMax, 100, TPS_TS_CONVERSION * engineConfiguration->tpsMin, 0, adc);
DISPLAY_TEXT(Current_ADC)
DISPLAY(DISPLAY_FIELD(currentTpsAdc))
DISPLAY_TEXT(interpolate_between)
float result = interpolateMsg("TPS", TPS_TS_CONVERSION * CONFIG(DISPLAY_CONFIG(tpsMax)), 100,
DISPLAY_TEXT(and)
TPS_TS_CONVERSION * CONFIG(DISPLAY_CONFIG(tpsMin)), 0, adc);
if (result < engineConfiguration->tpsErrorDetectionTooLow) {
#if EFI_PROD_CODE
// too much noise with simulator

View File

@ -1,17 +1,29 @@
rem TODO better place for this stuff, more automation so that each file does not need to be handled separately. maybe regexp?
java -jar ../java_tools/ConfigDefinition.jar ^
rm gen_config2.log
java -DSystemOut.name=gen_config2 ^
-jar ../java_tools/ConfigDefinition.jar ^
-definition integration/engine_state.txt ^
-java_destination ../java_console/models/src/com/rusefi/config/generated/EngineState.java ^
-initialize_to_zero yes ^
-c_destination controllers/generated/engine_state_generated.h
java -jar ../java_tools/ConfigDefinition.jar ^
java -DSystemOut.name=gen_config2 ^
-jar ../java_tools/ConfigDefinition.jar ^
-definition integration/thermistor.txt ^
-initialize_to_zero yes ^
-java_destination ../java_console/models/src/com/rusefi/config/generated/ThermistorState.java ^
-c_destination controllers/generated/thermistor.h
java -cp ../java_tools/ConfigDefinition.jar ^
java -DSystemOut.name=gen_config2 ^
-cp ../java_tools/ConfigDefinition.jar ^
com.rusefi.ldmp.LiveDocsMetaParser ^
controllers/sensors/thermistors.cpp ^
"../"
java -DSystemOut.name=gen_config2 ^
-cp ../java_tools/ConfigDefinition.jar ^
com.rusefi.ldmp.LiveDocsMetaParser ^
controllers/sensors/tps.cpp ^
"../"

View File

@ -16,5 +16,8 @@ floatms_t airFlow
float minRpmKcurrentTPS
int currentTpsAdc
float tpsVoltageMCU
float tpsVoltageBoard
end_struct

View File

@ -1155,6 +1155,7 @@ end_struct
#define LDS_CLT_INDEX 0
#define LDS_IAT_INDEX 1
#define LDS_SPEED_DENSITY_INDEX 2
#define LDS_ENGINE_STATE_INDEX 3
#define GAUGE_NAME_VERSION "firmware"
#define GAUGE_NAME_VVT "VVT postion"

View File

@ -8,8 +8,6 @@ import org.jetbrains.annotations.NotNull;
import java.nio.ByteBuffer;
import java.util.Objects;
import java.util.Objects;
import static com.rusefi.config.FieldType.*;
/**
@ -75,6 +73,21 @@ public class Field {
return last.offset + 4;
}
public static String niceToString(Number value) {
// not enum field
Number number = value;
if (number instanceof Float)
return niceToString(number.floatValue());
return number.toString();
}
public static String niceToString(double value) {
int scale = (int) Math.log10(value);
int places = 1 + Math.max(0, 4 - scale);
double toScale = Math.pow(10, places);
return Double.toString(Math.round(value * toScale) / toScale);
}
public String getName() {
return name;
}
@ -161,8 +174,7 @@ public class Field {
public Object getAnyValue(ConfigurationImage ci) {
if (options == null) {
// not enum field
return getValue(ci);
return niceToString(getValue(ci));
}
if (type != INT8)
throw new IllegalStateException("Unsupported enum " + type);
@ -175,9 +187,11 @@ public class Field {
public Number getValue(ConfigurationImage ci) {
Objects.requireNonNull(ci);
Number value;
ByteBuffer wrapped = getByteBuffer(ci);
if (getType() == INT) {
ByteBuffer wrapped = ci.getByteBuffer(getOffset(), type.getStorageSize());
if (type == INT) {
value = wrapped.getInt();
} else if (type == INT16) {
value = wrapped.getShort();
} else {
value = wrapped.getFloat();
}

View File

@ -1,6 +1,6 @@
package com.rusefi.config.generated;
// this file was generated automatically by ConfigDefinition.jar based on integration/engine_state.txt Sun Jun 16 22:18:54 EDT 2019
// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration/engine_state.txt Mon Jun 17 20:32:33 EDT 2019
import com.rusefi.config.*;
@ -11,6 +11,9 @@ public class EngineState {
public static final Field TCHARGE_COFF = Field.create("TCHARGE_COFF", 12, FieldType.FLOAT);
public static final Field AIRFLOW = Field.create("AIRFLOW", 16, FieldType.FLOAT);
public static final Field MINRPMKCURRENTTPS = Field.create("MINRPMKCURRENTTPS", 20, FieldType.FLOAT);
public static final Field CURRENTTPSADC = Field.create("CURRENTTPSADC", 24, FieldType.INT);
public static final Field TPSVOLTAGEMCU = Field.create("TPSVOLTAGEMCU", 28, FieldType.FLOAT);
public static final Field TPSVOLTAGEBOARD = Field.create("TPSVOLTAGEBOARD", 32, FieldType.FLOAT);
public static final Field[] VALUES = {
ISTCHARGEAIRMODEL,
AIRMASS,
@ -18,5 +21,8 @@ public class EngineState {
TCHARGE_COFF,
AIRFLOW,
MINRPMKCURRENTTPS,
CURRENTTPSADC,
TPSVOLTAGEMCU,
TPSVOLTAGEBOARD,
};
}

View File

@ -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 Mon Jun 17 19:57:03 EDT 2019
// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on integration\rusefi_config.txt Mon Jun 17 21:03:13 EDT 2019
import com.rusefi.config.*;
@ -859,6 +859,7 @@ public class Fields {
public static final int knockVThreshold_offset = 1520;
public static final int lcdThreadPeriodMs_offset = 720;
public static final int LDS_CLT_INDEX = 0;
public static final int LDS_ENGINE_STATE_INDEX = 3;
public static final int LDS_IAT_INDEX = 1;
public static final int LDS_SPEED_DENSITY_INDEX = 2;
public static final int LE_COMMAND_LENGTH = 200;

View File

@ -4,8 +4,6 @@ import com.rusefi.config.Field;
import com.rusefi.core.Pair;
import org.junit.Test;
import java.util.Iterator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -29,5 +27,16 @@ public class FieldTest {
assertEquals(1.0, p.second);
}
}
@Test
public void testPrecisionDependingOnScale() {
assertEquals("1234567.1", Field.niceToString(1234567.123));
assertEquals("10000.0", Field.niceToString(10000.00002));
assertEquals("0.12302", Field.niceToString(0.12302));
assertEquals("0.002", Field.niceToString(0.002));
assertEquals("12.302", Field.niceToString(12.302));
assertEquals("123.02", Field.niceToString(123.02));
}
}

View File

@ -46,7 +46,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20190616;
public static final int CONSOLE_VERSION = 20190617;
public static final boolean SHOW_STIMULATOR = false;
public static final String INPUT_FILES_PATH = "..";
private static final String TAB_INDEX = "main_tab";

View File

@ -9,7 +9,7 @@ public class ThermistorsMeta {
new TextRequest("from_pin"),
new ConfigRequest("adcChannel"),
new TextRequest("EOL"),
new TextRequest("Analog_ECU_read"),
new TextRequest("Analog_ECU_reads"),
new FieldRequest("voltageBoard"),
new TextRequest("Rdivider"),
new ConfigRequest("analogInputDividerCoefficient"),

View File

@ -0,0 +1,25 @@
package com.rusefi.ldmp.generated;
import com.rusefi.ldmp.*;
public class TpsMeta {
public static final Request[] CONTENT = new Request[]{
new TextRequest("Analog_MCU_reads"),
new FieldRequest("tpsVoltageMCU"),
new TextRequest("Volts"),
new TextRequest("from_pin"),
new ConfigRequest("tps1_1AdcChannel"),
new TextRequest("EOL"),
new TextRequest("Analog_ECU_reads"),
new FieldRequest("tpsVoltageBoard"),
new TextRequest("Rdivider"),
new ConfigRequest("analogInputDividerCoefficient"),
new TextRequest("EOL"),
new TextRequest("Current_ADC"),
new FieldRequest("currentTpsAdc"),
new TextRequest("interpolate_between"),
new ConfigRequest("tpsMax"),
new TextRequest("and"),
new ConfigRequest("tpsMin"),
};
}

View File

@ -4,10 +4,13 @@ import com.opensr5.ConfigurationImage;
import com.rusefi.FileLog;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
import com.rusefi.config.generated.EngineState;
import com.rusefi.config.generated.Fields;
import com.rusefi.config.generated.ThermistorState;
import com.rusefi.core.Sensor;
import com.rusefi.core.SensorCentral;
import com.rusefi.ldmp.generated.ThermistorsMeta;
import com.rusefi.ldmp.generated.TpsMeta;
import com.rusefi.ui.config.ConfigField;
import com.rusefi.ui.livedocs.LiveDocPanel;
import com.rusefi.ui.util.UiUtils;
@ -24,9 +27,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import static com.rusefi.config.generated.Fields.LDS_CLT_INDEX;
import static com.rusefi.config.generated.Fields.LDS_IAT_INDEX;
/**
* (c) Andrey Belomutskiy 2013-2018
@ -48,8 +48,14 @@ public class FormulasPane {
public FormulasPane() {
content.add(centerProxy, BorderLayout.CENTER);
liveDocs.add(LiveDocPanel.getThermistorPanel("Coolant Sensor", "CLT", LDS_CLT_INDEX, ThermistorState.VALUES));
liveDocs.add(LiveDocPanel.getThermistorPanel("Intake Air Sensor", "IAT", LDS_IAT_INDEX, ThermistorState.VALUES));
liveDocs.add(LiveDocPanel.getPanel("Coolant Sensor", "CLT", Fields.LDS_CLT_INDEX,
ThermistorState.VALUES, ThermistorsMeta.CONTENT));
liveDocs.add(LiveDocPanel.getPanel("Intake Air Sensor", "IAT", Fields.LDS_IAT_INDEX,
ThermistorState.VALUES, ThermistorsMeta.CONTENT));
liveDocs.add(LiveDocPanel.getPanel("Throttle Position Sensor", "", Fields.LDS_ENGINE_STATE_INDEX,
EngineState.VALUES, TpsMeta.CONTENT));
centerProxy.add(new JLabel("Waiting for data..."), BorderLayout.CENTER);
@ -138,7 +144,7 @@ public class FormulasPane {
baseFuelStr + "ms";
String actualLastInjection = twoDecimals(Sensor.actualLastInjection);
String injTime = "$Fuel (ms) = " + baseFuel + getInjecctorLag() +
String injTime = "$Fuel (ms) = " + baseFuel + getInjecctorLag() +
" = " + actualLastInjection + "ms_per_injection$";
page = acceleration + injTime;
@ -175,7 +181,7 @@ public class FormulasPane {
int elEnrichLength = ConfigField.getIntValue(ci, Fields.ENGINELOADACCELLENGTH);
String tpsEnrichDelta = "$deltaTps = max(currentTps - previousTps, length = " + tpsEnrichLength +
") = " + tpsDelta +"$";
") = " + tpsDelta + "$";
double tpsAccelThreshold = ConfigField.getFloatValue(ci, Fields.TPSACCELENRICHMENTTHRESHOLD);
String tpsAccelMult = "fixme";//ConfigField.getFloatValue(ci, Fields.TPSACCELENRICHMENTMULTIPLIER);
@ -185,8 +191,8 @@ public class FormulasPane {
double tpsDecelMult = ConfigField.getFloatValue(ci, Fields.TPSDECELENLEANMENTMULTIPLIER);
String tpsEnrich = "$tpsAccelEnrich = if (" +
"(tpsDelta = " + tpsDelta + ") > (tpsThreshold = " + tpsAccelThreshold +"), tpsDelta, 0) * " +
"(tpsAccelMultiplier = " + tpsAccelMult + ") = " + tpsAccelValue + "$";
"(tpsDelta = " + tpsDelta + ") > (tpsThreshold = " + tpsAccelThreshold + "), tpsDelta, 0) * " +
"(tpsAccelMultiplier = " + tpsAccelMult + ") = " + tpsAccelValue + "$";
String loadEnrichDelta = "$deltaLoad = max(currentLoad - previousLoad, length = " + elEnrichLength +
") = " + elDelta + "$";

View File

@ -8,7 +8,6 @@ import com.rusefi.ldmp.ConfigRequest;
import com.rusefi.ldmp.FieldRequest;
import com.rusefi.ldmp.Request;
import com.rusefi.ldmp.TextRequest;
import com.rusefi.ldmp.generated.ThermistorsMeta;
import net.miginfocom.swing.MigLayout;
import org.jetbrains.annotations.NotNull;
@ -19,11 +18,11 @@ import java.util.List;
public class LiveDocPanel {
@NotNull
public static JPanel getThermistorPanel(String title, String instancePrefix, final int id, Field[] values) {
public static JPanel getPanel(String title, String instancePrefix, final int id, Field[] values, Request[] content) {
JPanel panel = new JPanel(new MigLayout());
panel.setBorder(BorderFactory.createTitledBorder(title));
List<RefreshActions> actions = createComponents(panel, ThermistorsMeta.CONTENT, values, instancePrefix);
List<RefreshActions> actions = createComponents(panel, content, values, instancePrefix);
LiveDocHolder holder = new LiveDocHolder(id, actions, values) {
@Override
@ -60,7 +59,8 @@ public class LiveDocPanel {
actionsList.add(new RefreshActions() {
@Override
public void refresh(BinaryProtocol bp, byte[] response) {
String value = field.getValue(new ConfigurationImage(response)).toString();
Number fieldValue = field.getValue(new ConfigurationImage(response));
String value = Field.niceToString(fieldValue);
label.setText(value);
}
});

View File

@ -1,6 +1,7 @@
package com.rusefi.ui.livedocs;
import com.rusefi.config.generated.ThermistorState;
import com.rusefi.ldmp.generated.ThermistorsMeta;
import com.rusefi.ui.livedocs.controls.Toolbox;
import com.rusefi.ui.util.FrameHelper;
import net.miginfocom.swing.MigLayout;
@ -19,8 +20,8 @@ public class LiveDocsSandbox {
comment.setForeground(Color.blue);
JPanel panels = new JPanel(new MigLayout("gap 0, insets 0"));
panels.add(LiveDocPanel.getThermistorPanel("Coolant Sensor", "CLT", LDS_CLT_INDEX, ThermistorState.VALUES), "wrap");
panels.add(LiveDocPanel.getThermistorPanel("Intake Air Sensor", "CLT", LDS_CLT_INDEX, ThermistorState.VALUES), "wrap");
panels.add(LiveDocPanel.getPanel("Coolant Sensor", "CLT", LDS_CLT_INDEX, ThermistorState.VALUES, ThermistorsMeta.CONTENT), "wrap");
panels.add(LiveDocPanel.getPanel("Intake Air Sensor", "CLT", LDS_CLT_INDEX, ThermistorState.VALUES, ThermistorsMeta.CONTENT), "wrap");
panels.add(getTChargePanel(), "wrap");

Binary file not shown.

View File

@ -42,8 +42,7 @@ public class LiveDocsMetaParser {
List<Request> r = parse(content);
SystemOut.println(r);
String className = "ThermistorMeta";
String className = getClassName(fileName);
String javaCode = generateJavaCode(r, className);
FileWriter fw = new FileWriter(destinationPath + "java_console/ui/src/com/rusefi/ldmp/generated/" + className + ".java");
fw.write(javaCode);
@ -54,7 +53,7 @@ public class LiveDocsMetaParser {
Stack<List<Request>> stack = new Stack<>();
List<Request> result = new ArrayList<>();
string = string.replaceAll("[()>]", " ");
string = string.replaceAll("[()>.]", " ");
SystemOut.println(string);
Scanner s = new Scanner(string);
while (s.hasNext()) {
@ -138,4 +137,16 @@ public class LiveDocsMetaParser {
return java.toString();
}
public static String getClassName(String cppSourceName) {
int lastDotIndex = cppSourceName.lastIndexOf('.');
if (lastDotIndex != -1)
cppSourceName = cppSourceName.substring(0, lastDotIndex);
int lastSlashIndex = cppSourceName.lastIndexOf('/');
if (lastDotIndex != -1)
cppSourceName = cppSourceName.substring(lastSlashIndex + 1);
return Character.toUpperCase(cppSourceName.charAt(0)) + cppSourceName.substring(1) + "Meta";
}
}

View File

@ -8,6 +8,11 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
public class LiveDocsMetaParserTest {
@Test
public void getClassName() {
assertEquals("TpsMeta", LiveDocsMetaParser.getClassName("controllers/sensors/tps.cpp"));
}
@Test
public void parseConfigElements() {
List<Request> r = LiveDocsMetaParser.parse("\t\t// TCHARGE_MODE_RPM_TPS\n" +
@ -21,6 +26,14 @@ public class LiveDocsMetaParserTest {
assertEquals(new ConfigRequest("tChargeMinRpmMinTps"), r.get(0));
}
@Test
public void parseField() {
List<Request> r = LiveDocsMetaParser.parse("\tDISPLAY_TEXT(Analog_MCU_reads);\n" +
"\tengine->engineState.DISPLAY_FIELD(currentTpsAdc) = adc;\n" +
"\tDISPLAY_TEXT(ADC_which_equals);\n");
assertEquals(3, r.size());
}
@Test
public void parseDisplayConfig() {
List<Request> r = LiveDocsMetaParser.parse("\t\t// DISPLAY_TEXT(interpolate(\")\n" +