EPIC: Improve toolset for default tune canned tune generation #4871

only: better method names
This commit is contained in:
rusefillc 2024-04-20 14:06:26 -04:00
parent f2167c862f
commit e906fd2e57
14 changed files with 53 additions and 53 deletions

View File

@ -18,7 +18,7 @@ public class ConfigFieldParserTest {
ReaderStateImpl state = new ReaderStateImpl();
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "uint8_t[8] field");
assertEquals(cf.getType(), "uint8_t");
assertEquals(cf.getTypeName(), "uint8_t");
assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 8);
assertEquals(cf.getSize(null), 8);
@ -31,7 +31,7 @@ public class ConfigFieldParserTest {
ReaderStateImpl state = new ReaderStateImpl();
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "uint8_t[8 x 16] field");
assertEquals(cf.getType(), "uint8_t");
assertEquals(cf.getTypeName(), "uint8_t");
assertEquals(cf.getArraySizes().length, 2);
assertEquals(cf.getArraySizes()[0], 8);
assertEquals(cf.getArraySizes()[1], 16);
@ -383,7 +383,7 @@ public class ConfigFieldParserTest {
{
ReaderStateImpl state = new ReaderStateImpl();
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field");
assertEquals(cf.getType(), "int");
assertEquals(cf.getTypeName(), "int");
assertEquals(cf.getName(), "field", "Unexpected Field Name");
}
@ -691,24 +691,24 @@ public class ConfigFieldParserTest {
assertNull(ConfigFieldImpl.parse(state, "int"));
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int field");
assertEquals(cf.getType(), "int");
assertEquals(cf.getTypeName(), "int");
assertEquals(cf.getName(), "field", "Name");
}
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_4 fie4_ld");
assertEquals(cf.getType(), "int_4");
assertEquals(cf.getTypeName(), "int_4");
assertEquals(cf.getName(), "fie4_ld");
}
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int_8 fi_eld;comm_;ts,1,1");
assertEquals(cf.getType(), "int_8");
assertEquals(cf.getTypeName(), "int_8");
assertEquals(cf.getName(), "fi_eld");
assertEquals(cf.getComment(), "comm_", "Comment");
assertEquals(cf.getTsInfo(), "ts,1,1");
}
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int[3 iterate] field");
assertEquals(cf.getType(), "int");
assertEquals(cf.getTypeName(), "int");
assertEquals(cf.getArraySizes().length, 1);
assertEquals(cf.getArraySizes()[0], 3);
assertTrue(cf.isIterate(), "isIterate");
@ -717,19 +717,19 @@ public class ConfigFieldParserTest {
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "int16_t crankingRpm;This,. value controls what RPM values we consider 'cranking' (any RPM below 'crankingRpm')\\nAnything above 'crankingRpm' would be 'running'");
assertEquals(cf.getName(), "crankingRpm");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "int16_t");
assertEquals(cf.getTypeName(), "int16_t");
}
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "MAP_sensor_config_s map");
assertEquals(cf.getName(), "map");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "MAP_sensor_config_s");
assertEquals(cf.getTypeName(), "MAP_sensor_config_s");
}
{
ConfigFieldImpl cf = ConfigFieldImpl.parse(state, "MAP_sensor_config_s map;@see hasMapSensor\\n@see isMapAveragingEnabled");
assertEquals(cf.getName(), "map");
assertEquals(cf.getArraySizes().length, 0);
assertEquals(cf.getType(), "MAP_sensor_config_s");
assertEquals(cf.getTypeName(), "MAP_sensor_config_s");
assertEquals(cf.getComment(), "@see hasMapSensor\\n@see isMapAveragingEnabled");
}
}

View File

@ -11,7 +11,7 @@ public interface ConfigField {
}
@Override
public ConfigStructure getParent() {
public ConfigStructure getParentStructureType() {
return null;
}
@ -66,7 +66,7 @@ public interface ConfigField {
}
@Override
public String getType() {
public String getTypeName() {
return null;
}
@ -163,7 +163,9 @@ public interface ConfigField {
}
}
ConfigStructure getParent();
ConfigStructure getParentStructureType();
String getTypeName();
ConfigStructure getStructureType();
@ -187,7 +189,6 @@ public interface ConfigField {
String getName();
String getType();
int getElementSize();

View File

@ -107,7 +107,7 @@ public class ConfigFieldImpl implements ConfigField {
}
@Override
public ConfigStructure getParent() {
public ConfigStructure getParentStructureType() {
return parent;
}
@ -120,7 +120,7 @@ public class ConfigFieldImpl implements ConfigField {
@Override
public ConfigStructure getStructureType() {
return getState().getStructures().get(getType());
return getState().getStructures().get(getTypeName());
}
@Override
@ -282,7 +282,7 @@ public class ConfigFieldImpl implements ConfigField {
* @see TypesHelper
*/
@Override
public String getType() {
public String getTypeName() {
return type;
}

View File

@ -337,13 +337,13 @@ public class ReaderStateImpl implements ReaderState {
throw new IllegalStateException(cf.getName() + ": Not enclosed in a struct");
ConfigStructureImpl structure = state.stack.peek();
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType());
Integer customTypeSize = state.tsCustomSize.get(cf.getType());
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getTypeName());
Integer customTypeSize = state.tsCustomSize.get(cf.getTypeName());
if (getPrimitiveSize != null && getPrimitiveSize > 1) {
if (log.debugEnabled())
log.debug("Need to align before " + cf.getName());
structure.addAlignmentFill(state, getPrimitiveSize);
} else if (state.structures.containsKey(cf.getType())) {
} else if (state.structures.containsKey(cf.getTypeName())) {
// we are here for struct members
structure.addAlignmentFill(state, 4);
} else if (customTypeSize != null) {
@ -355,7 +355,7 @@ public class ReaderStateImpl implements ReaderState {
for (int i = 1; i <= cf.getArraySizes()[0]; i++) {
String commentWithIndex = getCommentWithIndex(cf, i);
ConfigFieldImpl element = new ConfigFieldImpl(state, cf.getName() + i, commentWithIndex, null,
cf.getType(), new int[0], cf.getTsInfo(), false, cf.isHasAutoscale(), null, null);
cf.getTypeName(), new int[0], cf.getTsInfo(), false, cf.isHasAutoscale(), null, null);
element.setFromIterate(cf.getName(), i);
structure.addTs(element);
}

View File

@ -27,7 +27,7 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
String cEntry = getComment(configField.getComment(), iterator.currentOffset, configField.getUnits());
String typeName = configField.getType();
String typeName = configField.getTypeName();
String autoscaleSpec = configField.autoscaleSpec();
if (autoscaleSpec != null) {
@ -37,9 +37,9 @@ public class BaseCHeaderConsumer implements ConfigurationConsumer {
if (!configField.isArray()) {
// not an array
cEntry += "\t" + typeName + " " + configField.getName();
if (needZeroInit && TypesHelper.isPrimitive(configField.getType())) {
if (needZeroInit && TypesHelper.isPrimitive(configField.getTypeName())) {
// we need this cast in case of enums
cEntry += " = (" + configField.getType() + ")0";
cEntry += " = (" + configField.getTypeName() + ")0";
}
cEntry += ";" + EOL;
} else {

View File

@ -94,7 +94,7 @@ public class DataLogConsumer implements ConfigurationConsumer {
String typeString;
String autoscaleSpec = configField.autoscaleSpec();
if (TypesHelper.isFloat(configField.getType()) || (autoscaleSpec != null && !autoscaleSpec.equals("1, 1"))) {
if (TypesHelper.isFloat(configField.getTypeName()) || (autoscaleSpec != null && !autoscaleSpec.equals("1, 1"))) {
typeString = "float, \"%.3f\"";
} else {
typeString = "int, \"%d\"";

View File

@ -8,7 +8,6 @@ import com.rusefi.util.LazyFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@ -97,7 +96,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
if (cf.isArray() || cf.isFromIterate() || cf.isDirective())
return "";
if (!TypesHelper.isPrimitive(cf.getType()) && !TypesHelper.isBoolean(cf.getType())) {
if (!TypesHelper.isPrimitive(cf.getTypeName()) && !TypesHelper.isBoolean(cf.getTypeName())) {
return "";
}
@ -109,7 +108,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer {
if (javaName.startsWith(CONFIG_ENGINE_CONFIGURATION))
javaName = "engineConfiguration->" + javaName.substring(CONFIG_ENGINE_CONFIGURATION.length());
variables.add(new VariableRecord(userName, javaName + cf.getName(), cf.getType(), null));
variables.add(new VariableRecord(userName, javaName + cf.getName(), cf.getTypeName(), null));
mdContent.append("### " + userName + "\n");
mdContent.append(cf.getComment() + "\n\n");

View File

@ -54,7 +54,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer {
if (cf.isArray() || cf.isFromIterate() || cf.isDirective())
return "";
if (!TypesHelper.isPrimitive(cf.getType()) && !TypesHelper.isBoolean(cf.getType())) {
if (!TypesHelper.isPrimitive(cf.getTypeName()) && !TypesHelper.isBoolean(cf.getTypeName())) {
return "";
}

View File

@ -47,7 +47,7 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
}
private boolean isStringField(ConfigField configField) {
String custom = state.getTsCustomLine().get(configField.getType());
String custom = state.getTsCustomLine().get(configField.getTypeName());
return custom != null && custom.toLowerCase().startsWith(IniFileModel.FIELD_TYPE_STRING);
}
@ -83,23 +83,23 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
return tsPosition;
}
if (TypesHelper.isFloat(configField.getType())) {
if (TypesHelper.isFloat(configField.getTypeName())) {
writeJavaFieldName(nameWithPrefix, tsPosition);
content.append("FieldType.FLOAT)" + terminateField());
} else {
String enumOptions = state.getVariableRegistry().get(configField.getType() + VariableRegistry.ARRAY_FORMAT_ENUM);
String enumOptions = state.getVariableRegistry().get(configField.getTypeName() + VariableRegistry.ARRAY_FORMAT_ENUM);
if (enumOptions == null)
enumOptions = state.getVariableRegistry().get(configField.getType() + VariableRegistry.KEY_VALUE_FORMAT_ENUM);
enumOptions = state.getVariableRegistry().get(configField.getTypeName() + VariableRegistry.KEY_VALUE_FORMAT_ENUM);
if (enumOptions != null && !existingJavaEnums.contains(configField.getType())) {
existingJavaEnums.add(configField.getType());
content.append("\tpublic static final String[] " + configField.getType() + " = {" + enumOptions + "};" + EOL);
if (enumOptions != null && !existingJavaEnums.contains(configField.getTypeName())) {
existingJavaEnums.add(configField.getTypeName());
content.append("\tpublic static final String[] " + configField.getTypeName() + " = {" + enumOptions + "};" + EOL);
}
writeJavaFieldName(nameWithPrefix, tsPosition);
if (isStringField(configField)) {
String custom = state.getTsCustomLine().get(configField.getType());
String custom = state.getTsCustomLine().get(configField.getTypeName());
String[] tokens = custom.split(",");
String stringSize = tokens[3].trim();
content.append(stringSize + ", FieldType.STRING");
@ -107,7 +107,7 @@ public abstract class JavaFieldsConsumer implements ConfigurationConsumer {
content.append(getJavaType(configField.getElementSize()));
}
if (enumOptions != null) {
content.append(", " + configField.getType());
content.append(", " + configField.getTypeName());
}
content.append(")" + ".setScale(" + configField.autoscaleSpecNumber() + ")" +
terminateField());

View File

@ -30,7 +30,7 @@ class PerFieldWithStructuresIterator extends FieldIterator {
@Override
public void end() {
ConfigStructure cs = cf.getState().getStructures().get(cf.getType());
ConfigStructure cs = cf.getState().getStructures().get(cf.getTypeName());
String content;
if (cs != null) {
if (strategy.skip(cf)) {

View File

@ -71,7 +71,7 @@ public class SdCardFieldsContent {
categoryStr = ", " + categoryStr;
}
boolean isEnum = configField.getType().contains("_e");
boolean isEnum = configField.getTypeName().contains("_e");
if (isEnum)
return "";

View File

@ -97,9 +97,9 @@ public class TsOutput {
return tsPosition;
}
if (configField.getState().getTsCustomLine().containsKey(configField.getType())) {
if (configField.getState().getTsCustomLine().containsKey(configField.getTypeName())) {
// todo: rename 'bits' to 'customLine' or something since _not_ bits for array?
String bits = configField.getState().getTsCustomLine().get(configField.getType());
String bits = configField.getState().getTsCustomLine().get(configField.getTypeName());
if (!bits.startsWith("bits")) {
// 'array' would be handled here
bits = handleTsInfo(configField, bits, 5);
@ -109,10 +109,10 @@ public class TsOutput {
tsHeader.append(nameWithPrefix + " = " + bits);
if (!configField.getName().equals(next.getName()))
tsPosition += configField.getState().getTsCustomSize().get(configField.getType());
tsPosition += configField.getState().getTsCustomSize().get(configField.getTypeName());
} else if (configField.getArraySizes().length == 0) {
tsHeader.append(temporaryLineComment + nameWithPrefix + " = scalar, ");
tsHeader.append(TypesHelper.convertToTs(configField.getType()) + ",");
tsHeader.append(TypesHelper.convertToTs(configField.getTypeName()) + ",");
tsHeader.append(" " + tsPosition + ",");
tsHeader.append(" " + handleTsInfo(configField, configField.getTsInfo(), 1));
if (!configField.getName().equals(next.getName()))
@ -122,7 +122,7 @@ public class TsOutput {
// TS does not like those
} else {
tsHeader.append(nameWithPrefix + " = array, ");
tsHeader.append(TypesHelper.convertToTs(configField.getType()) + ",");
tsHeader.append(TypesHelper.convertToTs(configField.getTypeName()) + ",");
tsHeader.append(" " + tsPosition + ",");
tsHeader.append(" [");
boolean first = true;
@ -157,7 +157,7 @@ public class TsOutput {
if (tsInfo == null || tsInfo.trim().isEmpty()) {
// default units and scale
if (isConstantsSection) {
if (configField.getType().equalsIgnoreCase(Type.U16.cType) || configField.getType().equalsIgnoreCase(Type.S16.cType))
if (configField.getTypeName().equalsIgnoreCase(Type.U16.cType) || configField.getTypeName().equalsIgnoreCase(Type.S16.cType))
return quote("") + ", 1, 0, 0, 32000, 0";
return quote("") + ", 1, 0, 0, 100, 0";
}

View File

@ -49,7 +49,7 @@ public class MetaHelper {
fromIndex++; // skip underscore
if (cf == null)
continue;
String type = cf.getType();
String type = cf.getTypeName();
s = state.getStructures().get(type);
if (s != null) {

View File

@ -213,7 +213,7 @@ public class TuneCanTool implements TuneCanToolConstants {
log.info("Not found " + fieldName);
continue;
}
if (TypesHelper.isFloat(cf.getType()) && !cf.isArray()) {
if (TypesHelper.isFloat(cf.getTypeName()) && !cf.isArray()) {
float floatDefaultValue = Float.parseFloat(defaultValue.getValue());
float floatCustomValue = Float.parseFloat(customValue.getValue());
if (floatCustomValue != 0 && Math.abs(floatDefaultValue / floatCustomValue - 1) < 0.001) {
@ -227,21 +227,21 @@ public class TuneCanTool implements TuneCanToolConstants {
continue;
}
if (cf.getType().equals("boolean")) {
if (cf.getTypeName().equals("boolean")) {
sb.append(TuneTools.getAssignmentCode(defaultValue, cName, unquote(customValue.getValue())));
continue;
}
if (cf.isArray()) {
String parentReference;
if (cf.getParent().getName().equals("engine_configuration_s")) {
if (cf.getParentStructureType().getName().equals("engine_configuration_s")) {
parentReference = "engineConfiguration->";
} else if (cf.getParent().getName().equals("persistent_config_s")) {
} else if (cf.getParentStructureType().getName().equals("persistent_config_s")) {
parentReference = "config->";
} else {
// todo: for instance map.samplingAngle
//throw new IllegalStateException("Unexpected " + cf.getParent());
log.info(" " + cf);
log.info("Unable to locate parent: " + cf + " / parent=" + cf.getParentStructureType());
continue;
}
@ -295,7 +295,7 @@ public class TuneCanTool implements TuneCanToolConstants {
if (!Node.isNumeric(customValue.getValue())) {
// todo: smarter logic for enums
String type = cf.getType();
String type = cf.getTypeName();
if (isHardwareEnum(type)) {
continue;
}