SD card log fields list should be auto-generated #3985
This commit is contained in:
parent
060849c364
commit
d16582c6c7
|
@ -4,6 +4,7 @@ import com.devexperts.logging.Logging;
|
|||
import com.opensr5.ini.field.EnumIniField;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.output.ConfigStructure;
|
||||
import com.rusefi.output.DataLogConsumer;
|
||||
import com.rusefi.output.JavaFieldsConsumer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -397,7 +398,10 @@ public class ConfigField {
|
|||
return isFromIterate;
|
||||
}
|
||||
|
||||
// todo: find more usages for this method?
|
||||
/**
|
||||
* todo: find more usages for this method?
|
||||
* @see DataLogConsumer.getComment
|
||||
*/
|
||||
public String getCommentOrName() {
|
||||
if (comment == null || comment.trim().isEmpty())
|
||||
return quote(name);
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.rusefi.output;
|
||||
|
||||
import static com.rusefi.output.JavaSensorsConsumer.quote;
|
||||
|
||||
import com.rusefi.ConfigField;
|
||||
import com.rusefi.ReaderState;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SdCardFieldsConsumer implements ConfigurationConsumer {
|
||||
private final StringBuilder body = new StringBuilder();
|
||||
private final String outputFileName;
|
||||
|
||||
public SdCardFieldsConsumer(String outputFileName) {
|
||||
this.outputFileName = outputFileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startFile() {
|
||||
ConfigurationConsumer.super.startFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endFile() throws IOException {
|
||||
ConfigurationConsumer.super.endFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEndStruct(ReaderState state, ConfigStructure structure) throws IOException {
|
||||
if (state.stack.isEmpty()) {
|
||||
PerFieldWithStructuresIterator iterator = new PerFieldWithStructuresIterator(state, structure.tsFields, "",
|
||||
this::processOutput, ".");
|
||||
iterator.loop();
|
||||
String content = iterator.getContent();
|
||||
body.append(content);
|
||||
}
|
||||
}
|
||||
|
||||
private String processOutput(ReaderState readerState, ConfigField configField, String prefix) {
|
||||
|
||||
|
||||
return "\t{engine->outputChannels." + configField.getName() +
|
||||
", "
|
||||
+ DataLogConsumer.getComment(prefix, configField, readerState.variableRegistry) +
|
||||
", " +
|
||||
quote(configField.getUnits()) +
|
||||
", " +
|
||||
configField.getDigits() +
|
||||
|
||||
"},\n";
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.rusefi.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.rusefi.ReaderState;
|
||||
import com.rusefi.output.SdCardFieldsConsumer;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SdCardFieldsGeneratorTest {
|
||||
@Test
|
||||
public void outputs() {
|
||||
String test = "struct_no_prefix output_channels_s\n" +
|
||||
"uint16_t autoscale RPMValue;@@GAUGE_NAME_RPM@@;\"RPM\",1, 0, 0, 8000, 0\n" +
|
||||
"\n" +
|
||||
"uint16_t rpmAcceleration;dRPM;\"RPM/s\",1, 0, 0, 5, 0\n" +
|
||||
"\n" +
|
||||
"\tuint16_t autoscale speedToRpmRatio;@@GAUGE_NAME_GEAR_RATIO@@;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
|
||||
"\tint8_t autoscale internalMcuTemperature;@@GAUGE_NAME_CPU_TEMP@@;\"deg C\",1, 0, 0, 0, 0\n" +
|
||||
"end_struct";
|
||||
|
||||
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");
|
||||
state.variableRegistry.register("GAUGE_NAME_CPU_TEMP", "te");
|
||||
|
||||
|
||||
SdCardFieldsConsumer consumer = new SdCardFieldsConsumer(null);
|
||||
state.readBufferedReader(test, consumer);
|
||||
assertEquals("\t{engine->outputChannels.RPMValue, \"hello\", \"RPM\", 0},\n" +
|
||||
"\t{engine->outputChannels.rpmAcceleration, \"dRPM\", \"RPM/s\", 0},\n" +
|
||||
"\t{engine->outputChannels.speedToRpmRatio, \"ra\", \"value\", 0},\n" +
|
||||
"\t{engine->outputChannels.internalMcuTemperature, \"te\", \"deg C\", 0},\n" +
|
||||
"\t{engine->outputChannels.alignmentFill_at_7, \"need 4 byte alignment\", \"units\", 0},\n", consumer.getBody());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue