Skip to content

Commit 572dfe9

Browse files
committed
Support for yun upload via network
1 parent 52ec840 commit 572dfe9

28 files changed

+1581
-353
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/ArduinoConst.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class ArduinoConst {
6363
// tags to interpret the arduino input files
6464
public static final String BoardNameKeyTAG = "name";
6565
public static final String UploadToolTeensy = "teensy_reboot";
66+
public static final String Upload_ssh = "ssh upload";
6667

6768
public static final String ENV_KEY_ARDUINO_START = "A.";
6869
public static final String ENV_KEY_ARDUINO_PATH = ENV_KEY_ARDUINO_START + "RUNTIME.IDE.PATH";
@@ -112,8 +113,8 @@ public class ArduinoConst {
112113
// template Sketch information
113114

114115
public static final String ENV_KEY_SKETCH_TEMPLATE_FOLDER = ENV_KEY_JANTJE_START + "TEMPLATE_FOLDER";
115-
public static final String ENV_KEY_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_JANTJE_START + "TEMPLATE_USE_DEFAULT";
116-
116+
public static final String ENV_KEY_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_JANTJE_START + "TEMPLATE_USE_DEFAULT";
117+
117118
public static final String JANTJE_SIZE_COMMAND = "\"${A.COMPILER.PATH}${A.COMPILER.SIZE.CMD}\" --format=avr --mcu=${A.BUILD.MCU} \"${A.BUILD.PATH}/${A.BUILD.PROJECT_NAME}.elf\"";
118119

119120
public static final String ENV_KEY_WARNING_LEVEL_OFF = "";

it.baeyens.arduino.core/.classpath

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
4-
<classpathentry kind="src" path="src"/>
4+
<classpathentry excluding="it/baeyens/arduino/tools/uploaders/arduinoIDEstyle/" kind="src" path="src"/>
55
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6+
<classpathentry exported="true" kind="lib" path="lib/jsch-0.1.50.jar"/>
7+
<classpathentry exported="true" kind="lib" path="lib/jmdns-3.4.1.jar"/>
68
<classpathentry kind="output" path="bin"/>
79
</classpath>

it.baeyens.arduino.core/META-INF/MANIFEST.MF

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.core.runtime,
1010
org.eclipse.cdt.managedbuilder.core,
1111
org.eclipse.core.filesystem,
1212
org.eclipse.ui.ide,
13-
org.eclipse.cdt.core
13+
org.eclipse.cdt.core,
14+
org.eclipse.equinox.security;bundle-version="1.1.100"
1415
Bundle-Vendor: Jan Baeyens
1516
Bundle-ActivationPolicy: lazy
1617
Export-Package: it.baeyens.arduino.tools,
@@ -26,6 +27,14 @@ Import-Package: it.baeyens.arduino.arduino,
2627
org.eclipse.cdt.core.settings.model.util,
2728
org.eclipse.cdt.ui.newui,
2829
org.eclipse.cdt.utils,
30+
org.eclipse.ecf.core;version="3.0.0",
31+
org.eclipse.ecf.core.security,
32+
org.eclipse.ecf.filetransfer,
33+
org.eclipse.ecf.filetransfer.events,
34+
org.eclipse.ecf.filetransfer.identity,
2935
org.eclipse.ui.console,
3036
org.eclipse.ui.dialogs
3137
Bundle-Activator: it.baeyens.arduino.ui.activator
38+
Bundle-ClassPath: .,
39+
lib/jsch-0.1.50.jar,
40+
lib/jmdns-3.4.1.jar

it.baeyens.arduino.core/build.properties

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@ bin.includes = .,\
77
src/it/baeyens/arduino/ui/templates/sketch.cpp,\
88
src/it/baeyens/arduino/ui/templates/sketch.h,\
99
META-INF/,\
10-
OSGI-INF/l10n/bundle.properties
11-
src.includes = icons/
10+
OSGI-INF/l10n/,\
11+
OSGI-INF/,\
12+
OSGI-INF/l10n/bundle.properties,\
13+
bin/,\
14+
lib/jsch-0.1.50.jar,\
15+
lib/jmdns-3.4.1.jar
16+
src.includes = icons/,\
17+
bin/
18+
jars.compile.order = .,\
19+
library.jar
20+
jars.extra.classpath = lib/jsch-0.1.50.jar,\
21+
lib/jmdns-3.4.1.jar
200 KB
Binary file not shown.
243 KB
Binary file not shown.
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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 2013 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.packages.discoverers;
31+
32+
//import cc.arduino.packages.BoardPort;
33+
//import cc.arduino.packages.Discovery;
34+
import java.io.IOException;
35+
import java.net.InetAddress;
36+
import java.util.HashSet;
37+
import java.util.Hashtable;
38+
import java.util.Iterator;
39+
import java.util.Map;
40+
import java.util.Timer;
41+
42+
import javax.jmdns.JmDNS;
43+
import javax.jmdns.NetworkTopologyDiscovery;
44+
import javax.jmdns.ServiceEvent;
45+
import javax.jmdns.ServiceInfo;
46+
import javax.jmdns.ServiceListener;
47+
import javax.jmdns.impl.DNSTaskStarter;
48+
49+
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
50+
import cc.arduino.packages.discoverers.network.NetworkChecker;
51+
//import processing.app.Base;
52+
//import processing.app.helpers.NetUtils;
53+
//import processing.app.helpers.PreferencesMap;
54+
//import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
55+
56+
public class NetworkDiscovery implements ServiceListener, cc.arduino.packages.discoverers.network.NetworkTopologyListener {
57+
58+
private class bonour {
59+
public String address;
60+
public String name;
61+
62+
public String board;
63+
public String distroversion;
64+
65+
public String port;
66+
67+
public bonour() {
68+
address = "";
69+
name = "";
70+
board = "";
71+
distroversion = "";
72+
port = "";
73+
}
74+
75+
public String getLabel() {
76+
return name + " at " + address + " (" + board + ")" + distroversion + " " + port;
77+
}
78+
79+
}
80+
81+
private Timer timer;
82+
private final HashSet<bonour> myComPorts; // well not really com ports but we treat them like com ports
83+
private final Map<InetAddress, JmDNS> mappedJmDNSs;
84+
85+
public NetworkDiscovery() {
86+
DNSTaskStarter.Factory.setClassDelegate(new ArduinoDNSTaskStarter());
87+
this.myComPorts = new HashSet<bonour>();
88+
this.mappedJmDNSs = new Hashtable<InetAddress, JmDNS>();
89+
}
90+
91+
public String[] getList() {
92+
String[] ret = new String[myComPorts.size()];
93+
int curPort = 0;
94+
Iterator<bonour> iterator = myComPorts.iterator();
95+
while (iterator.hasNext()) {
96+
bonour board = iterator.next();
97+
ret[curPort++] = board.getLabel();
98+
}
99+
return ret;
100+
}
101+
102+
// @Override
103+
// public List<BoardPort> discovery() {
104+
// List<BoardPort> ports = clonePortsList();
105+
// Iterator<BoardPort> iterator = ports.iterator();
106+
// while (iterator.hasNext()) {
107+
// try {
108+
// BoardPort board = iterator.next();
109+
// if (!NetUtils.isReachable(InetAddress.getByName(board.getAddress()), Integer.parseInt(board.getPrefs().get("port")))) {
110+
// iterator.remove();
111+
// }
112+
// } catch (UnknownHostException e) {
113+
// iterator.remove();
114+
// }
115+
// }
116+
// return ports;
117+
// }
118+
119+
// private List<BoardPort> clonePortsList() {
120+
// synchronized (this) {
121+
// return new ArrayList<BoardPort>(this.ports);
122+
// }
123+
// }
124+
125+
public void start() {
126+
this.timer = new Timer(this.getClass().getName() + " timer");
127+
new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance()).start(timer);
128+
}
129+
130+
public void stop() {
131+
timer.purge();
132+
// we don't close each JmDNS instance as it's too slow
133+
}
134+
135+
@Override
136+
public void serviceAdded(ServiceEvent serviceEvent) {
137+
String type = serviceEvent.getType();
138+
String name = serviceEvent.getName();
139+
140+
JmDNS dns = serviceEvent.getDNS();
141+
142+
dns.requestServiceInfo(type, name);
143+
ServiceInfo serviceInfo = dns.getServiceInfo(type, name);
144+
if (serviceInfo != null) {
145+
dns.requestServiceInfo(type, name);
146+
}
147+
148+
}
149+
150+
@Override
151+
public void serviceRemoved(ServiceEvent serviceEvent) {
152+
String name = serviceEvent.getName();
153+
synchronized (this) {
154+
removeBoardswithSameName(name);
155+
}
156+
}
157+
158+
@Override
159+
public void serviceResolved(ServiceEvent serviceEvent) {
160+
ServiceInfo info = serviceEvent.getInfo();
161+
for (InetAddress inetAddress : info.getInet4Addresses()) {
162+
bonour newItem = new bonour();
163+
newItem.address = inetAddress.getHostAddress();
164+
newItem.name = serviceEvent.getName();
165+
if (info.hasData()) {
166+
newItem.board = info.getPropertyString("board");
167+
newItem.distroversion = info.getPropertyString("distro_version");
168+
}
169+
newItem.port = Integer.toString(info.getPort());
170+
171+
synchronized (this) {
172+
removeBoardswithSameAdress(newItem);
173+
myComPorts.add(newItem);
174+
}
175+
}
176+
}
177+
178+
private void removeBoardswithSameAdress(bonour newBoard) {
179+
Iterator<bonour> iterator = myComPorts.iterator();
180+
while (iterator.hasNext()) {
181+
bonour board = iterator.next();
182+
if (newBoard.address.equals(board.address)) {
183+
iterator.remove();
184+
}
185+
}
186+
}
187+
188+
private void removeBoardswithSameName(String name) {
189+
Iterator<bonour> iterator = myComPorts.iterator();
190+
while (iterator.hasNext()) {
191+
bonour board = iterator.next();
192+
if (name.equals(board.name)) {
193+
iterator.remove();
194+
}
195+
}
196+
}
197+
198+
@Override
199+
public void inetAddressAdded(InetAddress address) {
200+
if (mappedJmDNSs.containsKey(address)) {
201+
return;
202+
}
203+
try {
204+
JmDNS jmDNS = JmDNS.create(address);
205+
jmDNS.addServiceListener("_arduino._tcp.local.", this);
206+
mappedJmDNSs.put(address, jmDNS);
207+
} catch (Exception e) {
208+
e.printStackTrace();
209+
}
210+
}
211+
212+
@Override
213+
public void inetAddressRemoved(InetAddress address) {
214+
JmDNS jmDNS = mappedJmDNSs.remove(address);
215+
if (jmDNS != null) {
216+
try {
217+
jmDNS.close();
218+
} catch (IOException e) {
219+
e.printStackTrace();
220+
}
221+
}
222+
}
223+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 2013 Arduino LLC (http://www.arduino.cc/)
28+
*/
29+
30+
package cc.arduino.packages.discoverers.network;
31+
32+
import javax.jmdns.NetworkTopologyDiscovery;
33+
import java.net.InetAddress;
34+
import java.util.*;
35+
36+
public class NetworkChecker extends TimerTask {
37+
38+
private final NetworkTopologyListener topologyListener;
39+
private final NetworkTopologyDiscovery topology;
40+
41+
private Set<InetAddress> knownAddresses;
42+
43+
public NetworkChecker(NetworkTopologyListener topologyListener, NetworkTopologyDiscovery topology) {
44+
super();
45+
this.topologyListener = topologyListener;
46+
this.topology = topology;
47+
this.knownAddresses = Collections.synchronizedSet(new HashSet<InetAddress>());
48+
}
49+
50+
public void start(Timer timer) {
51+
timer.schedule(this, 0, 3000);
52+
}
53+
54+
@Override
55+
public void run() {
56+
try {
57+
InetAddress[] curentAddresses = topology.getInetAddresses();
58+
Set<InetAddress> current = new HashSet<InetAddress>(curentAddresses.length);
59+
for (InetAddress address : curentAddresses) {
60+
current.add(address);
61+
if (!knownAddresses.contains(address)) {
62+
topologyListener.inetAddressAdded(address);
63+
}
64+
}
65+
for (InetAddress address : knownAddresses) {
66+
if (!current.contains(address)) {
67+
topologyListener.inetAddressRemoved(address);
68+
}
69+
}
70+
knownAddresses = current;
71+
} catch (Exception e) {
72+
e.printStackTrace();
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)