why so many channels are hidden in debug ? #3614

This commit is contained in:
rusefillc 2021-11-28 22:02:18 -05:00
parent 86ff41cd17
commit 8d2487ce2e
2 changed files with 51 additions and 16 deletions

View File

@ -37,14 +37,8 @@ public class DataLogConsumer implements ConfigurationConsumer {
if (state.stack.isEmpty()) {
FieldIterator iterator = new FieldIterator(structure.tsFields);
for (int i = 0; i < structure.tsFields.size(); i++) {
iterator.start(i);
tsWriter.append(handle(iterator.cf));
iterator.end();
}
String content = handleFields(structure, iterator, "");
tsWriter.append(content);
}
if (fileName != null) {
@ -54,10 +48,30 @@ public class DataLogConsumer implements ConfigurationConsumer {
}
}
private String handle(ConfigField configField) {
private String handleFields(ConfigStructure structure, FieldIterator iterator, String prefix) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < structure.tsFields.size(); i++) {
iterator.start(i);
String content = handle(iterator.cf, prefix);
sb.append(content);
iterator.end();
}
return sb.toString();
}
private String handle(ConfigField configField, String prefix) {
if (configField.getName().contains("unused"))
return "";
ConfigStructure cs = configField.getState().structures.get(configField.getType());
if (cs != null) {
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";
return handleFields(cs, new FieldIterator(cs.tsFields), extraPrefix);
}
if (configField.isArray()) {
return "";
@ -74,8 +88,8 @@ public class DataLogConsumer implements ConfigurationConsumer {
}
String comment = state.variableRegistry.applyVariables(configField.getComment());
String[] comments = comment.split("\\\\n");
comment = comments[0];
String[] comments = comment == null ? new String[0] : comment.split("\\\\n");
comment = (comments.length > 0) ? comments[0] : "";
if (comment.isEmpty())
comment = configField.getName();
@ -83,7 +97,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
if (comment.charAt(0) != '"')
comment = quote(comment);
return "entry = " + configField.getName() + ", " + comment + ", " + typeString + "\n";
return "entry = " + prefix + configField.getName() + ", " + comment + ", " + typeString + "\n";
}
public CharArrayWriter getTsWriter() {

View File

@ -20,10 +20,9 @@ public class OutputsTest {
"bit enableFan1WithAc;+Turn on this fan when AC is on.\n" +
"end_struct\n";
ReaderState state = new ReaderState();
BufferedReader reader = new BufferedReader(new StringReader(test));
OutputsSectionConsumer tsProjectConsumer = new OutputsSectionConsumer(null, state);
state.readBufferedReader(reader, Collections.singletonList(tsProjectConsumer));
state.readBufferedReader(test, Collections.singletonList(tsProjectConsumer));
assertEquals("afr_type = scalar, F32, 0, \"ms\", 1, 0\n" +
@ -81,10 +80,9 @@ public class OutputsTest {
ReaderState state = new ReaderState();
state.variableRegistry.register("PACK_MULT_PERCENT", 100);
state.variableRegistry.register("GAUGE_NAME_FUEL_BASE", "hello");
BufferedReader reader = new BufferedReader(new StringReader(test));
DataLogConsumer dataLogConsumer = new DataLogConsumer(null, state);
state.readBufferedReader(reader, Collections.singletonList(dataLogConsumer));
state.readBufferedReader(test, Collections.singletonList(dataLogConsumer));
assertEquals(
"entry = issue_294_31, \"issue_294_31\", int, \"%d\"\n" +
"entry = knock1, \"knock1\", int, \"%d\"\n" +
@ -98,4 +96,27 @@ public class OutputsTest {
"entry = enableFan1WithAc, \"+Turn on this fan when AC is on.\", int, \"%d\"\n", new String(dataLogConsumer.getTsWriter().toCharArray()));
}
@Test
public void sensorStruct() throws IOException {
String test = "struct total\n" +
" struct pid_status_s\n" +
" \tfloat iTerm;;\"\", 1, 0, -10000, 10000, 4\n" +
" \tfloat dTerm;;\"\", 1, 0, -10000, 10000, 4\n" +
" end_struct\n" +
"\tpid_status_s alternatorStatus\n" +
"\tpid_status_s idleStatus\n" +
"end_struct\n";
ReaderState state = new ReaderState();
DataLogConsumer dataLogConsumer = new DataLogConsumer(null, state);
state.readBufferedReader(test, Collections.singletonList(dataLogConsumer));
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",
new String(dataLogConsumer.getTsWriter().toCharArray()));
}
}