logging of live data structs was: data points #3614

This commit is contained in:
rusefillc 2022-04-16 00:48:01 -04:00
parent 24ebcc8989
commit b9e56a36c7
6 changed files with 68 additions and 24 deletions

View File

@ -24,13 +24,12 @@ public enum Sensor {
* Please note that these enum names are used to make 'set_mock_XXX_voltage' commands
*/
// RPM, vss
RPMValue(GAUGE_NAME_RPM, SensorCategory.SENSOR_INPUTS, FieldType.UINT16, 4, 1, 0, 8000, "RPM"),
speedToRpmRatio("SpeedToRpm", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 6, 1.0 / PACK_MULT_PERCENT, 0, 5, "RPM/kph"),
vehicleSpeedKph(GAUGE_NAME_VVS, SensorCategory.OPERATIONS, FieldType.UINT8, 10, 1, 0, 150, "kph"),
RPMValue("RPM", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 4, 1.0, 0.0, 8000.0, "RPM"),
rpmAcceleration("dRPM", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 6, 1.0, 0.0, 5.0, "RPM/s"),
speedToRpmRatio("Gearbox Ratio", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 8, 0.01, 0.0, 0.0, "value"),
vehicleSpeedKph("Vehicle Speed", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 10, 1.0, 0.0, 0.0, "kph"),
internalMcuTemperature("CPU Temperature", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 11, 1.0, 0.0, 0.0, "deg C"),
// Temperatures
internalMcuTemperature(GAUGE_NAME_CPU_TEMP, SensorCategory.OPERATIONS, FieldType.INT8, 11, 1, 0, 5, "C"),
CLT(GAUGE_NAME_CLT, SensorCategory.SENSOR_INPUTS, FieldType.INT16, 12, 1.0 / PACK_MULT_TEMPERATURE, -40, 150, "deg C"),
IAT(GAUGE_NAME_IAT, SensorCategory.SENSOR_INPUTS, FieldType.INT16, 14, 1.0 / PACK_MULT_TEMPERATURE, -40, 150, "deg C"),
AuxT1("AuxT1", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 16, 1.0 / PACK_MULT_TEMPERATURE, -40, 150, "deg C"),
@ -158,6 +157,20 @@ public enum Sensor {
// Synthetic (console only) channels
ETB_CONTROL_QUALITY("ETB metric", SensorCategory.SNIFFING, "", 100),
cranking("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 780, 1.0, -1.0, -1.0, ""),
running("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 800, 1.0, -1.0, -1.0, ""),
etbFeedForward("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 828, 1.0, -1.0, -1.0, ""),
targetFromTable("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 832, 1.0, -1.0, -1.0, ""),
sparkDwell("ignition dwell duration in ms\nSee also dwellAngle", SensorCategory.SENSOR_INPUTS, FieldType.INT, 836, 1.0, -1.0, -1.0, ""),
dwellAngle("ignition dwell duration as crankshaft angle\nNAN if engine is stopped\nSee also sparkDwell", SensorCategory.SENSOR_INPUTS, FieldType.INT, 840, 1.0, -1.0, -1.0, ""),
baseDwell("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 972, 1.0, -1.0, -1.0, ""),
dwellVoltageCorrection("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 976, 1.0, -1.0, -1.0, ""),
etb_idlePosition("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 980, 1.0, -1.0, -1.0, ""),
trim("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 984, 1.0, -1.0, -1.0, ""),
luaAdjustment("", SensorCategory.SENSOR_INPUTS, FieldType.INT, 988, 1.0, -1.0, -1.0, ""),
;
private final String name;

Binary file not shown.

View File

@ -4,10 +4,7 @@ import com.devexperts.logging.Logging;
import com.opensr5.ini.RawIniFile;
import com.opensr5.ini.field.EnumIniField;
import com.rusefi.enum_reader.Value;
import com.rusefi.output.CHeaderConsumer;
import com.rusefi.output.ConfigStructure;
import com.rusefi.output.ConfigurationConsumer;
import com.rusefi.output.FileJavaFieldsConsumer;
import com.rusefi.output.*;
import com.rusefi.util.IoUtils;
import com.rusefi.util.SystemOut;
@ -334,4 +331,8 @@ public class ReaderState {
prependFiles.add(fileName);
inputFiles.add(fileName);
}
public void addDestination(ConfigurationConsumer consumer) {
destinations.add(consumer);
}
}

View File

@ -2,6 +2,7 @@ package com.rusefi.ldmp;
import com.rusefi.ConfigDefinition;
import com.rusefi.ReaderState;
import com.rusefi.output.JavaSensorsConsumer;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
@ -34,7 +35,11 @@ public class UsagesReader {
Yaml yaml = new Yaml();
Map<String, Object> data = yaml.load(new FileReader(yamlFileName));
StringBuilder totalSensors = new StringBuilder();
EntryHandler handler = new EntryHandler() {
int sensorTsPosition = 0;
@Override
public void onEntry(String name, List elements) throws IOException {
String javaName = (String) elements.get(0);
@ -61,16 +66,26 @@ public class UsagesReader {
state.setDefinitionInputFile(folder + File.separator + name + ".txt");
state.withC_Defines = withCDefines;
JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer(state, sensorTsPosition);
state.addDestination(javaSensorsConsumer);
state.addPrepend(prepend);
state.addCHeaderDestination(folder + File.separator + name + "_generated.h");
state.addJavaDestination("../java_console/models/src/main/java/com/rusefi/config/generated/" + javaName);
state.doJob();
sensorTsPosition = javaSensorsConsumer.sensorTsPosition;
totalSensors.append(javaSensorsConsumer.getContent());
}
};
UsagesReader usagesReader = new UsagesReader();
usagesReader.handleYaml(data, handler);
usagesReader.writeFiles();
try (FileWriter fw = new FileWriter("console/binary/generated/sensors.java")) {
fw.write(totalSensors.toString());
}
}
interface EntryHandler {

View File

@ -8,12 +8,14 @@ import java.util.List;
public class JavaSensorsConsumer implements ConfigurationConsumer {
private final ReaderState state;
public int sensorTsPosition;
private final StringBuilder sb = new StringBuilder();
public JavaSensorsConsumer(ReaderState state) {
public JavaSensorsConsumer(ReaderState state, int sensorTsPosition) {
this.state = state;
this.sensorTsPosition = sensorTsPosition;
}
@Override
@ -27,11 +29,11 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
@Override
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
if (state.stack.isEmpty()) {
writeJavaFields(structure.tsFields, "", 0);
sensorTsPosition = writeJavaFields(structure.tsFields, "", sensorTsPosition);
}
}
private void writeJavaFields(List<ConfigField> tsFields, String prefix, int tsPosition) {
private int writeJavaFields(List<ConfigField> tsFields, String prefix, int tsPosition) {
FieldIterator iterator = new FieldIterator(tsFields);
for (int i = 0; i < tsFields.size(); i++) {
iterator.start(i);
@ -41,6 +43,7 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
iterator.end();
}
return tsPosition;
}
private int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int i, ConfigField prev) {
@ -51,12 +54,20 @@ public class JavaSensorsConsumer implements ConfigurationConsumer {
}
sb.append(configField.getName()).append("(");
sb.append(configField.getComment()).append(", ");
String string = state.variableRegistry.applyVariables(configField.getComment());
if (string == null) {
string = "\"\"";
} else if (string.isEmpty() || string.charAt(0) != '"') {
// huh? weird conditional quoting?
string = quote(string);
}
sb.append(string).append(", ");
sb.append("SensorCategory.SENSOR_INPUTS, ");
sb.append(JavaFieldsConsumer.getJavaType(configField.getElementSize())).append(", ");
sb.append(tsPosition).append(", ");
sb.append("1").append(", "); // scale
sb.append(configField.autoscaleSpecNumber()).append(", "); // scale
sb.append(configField.getMin()).append(", ");
sb.append(configField.getMax()).append(", ");

View File

@ -11,26 +11,30 @@ import static org.junit.Assert.assertEquals;
public class JavaSensorsConsumerTest {
@Test
public void generateJavaSensors() throws IOException {
ReaderState state = new ReaderState();
state.variableRegistry.register("PACK_MULT_PERCENT", 100);
state.variableRegistry.register("GAUGE_NAME_RPM", "\"hello\"");
state.variableRegistry.register("GAUGE_NAME_GEAR_RATIO", "ra");
String outputChannels = "" +
"\n" +
"" +
"struct_no_prefix output_channels_s\n" +
"bit sd_present\n" +
"uint16_t autoscale RPMValue;GAUGE_NAME_RPM;\"RPM\",1, 0, 0, 8000, 0\n" +
"uint16_t autoscale RPMValue;@@GAUGE_NAME_RPM@@;\"RPM\",1, 0, 0, 8000, 0\n" +
"uint16_t rpmAcceleration;dRPM;\"RPM/s\",1, 0, 0, 5, 0\n" +
"\tuint16_t autoscale speedToRpmRatio;name;\"value\",{1/100}, 0, 0, 0, 0\n" +
"\tuint16_t autoscale speedToRpmRatio;@@GAUGE_NAME_GEAR_RATIO@@;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
"\tuint8_t autoscale vehicleSpeedKph;name2;\"kph\",1, 0, 0, 0, 0\n" +
"\tint8_t autoscale internalMcuTemperature;mcu;\"deg C\",1, 0, 0, 0, 0\n" +
"end_struct\n";
ReaderState state = new ReaderState();
JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer(state);
JavaSensorsConsumer javaSensorsConsumer = new JavaSensorsConsumer(state, 0);
state.readBufferedReader(outputChannels, javaSensorsConsumer);
assertEquals("RPMValue(GAUGE_NAME_RPM, SensorCategory.SENSOR_INPUTS, FieldType.INT16, 4, 1, 0.0, 8000.0, \"RPM\"),\n" +
"rpmAcceleration(dRPM, SensorCategory.SENSOR_INPUTS, FieldType.INT16, 6, 1, 0.0, 5.0, \"RPM/s\"),\n" +
"speedToRpmRatio(name, SensorCategory.SENSOR_INPUTS, FieldType.INT16, 8, 1, 0.0, 0.0, \"value\"),\n" +
"vehicleSpeedKph(name2, SensorCategory.SENSOR_INPUTS, FieldType.INT8, 10, 1, 0.0, 0.0, \"kph\"),\n" +
"internalMcuTemperature(mcu, SensorCategory.SENSOR_INPUTS, FieldType.INT8, 11, 1, 0.0, 0.0, \"deg C\"),\n",
assertEquals("RPMValue(\"hello\", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 4, 1.0, 0.0, 8000.0, \"RPM\"),\n" +
"rpmAcceleration(\"dRPM\", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 6, 1.0, 0.0, 5.0, \"RPM/s\"),\n" +
"speedToRpmRatio(\"ra\", SensorCategory.SENSOR_INPUTS, FieldType.INT16, 8, 0.01, 0.0, 0.0, \"value\"),\n" +
"vehicleSpeedKph(\"name2\", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 10, 1.0, 0.0, 0.0, \"kph\"),\n" +
"internalMcuTemperature(\"mcu\", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 11, 1.0, 0.0, 0.0, \"deg C\"),\n",
javaSensorsConsumer.getContent());