Skip to content

Commit e029acc

Browse files
PaulStoffregencmaglie
authored andcommitted
Add PluggableDiscoveryMessage for BoardPort change metadata
1 parent b606657 commit e029acc

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ public void run() {
7272
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
7373

7474
while (program != null && program.isAlive()) {
75-
BoardPort port = mapper.readValue(parser, BoardPort.class);
76-
if (port != null) {
75+
PluggableDiscoveryMessage msg = mapper.readValue(parser, PluggableDiscoveryMessage.class);
76+
if (msg != null) {
7777
System.out.println(discoveryName + ": received json");
78-
String address = port.getAddress();
79-
if (address != null) {
80-
if (address.equals("Error: START_SYNC not supported")) {
78+
String event = msg.getEventType();
79+
if (event != null) {
80+
if (event.equals("Error: START_SYNC not supported")) {
8181
if (pollingThread == null) {
8282
startPolling();
8383
}
8484
} else {
85-
update(port);
85+
update(msg);
8686
}
8787
}
8888
}
@@ -158,21 +158,22 @@ private void write(String command) {
158158
}
159159
}
160160

161-
private synchronized void update(BoardPort port) {
161+
private synchronized void update(PluggableDiscoveryMessage port) {
162162
// Update the list of discovered ports, which may involve
163163
// adding a new port, replacing the info for a previously
164164
// discovered port, or removing a port. This function
165165
// must be synchronized with listDiscoveredBoards(), to
166166
// avoid changing the list while it's being accessed by
167167
// another thread.
168168
String address = port.getAddress();
169+
if (address == null) return; // address required for "add" & "remove"
169170
for (BoardPort bp : portList) {
170171
if (address.equals(bp.getAddress())) {
171172
// if address already on the list, discard old info
172173
portList.remove(bp);
173174
}
174175
}
175-
if (port.isOnline()) {
176+
if (port.getEventType().equals("add")) {
176177
if (port.getLabel() == null) {
177178
// if no label, use address
178179
port.setLabel(address);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of Arduino.
3+
*
4+
* Arduino is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2018 Arduino SA (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.packages.discoverers;
31+
import cc.arduino.packages.BoardPort;
32+
33+
public class PluggableDiscoveryMessage extends BoardPort {
34+
private String eventType; // "add", "remove", "Error: START_SYNC not supported"
35+
public String getEventType() {
36+
return eventType;
37+
}
38+
}
39+

0 commit comments

Comments
 (0)