diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index b37cb5e04e..13492c45a4 100644 Binary files a/java_tools/ConfigDefinition.jar and b/java_tools/ConfigDefinition.jar differ diff --git a/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java b/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java index 1919441a07..8ec987fcc3 100644 --- a/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/com/rusefi/ConfigDefinition.java @@ -288,7 +288,12 @@ public class ConfigDefinition { name = line.substring(0, index); line = line.substring(index).trim(); } - VariableRegistry.INSTANCE.register(name, line); + if (VariableRegistry.isNumeric(line)) { + Integer v = Integer.valueOf(line); + VariableRegistry.INSTANCE.register(name, v); + } else { + VariableRegistry.INSTANCE.register(name, line); + } } private static String getMd5(byte[] content) { diff --git a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java index 74e727c424..2fd7c5f316 100644 --- a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java +++ b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java @@ -15,6 +15,8 @@ import static com.rusefi.ReaderState.MULT_TOKEN; * 3/30/2015 */ public class VariableRegistry { + private static final String _16_HEX_SUFFIX = "_16_hex"; + private static final String _HEX_SUFFIX = "_hex"; private TreeMap data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public static final VariableRegistry INSTANCE = new VariableRegistry(); @@ -69,18 +71,31 @@ public class VariableRegistry { if (!value.contains("\n")) { // multi-lines are not supported in C headers - cAllDefinitions.put(var, "#define " + var + " " + value + EOL); + if (!var.endsWith(_16_HEX_SUFFIX) && !var.endsWith(_HEX_SUFFIX)) { + cAllDefinitions.put(var, "#define " + var + " " + value + EOL); + } } tryToRegisterAsInteger(var, value); } + public static boolean isNumeric(String str) { + try { + Integer.parseInt(str); + return true; + } catch (NumberFormatException e) { + return false; + } + } + @SuppressWarnings("StringConcatenationInsideStringBufferAppend") private void tryToRegisterAsInteger(String var, String value) { try { int intValue = Integer.parseInt(value); SystemOut.println("key [" + var + "] value: " + intValue); intValues.put(var, intValue); - javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL); + if (!var.endsWith(_HEX_SUFFIX)) { + javaDefinitions.put(var, "\tpublic static final int " + var + " = " + intValue + ";" + EOL); + } } catch (NumberFormatException e) { SystemOut.println("Not an integer: " + value); @@ -105,7 +120,9 @@ public class VariableRegistry { */ public void register(String name, int value) { register(name, Integer.toString(value)); - register(name + "_hex", Integer.toString(value, 16)); + register(name + _HEX_SUFFIX, Integer.toString(value, 16)); + String _16_hex = String.format("\\\\x%02x\\\\x%02x", (value >> 8) & 0xFF, value & 0xFF); + register(name + _16_HEX_SUFFIX, _16_hex); } public void writeDefinesToFile(String fileName) throws IOException { diff --git a/java_tools/configuration_definition/src/com/rusefi/test/VariableRegistryTest.java b/java_tools/configuration_definition/src/com/rusefi/test/VariableRegistryTest.java index b824879d17..f0d23d1303 100644 --- a/java_tools/configuration_definition/src/com/rusefi/test/VariableRegistryTest.java +++ b/java_tools/configuration_definition/src/com/rusefi/test/VariableRegistryTest.java @@ -21,5 +21,7 @@ public class VariableRegistryTest { assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd")); // both decimal and hex values here assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff")); + + assertEquals("\\x01\\x00", VariableRegistry.INSTANCE.applyVariables("@@var_16_hex@@")); } }