Skip to content

Commit b606657

Browse files
PaulStoffregencmaglie
authored andcommitted
PluggableDiscovery check for START_SYNC not supported
1 parent 5ba56ab commit b606657

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

arduino-core/src/cc/arduino/packages/discoverers/PluggableDiscovery.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public PluggableDiscovery(String discoveryName, String[] cmd) {
5656
this.cmd = cmd;
5757
this.discoveryName = discoveryName;
5858
portList = new LinkedList<>();
59-
System.out.println("Starting: " + PApplet.join(cmd, " "));
59+
System.out.println(discoveryName + ": Starting: " + PApplet.join(cmd, " "));
6060
}
6161

6262
@Override
@@ -74,19 +74,25 @@ public void run() {
7474
while (program != null && program.isAlive()) {
7575
BoardPort port = mapper.readValue(parser, BoardPort.class);
7676
if (port != null) {
77-
System.out.println(discoveryName + " received json");
78-
//
79-
// TODO: check for START_SYNC not supported, call startPolling()
80-
//
81-
update(port);
77+
System.out.println(discoveryName + ": received json");
78+
String address = port.getAddress();
79+
if (address != null) {
80+
if (address.equals("Error: START_SYNC not supported")) {
81+
if (pollingThread == null) {
82+
startPolling();
83+
}
84+
} else {
85+
update(port);
86+
}
87+
}
8288
}
8389
}
84-
System.out.println("thread exit normally");
90+
System.out.println(discoveryName + ": thread exit normally");
8591
} catch (InterruptedException e) {
86-
System.out.println("thread exit by interrupt");
92+
System.out.println(discoveryName + ": thread exit by interrupt");
8793
e.printStackTrace();
8894
} catch (Exception e) {
89-
System.out.println("thread exit other exception");
95+
System.out.println(discoveryName + ": thread exit other exception");
9096
e.printStackTrace();
9197
}
9298
try {
@@ -160,9 +166,6 @@ private synchronized void update(BoardPort port) {
160166
// avoid changing the list while it's being accessed by
161167
// another thread.
162168
String address = port.getAddress();
163-
if (address == null) {
164-
return; // address is required
165-
}
166169
for (BoardPort bp : portList) {
167170
if (address.equals(bp.getAddress())) {
168171
// if address already on the list, discard old info
@@ -191,8 +194,7 @@ public synchronized List<BoardPort> listDiscoveredBoards() {
191194
// a clean copy.
192195
final List<BoardPort> portListCopy = new ArrayList<>();
193196
for (BoardPort bp : portList) {
194-
//portListCopy.add(new BoardPort(bp));
195-
portListCopy.add(bp);
197+
portListCopy.add(new BoardPort(bp));
196198
}
197199
return portListCopy;
198200
}

0 commit comments

Comments
 (0)