parent
ca4e8d1a2c
commit
a9c63c92a1
Binary file not shown.
|
@ -54,6 +54,8 @@ public class ConfigField {
|
||||||
private final String trueName;
|
private final String trueName;
|
||||||
private final String falseName;
|
private final String falseName;
|
||||||
private boolean isFromIterate;
|
private boolean isFromIterate;
|
||||||
|
private String iterateOriginalName;
|
||||||
|
private int iterateIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo: one day someone should convert this into a builder
|
* todo: one day someone should convert this into a builder
|
||||||
|
@ -390,8 +392,18 @@ public class ConfigField {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void isFromIterate(boolean isFromIterate) {
|
public void setFromIterate(String iterateOriginalName, int iterateIndex) {
|
||||||
this.isFromIterate = isFromIterate;
|
this.iterateOriginalName = iterateOriginalName;
|
||||||
|
this.iterateIndex = iterateIndex;
|
||||||
|
this.isFromIterate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIterateOriginalName() {
|
||||||
|
return iterateOriginalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIterateIndex() {
|
||||||
|
return iterateIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFromIterate() {
|
public boolean isFromIterate() {
|
||||||
|
|
|
@ -309,7 +309,7 @@ public class ReaderState {
|
||||||
String commentWithIndex = getCommentWithIndex(cf, i);
|
String commentWithIndex = getCommentWithIndex(cf, i);
|
||||||
ConfigField element = new ConfigField(state, cf.getName() + i, commentWithIndex, null,
|
ConfigField element = new ConfigField(state, cf.getName() + i, commentWithIndex, null,
|
||||||
cf.getType(), new int[0], cf.getTsInfo(), false, false, cf.isHasAutoscale(), null, null);
|
cf.getType(), new int[0], cf.getTsInfo(), false, false, cf.isHasAutoscale(), null, null);
|
||||||
element.isFromIterate(true);
|
element.setFromIterate(cf.getName(), i);
|
||||||
structure.addTs(element);
|
structure.addTs(element);
|
||||||
}
|
}
|
||||||
} else if (cf.isDirective()) {
|
} else if (cf.isDirective()) {
|
||||||
|
|
|
@ -23,7 +23,8 @@ public class SdCardFieldsConsumer implements ConfigurationConsumer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endFile() throws IOException {
|
public void endFile() throws IOException {
|
||||||
output.write("static constexpr LogField fields[] = {\r\n");
|
output.write("static constexpr LogField fields[] = {\r\n" +
|
||||||
|
"{packedTime, GAUGE_NAME_TIME, \"sec\", 0},\n");
|
||||||
output.write(getBody());
|
output.write(getBody());
|
||||||
output.write("};\r\n");
|
output.write("};\r\n");
|
||||||
output.close();
|
output.close();
|
||||||
|
@ -48,7 +49,16 @@ public class SdCardFieldsConsumer implements ConfigurationConsumer {
|
||||||
if (configField.isBit())
|
if (configField.isBit())
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
return "\t{engine->outputChannels." + configField.getName() +
|
if (configField.isFromIterate()) {
|
||||||
|
String name = configField.getIterateOriginalName() + "[" + (configField.getIterateIndex() - 1) + "]";
|
||||||
|
return getLine(readerState, configField, prefix, name);
|
||||||
|
} else {
|
||||||
|
return getLine(readerState, configField, prefix, configField.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getLine(ReaderState readerState, ConfigField configField, String prefix, String name) {
|
||||||
|
return "\t{engine->outputChannels." + name +
|
||||||
", "
|
", "
|
||||||
+ DataLogConsumer.getComment(prefix, configField, readerState.variableRegistry) +
|
+ DataLogConsumer.getComment(prefix, configField, readerState.variableRegistry) +
|
||||||
", " +
|
", " +
|
||||||
|
|
|
@ -48,4 +48,20 @@ public class SdCardFieldsGeneratorTest {
|
||||||
state.readBufferedReader(test, consumer);
|
state.readBufferedReader(test, consumer);
|
||||||
assertEquals("\t{engine->outputChannels.RPMValue, \"feee\", \"RPM\", 2},\n", consumer.getBody());
|
assertEquals("\t{engine->outputChannels.RPMValue, \"feee\", \"RPM\", 2},\n", consumer.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void array() {
|
||||||
|
String test = "struct_no_prefix output_channels_s\n" +
|
||||||
|
"uint16_t[4 iterate] recentErrorCode;;\"error\", 1, 0, 0, 0, 0\n" +
|
||||||
|
"end_struct";
|
||||||
|
|
||||||
|
ReaderState state = new ReaderState();
|
||||||
|
|
||||||
|
SdCardFieldsConsumer consumer = new SdCardFieldsConsumer(LazyFile.TEST);
|
||||||
|
state.readBufferedReader(test, consumer);
|
||||||
|
assertEquals("\t{engine->outputChannels.recentErrorCode[0], \"recentErrorCode 1\", \"error\", 0},\n" +
|
||||||
|
"\t{engine->outputChannels.recentErrorCode[1], \"recentErrorCode 2\", \"error\", 0},\n" +
|
||||||
|
"\t{engine->outputChannels.recentErrorCode[2], \"recentErrorCode 3\", \"error\", 0},\n" +
|
||||||
|
"\t{engine->outputChannels.recentErrorCode[3], \"recentErrorCode 4\", \"error\", 0},\n", consumer.getBody());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue