Skip to content

Commit f830e00

Browse files
author
Federico Fissore
committed
httpuploader first checks if the board is ready, then uploads the sketch
1 parent ef9070e commit f830e00

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

app/src/processing/app/debug/HttpUploader.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.commons.httpclient.HttpClient;
44
import org.apache.commons.httpclient.HttpStatus;
5+
import org.apache.commons.httpclient.methods.GetMethod;
56
import org.apache.commons.httpclient.methods.PostMethod;
67
import org.apache.commons.httpclient.methods.multipart.FilePart;
78
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
@@ -29,15 +30,16 @@ public class HttpUploader extends Uploader {
2930

3031
private final HttpClient client;
3132
private final String ipAddress;
33+
private final String baseUrl;
3234

3335
public HttpUploader(String port) {
3436
this.client = new HttpClient();
35-
this.client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
3637
Matcher matcher = IPV4_ADDRESS.matcher(port);
3738
if (!matcher.find()) {
3839
throw new IllegalArgumentException(port);
3940
}
4041
this.ipAddress = matcher.group(1);
42+
this.baseUrl = "https://" + ipAddress;
4143
}
4244

4345
public boolean requiresAuthorization() {
@@ -55,6 +57,21 @@ public boolean uploadUsingPreferences(String buildPath, String className, boolea
5557
return false;
5658
}
5759

60+
this.client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
61+
62+
int sleptTimes = 1;
63+
while (boardNotReady()) {
64+
try {
65+
Thread.sleep(100);
66+
} catch (InterruptedException e) {
67+
throw new RunnerException(e);
68+
}
69+
if (sleptTimes >= 3) {
70+
throw new RunnerException("The board is not yet ready");
71+
}
72+
sleptTimes += 1;
73+
}
74+
5875
FilePart sketch;
5976
try {
6077
sketch = new FilePart("sketch", new File(buildPath, className + ".hex"));
@@ -88,8 +105,17 @@ public boolean uploadUsingPreferences(String buildPath, String className, boolea
88105
}
89106
}
90107

108+
protected boolean boardNotReady() {
109+
GetMethod get = new GetMethod(baseUrl + "/ready");
110+
try {
111+
return client.executeMethod(get) != HttpStatus.SC_OK;
112+
} catch (IOException e) {
113+
return true;
114+
}
115+
}
116+
91117
protected PostMethod newPostMethod() {
92-
return new PostMethod("https://" + ipAddress + "/upload");
118+
return new PostMethod(baseUrl + "/upload");
93119
}
94120

95121
@Override

0 commit comments

Comments
 (0)