1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-17 11:54:33 +01:00

Add PluggableDiscoveryMessage for BoardPort change metadata

This commit is contained in:
PaulStoffregen 2018-10-01 13:33:19 -07:00 committed by Cristian Maglie
parent b6066573b9
commit e029acc699
2 changed files with 48 additions and 8 deletions

View File

@ -72,17 +72,17 @@ public class PluggableDiscovery implements Discovery {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
while (program != null && program.isAlive()) {
BoardPort port = mapper.readValue(parser, BoardPort.class);
if (port != null) {
PluggableDiscoveryMessage msg = mapper.readValue(parser, PluggableDiscoveryMessage.class);
if (msg != null) {
System.out.println(discoveryName + ": received json");
String address = port.getAddress();
if (address != null) {
if (address.equals("Error: START_SYNC not supported")) {
String event = msg.getEventType();
if (event != null) {
if (event.equals("Error: START_SYNC not supported")) {
if (pollingThread == null) {
startPolling();
}
} else {
update(port);
update(msg);
}
}
}
@ -158,7 +158,7 @@ public class PluggableDiscovery implements Discovery {
}
}
private synchronized void update(BoardPort port) {
private synchronized void update(PluggableDiscoveryMessage port) {
// Update the list of discovered ports, which may involve
// adding a new port, replacing the info for a previously
// discovered port, or removing a port. This function
@ -166,13 +166,14 @@ public class PluggableDiscovery implements Discovery {
// avoid changing the list while it's being accessed by
// another thread.
String address = port.getAddress();
if (address == null) return; // address required for "add" & "remove"
for (BoardPort bp : portList) {
if (address.equals(bp.getAddress())) {
// if address already on the list, discard old info
portList.remove(bp);
}
}
if (port.isOnline()) {
if (port.getEventType().equals("add")) {
if (port.getLabel() == null) {
// if no label, use address
port.setLabel(address);

View File

@ -0,0 +1,39 @@
/*
* This file is part of Arduino.
*
* Arduino is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2018 Arduino SA (http://www.arduino.cc/)
*/
package cc.arduino.packages.discoverers;
import cc.arduino.packages.BoardPort;
public class PluggableDiscoveryMessage extends BoardPort {
private String eventType; // "add", "remove", "Error: START_SYNC not supported"
public String getEventType() {
return eventType;
}
}