User board-specific terms in error messages #3886

EFI_ADC_13 used multiple times in hellen121vag #2925

enforcing new constraint
This commit is contained in:
rusefillc 2022-02-03 13:11:43 -05:00
parent 5f8d481f31
commit fd712d50e1
2 changed files with 25 additions and 29 deletions

Binary file not shown.

View File

@ -16,6 +16,9 @@ public class PinoutLogic {
private final File[] boardYamlFiles; private final File[] boardYamlFiles;
private final String boardName; private final String boardName;
private final ArrayList<PinState> globalList = new ArrayList<>();
private final Map</*id*/String, /*tsName*/String> tsNameById = new HashMap<>();
public PinoutLogic(String boardName, File[] boardYamlFiles) { public PinoutLogic(String boardName, File[] boardYamlFiles) {
this.boardName = boardName; this.boardName = boardName;
@ -48,7 +51,7 @@ public class PinoutLogic {
for (int ii = classList.size(); ii <= index; ii++) { for (int ii = classList.size(); ii <= index; ii++) {
classList.add(null); classList.add(null);
} }
classList.set(index, listPin.getPinName()); classList.set(index, listPin.getPinTsName());
break; break;
} }
} }
@ -85,8 +88,7 @@ public class PinoutLogic {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static void processYamlFile(File yamlFile, private void processYamlFile(File yamlFile) throws IOException {
ArrayList<PinState> listPins) throws IOException {
Yaml yaml = new Yaml(); Yaml yaml = new Yaml();
Map<String, Object> yamlData = yaml.load(new FileReader(yamlFile)); Map<String, Object> yamlData = yaml.load(new FileReader(yamlFile));
if (yamlData == null) { if (yamlData == null) {
@ -101,11 +103,10 @@ public class PinoutLogic {
SystemOut.println(data); SystemOut.println(data);
Objects.requireNonNull(data, "data"); Objects.requireNonNull(data, "data");
for (Map<String, Object> pin : data) { for (Map<String, Object> pin : data) {
ArrayList<PinState> thisPinList = new ArrayList<>();
Object pinId = pin.get("id"); Object pinId = pin.get("id");
Object pinClass = pin.get("class"); Object pinClass = pin.get("class");
String pinName = (String) pin.get("ts_name"); String pinTsName = (String) pin.get("ts_name");
if (pinId == null || pinClass == null || pinName == null) { if (pinId == null || pinClass == null || pinTsName == null) {
continue; continue;
} }
if (pinId instanceof ArrayList) { if (pinId instanceof ArrayList) {
@ -114,34 +115,27 @@ public class PinoutLogic {
throw new IllegalStateException("Expected multiple classes for " + pinIds); throw new IllegalStateException("Expected multiple classes for " + pinIds);
for (int i = 0; i < pinIds.size(); i++) { for (int i = 0; i < pinIds.size(); i++) {
String id = pinIds.get(i); String id = pinIds.get(i);
addPinToList(listPins, thisPinList, id, pinName, ((ArrayList<String>) pinClass).get(i)); addPinToList(id, pinTsName, ((ArrayList<String>) pinClass).get(i));
} }
} else if (pinId instanceof String) { } else if (pinId instanceof String) {
String pinIdString = (String) pinId; String pinIdString = (String) pinId;
if (pinIdString.length() == 0) { if (pinIdString.length() == 0) {
throw new IllegalStateException("Unexpected empty ID field"); throw new IllegalStateException("Unexpected empty ID field");
} }
addPinToList(listPins, thisPinList, pinIdString, pinName, (String) pinClass); addPinToList(pinIdString, pinTsName, (String) pinClass);
} else { } else {
throw new IllegalStateException("Unexpected type of ID field: " + pinId.getClass().getSimpleName()); throw new IllegalStateException("Unexpected type of ID field: " + pinId.getClass().getSimpleName());
} }
listPins.addAll(thisPinList);
} }
} }
private static void addPinToList(ArrayList<PinState> listPins, ArrayList<PinState> thisPinList, String id, String pinName, String pinClass) { private void addPinToList(String id, String pinTsName, String pinClass) {
/* String existingTsName = tsNameById.get(id);
This doesn't work as expected because it's possible that a board has multiple connector pins connected to the same MCU pin. if (existingTsName != null && !existingTsName.equals(pinTsName))
https://github.com/rusefi/rusefi/issues/2897 throw new IllegalStateException("ID used multiple times with different ts_name: " + id);
https://github.com/rusefi/rusefi/issues/2925 tsNameById.put(id, pinTsName);
for (int i = 0; i < listPins.size(); i++) { PinState thisPin = new PinState(id, pinTsName, pinClass);
if (id.equals(listPins.get(i).get("id"))) { globalList.add(thisPin);
throw new IllegalStateException("ID used multiple times: " + id);
}
}
*/
PinState thisPin = new PinState(id, pinName, pinClass);
thisPinList.add(thisPin);
} }
public static PinoutLogic create(String boardName) { public static PinoutLogic create(String boardName) {
@ -155,11 +149,10 @@ public class PinoutLogic {
} }
public void processYamls(VariableRegistry registry, ReaderState state) throws IOException { public void processYamls(VariableRegistry registry, ReaderState state) throws IOException {
ArrayList<PinState> listPins = new ArrayList<>();
for (File yamlFile : boardYamlFiles) { for (File yamlFile : boardYamlFiles) {
processYamlFile(yamlFile, listPins); processYamlFile(yamlFile);
} }
registerPins(listPins, registry, state); registerPins(globalList, registry, state);
} }
public List<String> getInputFiles() { public List<String> getInputFiles() {
@ -172,13 +165,16 @@ public class PinoutLogic {
} }
private static class PinState { private static class PinState {
/**
* ID is not unique
*/
private final String id; private final String id;
private final String pinName; private final String pinTsName;
private final String pinClass; private final String pinClass;
public PinState(String id, String pinName, String pinClass) { public PinState(String id, String pinName, String pinClass) {
this.id = id; this.id = id;
this.pinName = pinName; this.pinTsName = pinName;
this.pinClass = pinClass; this.pinClass = pinClass;
} }
@ -186,8 +182,8 @@ public class PinoutLogic {
return id; return id;
} }
public String getPinName() { public String getPinTsName() {
return pinName; return pinTsName;
} }
public String getPinClass() { public String getPinClass() {