Skip to content

Commit 2a51a76

Browse files
author
jantje
committed
#333 network port is now extracted from bonjour
Also auth is extracted but not jet used.
1 parent 97aefec commit 2a51a76

File tree

5 files changed

+110
-42
lines changed

5 files changed

+110
-42
lines changed

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

+22-6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ public class Const {
126126
public static final String ENV_KEY_UPLOAD_DISABLE_FLUSHING = ENV_KEY_BOARD_START + "UPLOAD.DISABLE_FLUSHING";
127127
public static final String ENV_KEY_WAIT_FOR_UPLOAD_PORT = ENV_KEY_BOARD_START + "UPLOAD.WAIT_FOR_UPLOAD_PORT";
128128
public static final String ENV_KEY_RESET_BEFORE_UPLOAD = ENV_KEY_BOARD_START + "UPLOAD.FORCE_RESET_BEFORE_UPLOAD";
129+
public static final String ENV_KEY_NETWORK_PORT = ENV_KEY_BOARD_START + "NETWORK.PORT";
130+
public static final String ENV_KEY_NETWORK_AUTH = ENV_KEY_BOARD_START + "NETWORK.AUTH";
129131

130132
public static final String ENV_KEY_BUILD_CORE = ENV_KEY_BOARD_START + "BUILD.CORE";
131133
public static final String ENV_KEY_BUILD_CORE_PATH = ENV_KEY_BOARD_START + "BUILD.CORE.PATH";
@@ -139,13 +141,15 @@ public class Const {
139141
public static final String ENV_KEY_JANTJE_SIZE_SWITCH = ENV_KEY_JANTJE_START + "SIZE.SWITCH";
140142
public static final String ENV_KEY_JANTJE_BOARDS_FILE = ENV_KEY_JANTJE_START + "BOARDS_FILE";
141143
public static final String ENV_KEY_JANTJE_PLATFORM_FILE = ENV_KEY_JANTJE_START + "PLATFORM_FILE";
142-
public static final String ENV_KEY_JANTJE_REFERENCED_PLATFORM_FILE = ENV_KEY_JANTJE_START + "REFERENCED_PLATFORM_FILE";
144+
public static final String ENV_KEY_JANTJE_REFERENCED_PLATFORM_FILE = ENV_KEY_JANTJE_START
145+
+ "REFERENCED_PLATFORM_FILE";
143146
public static final String ENV_KEY_JANTJE_COM_PORT = ENV_KEY_JANTJE_START + "COM_PORT";
144147
public static final String ENV_KEY_JANTJE_BOARD_NAME = ENV_KEY_JANTJE_START + "BOARD_NAME";
145148

146149
public static final String ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.COMPILE";
147150
public static final String ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.C.COMPILE";
148-
public static final String ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.CPP.COMPILE";
151+
public static final String ENV_KEY_JANTJE_ADDITIONAL_CPP_COMPILE_OPTIONS = ENV_KEY_JANTJE_START
152+
+ "EXTRA.CPP.COMPILE";
149153
public static final String ENV_KEY_JANTJE_PACKAGE_ID = ENV_KEY_JANTJE_START + "PACKAGE_ID";
150154
public static final String ENV_KEY_JANTJE_ARCITECTURE_ID = ENV_KEY_JANTJE_START + "ARCHITECTURE_ID";
151155
public static final String ENV_KEY_JANTJE_BOARD_ID = ENV_KEY_JANTJE_START + "BOARD_ID";
@@ -157,15 +161,25 @@ public class Const {
157161
// template Sketch information
158162

159163
public static final String ENV_KEY_JANTJE_SKETCH_TEMPLATE_FOLDER = ENV_KEY_JANTJE_START + "TEMPLATE_FOLDER";
160-
public static final String ENV_KEY_JANTJE_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_JANTJE_START + "TEMPLATE_USE_DEFAULT";
164+
public static final String ENV_KEY_JANTJE_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_JANTJE_START
165+
+ "TEMPLATE_USE_DEFAULT";
161166

162167
public static final String ENV_KEY_WARNING_LEVEL_OFF = " -w ";
163168
public static final String ENV_KEY_WARNING_LEVEL_ON = " -Wall ";
164169

165170
public static final String ENV_KEY_GNU_SERIAL_PORTS = "gnu.io.rxtx.SerialPorts";
166171
public static final String ENV_VALUE_GNU_SERIAL_PORTS_LINUX = "/dev/ttyACM0:/dev/ttyACM1:/dev/ttyACM2:/dev/ttyACM3:/dev/ttyUSB0::/dev/ttyUSB1::/dev/ttyUSB2::/dev/ttyUSB3::/dev/ttyUSB4";
167172
// scope stuff
168-
public static final short SCOPE_START_DATA = (short) 0xCDAB;// This is the 205 171 or -85 -51 flag that indicates scope data is following least significant first 0xCDAB;
173+
public static final short SCOPE_START_DATA = (short) 0xCDAB;// This is the
174+
// 205 171 or
175+
// -85 -51 flag
176+
// that
177+
// indicates
178+
// scope data is
179+
// following
180+
// least
181+
// significant
182+
// first 0xCDAB;
169183
public static final String EXAMPLE_FOLDER_NAME = "examples";
170184

171185
public static final String PRE_PROCESSING_BOARDS_TXT = "pre_processing_boards.txt";
@@ -205,13 +219,15 @@ public static String get_ENV_KEY_RECIPE(String action) {
205219
}
206220

207221
/**
208-
* given a action and a tool return the environment key that matches it's recipe
222+
* given a action and a tool return the environment key that matches it's
223+
* recipe
209224
*
210225
* @param action
211226
* @return he environment variable key to find the recipe
212227
*/
213228
public static String get_ENV_KEY_RECIPE(String tool, String action) {
214-
return ENV_KEY_BOARD_START + "TOOLS" + DOT + tool.toUpperCase() + DOT + action.toUpperCase() + DOT + ENV_PATTERN;
229+
return ENV_KEY_BOARD_START + "TOOLS" + DOT + tool.toUpperCase() + DOT + action.toUpperCase() + DOT
230+
+ ENV_PATTERN;
215231
}
216232

217233
public static String get_Jantje_KEY_PROTOCOL(String action) {

it.baeyens.arduino.core/src/cc/arduino/packages/discoverers/NetworkDiscovery.java

+61-26
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,22 @@ public class NetworkDiscovery
5555
private class bonour {
5656
public String address;
5757
public String name;
58-
5958
public String board;
6059
public String distroversion;
61-
6260
public String port;
61+
public boolean ssh_upload;
62+
public boolean tcp_check;
63+
public boolean auth_upload;
6364

6465
public bonour() {
6566
this.address = ""; //$NON-NLS-1$
6667
this.name = ""; //$NON-NLS-1$
6768
this.board = ""; //$NON-NLS-1$
6869
this.distroversion = ""; //$NON-NLS-1$
6970
this.port = ""; //$NON-NLS-1$
71+
this.ssh_upload = true;
72+
this.tcp_check = true;
73+
this.auth_upload = false;
7074
}
7175

7276
public String getLabel() {
@@ -97,30 +101,6 @@ public String[] getList() {
97101
return ret;
98102
}
99103

100-
// @Override
101-
// public List<BoardPort> discovery() {
102-
// List<BoardPort> ports = clonePortsList();
103-
// Iterator<BoardPort> iterator = ports.iterator();
104-
// while (iterator.hasNext()) {
105-
// try {
106-
// BoardPort board = iterator.next();
107-
// if (!NetUtils.isReachable(InetAddress.getByName(board.getAddress()),
108-
// Integer.parseInt(board.getPrefs().get("port")))) {
109-
// iterator.remove();
110-
// }
111-
// } catch (UnknownHostException e) {
112-
// iterator.remove();
113-
// }
114-
// }
115-
// return ports;
116-
// }
117-
118-
// private List<BoardPort> clonePortsList() {
119-
// synchronized (this) {
120-
// return new ArrayList<BoardPort>(this.ports);
121-
// }
122-
// }
123-
124104
public void start() {
125105
this.timer = new Timer(this.getClass().getName() + " timer"); //$NON-NLS-1$
126106
new NetworkChecker(this, NetworkTopologyDiscovery.Factory.getInstance()).start(this.timer);
@@ -166,6 +146,15 @@ public void serviceResolved(ServiceEvent serviceEvent) {
166146
newItem.board = info.getPropertyString("board"); //$NON-NLS-1$
167147
newItem.distroversion = info.getPropertyString("distro_version"); //$NON-NLS-1$
168148
newItem.name = info.getServer();
149+
String useSSH = info.getPropertyString("ssh_upload"); //$NON-NLS-1$
150+
String checkTCP = info.getPropertyString("tcp_check"); //$NON-NLS-1$
151+
String useAuth = info.getPropertyString("auth_upload"); //$NON-NLS-1$
152+
if (useSSH != null && useSSH.contentEquals("no")) //$NON-NLS-1$
153+
newItem.ssh_upload = false;
154+
if (checkTCP != null && checkTCP.contentEquals("no")) //$NON-NLS-1$
155+
newItem.tcp_check = false;
156+
if (useAuth != null && useAuth.contentEquals("yes")) //$NON-NLS-1$
157+
newItem.auth_upload = true;
169158
}
170159
while (newItem.name.endsWith(".")) { //$NON-NLS-1$
171160
newItem.name = newItem.name.substring(0, newItem.name.length() - 1);
@@ -226,4 +215,50 @@ public void inetAddressRemoved(InetAddress address) {
226215
}
227216
}
228217
}
218+
219+
private bonour getBoardByName(String name) {
220+
Iterator<bonour> iterator = this.myComPorts.iterator();
221+
while (iterator.hasNext()) {
222+
bonour board = iterator.next();
223+
if (name.equals(board.name)) {
224+
return board;
225+
}
226+
}
227+
return null;
228+
}
229+
230+
public String getAddress(String name) {
231+
bonour board = getBoardByName(name);
232+
if (board == null)
233+
return null;
234+
return board.address;
235+
}
236+
237+
public String getPort(String name) {
238+
bonour board = getBoardByName(name);
239+
if (board == null)
240+
return null;
241+
return board.port;
242+
}
243+
244+
public boolean hasAuth(String name) {
245+
bonour board = getBoardByName(name);
246+
if (board == null)
247+
return false;
248+
return board.auth_upload;
249+
}
250+
251+
public boolean isSSH(String name) {
252+
bonour board = getBoardByName(name);
253+
if (board == null)
254+
return false;
255+
return board.ssh_upload;
256+
}
257+
258+
public boolean needstcpCheck(String name) {
259+
bonour board = getBoardByName(name);
260+
if (board == null)
261+
return false;
262+
return board.tcp_check;
263+
}
229264
}

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/Helpers.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import it.baeyens.arduino.managers.ArduinoPlatform;
6767
import it.baeyens.arduino.managers.Manager;
6868
import it.baeyens.arduino.managers.ToolDependency;
69+
import it.baeyens.arduino.ui.Activator;
6970

7071
/**
7172
* ArduinoHelpers is a static class containing general purpose functions
@@ -531,7 +532,7 @@ private static void setTheEnvironmentVariablesSetTheDefaults(IContributedEnviron
531532
platformPath.removeLastSegments(numSegmentsToSubtractForHardwarePath).toString());
532533
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_PLATFORM_PATH,
533534
platformPath.removeLastSegments(1).toString());
534-
setBuildEnvironmentVariable(contribEnv, confDesc, "A.SERIAL.PORT", //$NON-NLS-1$
535+
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT,
535536
makeEnvironmentVar(Const.ENV_KEY_JANTJE_COM_PORT));
536537
if (Platform.getOS().equals(Platform.OS_WIN32)) {
537538
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MAKE_LOCATION,
@@ -1076,8 +1077,15 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
10761077
if (programmer.equalsIgnoreCase(Const.DEFAULT)) {
10771078
String uploadTool = contribEnv.getVariable(get_ENV_KEY_TOOL(ACTION_UPLOAD), confDesc).getValue();
10781079
String MComPort = contribEnv.getVariable(Const.ENV_KEY_JANTJE_COM_PORT, confDesc).getValue();
1079-
if (getHostFromComPort(MComPort) != null) {
1080+
String host = getHostFromComPort(MComPort);
1081+
if (host != null) {
10801082
String platform = contribEnv.getVariable(Const.ENV_KEY_JANTJE_ARCITECTURE_ID, confDesc).getValue();
1083+
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_NETWORK_PORT,
1084+
Activator.bonjourDiscovery.getPort(host));
1085+
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_NETWORK_AUTH,
1086+
Activator.bonjourDiscovery.hasAuth(host) ? TRUE : FALSE);
1087+
setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT, host);
1088+
10811089
try {
10821090
String key = ENV_KEY_BOARD_START + platform.toUpperCase() + DOT + NETWORK + DOT
10831091
+ ACTION_UPLOAD.toUpperCase() + DOT + ENV_TOOL;
@@ -1092,7 +1100,8 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
10921100
// simply ignore
10931101
}
10941102
}
1095-
setBuildEnvironmentVariable(contribEnv, confDesc, get_Jantje_KEY_RECIPE(ACTION_UPLOAD), makeEnvironmentVar(get_ENV_KEY_RECIPE(uploadTool, ACTION_UPLOAD)));
1103+
setBuildEnvironmentVariable(contribEnv, confDesc, get_Jantje_KEY_RECIPE(ACTION_UPLOAD),
1104+
makeEnvironmentVar(get_ENV_KEY_RECIPE(uploadTool, ACTION_UPLOAD)));
10961105
setBuildEnvironmentVariable(contribEnv, confDesc, get_ENV_KEY_TOOL(ACTION_PROGRAM),
10971106
makeEnvironmentVar(get_ENV_KEY_TOOL(ACTION_UPLOAD)));
10981107
} else {
@@ -1335,7 +1344,8 @@ private static String makeEnvironmentVar(String variableName) {
13351344

13361345
/**
13371346
* Give the string entered in the com port try to extract a host. If no host
1338-
* is found return null yun at xxx.yyy.zzz (arduino yun) returns yun.local
1347+
* is found return null yun.local at xxx.yyy.zzz (arduino yun) returns
1348+
* yun.local
13391349
*
13401350
* @param mComPort
13411351
* @return

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/uploaders/UploadSketchWrapper.java

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void internalUpload(IProject Project, String cConf) {
6464
Const.EMPTY_STRING);
6565
String uploadClass = Common.getBuildEnvironmentVariable(Project, cConf,
6666
Const.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), Const.EMPTY_STRING);
67+
6768
this.myConsole = Helpers.findConsole(Messages.Upload_console);
6869
this.myConsole.clearConsole();
6970
this.myConsole.activate();

it.baeyens.arduino.core/src/it/baeyens/arduino/tools/uploaders/arduinoUploader.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class arduinoUploader implements IRealUpload {
3232
}
3333

3434
@Override
35-
public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer, IProgressMonitor monitor) {
35+
public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean usingProgrammer,
36+
IProgressMonitor monitor) {
3637
String MComPort = Const.EMPTY_STRING;
3738
String boardName = Const.EMPTY_STRING;
3839

@@ -46,19 +47,24 @@ public boolean uploadUsingPreferences(IFile hexFile, IProject project, boolean u
4647
} catch (Exception e) {// ignore all errors
4748
}
4849
try {
49-
boardName = envManager.getVariable(Const.ENV_KEY_JANTJE_BOARD_NAME, configurationDescription, true).getValue();
50+
boardName = envManager.getVariable(Const.ENV_KEY_JANTJE_BOARD_NAME, configurationDescription, true)
51+
.getValue();
5052
} catch (Exception e) {// ignore all errors
5153
}
52-
String NewSerialPort = ArduinoSerial.makeArduinoUploadready(this.myConsole.newMessageStream(), this.myProject, this.mycConf, MComPort);
54+
String NewSerialPort = ArduinoSerial.makeArduinoUploadready(this.myConsole.newMessageStream(), this.myProject,
55+
this.mycConf, MComPort);
5356

54-
IEnvironmentVariable var = new EnvironmentVariable(Const.ENV_KEY_SERIAL_PORT, NewSerialPort);
57+
IEnvironmentVariable var = new EnvironmentVariable(Const.ENV_KEY_JANTJE_COM_PORT, NewSerialPort);
5558
contribEnv.addVariable(var, configurationDescription);
56-
var = new EnvironmentVariable(Const.ENV_KEY_SERIAL_PORT_FILE, NewSerialPort.replace("/dev/", Const.EMPTY_STRING)); //$NON-NLS-1$
59+
var = new EnvironmentVariable(Const.ENV_KEY_SERIAL_PORT_FILE,
60+
NewSerialPort.replace("/dev/", Const.EMPTY_STRING)); //$NON-NLS-1$
5761
contribEnv.addVariable(var, configurationDescription);
5862

5963
String command = Const.EMPTY_STRING;
6064
try {
61-
command = envManager.getVariable(Const.get_Jantje_KEY_RECIPE(Const.ACTION_UPLOAD), configurationDescription, true).getValue();
65+
command = envManager
66+
.getVariable(Const.get_Jantje_KEY_RECIPE(Const.ACTION_UPLOAD), configurationDescription, true)
67+
.getValue();
6268
} catch (Exception e) {// ignore all errors
6369
}
6470

0 commit comments

Comments
 (0)