26
26
import cc .arduino .utils .network .HttpConnectionManager ;
27
27
import com .fasterxml .jackson .databind .DeserializationFeature ;
28
28
import com .fasterxml .jackson .databind .ObjectMapper ;
29
+ import org .apache .logging .log4j .LogManager ;
30
+ import org .apache .logging .log4j .Logger ;
29
31
import processing .app .debug .TargetBoard ;
30
32
import processing .app .debug .TargetPackage ;
31
33
import processing .app .debug .TargetPlatform ;
58
60
* know if name is proper Java package syntax.)
59
61
*/
60
62
public class Platform {
63
+ private static Logger log = LogManager .getLogger (Platform .class );
61
64
62
65
/**
63
66
* Set the default L & F. While I enjoy the bounty of the sixteen possible
@@ -163,6 +166,7 @@ private static void loadLib(File lib) {
163
166
}
164
167
165
168
private native String resolveDeviceAttachedToNative (String serial );
169
+
166
170
private native String [] listSerialsNative ();
167
171
168
172
public String preListAllCandidateDevices () {
@@ -173,47 +177,36 @@ public List<String> listSerials() {
173
177
return new ArrayList <>(Arrays .asList (listSerialsNative ()));
174
178
}
175
179
176
- public List <String > listSerialsNames (){
180
+ public List <String > listSerialsNames () {
177
181
List <String > list = new LinkedList <>();
178
182
for (String port : listSerialsNative ()) {
179
183
list .add (port .split ("_" )[0 ]);
180
184
}
181
185
return list ;
182
186
}
183
187
184
- public static class BoardCloudAPIid {
185
- public BoardCloudAPIid () { }
186
- private String name ;
187
- private String architecture ;
188
- private String id ;
189
- public String getName () { return name ; }
190
- public String getArchitecture () { return architecture ; }
191
- public String getId () { return id ; }
192
- public void setName (String tmp ) { name = tmp ; }
193
- public void setArchitecture (String tmp ) { architecture = tmp ; }
194
- public void setId (String tmp ) { id = tmp ; }
195
- }
196
-
197
188
public synchronized void getBoardWithMatchingVidPidFromCloud (String vid , String pid ) {
198
189
// this method is less useful in Windows < WIN10 since you need drivers to be already installed
199
190
ObjectMapper mapper = new ObjectMapper ();
200
191
mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
201
192
try {
202
- URL jsonUrl = new URL ("http" , "api- builder.arduino.cc" , 80 , " /builder/v1/boards/0x" + vid + " /0x" + pid );
193
+ URL jsonUrl = new URL (String . format ( "https:// builder.arduino.cc/builder/v1/boards/0x%s /0x%s" , vid , pid ) );
203
194
204
195
final HttpURLConnection httpConnection = new HttpConnectionManager (jsonUrl )
205
196
.makeConnection ();
206
197
int code = httpConnection .getResponseCode ();
207
198
if (code == 404 ) {
199
+ log .warn ("Fail to get the Vid Pid information from the builder response code={}" , code );
208
200
return ;
209
201
}
210
202
InputStream is = httpConnection .getInputStream ();
211
203
BoardCloudAPIid board = mapper .readValue (is , BoardCloudAPIid .class );
204
+ log .info ("Board info from the cloud {}" , board );
212
205
// Launch a popup with a link to boardmanager#board.getName()
213
206
// replace spaces with &
214
207
String realBoardName = board .getName ().replaceAll ("\\ (.*?\\ )" , "" ).trim ();
215
208
String boardNameReplaced = realBoardName .replaceAll (" " , "&" );
216
- String message = I18n .format (tr ("{0}Install this package{1} to use your {2} board" ), "<a href=\" http://boardsmanager/all#" + boardNameReplaced + "\" >" , "</a>" , realBoardName );
209
+ String message = I18n .format (tr ("{0}Install this package{1} to use your {2} board" ), "<a href=\" http://boardsmanager/all#" + boardNameReplaced + "\" >" , "</a>" , realBoardName );
217
210
BaseNoGui .setBoardManagerLink (message );
218
211
} catch (Exception e ) {
219
212
// No connection no problem, fail silently
@@ -250,7 +243,7 @@ public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String
250
243
boardData .put ("board" , board );
251
244
boardData .put ("vid" , vids .get (i ));
252
245
boardData .put ("pid" , pids .get (i ));
253
- String extrafields = vid_pid_iSerial .substring (vidPid .length ()+ 1 );
246
+ String extrafields = vid_pid_iSerial .substring (vidPid .length () + 1 );
254
247
String [] parts = extrafields .split ("_" );
255
248
boardData .put ("iserial" , parts [0 ]);
256
249
return boardData ;
@@ -263,6 +256,58 @@ public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String
263
256
return null ;
264
257
}
265
258
259
+ public static class BoardCloudAPIid {
260
+ public BoardCloudAPIid () {
261
+ }
262
+
263
+ private String name ;
264
+ private String fqbn ;
265
+ private String architecture ;
266
+ private String id ;
267
+
268
+ public String getName () {
269
+ return name ;
270
+ }
271
+
272
+ public String getFqbn () {
273
+ return fqbn ;
274
+ }
275
+
276
+ public String getArchitecture () {
277
+ return architecture ;
278
+ }
279
+
280
+ public String getId () {
281
+ return id ;
282
+ }
283
+
284
+ public void setName (String tmp ) {
285
+ name = tmp ;
286
+ }
287
+
288
+ public void setFqbn (String fqbn ) {
289
+ this .fqbn = fqbn ;
290
+ }
291
+
292
+ public void setArchitecture (String tmp ) {
293
+ architecture = tmp ;
294
+ }
295
+
296
+ public void setId (String tmp ) {
297
+ id = tmp ;
298
+ }
299
+
300
+ @ Override
301
+ public String toString () {
302
+ return "BoardCloudAPIid{" +
303
+ "name='" + name + '\'' +
304
+ ", fqbn='" + fqbn + '\'' +
305
+ ", architecture='" + architecture + '\'' +
306
+ ", id='" + id + '\'' +
307
+ '}' ;
308
+ }
309
+ }
310
+
266
311
public String resolveDeviceByBoardID (Map <String , TargetPackage > packages , String boardId ) {
267
312
assert packages != null ;
268
313
assert boardId != null ;
0 commit comments