@@ -46,7 +46,6 @@ public class SerialDiscovery implements Discovery, Runnable {
4646 private final List <String > oldPorts = new ArrayList <>();
4747 public boolean uploadInProgress = false ;
4848 public boolean pausePolling = false ;
49- private BoardPort oldUploadBoardPort = null ;
5049 private final BoardCloudResolver boardCloudResolver = new BoardCloudResolver ();
5150
5251
@@ -56,7 +55,7 @@ public List<BoardPort> listDiscoveredBoards() {
5655 }
5756
5857 @ Override
59- public List <BoardPort > listDiscoveredBoards (boolean complete ) {
58+ public synchronized List <BoardPort > listDiscoveredBoards (boolean complete ) {
6059 if (complete ) {
6160 return new ArrayList <>(serialBoardPorts );
6261 }
@@ -69,7 +68,7 @@ public List<BoardPort> listDiscoveredBoards(boolean complete) {
6968 return onlineBoardPorts ;
7069 }
7170
72- public void setSerialBoardPorts (List <BoardPort > newSerialBoardPorts ) {
71+ public synchronized void setSerialBoardPorts (List <BoardPort > newSerialBoardPorts ) {
7372 serialBoardPorts .clear ();
7473 serialBoardPorts .addAll (newSerialBoardPorts );
7574 }
@@ -116,27 +115,17 @@ public synchronized void forceRefresh() {
116115 return ;
117116 }
118117
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-
124118 oldPorts .clear ();
125119 oldPorts .addAll (ports );
126120
121+ // set unreachable ports offline
127122 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 ())) {
136124 board .setOnlineStatus (false );
137125 }
138126 }
139127
128+ // add information for newly added ports
140129 for (String newPort : ports ) {
141130
142131 String [] parts = newPort .split ("_" );
@@ -161,35 +150,35 @@ public synchronized void forceRefresh() {
161150
162151 BoardPort boardPort = null ;
163152 int i = 0 ;
164- // create new board or update existing
153+
154+ // create new board if in ports but not in boardPorts
165155 for (BoardPort board : boardPorts ) {
166- if (board .toString ().equals (newPort )) {
156+ if (board .toCompleteString ().equalsIgnoreCase (newPort )) {
167157 boardPort = boardPorts .get (i );
158+ boardPorts .get (i ).setOnlineStatus (true );
168159 break ;
169160 }
170161 i ++;
171162 }
172- if ( boardPort == null ) {
173- boardPort = new BoardPort ();
174- boardPorts . add ( boardPort ) ;
163+
164+ if ( boardPort != null ) {
165+ continue ;
175166 }
167+
168+ boardPort = new BoardPort ();
169+ boardPorts .add (boardPort );
176170 boardPort .setAddress (port );
177171 boardPort .setProtocol ("serial" );
178172 boardPort .setOnlineStatus (true );
179173
180- String label = port ;
174+ boardPort . setLabel ( port ) ;
181175
182176 if (boardData != null ) {
183177 boardPort .getPrefs ().put ("vid" , boardData .get ("vid" ).toString ());
184178 boardPort .getPrefs ().put ("pid" , boardData .get ("pid" ).toString ());
185179
186180 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 );
193182
194183 TargetBoard board = (TargetBoard ) boardData .get ("board" );
195184 if (board != null ) {
@@ -208,8 +197,6 @@ public synchronized void forceRefresh() {
208197 boardPort .getPrefs ().put ("iserial" , "" );
209198 }
210199 }
211-
212- boardPort .setLabel (label );
213200 }
214201 setSerialBoardPorts (boardPorts );
215202 }
0 commit comments