mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
showing discovered boards
This commit is contained in:
parent
32bb7f69de
commit
ad866ca5ed
@ -28,6 +28,7 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import javax.jmdns.ServiceEvent;
|
||||
import javax.swing.*;
|
||||
|
||||
import processing.app.debug.TargetBoard;
|
||||
@ -42,6 +43,8 @@ import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import processing.app.packages.Library;
|
||||
import processing.app.packages.LibraryList;
|
||||
import processing.app.tools.ZipDeflater;
|
||||
import processing.app.zeroconf.BoardListener;
|
||||
import processing.app.zeroconf.Discovery;
|
||||
import processing.core.*;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -113,6 +116,7 @@ public class Base {
|
||||
// int editorCount;
|
||||
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||
Editor activeEditor;
|
||||
final Map<String, Map<String, Object>> boardsViaNetwork;
|
||||
|
||||
static File portableFolder = null;
|
||||
static final String portableSketchbookFolder = "sketchbook";
|
||||
@ -253,6 +257,8 @@ public class Base {
|
||||
public Base(String[] args) throws Exception {
|
||||
platform.init(this);
|
||||
|
||||
this.boardsViaNetwork = new HashMap<String, Map<String, Object>>();
|
||||
|
||||
// Get the sketchbook path, and make sure it's set properly
|
||||
String sketchbookPath = Preferences.get("sketchbook.path");
|
||||
|
||||
@ -400,6 +406,21 @@ public class Base {
|
||||
if (Preferences.getBoolean("update.check")) {
|
||||
new UpdateCheck(this);
|
||||
}
|
||||
|
||||
new Discovery(new BoardListener() {
|
||||
@Override
|
||||
public void boardOffline(ServiceEvent serviceEvent) {
|
||||
Base.this.boardsViaNetwork.remove(serviceEvent.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void boardOnline(ServiceEvent serviceEvent) {
|
||||
Map<String, Object> board = new HashMap<String, Object>();
|
||||
board.put("addresses", serviceEvent.getInfo().getInet4Addresses());
|
||||
board.put("type", serviceEvent.getType());
|
||||
Base.this.boardsViaNetwork.put(serviceEvent.getName(), board);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -975,14 +975,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
|
||||
protected void populateSerialMenu() {
|
||||
// getting list of ports
|
||||
|
||||
JMenuItem rbMenuItem;
|
||||
|
||||
//System.out.println("Clearing serial port menu.");
|
||||
|
||||
serialMenu.removeAll();
|
||||
boolean empty = true;
|
||||
|
||||
try
|
||||
{
|
||||
@ -991,8 +984,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
{
|
||||
CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
|
||||
//System.out.println("Found communication port: " + commportidentifier);
|
||||
if (commportidentifier.getPortType() == CommPortIdentifier.PORT_SERIAL)
|
||||
{
|
||||
if (commportidentifier.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
||||
//System.out.println("Adding port to serial port menu: " + commportidentifier);
|
||||
String curr_port = commportidentifier.getName();
|
||||
|
||||
@ -1001,32 +993,26 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
if (additionalDescription != null) {
|
||||
description += " (" + additionalDescription + ")";
|
||||
}
|
||||
rbMenuItem = new JCheckBoxMenuItem(description, curr_port.equals(Preferences.get("serial.port")));
|
||||
JCheckBoxMenuItem rbMenuItem = new JCheckBoxMenuItem(description, curr_port.equals(Preferences.get("serial.port")));
|
||||
rbMenuItem.addActionListener(new SerialMenuListener(curr_port));
|
||||
//serialGroup.add(rbMenuItem);
|
||||
serialMenu.add(rbMenuItem);
|
||||
empty = false;
|
||||
}
|
||||
}
|
||||
if (!empty) {
|
||||
//System.out.println("enabling the serialMenu");
|
||||
serialMenu.setEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception exception)
|
||||
{
|
||||
} catch (Exception exception) {
|
||||
System.out.println(_("error retrieving port list"));
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
if (serialMenu.getItemCount() == 0) {
|
||||
serialMenu.setEnabled(false);
|
||||
for (Map.Entry<String, Map<String, Object>> entry : base.boardsViaNetwork.entrySet()) {
|
||||
Inet4Address[] a = (Inet4Address[]) entry.getValue().get("addresses");
|
||||
String label = entry.getKey() + "@" + a[0].toString();
|
||||
JCheckBoxMenuItem rbMenuItem = new JCheckBoxMenuItem(label, label.equals(Preferences.get("serial.port")));
|
||||
rbMenuItem.addActionListener(new SerialMenuListener(label));
|
||||
serialMenu.add(rbMenuItem);
|
||||
}
|
||||
|
||||
//serialMenu.addSeparator();
|
||||
//serialMenu.add(item);
|
||||
serialMenu.setEnabled(serialMenu.getMenuComponentCount() > 0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,12 @@
|
||||
package processing.app.zeroconf;
|
||||
|
||||
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
|
||||
|
||||
import javax.jmdns.JmDNS;
|
||||
import javax.jmdns.NetworkTopologyDiscovery;
|
||||
import javax.jmdns.ServiceEvent;
|
||||
import javax.jmdns.ServiceListener;
|
||||
import javax.jmdns.impl.DNSTaskStarter;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
@ -11,6 +14,10 @@ public class Discovery implements ServiceListener {
|
||||
|
||||
private final BoardListener listener;
|
||||
|
||||
static {
|
||||
DNSTaskStarter.Factory.setClassDelegate(new ArduinoDNSTaskStarter());
|
||||
}
|
||||
|
||||
public Discovery(BoardListener listener) throws IOException {
|
||||
this.listener = listener;
|
||||
for (InetAddress addr : NetworkTopologyDiscovery.Factory.getInstance().getInetAddresses()) {
|
||||
@ -21,7 +28,7 @@ public class Discovery implements ServiceListener {
|
||||
|
||||
@Override
|
||||
public void serviceAdded(ServiceEvent serviceEvent) {
|
||||
serviceEvent.getDNS().requestServiceInfo(serviceEvent.getInfo().getServer(), serviceEvent.getName(), true);
|
||||
serviceEvent.getDNS().requestServiceInfo(serviceEvent.getInfo().getServer(), serviceEvent.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,4 +40,5 @@ public class Discovery implements ServiceListener {
|
||||
public void serviceResolved(ServiceEvent serviceEvent) {
|
||||
listener.boardOnline(serviceEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
package processing.app.zeroconf.jmdns;
|
||||
|
||||
import javax.jmdns.impl.DNSIncoming;
|
||||
import javax.jmdns.impl.DNSTaskStarter;
|
||||
import javax.jmdns.impl.JmDNSImpl;
|
||||
import javax.jmdns.impl.ServiceInfoImpl;
|
||||
import javax.jmdns.impl.tasks.RecordReaper;
|
||||
import java.util.Timer;
|
||||
|
||||
public class ArduinoDNSTaskStarter implements DNSTaskStarter.Factory.ClassDelegate {
|
||||
|
||||
@Override
|
||||
public DNSTaskStarter newDNSTaskStarter(final JmDNSImpl jmDNSImpl) {
|
||||
final DNSTaskStarter.DNSTaskStarterImpl delegate = new DNSTaskStarter.DNSTaskStarterImpl(jmDNSImpl);
|
||||
final DNSTaskStarter.DNSTaskStarterImpl.StarterTimer timer = new DNSTaskStarter.DNSTaskStarterImpl.StarterTimer("JmDNS(" + jmDNSImpl.getName() + ").Timer", true);
|
||||
|
||||
return new DNSTaskStarter() {
|
||||
|
||||
public void purgeTimer() {
|
||||
delegate.purgeTimer();
|
||||
}
|
||||
|
||||
public void purgeStateTimer() {
|
||||
delegate.purgeStateTimer();
|
||||
}
|
||||
|
||||
public void cancelTimer() {
|
||||
delegate.cancelTimer();
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
public void cancelStateTimer() {
|
||||
delegate.cancelStateTimer();
|
||||
}
|
||||
|
||||
public void startProber() {
|
||||
delegate.startProber();
|
||||
}
|
||||
|
||||
public void startAnnouncer() {
|
||||
delegate.startAnnouncer();
|
||||
}
|
||||
|
||||
public void startRenewer() {
|
||||
delegate.startRenewer();
|
||||
}
|
||||
|
||||
public void startCanceler() {
|
||||
delegate.startCanceler();
|
||||
}
|
||||
|
||||
public void startReaper() {
|
||||
new RecordReaper(jmDNSImpl) {
|
||||
@Override
|
||||
public void start(Timer timer) {
|
||||
if (!this.getDns().isCanceling() && !this.getDns().isCanceled()) {
|
||||
timer.schedule(this, 0, 500);
|
||||
}
|
||||
}
|
||||
}.start(timer);
|
||||
}
|
||||
|
||||
public void startServiceInfoResolver(ServiceInfoImpl info) {
|
||||
delegate.startServiceInfoResolver(info);
|
||||
}
|
||||
|
||||
public void startTypeResolver() {
|
||||
delegate.startTypeResolver();
|
||||
}
|
||||
|
||||
public void startServiceResolver(String type) {
|
||||
delegate.startServiceResolver(type);
|
||||
}
|
||||
|
||||
public void startResponder(DNSIncoming in, int port) {
|
||||
delegate.startResponder(in, port);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user