@@ -56,7 +56,7 @@ public PluggableDiscovery(String discoveryName, String[] cmd) {
56
56
this .cmd = cmd ;
57
57
this .discoveryName = discoveryName ;
58
58
portList = new LinkedList <>();
59
- System .out .println (" Starting: " + PApplet .join (cmd , " " ));
59
+ System .out .println (discoveryName + ": Starting: " + PApplet .join (cmd , " " ));
60
60
}
61
61
62
62
@ Override
@@ -74,19 +74,25 @@ public void run() {
74
74
while (program != null && program .isAlive ()) {
75
75
BoardPort port = mapper .readValue (parser , BoardPort .class );
76
76
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
+ }
82
88
}
83
89
}
84
- System .out .println (" thread exit normally" );
90
+ System .out .println (discoveryName + ": thread exit normally" );
85
91
} catch (InterruptedException e ) {
86
- System .out .println (" thread exit by interrupt" );
92
+ System .out .println (discoveryName + ": thread exit by interrupt" );
87
93
e .printStackTrace ();
88
94
} catch (Exception e ) {
89
- System .out .println (" thread exit other exception" );
95
+ System .out .println (discoveryName + ": thread exit other exception" );
90
96
e .printStackTrace ();
91
97
}
92
98
try {
@@ -160,9 +166,6 @@ private synchronized void update(BoardPort port) {
160
166
// avoid changing the list while it's being accessed by
161
167
// another thread.
162
168
String address = port .getAddress ();
163
- if (address == null ) {
164
- return ; // address is required
165
- }
166
169
for (BoardPort bp : portList ) {
167
170
if (address .equals (bp .getAddress ())) {
168
171
// if address already on the list, discard old info
@@ -191,8 +194,7 @@ public synchronized List<BoardPort> listDiscoveredBoards() {
191
194
// a clean copy.
192
195
final List <BoardPort > portListCopy = new ArrayList <>();
193
196
for (BoardPort bp : portList ) {
194
- //portListCopy.add(new BoardPort(bp));
195
- portListCopy .add (bp );
197
+ portListCopy .add (new BoardPort (bp ));
196
198
}
197
199
return portListCopy ;
198
200
}
0 commit comments