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 bbd8dba659..9bd2bb06e2 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 @@ -176,8 +176,7 @@ public class ConfigDefinition { new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry()); if (pinoutLogic != null) { - pinoutLogic.readFiles(); - pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), state, parseState); + pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader()); } // Parse the input files diff --git a/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java b/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java index a2b377b521..091ba83e8b 100644 --- a/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java +++ b/java_tools/configuration_definition/src/main/java/com/rusefi/pinout/PinoutLogic.java @@ -43,7 +43,7 @@ public class PinoutLogic { return null; } - private static void registerPins(String boardName, ArrayList listPins, VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) { + private static void registerPins(String boardName, ArrayList listPins, VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) { if (listPins == null || listPins.isEmpty()) { return; } @@ -61,7 +61,7 @@ public class PinoutLogic { } PinType listPinType = PinType.find(className); String pinType = listPinType.getPinType(); - EnumsReader.EnumState enumList = state.getEnumsReader().getEnums().get(pinType); + EnumsReader.EnumState enumList = enumsReader.getEnums().get(pinType); Objects.requireNonNull(enumList, "Enum for " + pinType); Map.Entry kv = find(enumList, id); if (kv == null) { @@ -80,7 +80,7 @@ public class PinoutLogic { String outputEnumName = namePinType.getOutputEnumName(); String pinType = namePinType.getPinType(); String nothingName = namePinType.getNothingName(); - EnumsReader.EnumState enumList = state.getEnumsReader().getEnums().get(pinType); + EnumsReader.EnumState enumList = enumsReader.getEnums().get(pinType); EnumPair pair = enumToOptionsList(nothingName, enumList, kv.getValue()); if (pair.getSimpleForm().length() > 0) { // we seem to be here if specific pin category like switch_inputs has no pins @@ -194,8 +194,9 @@ public class PinoutLogic { return new PinoutLogic(new FileSystemBoardInputsImpl(boardName)); } - public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) throws IOException { - registerPins(boardInputs.getName(), globalList, registry, state, parseState); + public void registerBoardSpecificPinNames(VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) throws IOException { + readFiles(); + registerPins(boardInputs.getName(), globalList, registry, parseState, enumsReader); try (Writer getTsNameByIdFile = boardInputs.getWriter()) { getTsNameByIdFile.append(header); @@ -218,7 +219,7 @@ public class PinoutLogic { } } - public void readFiles() throws IOException { + private void readFiles() throws IOException { for (Object yamlFile : boardInputs.getBoardYamlKeys()) { header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n"); readMetaInfo(yamlFile.toString(), boardInputs.getReader(yamlFile)); diff --git a/java_tools/configuration_definition/src/test/java/com/rusefi/pinout/PinoutLogicIntegratedTest.java b/java_tools/configuration_definition/src/test/java/com/rusefi/pinout/PinoutLogicIntegratedTest.java new file mode 100644 index 0000000000..4c3897866f --- /dev/null +++ b/java_tools/configuration_definition/src/test/java/com/rusefi/pinout/PinoutLogicIntegratedTest.java @@ -0,0 +1,73 @@ +package com.rusefi.pinout; + +import com.rusefi.EnumsReader; +import com.rusefi.VariableRegistry; +import com.rusefi.newparse.ParseState; +import org.junit.Test; + +import java.io.*; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class PinoutLogicIntegratedTest { + @Test + public void testWholeThing() throws IOException { + StringWriter testWriter = new StringWriter(); + + Reader input = new StringReader("pins:\n" + + " - pin: 1\n" + + " id: [E11, E11]\n" + + " class: [event_inputs, switch_inputs]\n" + + " function: Digital trigger/switch input for instance Hall type CAM\n" + + " ts_name: Digital 2\n" + + " type: din"); + + BoardInputs testBoard = new BoardInputs() { + @Override + public List getBoardYamlKeys() { + return Collections.singletonList("key"); + } + + @Override + public Reader getReader(Object yamlKey) { + return input; + } + + @Override + public String getName() { + return "test"; + } + + @Override + public List getInputFiles() { + throw new UnsupportedOperationException(); + } + + @Override + public Writer getWriter() { + return testWriter; + } + }; + + VariableRegistry registry = new VariableRegistry(); + EnumsReader enumsReader = new EnumsReader(); + + enumsReader.read(new StringReader("#define output_pin_e_enum \"NONE\", \"INVALID\", \"PA0\", \"PA1\", \"PA2\"\n" + + "custom output_pin_e 2 bits, U16, @OFFSET@, [0:7], @@output_pin_e_enum@@\n")); + + enumsReader.read(new StringReader("#define Gpio_enum \"NONE\", \"INVALID\", \"PA0\", \"PA1\", \"PA2\", \"PA3\"\n" + + "\n" + + "custom Gpio 2 bits, U16, @OFFSET@, [0:7], @@Gpio_enum@@")); + + ParseState definitionState = new ParseState(); + + PinoutLogic logic = new PinoutLogic(testBoard); + + //logic.registerBoardSpecificPinNames(registry, definitionState, enumsReader); + + // assertEquals("", testWriter.getBuffer().toString()); + + } +}