logging of live data structs was: data points #3614
This commit is contained in:
parent
5ea6edda62
commit
60ee5a3320
|
@ -88,12 +88,8 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
String[] tokens = custom.split(",");
|
||||
String stringSize = tokens[3].trim();
|
||||
javaFieldsWriter.write(stringSize + ", FieldType.STRING");
|
||||
} else if (configField.getElementSize() == 1) {
|
||||
javaFieldsWriter.write("FieldType.INT8");
|
||||
} else if (configField.getElementSize() == 2) {
|
||||
javaFieldsWriter.write("FieldType.INT16");
|
||||
} else {
|
||||
javaFieldsWriter.write("FieldType.INT");
|
||||
javaFieldsWriter.write(getJavaType(configField.getElementSize()));
|
||||
}
|
||||
if (enumOptions != null) {
|
||||
javaFieldsWriter.write(", " + configField.getType());
|
||||
|
@ -107,6 +103,16 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
|
|||
return tsPosition;
|
||||
}
|
||||
|
||||
public static String getJavaType(int elementSize) {
|
||||
if (elementSize == 1) {
|
||||
return ("FieldType.INT8");
|
||||
} else if (elementSize == 2) {
|
||||
return "FieldType.INT16";
|
||||
} else {
|
||||
return "FieldType.INT";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isStringField(ConfigField configField) {
|
||||
String custom = state.tsCustomLine.get(configField.getType());
|
||||
return custom != null && custom.toLowerCase().startsWith(IniFileModel.FIELD_TYPE_STRING);
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class JavaSensorsConsumer implements ConfigurationConsumer {
|
||||
private final ReaderState state;
|
||||
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
|
||||
public JavaSensorsConsumer(ReaderState state) {
|
||||
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFile() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endFile() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState readerState, ConfigStructure structure) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
writeJavaFields(structure.tsFields, "", 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeJavaFields(List<ConfigField> tsFields, String prefix, int tsPosition) {
|
||||
FieldIterator iterator = new FieldIterator(tsFields);
|
||||
for (int i = 0; i < tsFields.size(); i++) {
|
||||
iterator.start(i);
|
||||
tsPosition = writeOneField(iterator.cf, prefix, tsPosition, iterator.next,
|
||||
iterator.bitState.get(),
|
||||
iterator.getPrev());
|
||||
|
||||
iterator.end();
|
||||
}
|
||||
}
|
||||
|
||||
private int writeOneField(ConfigField configField, String prefix, int tsPosition, ConfigField next, int i, ConfigField prev) {
|
||||
if (configField.isBit()) {
|
||||
// do not support bits for now but need to account for size
|
||||
tsPosition += configField.getSize(next);
|
||||
return tsPosition;
|
||||
}
|
||||
sb.append(configField.getName()).append("(");
|
||||
|
||||
sb.append(configField.getComment()).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.getMin()).append(", ");
|
||||
sb.append(configField.getMax()).append(", ");
|
||||
|
||||
sb.append(quote(configField.getUnits())).append(")");
|
||||
|
||||
|
||||
sb.append(",");
|
||||
sb.append("\n");
|
||||
|
||||
|
||||
tsPosition += configField.getSize(next);
|
||||
return tsPosition;
|
||||
}
|
||||
|
||||
private static String quote(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.JavaSensorsConsumer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class JavaSensorsConsumerTest {
|
||||
@Test
|
||||
public void generateJavaSensors() throws IOException {
|
||||
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 rpmAcceleration;dRPM;\"RPM/s\",1, 0, 0, 5, 0\n" +
|
||||
"\tuint16_t autoscale speedToRpmRatio;name;\"value\",{1/100}, 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);
|
||||
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",
|
||||
javaSensorsConsumer.getContent());
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue