unique names in case of iteration

This commit is contained in:
rusefillc 2022-04-18 11:06:57 -04:00
parent 218cd70e08
commit a6d3b2f028
4 changed files with 24 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.output.JavaSensorsConsumer.quote;
/**
* This is an immutable model of an individual field
@ -373,5 +374,12 @@ public class ConfigField {
public boolean isFromIterate() {
return isFromIterate;
}
// todo: find more usages for this method?
public String getCommentOrName() {
if (comment == null || comment.trim().isEmpty())
return quote(name);
return comment;
}
}

View File

@ -7,12 +7,15 @@ import com.rusefi.enum_reader.Value;
import com.rusefi.output.*;
import com.rusefi.util.IoUtils;
import com.rusefi.util.SystemOut;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.util.*;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.ConfigField.BOOLEAN_T;
import static com.rusefi.ConfigField.unquote;
import static com.rusefi.output.JavaSensorsConsumer.quote;
/**
* We keep state here as we read configuration definition
@ -292,7 +295,7 @@ public class ReaderState {
if (cf.isIterate()) {
structure.addC(cf);
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
ConfigField element = new ConfigField(state, cf.getName() + i, cf.getComment(), null,
ConfigField element = new ConfigField(state, cf.getName() + i, getCommentWithIndex(cf, i), null,
cf.getType(), new int[0], cf.getTsInfo(), false, false, cf.isHasAutoscale(), null, null);
element.isFromIterate(true);
structure.addTs(element);
@ -304,6 +307,12 @@ public class ReaderState {
}
}
@NotNull
private static String getCommentWithIndex(ConfigField cf, int i) {
String unquoted = unquote(cf.getCommentOrName());
return quote(unquoted + " " + i);
}
public String getHeader() {
if (headerMessage == null)
throw new NullPointerException("No header message yet");

View File

@ -67,7 +67,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
String comment = getComment(prefix, configField, state.variableRegistry);
if (comments.contains(comment))
throw new IllegalStateException(comment + " already present in the outputs!");
throw new IllegalStateException(comment + " already present in the outputs! " + configField);
comments.add(comment);
return "entry = " + prefix + configField.getName() + ", " + comment + ", " + typeString + "\n";
}

View File

@ -86,6 +86,7 @@ public class OutputsTest {
String test = "struct total\n" +
"bit issue_294_31,\"si_example\",\"nada_example\"\n" +
"uint8_t[2 iterate] autoscale knock;;\"\",1, 0, 0, 0, 0\n" +
"uint8_t[2 iterate] autoscale withName;\"MyNameIsEarl\";\"\",1, 0, 0, 0, 0\n" +
"\tuint16_t autoscale baseFuel;@@GAUGE_NAME_FUEL_BASE@@\\nThis is the raw value we take from the fuel map or base fuel algorithm, before the corrections;\"mg\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
"float afr_type;PID dTime;\"ms\", 1, 0, 0, 3000, 0\n" +
"uint16_t autoscale speedToRpmRatio;s2rpm;\"value\",{1/@@PACK_MULT_PERCENT@@}, 0, 0, 0, 0\n" +
@ -103,8 +104,10 @@ public class OutputsTest {
state.readBufferedReader(test, (dataLogConsumer));
assertEquals(
"entry = issue_294_31, \"issue_294_31\", int, \"%d\"\n" +
"entry = knock1, \"knock1\", int, \"%d\"\n" +
"entry = knock2, \"knock2\", int, \"%d\"\n" +
"entry = knock1, \"knock 1\", int, \"%d\"\n" +
"entry = knock2, \"knock 2\", int, \"%d\"\n" +
"entry = withName1, \"MyNameIsEarl 1\", int, \"%d\"\n" +
"entry = withName2, \"MyNameIsEarl 2\", int, \"%d\"\n" +
"entry = baseFuel, \"hello\", float, \"%.3f\"\n" +
"entry = afr_type, \"PID dTime\", float, \"%.3f\"\n" +
"entry = speedToRpmRatio, \"s2rpm\", float, \"%.3f\"\n" +