mirror of https://github.com/FOME-Tech/fome-fw.git
output channel name duplication fix #3681
This commit is contained in:
parent
190514823f
commit
034e704608
Binary file not shown.
|
@ -9,13 +9,16 @@ import org.jetbrains.annotations.NotNull;
|
|||
import java.io.CharArrayWriter;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static com.rusefi.ConfigField.unquote;
|
||||
import static org.abego.treelayout.internal.util.java.lang.string.StringUtil.quote;
|
||||
|
||||
public class DataLogConsumer implements ConfigurationConsumer {
|
||||
private final String fileName;
|
||||
private final ReaderState state;
|
||||
private final CharArrayWriter tsWriter = new CharArrayWriter();
|
||||
private final TreeSet<String> comments = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
public DataLogConsumer(String fileName, ReaderState state) {
|
||||
this.fileName = fileName;
|
||||
|
@ -88,19 +91,22 @@ public class DataLogConsumer implements ConfigurationConsumer {
|
|||
typeString = "int, \"%d\"";
|
||||
}
|
||||
|
||||
String comment = getComment(configField, state.variableRegistry);
|
||||
String comment = getComment(prefix, configField, state.variableRegistry);
|
||||
|
||||
if (comments.contains(comment))
|
||||
throw new IllegalStateException(comment + " already present in the outputs!");
|
||||
comments.add(comment);
|
||||
return "entry = " + prefix + configField.getName() + ", " + comment + ", " + typeString + "\n";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getComment(ConfigField configField, VariableRegistry variableRegistry) {
|
||||
public static String getComment(String prefix, ConfigField configField, VariableRegistry variableRegistry) {
|
||||
String comment = variableRegistry.applyVariables(configField.getComment());
|
||||
String[] comments = comment == null ? new String[0] : comment.split("\\\\n");
|
||||
comment = (comments.length > 0) ? comments[0] : "";
|
||||
|
||||
if (comment.isEmpty())
|
||||
comment = configField.getName();
|
||||
comment = prefix + unquote(configField.getName());
|
||||
|
||||
if (comment.charAt(0) != '"')
|
||||
comment = quote(comment);
|
||||
|
|
|
@ -67,7 +67,7 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
|||
return handleFields(cs, new FieldIterator(cs.tsFields), extraPrefix);
|
||||
}
|
||||
|
||||
String comment = getComment(configField, state.variableRegistry);
|
||||
String comment = getComment("", configField, state.variableRegistry);
|
||||
comment = ConfigField.unquote(comment);
|
||||
if (!prefix.isEmpty()) {
|
||||
comment = prefix + " " + comment;
|
||||
|
|
|
@ -13,8 +13,6 @@ import java.util.Collections;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OutputsTest {
|
||||
private com.rusefi.output.GaugeConsumer GaugeConsumer;
|
||||
|
||||
@Test
|
||||
public void generateSomething() throws IOException {
|
||||
String test = "struct total\n" +
|
||||
|
@ -117,10 +115,10 @@ public class OutputsTest {
|
|||
GaugeConsumer gaugeConsumer = new GaugeConsumer(null, state);
|
||||
state.readBufferedReader(test, Arrays.asList(dataLogConsumer, gaugeConsumer));
|
||||
assertEquals(
|
||||
"entry = alternatorStatus_iTerm, \"iTerm\", float, \"%.3f\"\n" +
|
||||
"entry = alternatorStatus_dTerm, \"dTerm\", float, \"%.3f\"\n" +
|
||||
"entry = idleStatus_iTerm, \"iTerm\", float, \"%.3f\"\n" +
|
||||
"entry = idleStatus_dTerm, \"dTerm\", float, \"%.3f\"\n",
|
||||
"entry = alternatorStatus_iTerm, \"alternatorStatus_iTerm\", float, \"%.3f\"\n" +
|
||||
"entry = alternatorStatus_dTerm, \"alternatorStatus_dTerm\", float, \"%.3f\"\n" +
|
||||
"entry = idleStatus_iTerm, \"idleStatus_iTerm\", float, \"%.3f\"\n" +
|
||||
"entry = idleStatus_dTerm, \"idleStatus_dTerm\", float, \"%.3f\"\n",
|
||||
new String(dataLogConsumer.getTsWriter().toCharArray()));
|
||||
|
||||
assertEquals("alternatorStatus_iTermGauge = alternatorStatus_iTerm,\"alternatorStatus_ iTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
||||
|
|
Loading…
Reference in New Issue