a few drop downs have "3" option which only confuses users #5942

This commit is contained in:
Andrey 2024-02-14 16:20:05 -05:00
parent c0a576f8a3
commit bc338e4cbc
2 changed files with 32 additions and 6 deletions

View File

@ -96,12 +96,29 @@ public class ConfigFieldParserTest {
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
assertEquals("afr_type1 = bits, S08, 0, [0:1], \"BPSX\", \"Innovate\", \"14Point7\"\n" +
"afr_type2 = bits, S08, 1, [0:1], \"BPSX\", \"Innovate\", \"14Point7\"\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, S16, 2, \"\", 1, 0, 0, 32000, 0\n" +
"; total TS size = 4\n", tsProjectConsumer.getContent());
}
@Test
public void testCustomEnumWithTsVariable() {
String test = "struct pid_s\n" +
"#define ego_sensor_e_enum \"BPSX\", \"Innovate\", \"14Point7\"\n" +
"custom ego_sensor_e 1 bits, S08, @OFFSET@, [0:1], $ego_sensor_e_list\n" +
"ego_sensor_e afr_type1;\n" +
"int16_t int\n" +
"end_struct\n";
ReaderStateImpl state = new ReaderStateImpl();
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
assertEquals("afr_type1 = bits, S08, 0, [0:1], $ego_sensor_e_list\n" +
"int = scalar, S16, 2, \"\", 1, 0, 0, 32000, 0\n" +
"; total TS size = 4\n", tsProjectConsumer.getContent());
}
@Test
public void testShortForm() {
String test = "struct pid_s\n" +
@ -135,8 +152,8 @@ public class ConfigFieldParserTest {
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
assertEquals("int = scalar, S08, 0, \"\", 1, 0, 0, 100, 0\n" +
"afr_type1 = bits, S16, 2, [0:1], \"BPSX\", \"Innovate\", \"14Point7\"\n" +
"afr_type2 = bits, S16, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\"\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" +
"; total TS size = 8\n", tsProjectConsumer.getContent());
}
@ -153,7 +170,7 @@ public class ConfigFieldParserTest {
TestTSProjectConsumer tsProjectConsumer = new TestTSProjectConsumer("", state);
state.readBufferedReader(test, tsProjectConsumer);
assertEquals("int2 = scalar, S08, 0, \"\", 1, 0, 0, 100, 0\n" +
"afr_type3 = bits, S32, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\"\n" +
"afr_type3 = bits, S32, 4, [0:1], \"BPSX\", \"Innovate\", \"14Point7\", \"INVALID\"\n" +
"; total TS size = 8\n", tsProjectConsumer.getContent());
}

View File

@ -171,9 +171,18 @@ public class ReaderStateImpl implements ReaderState {
EnumIniField.ParseBitRange bitRange = new EnumIniField.ParseBitRange().invoke(rawLine.getTokens()[3]);
int totalCount = 1 << (bitRange.getBitSize0() + 1);
List<String> enums = Arrays.asList(rawLine.getTokens()).subList(4, rawLine.getTokens().length);
int enumCount = EnumIniField.EnumKeyValueMap.isKeyValueSyntax(EnumIniField.getEnumValuesSection(tunerStudioLine)) ? enums.size() / 2 : enums.size();
boolean isKeyValueSyntax = EnumIniField.EnumKeyValueMap.isKeyValueSyntax(EnumIniField.getEnumValuesSection(tunerStudioLine));
int enumCount = isKeyValueSyntax ? enums.size() / 2 : enums.size();
if (enumCount > totalCount)
throw new IllegalStateException(name + ": Too many options in " + tunerStudioLine + " capacity=" + totalCount + "/size=" + enums.size());
boolean looksLikeListVariableSyntax = enumCount == 1;
if (!isKeyValueSyntax && !looksLikeListVariableSyntax) {
StringBuilder sb = new StringBuilder(tunerStudioLine);
for (int i = enumCount; i < totalCount; i++) {
sb.append(", ").append(InvalidConstant.QUOTED_INVALID);
}
tunerStudioLine = sb.toString();
}
/*
this does not work right now since smt32 and kinetis enum sizes could be different but same .txt file
todo: identify relevant bitsizes and use variables for bitsizes?