2 byte pin index #4097

let's have another go?
This commit is contained in:
rusefillc 2022-04-25 00:18:53 -04:00
parent 1eb4dfe34e
commit f3fb27003f
4 changed files with 51 additions and 6 deletions

Binary file not shown.

View File

@ -287,13 +287,16 @@ public class ReaderState {
ConfigStructure structure = state.stack.peek(); ConfigStructure structure = state.stack.peek();
Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType()); Integer getPrimitiveSize = TypesHelper.getPrimitiveSize(cf.getType());
Integer customTypeSize = state.tsCustomSize.get(cf.getType());
if (getPrimitiveSize != null && getPrimitiveSize > 1) { if (getPrimitiveSize != null && getPrimitiveSize > 1) {
if (log.debugEnabled()) if (log.debugEnabled())
log.debug("Need to align before " + cf.getName()); log.debug("Need to align before " + cf.getName());
structure.addAlignmentFill(state, getPrimitiveSize); structure.addAlignmentFill(state, getPrimitiveSize);
} else if (getPrimitiveSize == null) { } else if (state.structures.containsKey(cf.getType())) {
// we are here for struct members // we are here for struct members
structure.addAlignmentFill(state, 4); structure.addAlignmentFill(state, 4);
} else if (customTypeSize != null) {
structure.addAlignmentFill(state, customTypeSize % 8);
} }
if (cf.isIterate()) { if (cf.isIterate()) {

View File

@ -55,6 +55,8 @@ public class ConfigStructure {
} }
public void addAlignmentFill(ReaderState state, int alignment) { 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 * we make alignment decision based on C fields since we expect iteration and non-iteration fields
* to match in size * to match in size
@ -70,6 +72,8 @@ public class ConfigStructure {
totalSize = iterator.currentOffset; totalSize = iterator.currentOffset;
int fillSize = totalSize % alignment == 0 ? 0 : alignment - (totalSize % alignment); 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) { if (fillSize != 0) {
int[] fillSizeArray; int[] fillSizeArray;

View File

@ -79,7 +79,7 @@ public class ConfigFieldParserTest {
public void testCustomEnum() throws IOException { public void testCustomEnum() throws IOException {
String test = "struct pid_s\n" + String test = "struct pid_s\n" +
"#define ego_sensor_e_enum \"BPSX\", \"Innovate\", \"14Point7\"\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_type1;\n" +
"ego_sensor_e afr_type2;\n" + "ego_sensor_e afr_type2;\n" +
"int8_t int\n" + "int8_t int\n" +
@ -88,14 +88,52 @@ public class ConfigFieldParserTest {
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state); TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, (tsProjectConsumer)); state.readBufferedReader(test, (tsProjectConsumer));
assertEquals("afr_type1 = bits, S32, 0, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + assertEquals("afr_type1 = bits, S08, 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, S08, 1, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" +
"afr_type2 = bits, S32, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" + "int = scalar, S08, 2, \"\", 1, 0, 0, 100, 0\n" +
"int = scalar, S08, 5, \"\", 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" + "alignmentFill_at_6 = array, U08, 6, [2], \"units\", 1, 0, -20, 100, 0\n" +
"; total TS size = 8\n", tsProjectConsumer.getContent()); "; 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 @Test
public void alignFourByteTypes() throws IOException { public void alignFourByteTypes() throws IOException {
// we expect padding before each 4 byte field // we expect padding before each 4 byte field