1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-02 13:24:12 +01:00

SerialDiscovery: refactor search loop

This commit is contained in:
Cristian Maglie 2020-03-23 17:31:12 +01:00 committed by Cristian Maglie
parent bb629d1ba0
commit 8208376507

View File

@ -148,29 +148,20 @@ public class SerialDiscovery implements Discovery, Runnable {
Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages); Map<String, Object> boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages);
BoardPort boardPort = null; // if port has been already discovered bring it back online
int i = 0; BoardPort oldBoardPort = boardPorts.stream() //
.filter(bp -> bp.toCompleteString().equalsIgnoreCase(newPort)) //
// create new board if in ports but not in boardPorts .findAny().orElse(null);
for (BoardPort board : boardPorts) { if (oldBoardPort != null) {
if (board.toCompleteString().equalsIgnoreCase(newPort)) { oldBoardPort.setOnlineStatus(true);
boardPort = boardPorts.get(i);
boardPorts.get(i).setOnlineStatus(true);
break;
}
i++;
}
if (boardPort != null) {
continue; continue;
} }
boardPort = new BoardPort(); BoardPort boardPort = new BoardPort();
boardPorts.add(boardPort); boardPorts.add(boardPort);
boardPort.setAddress(port); boardPort.setAddress(port);
boardPort.setProtocol("serial"); boardPort.setProtocol("serial");
boardPort.setOnlineStatus(true); boardPort.setOnlineStatus(true);
boardPort.setLabel(port); boardPort.setLabel(port);
if (boardData != null) { if (boardData != null) {