Skip to content

Commit 1c964dd

Browse files
author
jantje
committed
Make yunshield work
It seemed the passworddialog was no longer on a UI thread making it fail with a null pointer. For the yun shield there is a tools.[tool]_network.upload.pattern command for the upload For the yun shield the -v is not optional
1 parent 1f16215 commit 1c964dd

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

it.baeyens.arduino.core/config/pre_processing_platform_default.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ tools.esp8266OTA={tools.esptool.network_cmd}
1313
tools.esp8266OTA.upload.pattern={tools.esptool.upload.network_pattern}
1414
esp8266.network.upload.tool=esp8266OTA
1515
TOOLS.ESPTOOL.NETWORK.PASSWORD={NETWORK.AUTH}
16+
17+
#for yun shield to work
18+
TOOLS.AVRDUDE_REMOTE.UPLOAD.VERBOSE=-v

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
77
import org.eclipse.equinox.security.storage.StorageException;
88
import org.eclipse.jface.window.Window;
9+
import org.eclipse.swt.widgets.Display;
910
import org.eclipse.ui.PlatformUI;
1011

1112
import it.baeyens.arduino.common.Common;
@@ -16,6 +17,7 @@ public class PasswordManager {
1617
private String myPassword;
1718
private String myLogin = null;
1819
private String myhost = null;
20+
boolean ret = false;
1921

2022
public PasswordManager() {
2123
// no constructor needed
@@ -34,6 +36,28 @@ public String getHost() {
3436
}
3537

3638
public boolean setHost(String host, boolean askPwdIfNotFound) {
39+
if (!askPwdIfNotFound) { // if we do not ask the pwd if it is not found
40+
// we do not need to be on a gui thread
41+
return internalSetHost(host, askPwdIfNotFound);
42+
}
43+
44+
Runnable myRunnable = new Runnable() {
45+
46+
@Override
47+
public void run() {
48+
try {
49+
PasswordManager.this.ret = internalSetHost(host, askPwdIfNotFound);
50+
} catch (Exception e) {// ignore as we get errors when closing
51+
// down
52+
}
53+
}
54+
55+
};
56+
Display.getDefault().syncExec(myRunnable);
57+
return this.ret;
58+
}
59+
60+
protected boolean internalSetHost(String host, boolean askPwdIfNotFound) {
3761
this.myhost = host;
3862
this.myPassword = null;
3963
this.myLogin = null;

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.io.PrintStream;
66

77
import org.eclipse.core.resources.IFile;
8+
import org.eclipse.core.resources.IProject;
89
import org.eclipse.core.runtime.IProgressMonitor;
910
import org.eclipse.core.runtime.IStatus;
1011
import org.eclipse.core.runtime.Status;
@@ -28,15 +29,19 @@ public class SSHUpload implements IRealUpload {
2829
private MessageConsoleStream myHighLevelConsoleStream;
2930
private MessageConsoleStream myOutconsole;
3031
private MessageConsoleStream myErrconsole;
32+
private String myUpLoadTool;
33+
private IProject myProject;
3134

32-
SSHUpload(MessageConsoleStream HighLevelConsoleStream, MessageConsoleStream Outconsole,
33-
MessageConsoleStream Errconsole, String host) {
35+
SSHUpload(IProject project, String upLoadTool, MessageConsoleStream HighLevelConsoleStream,
36+
MessageConsoleStream Outconsole, MessageConsoleStream Errconsole, String host) {
3437

3538
this.myHost = host;
3639

3740
this.myHighLevelConsoleStream = HighLevelConsoleStream;
3841
this.myErrconsole = Errconsole;
3942
this.myOutconsole = Outconsole;
43+
this.myUpLoadTool = upLoadTool;
44+
this.myProject = project;
4045
}
4146

4247
@Override
@@ -71,11 +76,9 @@ public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IP
7176
// String additionalParams = verbose ?
7277
// prefs.get("upload.params.verbose") :
7378
// prefs.get("upload.params.quiet");
74-
String additionalParams = Const.EMPTY_STRING;// Common.getBuildEnvironmentVariable(myProject,
75-
// myCConf,
76-
// ArduinoConst.
77-
// upload.params.quiet,
78-
// "");
79+
String remoteUploadCommand = Common.getBuildEnvironmentVariable(this.myProject,
80+
"A.TOOLS." + this.myUpLoadTool.toUpperCase() + "_REMOTE.UPLOAD.PATTERN", //$NON-NLS-1$ //$NON-NLS-2$
81+
"run-avrdude /tmp/sketch.hex "); //$NON-NLS-1$
7982

8083
// not sure why but I need to swap err and out not to get red text
8184
PrintStream stderr = new PrintStream(this.myOutconsole);
@@ -85,8 +88,8 @@ public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IP
8588
ret = ssh.execSyncCommand("merge-sketch-with-bootloader.lua /tmp/sketch.hex", stdout, stderr); //$NON-NLS-1$
8689
this.myHighLevelConsoleStream.println("kill-bridge"); //$NON-NLS-1$
8790
ssh.execSyncCommand("kill-bridge", stdout, stderr); //$NON-NLS-1$
88-
this.myHighLevelConsoleStream.println("run-avrdude /tmp/sketch.hex '" + additionalParams + "'"); //$NON-NLS-1$ //$NON-NLS-2$
89-
ret = ret && ssh.execSyncCommand("run-avrdude /tmp/sketch.hex '" + additionalParams + "'", stdout, stderr); //$NON-NLS-1$ //$NON-NLS-2$
91+
this.myHighLevelConsoleStream.println(remoteUploadCommand);
92+
ret = ret && ssh.execSyncCommand(remoteUploadCommand, stdout, stderr);
9093

9194
} catch (JSchException e) {
9295
String message = e.getMessage();

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ public void internalUpload(IProject Project, String cConf) {
5757
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, Messages.Upload_Project_nature_unaccesible, e));
5858
}
5959

60-
String UpLoadTool = Common.getBuildEnvironmentVariable(Project, cConf, Const.get_ENV_KEY_TOOL(Const.ACTION_UPLOAD), Const.EMPTY_STRING);
61-
String MComPort = Common.getBuildEnvironmentVariable(Project, cConf, Const.ENV_KEY_JANTJE_COM_PORT, Const.EMPTY_STRING);
62-
String uploadClass = Common.getBuildEnvironmentVariable(Project, cConf, Const.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), Const.EMPTY_STRING);
60+
String UpLoadTool = Common.getBuildEnvironmentVariable(Project, cConf,
61+
Const.get_ENV_KEY_TOOL(Const.ACTION_UPLOAD), Const.EMPTY_STRING);
62+
String MComPort = Common.getBuildEnvironmentVariable(Project, cConf, Const.ENV_KEY_JANTJE_COM_PORT,
63+
Const.EMPTY_STRING);
64+
String uploadClass = Common.getBuildEnvironmentVariable(Project, cConf,
65+
Const.get_ENV_KEY_TOOL(Const.UPLOAD_CLASS), Const.EMPTY_STRING);
6366

6467
this.myConsole = Helpers.findConsole(Messages.Upload_console);
6568
this.myConsole.clearConsole();
@@ -84,12 +87,14 @@ public void internalUpload(IProject Project, String cConf) {
8487
} else {
8588
this.myHighLevelConsoleStream.println(Messages.Upload_ssh);
8689

87-
realUploader = new SSHUpload(this.myHighLevelConsoleStream, this.myOutconsoleStream, this.myErrconsoleStream, host);
90+
realUploader = new SSHUpload(Project, UpLoadTool, this.myHighLevelConsoleStream,
91+
this.myOutconsoleStream, this.myErrconsoleStream, host);
8892
uploadJobName = Const.UPLOAD_SSH;
8993
}
9094
} else if (UpLoadTool.equalsIgnoreCase(Const.UPLOAD_TOOL_TEENSY)) {
9195
this.myHighLevelConsoleStream.println(Messages.Upload_generic);
92-
realUploader = new GenericLocalUploader(UpLoadTool, Project, cConf, this.myConsole, this.myErrconsoleStream, this.myOutconsoleStream);
96+
realUploader = new GenericLocalUploader(UpLoadTool, Project, cConf, this.myConsole, this.myErrconsoleStream,
97+
this.myOutconsoleStream);
9398
uploadJobName = UpLoadTool;
9499
} else {
95100
this.myHighLevelConsoleStream.println(Messages.Upload_arduino);
@@ -108,9 +113,10 @@ public void internalUpload(IProject Project, String cConf) {
108113
protected IStatus run(IProgressMonitor monitor) {
109114
try {
110115
String uploadflag = "FuStatus"; //$NON-NLS-1$
111-
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't', '/', 'e', 'c', 'l', 'i', 'p',
112-
's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/', 'u', 'p', 'l', 'o', 'a', 'd', 'S', 't', 'a', 'r', 't', '.',
113-
'h', 't', 'm', 'l', '?', 'u', '=' };
116+
char[] uri = { 'h', 't', 't', 'p', ':', '/', '/', 'b', 'a', 'e', 'y', 'e', 'n', 's', '.', 'i', 't',
117+
'/', 'e', 'c', 'l', 'i', 'p', 's', 'e', '/', 'd', 'o', 'w', 'n', 'l', 'o', 'a', 'd', '/',
118+
'u', 'p', 'l', 'o', 'a', 'd', 'S', 't', 'a', 'r', 't', '.', 'h', 't', 'm', 'l', '?', 'u',
119+
'=' };
114120
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(Const.NODE_ARDUINO);
115121
int curFsiStatus = myScope.getInt(uploadflag, 0) + 1;
116122
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
@@ -128,7 +134,8 @@ protected IStatus run(IProgressMonitor monitor) {
128134
}
129135

130136
/**
131-
* UploadJobWrapper stops the serial port and restarts the serial port as needed. in between it calls the real uploader IUploader
137+
* UploadJobWrapper stops the serial port and restarts the serial port as
138+
* needed. in between it calls the real uploader IUploader
132139
*
133140
* @author jan
134141
*
@@ -154,14 +161,16 @@ protected IStatus run(IProgressMonitor monitor) {
154161
try {
155162
monitor.beginTask(Messages.Upload_uploading + " \"" + this.myProject.getName() + "\" " + this.myNAmeTag, //$NON-NLS-1$//$NON-NLS-2$
156163
2);
157-
myComPort = Common.getBuildEnvironmentVariable(this.myProject, this.myCConf, Const.ENV_KEY_JANTJE_COM_PORT, ""); //$NON-NLS-1$
164+
myComPort = Common.getBuildEnvironmentVariable(this.myProject, this.myCConf,
165+
Const.ENV_KEY_JANTJE_COM_PORT, ""); //$NON-NLS-1$
158166

159167
try {
160168
WeStoppedTheComPort = Common.StopSerialMonitor(myComPort);
161169
} catch (Exception e) {
162170
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_com_port, e));
163171
}
164-
IFile hexFile = this.myProject.getFile(new Path(this.myCConf).append(this.myProject.getName() + ".hex")); //$NON-NLS-1$
172+
IFile hexFile = this.myProject
173+
.getFile(new Path(this.myCConf).append(this.myProject.getName() + ".hex")); //$NON-NLS-1$
165174
if (this.myUploader.uploadUsingPreferences(hexFile, false, monitor)) {
166175
UploadSketchWrapper.this.myHighLevelConsoleStream.println(Messages.Upload_Done);
167176
} else {
@@ -176,7 +185,8 @@ protected IStatus run(IProgressMonitor monitor) {
176185
Common.StartSerialMonitor(myComPort);
177186
}
178187
} catch (Exception e) {
179-
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID, Messages.Upload_Error_serial_monitor_restart, e));
188+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
189+
Messages.Upload_Error_serial_monitor_restart, e));
180190
}
181191
monitor.done();
182192
}

0 commit comments

Comments
 (0)