diff --git a/java_tools/ConfigDefinition.jar b/java_tools/ConfigDefinition.jar index c8c6980c51..091a87e4ac 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/ReaderState.java b/java_tools/configuration_definition/src/main/java/com/rusefi/ReaderState.java index 3436119b9b..da3cff3874 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/ReaderState.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/ReaderState.java @@ -287,13 +287,16 @@ public class ReaderState { ConfigStructure structure = state.stack.peek(); Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType()); + Integer customTypeSize = state.tsCustomSize.get(cf.getType()); if (getPrimitiveSize != null && getPrimitiveSize > 1) { if (log.debugEnabled()) log.debug("Need to align before " + cf.getName()); structure.addAlignmentFill(state, getPrimitiveSize); - } else if (getPrimitiveSize == null) { + } else if (state.structures.containsKey(cf.getType())) { // we are here for struct members structure.addAlignmentFill(state, 4); + } else if (customTypeSize != null) { + structure.addAlignmentFill(state, customTypeSize % 8); } if (cf.isIterate()) { diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java b/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java index c942c32690..ba68a4dab2 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/output/ConfigStructure.java @@ -55,6 +55,8 @@ public class ConfigStructure { } public void addAlignmentFill(ReaderState state, int alignment) { + if (alignment == 0) + return; /** * we make alignment decision based on C fields since we expect iteration and non-iteration fields * to match in size @@ -70,6 +72,8 @@ public class ConfigStructure { totalSize = iterator.currentOffset; int fillSize = totalSize % alignment == 0 ? 0 : alignment - (totalSize % alignment); + if (fillSize > 3) + throw new IllegalStateException("Fill size does not look right: " + fillSize); if (fillSize != 0) { int[] fillSizeArray; diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java index 96bcb57345..b2994cd4a0 100644 --- a/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/test/ConfigFieldParserTest.java @@ -79,7 +79,7 @@ public class ConfigFieldParserTest { public void testCustomEnum() throws IOException { String test = "struct pid_s\n" + "#define ego_sensor_e_enum \"BPSX\", \"Innovate\", \"14Point7\"\n" + - "custom ego_sensor_e 1 bits, S32, @OFFSET@, [0:1], @@ego_sensor_e_enum@@\n" + + "custom ego_sensor_e 1 bits, S08, @OFFSET@, [0:1], @@ego_sensor_e_enum@@\n" + "ego_sensor_e afr_type1;\n" + "ego_sensor_e afr_type2;\n" + "int8_t int\n" + @@ -88,14 +88,52 @@ public class ConfigFieldParserTest { TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state); state.readBufferedReader(test, (tsProjectConsumer)); - assertEquals("afr_type1 = bits, S32, 0, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + - "alignmentFill_at_1 = array, U08, 1, [3], \"units\", 1, 0, -20, 100, 0\n" + - "afr_type2 = bits, S32, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + - "int = scalar, S08, 5, \"\", 1, 0, 0, 100, 0\n" + + assertEquals("afr_type1 = bits, S08, 0, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + + "afr_type2 = bits, S08, 1, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + + "int = scalar, S08, 2, \"\", 1, 0, 0, 100, 0\n" + + "alignmentFill_at_3 = scalar, U08, 3, \"units\", 1, 0, -20, 100, 0\n" + + "; total TS size = 4\n", tsProjectConsumer.getContent()); + } + + @Test + public void test2byteCustomEnum() throws IOException { + String test = "struct pid_s\n" + + "#define ego_sensor_e_enum \"BPSX\", \"Innovate\", \"14Point7\"\n" + + "custom ego_sensor_e2 2 bits, S16, @OFFSET@, [0:1], @@ego_sensor_e_enum@@\n" + + "int8_t int\n" + + "ego_sensor_e2 afr_type1;\n" + + "ego_sensor_e2 afr_type2;\n" + + "end_struct\n"; + ReaderState state = new ReaderState(); + + TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state); + state.readBufferedReader(test, (tsProjectConsumer)); + assertEquals("int = scalar, S08, 0, \"\", 1, 0, 0, 100, 0\n" + + "alignmentFill_at_1 = scalar, U08, 1, \"units\", 1, 0, -20, 100, 0\n" + + "afr_type1 = bits, S16, 2, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + + "afr_type2 = bits, S16, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + "alignmentFill_at_6 = array, U08, 6, [2], \"units\", 1, 0, -20, 100, 0\n" + "; total TS size = 8\n", tsProjectConsumer.getContent()); } + @Test + public void test4byteCustomEnum() throws IOException { + String test = "struct pid_s\n" + + "#define ego_sensor_e_enum \"BPSX\", \"Innovate\", \"14Point7\"\n" + + "custom ego_sensor_e4 4 bits, S32, @OFFSET@, [0:1], @@ego_sensor_e_enum@@\n" + + "int8_t int2\n" + + "ego_sensor_e4 afr_type3;\n" + + "end_struct\n"; + ReaderState state = new ReaderState(); + + TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state); + state.readBufferedReader(test, (tsProjectConsumer)); + assertEquals("int2 = scalar, S08, 0, \"\", 1, 0, 0, 100, 0\n" + + "alignmentFill_at_1 = array, U08, 1, [3], \"units\", 1, 0, -20, 100, 0\n" + + "afr_type3 = bits, S32, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + + "; total TS size = 8\n", tsProjectConsumer.getContent()); + } + @Test public void alignFourByteTypes() throws IOException { // we expect padding before each 4 byte field