diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index cfcc4721b0..67f8ae17a6 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/ConfigDefinition.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java index fde6aaf1ef..1eb1d0403c 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigDefinition.java @@ -230,7 +230,9 @@ public class ConfigDefinition { SystemOut.println(state.enumsReader.getEnums() + " total enumsReader"); } - long crc32 = signatureHash(state, tsPath, inputAllFiles); + ParseState parseState = new ParseState(state.enumsReader); + // Add the variable for the config signature + long crc32 = signatureHash(state, parseState, tsPath, inputAllFiles); handleFiringOrder(firingEnumFileName, state.variableRegistry); @@ -247,10 +249,8 @@ public class ConfigDefinition { // Parse the input files { - ParseState parseState = new ParseState(state.enumsReader); - // First process yaml files - //processYamls(listener, yamlFiles); + //processYamls(parseState, yamlFiles); // Process firing order enum handleFiringOrder(firingEnumFileName, parseState); @@ -262,7 +262,7 @@ public class ConfigDefinition { //for (String prependFile : prependFiles) { // TODO: fix signature define file parsing - //parseFile(listener, prependFile); + //parseFile(parseState, prependFile); //} } @@ -275,12 +275,11 @@ public class ConfigDefinition { // Write C structs // CStructWriter cStructs = new CStructWriter(); - // cStructs.writeCStructs(listener, destCHeaderFileName + ".test"); + // cStructs.writeCStructs(parseState, destCHeaderFileName + ".test"); // Write tunerstudio layout // TsWriter writer = new TsWriter(); - // writer.writeTunerstudio(listener, "TODO", tsPath + "/test.ini"); - + // writer.writeTunerstudio(parseState, tsPath + "/rusefi.input", tsPath + "/" + TSProjectConsumer.TS_FILE_OUTPUT_NAME); } BufferedReader definitionReader = new BufferedReader(new InputStreamReader(new FileInputStream(definitionInputFile), IoUtils.CHARSET.name())); @@ -346,7 +345,7 @@ public class ConfigDefinition { } } - private static long signatureHash(ReaderState state, String tsPath, List inputAllFiles) throws IOException { + private static long signatureHash(ReaderState state, ParseState parseState, String tsPath, List inputAllFiles) throws IOException { // get CRC32 of given input files long crc32 = 0; for (String iFile : inputAllFiles) { @@ -356,8 +355,13 @@ public class ConfigDefinition { } SystemOut.println("CRC32 from all input files = " + crc32); // store the CRC32 as a built-in variable - if (tsPath != null) // nasty trick - do not insert signature into live data files + + // nasty trick - do not insert signature into live data files + if (tsPath != null) { state.variableRegistry.register(SIGNATURE_HASH, "" + crc32); + parseState.addDefinition(SIGNATURE_HASH, Long.toString(crc32), Definition.OverwritePolicy.NotAllowed); + } + return crc32; } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigField.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigField.java index 01abce18c7..0ee7f8262f 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigField.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ConfigField.java @@ -212,7 +212,7 @@ public class ConfigField { public String getCommentContent() { if (comment == null || comment.isEmpty()) return comment; - return comment.charAt(0) == TS_COMMENT_TAG ? comment.substring(1) : comment; + return (comment.charAt(0) == TS_COMMENT_TAG ? comment.substring(1) : comment).trim(); } public int[] getArraySizes() { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/layout/ScalarLayout.java b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/layout/ScalarLayout.java index de9ebf6588..395d146e97 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/layout/ScalarLayout.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/layout/ScalarLayout.java @@ -85,6 +85,28 @@ public class ScalarLayout extends Layout { printAfterArrayLength(ps); } + private String makeScaleString() { + float scale = this.options.scale; + + int mul, div; + + if (scale < 1) { + mul = Math.round(1 / scale); + div = 1; + } else { + mul = 1; + div = Math.round(scale); + } + + float actualScale = (float)mul / div; + + if (mul < 1 || div < 1 || (Math.abs(scale - actualScale) < 0.0001f)) { + throw new RuntimeException("assertion failure: scale string generation failure for " + this.name); + } + + return mul + ", " + div; + } + @Override public void writeCLayout(PrintStream ps) { this.writeCOffsetHeader(ps, this.options.comment, this.options.units); @@ -92,7 +114,7 @@ public class ScalarLayout extends Layout { String cTypeName = this.type.cType.replaceAll("^int32_t$", "int"); if (this.autoscale) { - cTypeName = "scaled_channel<" + cTypeName + ", " + Math.round(1 / this.options.scale) + ">"; + cTypeName = "scaled_channel<" + cTypeName + ", " + makeScaleString() + ">"; } ps.print("\t" + cTypeName + " " + this.name); @@ -120,7 +142,7 @@ public class ScalarLayout extends Layout { String cTypeName = this.type.cType.replaceAll("^int32_t$", "int"); if (this.autoscale) { - cTypeName = "scaled_channel<" + cTypeName + ", " + Math.round(1 / this.options.scale) + ">"; + cTypeName = "scaled_channel<" + cTypeName + ", " + makeScaleString() + ">"; } ps.println("\t" + cTypeName + " " + this.name + "[" + al + "];"); diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsMetadata.java b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsMetadata.java index dc193783a3..5209bd0fa8 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsMetadata.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsMetadata.java @@ -12,12 +12,16 @@ public class TsMetadata { } comment = comment.trim(); - if (!comment.startsWith("+")) { - return; + + // LEGACY FEATURE: clips off the previously-required + + if (comment.startsWith("+")) { + // Clip off leading +, and any leading/trailing whitespace + comment = comment.substring(1).trim(); } - // Clip off leading +, and any leading/trailing whitespace - comment = comment.substring(1).trim(); + if (comment.length() == 0) { + return; + } comments.add("\t" + name + " = \"" + comment + "\""); } diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsWriter.java b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsWriter.java index 716dc576de..303bee38ec 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsWriter.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/newparse/outputs/TsWriter.java @@ -18,9 +18,6 @@ public class TsWriter { BufferedReader is = new BufferedReader(new FileReader(inputFile)); PrintStream ps = new PrintStream(new FileOutputStream(outputFile)); - // TODO: handle signature - parser.addDefinition("TS_SIGNATURE", "sig", Definition.OverwritePolicy.NotAllowed); - while (is.ready()) { String line = is.readLine(); @@ -45,6 +42,9 @@ public class TsWriter { line = line.replace(match.group(0), ""); } + // Don't strip surrounding quotes of the FIRST replace of the line - only do it in nested replacements + boolean isNested = false; + // While there is a line to replace, do it while (line.contains("@@")) { match = VAR.matcher(line); @@ -55,7 +55,19 @@ public class TsWriter { String varName = match.group(1); Definition def = parser.findDefinition(varName); - line = line.replaceAll(match.group(0), def != null ? def.toString() : "MISSING DEFINITION"); + + String replacement = def != null ? def.toString() : "MISSING DEFINITION"; + + // Strip off any quotes from the resolved string - we may be trying to concatenate inside a string literal where quotes aren't allowed + while (isNested && replacement.startsWith("\"") && replacement.endsWith("\"")) { + replacement = replacement.substring(1, replacement.length() - 1); + } + + line = line.replaceAll(match.group(0), replacement); + + if (!isNested) { + isNested = true; + } } // TODO: remove extra whitespace from the line