@@ -46,7 +46,6 @@ public class SerialDiscovery implements Discovery, Runnable {
46
46
private final List <String > oldPorts = new ArrayList <>();
47
47
public boolean uploadInProgress = false ;
48
48
public boolean pausePolling = false ;
49
- private BoardPort oldUploadBoardPort = null ;
50
49
private final BoardCloudResolver boardCloudResolver = new BoardCloudResolver ();
51
50
52
51
@@ -56,7 +55,7 @@ public List<BoardPort> listDiscoveredBoards() {
56
55
}
57
56
58
57
@ Override
59
- public List <BoardPort > listDiscoveredBoards (boolean complete ) {
58
+ public synchronized List <BoardPort > listDiscoveredBoards (boolean complete ) {
60
59
if (complete ) {
61
60
return new ArrayList <>(serialBoardPorts );
62
61
}
@@ -69,7 +68,7 @@ public List<BoardPort> listDiscoveredBoards(boolean complete) {
69
68
return onlineBoardPorts ;
70
69
}
71
70
72
- public void setSerialBoardPorts (List <BoardPort > newSerialBoardPorts ) {
71
+ public synchronized void setSerialBoardPorts (List <BoardPort > newSerialBoardPorts ) {
73
72
serialBoardPorts .clear ();
74
73
serialBoardPorts .addAll (newSerialBoardPorts );
75
74
}
@@ -116,27 +115,17 @@ public synchronized void forceRefresh() {
116
115
return ;
117
116
}
118
117
119
- // if (updating) {}
120
- // a port will disappear, another will appear
121
- // use this information to "merge" the boards
122
- // updating must be signaled by SerialUpload class
123
-
124
118
oldPorts .clear ();
125
119
oldPorts .addAll (ports );
126
120
121
+ // set unreachable ports offline
127
122
for (BoardPort board : boardPorts ) {
128
- if (ports .contains (board .toString ())) {
129
- if (board .isOnline ()) {
130
- ports .remove (ports .indexOf (board .toString ()));
131
- }
132
- } else {
133
- if (uploadInProgress && board .isOnline ()) {
134
- oldUploadBoardPort = board ;
135
- }
123
+ if (!ports .contains (board .toCompleteString ())) {
136
124
board .setOnlineStatus (false );
137
125
}
138
126
}
139
127
128
+ // add information for newly added ports
140
129
for (String newPort : ports ) {
141
130
142
131
String [] parts = newPort .split ("_" );
@@ -161,35 +150,35 @@ public synchronized void forceRefresh() {
161
150
162
151
BoardPort boardPort = null ;
163
152
int i = 0 ;
164
- // create new board or update existing
153
+
154
+ // create new board if in ports but not in boardPorts
165
155
for (BoardPort board : boardPorts ) {
166
- if (board .toString ().equals (newPort )) {
156
+ if (board .toCompleteString ().equalsIgnoreCase (newPort )) {
167
157
boardPort = boardPorts .get (i );
158
+ boardPorts .get (i ).setOnlineStatus (true );
168
159
break ;
169
160
}
170
161
i ++;
171
162
}
172
- if ( boardPort == null ) {
173
- boardPort = new BoardPort ();
174
- boardPorts . add ( boardPort ) ;
163
+
164
+ if ( boardPort != null ) {
165
+ continue ;
175
166
}
167
+
168
+ boardPort = new BoardPort ();
169
+ boardPorts .add (boardPort );
176
170
boardPort .setAddress (port );
177
171
boardPort .setProtocol ("serial" );
178
172
boardPort .setOnlineStatus (true );
179
173
180
- String label = port ;
174
+ boardPort . setLabel ( port ) ;
181
175
182
176
if (boardData != null ) {
183
177
boardPort .getPrefs ().put ("vid" , boardData .get ("vid" ).toString ());
184
178
boardPort .getPrefs ().put ("pid" , boardData .get ("pid" ).toString ());
185
179
186
180
String iserial = boardData .get ("iserial" ).toString ();
187
- if (iserial .length () >= 10 ) {
188
- boardPort .getPrefs ().put ("iserial" , iserial );
189
- }
190
- if (uploadInProgress && oldUploadBoardPort !=null ) {
191
- oldUploadBoardPort .getPrefs ().put ("iserial" , iserial );
192
- }
181
+ boardPort .getPrefs ().put ("iserial" , iserial );
193
182
194
183
TargetBoard board = (TargetBoard ) boardData .get ("board" );
195
184
if (board != null ) {
@@ -208,8 +197,6 @@ public synchronized void forceRefresh() {
208
197
boardPort .getPrefs ().put ("iserial" , "" );
209
198
}
210
199
}
211
-
212
- boardPort .setLabel (label );
213
200
}
214
201
setSerialBoardPorts (boardPorts );
215
202
}
0 commit comments