mirror of https://github.com/FOME-Tech/fome-fw.git
future fully integrated PinoutLogic test
This commit is contained in:
parent
fab6076224
commit
c14d791d53
|
@ -176,8 +176,7 @@ public class ConfigDefinition {
|
||||||
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
new TriggerWheelTSLogic().execute(triggersInputFolder, state.getVariableRegistry());
|
||||||
|
|
||||||
if (pinoutLogic != null) {
|
if (pinoutLogic != null) {
|
||||||
pinoutLogic.readFiles();
|
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), parseState, state.getEnumsReader());
|
||||||
pinoutLogic.registerBoardSpecificPinNames(state.getVariableRegistry(), state, parseState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the input files
|
// Parse the input files
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class PinoutLogic {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) {
|
private static void registerPins(String boardName, ArrayList<PinState> listPins, VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) {
|
||||||
if (listPins == null || listPins.isEmpty()) {
|
if (listPins == null || listPins.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class PinoutLogic {
|
||||||
}
|
}
|
||||||
PinType listPinType = PinType.find(className);
|
PinType listPinType = PinType.find(className);
|
||||||
String pinType = listPinType.getPinType();
|
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);
|
Objects.requireNonNull(enumList, "Enum for " + pinType);
|
||||||
Map.Entry<String, Value> kv = find(enumList, id);
|
Map.Entry<String, Value> kv = find(enumList, id);
|
||||||
if (kv == null) {
|
if (kv == null) {
|
||||||
|
@ -80,7 +80,7 @@ public class PinoutLogic {
|
||||||
String outputEnumName = namePinType.getOutputEnumName();
|
String outputEnumName = namePinType.getOutputEnumName();
|
||||||
String pinType = namePinType.getPinType();
|
String pinType = namePinType.getPinType();
|
||||||
String nothingName = namePinType.getNothingName();
|
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());
|
EnumPair pair = enumToOptionsList(nothingName, enumList, kv.getValue());
|
||||||
if (pair.getSimpleForm().length() > 0) {
|
if (pair.getSimpleForm().length() > 0) {
|
||||||
// we seem to be here if specific pin category like switch_inputs has no pins
|
// 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));
|
return new PinoutLogic(new FileSystemBoardInputsImpl(boardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerBoardSpecificPinNames(VariableRegistry registry, ReaderStateImpl state, DefinitionsState parseState) throws IOException {
|
public void registerBoardSpecificPinNames(VariableRegistry registry, DefinitionsState parseState, EnumsReader enumsReader) throws IOException {
|
||||||
registerPins(boardInputs.getName(), globalList, registry, state, parseState);
|
readFiles();
|
||||||
|
registerPins(boardInputs.getName(), globalList, registry, parseState, enumsReader);
|
||||||
|
|
||||||
try (Writer getTsNameByIdFile = boardInputs.getWriter()) {
|
try (Writer getTsNameByIdFile = boardInputs.getWriter()) {
|
||||||
getTsNameByIdFile.append(header);
|
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()) {
|
for (Object yamlFile : boardInputs.getBoardYamlKeys()) {
|
||||||
header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n");
|
header.append("// auto-generated by PinoutLogic.java based on " + yamlFile + "\n");
|
||||||
readMetaInfo(yamlFile.toString(), boardInputs.getReader(yamlFile));
|
readMetaInfo(yamlFile.toString(), boardInputs.getReader(yamlFile));
|
||||||
|
|
|
@ -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<String> 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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue