diff --git a/java_console/shared_io/src/main/java/com/rusefi/core/Tuple.java b/java_console/shared_io/src/main/java/com/rusefi/core/Tuple.java new file mode 100644 index 0000000000..cb3f376318 --- /dev/null +++ b/java_console/shared_io/src/main/java/com/rusefi/core/Tuple.java @@ -0,0 +1,11 @@ +package com.rusefi.core; + +public class Tuple extends Pair { + + public final Z third; + + public Tuple(String first, String second, Z third) { + super(first, second); + this.third = third; + } +} diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index 008a9f4917..1325f256b8 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java index b83f2bd07a..3284fb40b2 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetConfigValueConsumer.java @@ -3,7 +3,7 @@ package com.rusefi.output; import com.rusefi.ConfigField; import com.rusefi.ReaderState; import com.rusefi.TypesHelper; -import com.rusefi.core.Pair; +import com.rusefi.core.Tuple; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -18,7 +18,6 @@ import static com.rusefi.output.ConfigStructure.ALIGNMENT_FILL_AT; import static com.rusefi.output.DataLogConsumer.UNUSED; import static com.rusefi.output.GetOutputValueConsumer.getHashConflicts; import static com.rusefi.output.GetOutputValueConsumer.wrapSwitchStatement; -import static com.rusefi.output.JavaSensorsConsumer.quote; @SuppressWarnings("StringConcatenationInsideStringBufferAppend") public class GetConfigValueConsumer implements ConfigurationConsumer { @@ -26,17 +25,6 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { private static final String ENGINE_CONFIGURATION = "engineConfiguration."; static final String FILE_HEADER = "#include \"pch.h\"\n" + "#include \"value_lookup.h\"\n"; - private static final String FIND_METHOD = - "plain_get_float_s * findFloat(const char *name) {\n" + - "\tplain_get_float_s *currentF = &getF_plain[0];\n" + - "\twhile (currentF < getF_plain + efi::size(getF_plain)) {\n" + - "\t\tif (strEqualCaseInsensitive(name, currentF->token)) {\n" + - "\t\t\treturn currentF;\n" + - "\t\t}\n" + - "\t\tcurrentF++;\n" + - "\t}\n" + - "\treturn nullptr;\n" + - "}\n"; private static final String GET_METHOD_HEADER = "float getConfigValueByName(const char *name) {\n" + @@ -52,10 +40,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { "\t}\n" + "\n"; private static final String SET_METHOD_FOOTER = "}\n"; - private final List> getterPairs = new ArrayList<>(); - private final List> setterPairs = new ArrayList<>(); - private final StringBuilder allFloatAddresses = new StringBuilder( - "static plain_get_float_s getF_plain[] = {\n"); + private final List> variables = new ArrayList<>(); private final String outputFileName; public GetConfigValueConsumer(String outputFileName) { @@ -102,16 +87,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { if (javaName.startsWith(CONFIG_ENGINE_CONFIGURATION)) javaName = "engineConfiguration->" + javaName.substring(CONFIG_ENGINE_CONFIGURATION.length()); - - getterPairs.add(new Pair<>(userName, javaName + cf.getName())); - - if (TypesHelper.isFloat(cf.getType())) { - allFloatAddresses.append("\t{" + quote(userName) + ", &engineConfiguration->" + userName + "},\n"); - } else { - - setterPairs.add(new Pair<>(userName, javaName + cf.getName())); - - } + variables.add(new Tuple<>(userName, javaName + cf.getName(), cf.getType())); return ""; @@ -131,8 +107,6 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { public String getHeaderAndGetter() { return FILE_HEADER + - getFloatsSections() + - FIND_METHOD + getCompleteGetterBody(); } @@ -140,7 +114,7 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { public String getCompleteGetterBody() { StringBuilder switchBody = new StringBuilder(); - StringBuilder getterBody = GetOutputValueConsumer.getGetters(switchBody, getterPairs); + StringBuilder getterBody = GetOutputValueConsumer.getGetters(switchBody, variables); String fullSwitch = wrapSwitchStatement(switchBody); @@ -149,21 +123,19 @@ public class GetConfigValueConsumer implements ConfigurationConsumer { getterBody + GET_METHOD_FOOTER; } - @NotNull - public String getFloatsSections() { - return allFloatAddresses + "};\n\n"; - } - public String getSetterBody() { StringBuilder switchBody = new StringBuilder(); StringBuilder setterBody = new StringBuilder(); - HashMap hashConflicts = getHashConflicts(setterPairs); + HashMap hashConflicts = getHashConflicts(variables); + + for (Tuple pair : variables) { + + String cast = TypesHelper.isFloat(pair.third) ? "" : "(int)"; - for (Pair pair : setterPairs) { int hash = HashUtil.hash(pair.first); - String str = getAssignment("(int)", pair.second); + String str = getAssignment(cast, pair.second); if (hashConflicts.get(hash).get() == 1) { switchBody.append("\t\tcase " + hash + ":\n"); switchBody.append(str); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java index 1555f81cf5..80800771ef 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/GetOutputValueConsumer.java @@ -82,7 +82,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer { } @NotNull - static StringBuilder getGetters(StringBuilder switchBody, List> getterPairs) { + static StringBuilder getGetters(StringBuilder switchBody, List> getterPairs) { HashMap hashConflicts = getHashConflicts(getterPairs); StringBuilder getterBody = new StringBuilder(); @@ -102,7 +102,7 @@ public class GetOutputValueConsumer implements ConfigurationConsumer { } @NotNull - static HashMap getHashConflicts(List> getterPairs1) { + static HashMap getHashConflicts(List> getterPairs1) { HashMap hashConflicts = new HashMap<>(); for (Pair pair : getterPairs1) { hashConflicts.computeIfAbsent(HashUtil.hash(pair.first), integer -> new AtomicInteger(0)).incrementAndGet(); diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/test/GetConfigValueConsumerTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/test/GetConfigValueConsumerTest.java index b1348b53b1..b6cadbffb8 100644 --- a/java_tools/configuration_definition/src/test/java/com/rusefi/test/GetConfigValueConsumerTest.java +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/test/GetConfigValueConsumerTest.java @@ -22,12 +22,6 @@ public class GetConfigValueConsumerTest { GetConfigValueConsumer getConfigValueConsumer = new GetConfigValueConsumer(null); state.readBufferedReader(test, getConfigValueConsumer); - assertEquals( - "static plain_get_float_s getF_plain[] = {\n" + - "};\n\n" - , getConfigValueConsumer.getFloatsSections()); - - assertEquals( "float getConfigValueByName(const char *name) {\n" + "\t{\n" + @@ -54,6 +48,11 @@ public class GetConfigValueConsumerTest { assertEquals("\tint hash = djb2lowerCase(name);\n" + "\tswitch(hash) {\n" + + "\t\tcase -672272162:\n" + + "\t{\n" + + "\t\tconfig->iat.config.tempC_1 = value;\n" + + "\t\treturn;\n" + + "\t}\n" + "\t\tcase -1237776078:\n" + "\t{\n" + "\t\tconfig->iat.adcChannel = (int)value;\n" + @@ -61,12 +60,6 @@ public class GetConfigValueConsumerTest { "\t}\n" + "\t}\n", getConfigValueConsumer.getSetterBody()); - assertEquals( - "static plain_get_float_s getF_plain[] = {\n" + - "\t{\"iat.config.tempC_1\", &engineConfiguration->iat.config.tempC_1},\n" + - "};\n" + - "\n", getConfigValueConsumer.getFloatsSections()); - assertEquals("float getConfigValueByName(const char *name) {\n" + "\t{\n" + "\tint hash = djb2lowerCase(name);\n" + @@ -137,24 +130,6 @@ public class GetConfigValueConsumerTest { assertEquals("#include \"pch.h\"\n" + "#include \"value_lookup.h\"\n" + - "static plain_get_float_s getF_plain[] = {\n" + - "\t{\"clt.config.tempC_1\", &engineConfiguration->clt.config.tempC_1},\n" + - "\t{\"clt.config.map.sensor.highValue\", &engineConfiguration->clt.config.map.sensor.highValue},\n" + - "\t{\"clt.config.injector.flow\", &engineConfiguration->clt.config.injector.flow},\n" + - "\t{\"clt.config.bias_resistor\", &engineConfiguration->clt.config.bias_resistor},\n" + - "\t{\"afr_type\", &engineConfiguration->afr_type},\n" + - "};\n" + - "\n" + - "plain_get_float_s * findFloat(const char *name) {\n" + - "\tplain_get_float_s *currentF = &getF_plain[0];\n" + - "\twhile (currentF < getF_plain + efi::size(getF_plain)) {\n" + - "\t\tif (strEqualCaseInsensitive(name, currentF->token)) {\n" + - "\t\t\treturn currentF;\n" + - "\t\t}\n" + - "\t\tcurrentF++;\n" + - "\t}\n" + - "\treturn nullptr;\n" + - "}\n" + "float getConfigValueByName(const char *name) {\n" + "\t{\n" + "\tint hash = djb2lowerCase(name);\n" +