TS gauges section should be auto-generated #4972
This commit is contained in:
parent
ee04e7af39
commit
f13af3b71c
|
@ -414,6 +414,14 @@ public class ConfigFieldImpl implements ConfigField {
|
||||||
return Integer.parseInt(tokens[5].trim());
|
return Integer.parseInt(tokens[5].trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCategory() {
|
||||||
|
String[] tokens = getTokens();
|
||||||
|
if (tokens.length < 7)
|
||||||
|
return null;
|
||||||
|
return tokens[6].trim();
|
||||||
|
}
|
||||||
|
|
||||||
// see testUnquote
|
// see testUnquote
|
||||||
public static String unquote(String token) {
|
public static String unquote(String token) {
|
||||||
return VariableRegistry.unquote(token);
|
return VariableRegistry.unquote(token);
|
||||||
|
|
|
@ -6,13 +6,15 @@ import com.rusefi.ReaderState;
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.rusefi.output.DataLogConsumer.getHumanGaugeName;
|
import static com.rusefi.output.DataLogConsumer.getHumanGaugeName;
|
||||||
import static org.abego.treelayout.internal.util.java.lang.string.StringUtil.quote;
|
import static org.abego.treelayout.internal.util.java.lang.string.StringUtil.quote;
|
||||||
|
|
||||||
public class GaugeConsumer implements ConfigurationConsumer {
|
public class GaugeConsumer implements ConfigurationConsumer {
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
private final StringBuilder charArrayWriter = new StringBuilder();
|
private final LinkedHashMap<String, StringBuilder> byCategory = new LinkedHashMap<>();
|
||||||
|
|
||||||
public GaugeConsumer(String fileName) {
|
public GaugeConsumer(String fileName) {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
@ -25,14 +27,13 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
||||||
(state, configField, prefix) -> handle(configField, prefix));
|
(state, configField, prefix) -> handle(configField, prefix));
|
||||||
iterator.loop();
|
iterator.loop();
|
||||||
String content = iterator.getContent();
|
String content = iterator.getContent();
|
||||||
charArrayWriter.append(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileName != null) {
|
// if (fileName != null) {
|
||||||
FileWriter fw = new FileWriter(fileName);
|
// FileWriter fw = new FileWriter(fileName);
|
||||||
fw.write(charArrayWriter.toString());
|
// fw.write(charArrayWriter.toString());
|
||||||
fw.close();
|
// fw.close();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private String handle(ConfigField configField, String prefix) {
|
private String handle(ConfigField configField, String prefix) {
|
||||||
|
@ -47,18 +48,33 @@ public class GaugeConsumer implements ConfigurationConsumer {
|
||||||
double min = configField.getMin();
|
double min = configField.getMin();
|
||||||
double max = configField.getMax();
|
double max = configField.getMax();
|
||||||
int digits = configField.getDigits();
|
int digits = configField.getDigits();
|
||||||
|
String category = configField.getCategory();
|
||||||
|
if (category == null)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
StringBuilder sb = byCategory.computeIfAbsent(category, s -> new StringBuilder());
|
||||||
|
|
||||||
String fullName = prefix + configField.getName();
|
String fullName = prefix + configField.getName();
|
||||||
return fullName + "Gauge = " + fullName + "," + comment +
|
String gaugeEntry = fullName + "Gauge = " + fullName + "," + comment +
|
||||||
", " + quote(configField.getUnits()) +
|
", " + quote(configField.getUnits()) +
|
||||||
", " + min + "," + max +
|
", " + min + "," + max +
|
||||||
", " + min + "," + max +
|
", " + min + "," + max +
|
||||||
", " + min + "," + max +
|
", " + min + "," + max +
|
||||||
", " + digits + "," + digits +
|
", " + digits + "," + digits +
|
||||||
"\n";
|
"\n";
|
||||||
|
sb.append(gaugeEntry);
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return charArrayWriter.toString();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
for (Map.Entry<String, StringBuilder> e : byCategory.entrySet()) {
|
||||||
|
sb.append("\t").append("gaugeCategory = ").append(e.getKey()).append("\n");
|
||||||
|
sb.append(e.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,8 +164,8 @@ public class OutputsTest {
|
||||||
public void sensorStruct() {
|
public void sensorStruct() {
|
||||||
String test = "struct total\n" +
|
String test = "struct total\n" +
|
||||||
" struct pid_status_s\n" +
|
" struct pid_status_s\n" +
|
||||||
" \tfloat iTerm;;\"v\", 1, 0, -10000, 10000, 4\n" +
|
" \tfloat iTerm;;\"v\", 1, 0, -10000, 10000, 4, Alternator\n" +
|
||||||
" \tfloat dTerm;;\"v\", 1, 0, -10000, 10000, 4\n" +
|
" \tfloat dTerm;;\"v\", 1, 0, -10000, 10000, 4, Alternator\n" +
|
||||||
" end_struct\n" +
|
" end_struct\n" +
|
||||||
"\tpid_status_s alternatorStatus\n" +
|
"\tpid_status_s alternatorStatus\n" +
|
||||||
"\tpid_status_s idleStatus\n" +
|
"\tpid_status_s idleStatus\n" +
|
||||||
|
@ -182,7 +182,8 @@ public class OutputsTest {
|
||||||
"entry = idleStatus_dTerm, \"idleStatus_dTerm\", float, \"%.3f\"\n",
|
"entry = idleStatus_dTerm, \"idleStatus_dTerm\", float, \"%.3f\"\n",
|
||||||
dataLogConsumer.getContent());
|
dataLogConsumer.getContent());
|
||||||
|
|
||||||
assertEquals("alternatorStatus_iTermGauge = alternatorStatus_iTerm,\"alternatorStatus_ iTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
assertEquals("\tgaugeCategory = Alternator\n" +
|
||||||
|
"alternatorStatus_iTermGauge = alternatorStatus_iTerm,\"alternatorStatus_ iTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
||||||
"alternatorStatus_dTermGauge = alternatorStatus_dTerm,\"alternatorStatus_ dTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
"alternatorStatus_dTermGauge = alternatorStatus_dTerm,\"alternatorStatus_ dTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
||||||
"idleStatus_iTermGauge = idleStatus_iTerm,\"idleStatus_ iTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
"idleStatus_iTermGauge = idleStatus_iTerm,\"idleStatus_ iTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n" +
|
||||||
"idleStatus_dTermGauge = idleStatus_dTerm,\"idleStatus_ dTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n",
|
"idleStatus_dTermGauge = idleStatus_dTerm,\"idleStatus_ dTerm\", \"v\", -10000.0,10000.0, -10000.0,10000.0, -10000.0,10000.0, 4,4\n",
|
||||||
|
|
|
@ -125,6 +125,11 @@ public interface ConfigField {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCategory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getDigits() {
|
public int getDigits() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -201,6 +206,8 @@ public interface ConfigField {
|
||||||
|
|
||||||
int getDigits();
|
int getDigits();
|
||||||
|
|
||||||
|
public String getCategory();
|
||||||
|
|
||||||
String getIterateOriginalName();
|
String getIterateOriginalName();
|
||||||
|
|
||||||
int getIterateIndex();
|
int getIterateIndex();
|
||||||
|
|
Loading…
Reference in New Issue