mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
PluggableDiscovery: Factored out method to umarshal BoardPort from JSON
This commit is contained in:
parent
8e9f0cfd76
commit
4c188c9374
@ -126,7 +126,7 @@ public class BoardPort {
|
|||||||
// If found, boardName is set to the name from boards.txt
|
// If found, boardName is set to the name from boards.txt
|
||||||
// and the board is returned. If not found, null is returned.
|
// and the board is returned. If not found, null is returned.
|
||||||
public TargetBoard searchMatchingBoard() {
|
public TargetBoard searchMatchingBoard() {
|
||||||
if (identificationPrefs.isEmpty()) return null;
|
if (identificationPrefs == null || identificationPrefs.isEmpty()) return null;
|
||||||
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
|
for (TargetPackage targetPackage : BaseNoGui.packages.values()) {
|
||||||
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) {
|
||||||
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
||||||
|
@ -141,13 +141,9 @@ public class PluggableDiscovery implements Discovery {
|
|||||||
|
|
||||||
portList.clear();
|
portList.clear();
|
||||||
portsNode.forEach(portNode -> {
|
portsNode.forEach(portNode -> {
|
||||||
try {
|
BoardPort port = mapJsonNodeToBoardPort(mapper, node);
|
||||||
BoardPort port = mapper.treeToValue(portNode, BoardPort.class);
|
if (port != null) {
|
||||||
port.searchMatchingBoard();
|
|
||||||
addOrUpdate(port);
|
addOrUpdate(port);
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
System.err.println(format("{0}: Invalid BoardPort message", discoveryName));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -155,23 +151,16 @@ public class PluggableDiscovery implements Discovery {
|
|||||||
// Messages for SYNC updates
|
// Messages for SYNC updates
|
||||||
|
|
||||||
case "add":
|
case "add":
|
||||||
try {
|
BoardPort addedPort = mapJsonNodeToBoardPort(mapper, node);
|
||||||
BoardPort port = mapper.treeToValue(node.get("port"), BoardPort.class);
|
if (addedPort != null) {
|
||||||
port.searchMatchingBoard();
|
addOrUpdate(addedPort);
|
||||||
addOrUpdate(port);
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
System.err.println(format("{0}: Invalid BoardPort message", discoveryName));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case "remove":
|
case "remove":
|
||||||
try {
|
BoardPort removedPort = mapJsonNodeToBoardPort(mapper, node);
|
||||||
BoardPort port = mapper.treeToValue(node.get("port"), BoardPort.class);
|
if (removedPort != null) {
|
||||||
remove(port);
|
remove(removedPort);
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
System.err.println(format("{0}: Invalid BoardPort message", discoveryName));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -181,6 +170,18 @@ public class PluggableDiscovery implements Discovery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BoardPort mapJsonNodeToBoardPort(ObjectMapper mapper, JsonNode node) {
|
||||||
|
try {
|
||||||
|
BoardPort port = mapper.treeToValue(node.get("port"), BoardPort.class);
|
||||||
|
port.searchMatchingBoard();
|
||||||
|
return port;
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
System.err.println(format("{0}: Invalid BoardPort message", discoveryName));
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user