From 3c16ac025a84c4de27223afdfedce0ef6727aab9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 12 Nov 2015 16:39:48 +0100 Subject: [PATCH 1/4] Add iSerial to reported VID_PID string serial.port.iserial holds the iSerial value --- .../packages/discoverers/serial/SerialBoardsLister.java | 1 + .../src/cc/arduino/packages/uploaders/SerialUploader.java | 6 ++++++ arduino-core/src/processing/app/Platform.java | 3 ++- arduino-core/src/processing/app/linux/UDevAdmParser.java | 6 +++++- .../src/processing/app/macosx/SystemProfilerParser.java | 2 +- .../src/processing/app/windows/ListComPortsParser.java | 3 ++- 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java index 475fb6e94..c239d9a30 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java @@ -86,6 +86,7 @@ public class SerialBoardsLister extends TimerTask { if (boardData != null) { boardPort.getPrefs().put("vid", boardData.get("vid").toString()); boardPort.getPrefs().put("pid", boardData.get("pid").toString()); + boardPort.getPrefs().put("iserial", boardData.get("iserial").toString()); TargetBoard board = (TargetBoard) boardData.get("board"); if (board != null) { diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java index f39d4085f..75acaa9d0 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java @@ -37,6 +37,7 @@ package cc.arduino.packages.uploaders; import cc.arduino.LoadVIDPIDSpecificPreferences; import cc.arduino.packages.Uploader; import processing.app.*; +import cc.arduino.packages.BoardPort; import processing.app.debug.RunnerException; import processing.app.debug.TargetPlatform; import processing.app.helpers.OSUtils; @@ -152,6 +153,11 @@ public class SerialUploader extends Uploader { } } + BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port")); + if (boardPort.getPrefs().get("iserial") != null) { + prefs.put("serial.port.iserial", boardPort.getPrefs().get("iserial")); + } + prefs.put("build.path", buildPath); prefs.put("build.project_name", className); if (verbose) { diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index a779295d9..c6d62c8d7 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -161,11 +161,12 @@ public class Platform { List pids = new LinkedList(board.getPreferences().subTree("pid", 1).values()); for (int i = 0; i < vids.size(); i++) { String vidPid = vids.get(i) + "_" + pids.get(i); - if (vidPid.toUpperCase().equals(readVIDPID)) { + if (readVIDPID.contains(vidPid.toUpperCase())) { Map boardData = new HashMap(); boardData.put("board", board); boardData.put("vid", vids.get(i)); boardData.put("pid", pids.get(i)); + boardData.put("iserial", readVIDPID.substring(vidPid.length()+1)); return boardData; } } diff --git a/arduino-core/src/processing/app/linux/UDevAdmParser.java b/arduino-core/src/processing/app/linux/UDevAdmParser.java index 53793f83a..a32aabc55 100644 --- a/arduino-core/src/processing/app/linux/UDevAdmParser.java +++ b/arduino-core/src/processing/app/linux/UDevAdmParser.java @@ -12,9 +12,13 @@ public class UDevAdmParser { Object vid = properties.get("ID_VENDOR_ID"); Object pid = properties.get("ID_MODEL_ID"); + Object serial = properties.get("ID_SERIAL_SHORT"); if (vid == null || pid == null) return null; - return ("0x" + vid + "_0x" + pid).toUpperCase(); + if (serial == null) { + serial = ""; + } + return ("0x" + vid + "_0x" + pid).toUpperCase() + "_" + serial; } } diff --git a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java index d9a08b294..87df576fc 100644 --- a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java +++ b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java @@ -81,7 +81,7 @@ public class SystemProfilerParser { String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1); String serialMinusChar = serial.substring(0, serial.length() - 1); if (computedDevicePath.equalsIgnoreCase(serial) || computedDevicePathMinusChar.equalsIgnoreCase(serialMinusChar)) { - return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); + return (device.get(VID) + "_" + device.get(PID)).toUpperCase() + "_" + device.get(SERIAL_NUMBER); } } device = new HashMap<>(); diff --git a/arduino-core/src/processing/app/windows/ListComPortsParser.java b/arduino-core/src/processing/app/windows/ListComPortsParser.java index d02a0106a..702721c28 100644 --- a/arduino-core/src/processing/app/windows/ListComPortsParser.java +++ b/arduino-core/src/processing/app/windows/ListComPortsParser.java @@ -59,8 +59,9 @@ public class ListComPortsParser { String vidPidPart = lineParts[lineParts.length - 1]; Matcher vidMatcher = vidRegExp.matcher(vidPidPart); Matcher pidMatcher = pidRegExp.matcher(vidPidPart); + String iSerial = vidPidPart.substring(vidPidPart.lastIndexOf("\\")+1); if (vidMatcher.find() && pidMatcher.find()) { - return ("0x" + vidMatcher.group(1) + "_0x" + pidMatcher.group(1)).toUpperCase(); + return ("0x" + vidMatcher.group(1) + "_0x" + pidMatcher.group(1)).toUpperCase() + "_" + iSerial; } } } From 9d676a71c8fe985eb53c013a68d25578bfe82751 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 25 Nov 2015 12:20:16 +0100 Subject: [PATCH 2/4] Specify SSH authentication methods Solves upload to particularly configured SSH servers which wrongly chooses Kerberos auth method --- arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java index 8f77098c0..dca138ffb 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SSHUploader.java @@ -110,6 +110,8 @@ public class SSHUploader extends Uploader { SSHClientSetupChainRing sshClientSetupChain = new SSHConfigFileSetup(new SSHPwdSetup()); session = sshClientSetupChain.setup(port, jSch); + session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password"); + session.setUserInfo(new NoInteractionUserInfo(PreferencesData.get("runtime.pwd." + port.getAddress()))); session.connect(30000); From 7e17b5c3184ab1d1191c5c7eea7f5755578b80b0 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 18 Dec 2015 18:16:38 +0100 Subject: [PATCH 3/4] Move vid/pid resolving to cross platform jni lib --- .../serial/SerialBoardsLister.java | 4 +- arduino-core/src/processing/app/Platform.java | 25 ++++++++++--- .../src/processing/app/linux/Platform.java | 26 ------------- .../src/processing/app/macosx/Platform.java | 35 ------------------ .../src/processing/app/windows/Platform.java | 37 ------------------- build/build.xml | 34 +++++++++++++---- build/liblistSerials-1.0.4.zip.sha | 1 + 7 files changed, 50 insertions(+), 112 deletions(-) create mode 100644 build/liblistSerials-1.0.4.zip.sha diff --git a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java index c239d9a30..5ca99819b 100644 --- a/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java +++ b/arduino-core/src/cc/arduino/packages/discoverers/serial/SerialBoardsLister.java @@ -47,7 +47,7 @@ public class SerialBoardsLister extends TimerTask { } public void start(Timer timer) { - timer.schedule(this, 0, 3000); + timer.schedule(this, 0, 1000); } @Override @@ -75,7 +75,7 @@ public class SerialBoardsLister extends TimerTask { } for (String port : ports) { - Map boardData = platform.resolveDeviceAttachedTo(port, BaseNoGui.packages, devicesListOutput); + Map boardData = platform.resolveDeviceByVendorIdProductId(port, BaseNoGui.packages, devicesListOutput); BoardPort boardPort = new BoardPort(); boardPort.setAddress(port); diff --git a/arduino-core/src/processing/app/Platform.java b/arduino-core/src/processing/app/Platform.java index c6d62c8d7..29e5e733d 100644 --- a/arduino-core/src/processing/app/Platform.java +++ b/arduino-core/src/processing/app/Platform.java @@ -144,15 +144,30 @@ public class Platform { } } - public Map resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { - return null; + static { + loadLib(new File(BaseNoGui.getContentFile("lib"), System.mapLibraryName("listSerialsj"))); + }; + + private static void loadLib(File lib) { + try { + System.load(lib.getAbsolutePath()); + } catch (UnsatisfiedLinkError e) { + e.printStackTrace(); + System.out.println(e.getMessage()); + System.out.println("Cannot load native library " + lib.getAbsolutePath()); + System.out.println("The program has terminated!"); + System.exit(1); + } } + public native String resolveDeviceAttachedToNative(String serial); + public String preListAllCandidateDevices() { return null; } - protected Map resolveDeviceByVendorIdProductId(Map packages, String readVIDPID) { + public Map resolveDeviceByVendorIdProductId(String serial, Map packages, String devicesListOutput) { + String vid_pid_iSerial = resolveDeviceAttachedToNative(serial); for (TargetPackage targetPackage : packages.values()) { for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) { for (TargetBoard board : targetPlatform.getBoards().values()) { @@ -161,12 +176,12 @@ public class Platform { List pids = new LinkedList(board.getPreferences().subTree("pid", 1).values()); for (int i = 0; i < vids.size(); i++) { String vidPid = vids.get(i) + "_" + pids.get(i); - if (readVIDPID.contains(vidPid.toUpperCase())) { + if (vid_pid_iSerial.toUpperCase().contains(vidPid.toUpperCase())) { Map boardData = new HashMap(); boardData.put("board", board); boardData.put("vid", vids.get(i)); boardData.put("pid", pids.get(i)); - boardData.put("iserial", readVIDPID.substring(vidPid.length()+1)); + boardData.put("iserial", vid_pid_iSerial.substring(vidPid.length()+1)); return boardData; } } diff --git a/arduino-core/src/processing/app/linux/Platform.java b/arduino-core/src/processing/app/linux/Platform.java index 7a8024f46..f28df3555 100644 --- a/arduino-core/src/processing/app/linux/Platform.java +++ b/arduino-core/src/processing/app/linux/Platform.java @@ -120,30 +120,4 @@ public class Platform extends processing.app.Platform { public String getName() { return PConstants.platformNames[PConstants.LINUX]; } - - @Override - public Map resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { - assert packages != null; - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Executor executor = new DefaultExecutor(); - executor.setStreamHandler(new PumpStreamHandler(baos, null)); - - try { - CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial); - executor.execute(toDevicePath); - String devicePath = new String(baos.toByteArray()); - baos.reset(); - CommandLine commandLine = CommandLine.parse("udevadm info --query=property -p " + devicePath); - executor.execute(commandLine); - String vidPid = new UDevAdmParser().extractVIDAndPID(new String(baos.toByteArray())); - - if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - - return super.resolveDeviceByVendorIdProductId(packages, vidPid); - } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - } } diff --git a/arduino-core/src/processing/app/macosx/Platform.java b/arduino-core/src/processing/app/macosx/Platform.java index 102291cd4..7c0768823 100644 --- a/arduino-core/src/processing/app/macosx/Platform.java +++ b/arduino-core/src/processing/app/macosx/Platform.java @@ -164,41 +164,6 @@ public class Platform extends processing.app.Platform { return PConstants.platformNames[PConstants.MACOSX]; } - @Override - public Map resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { - assert packages != null; - if (devicesListOutput == null) { - return super.resolveDeviceAttachedTo(serial, packages, null); - } - - try { - String vidPid = new SystemProfilerParser().extractVIDAndPID(devicesListOutput, serial); - - if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - - return super.resolveDeviceByVendorIdProductId(packages, vidPid); - } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - } - - @Override - public String preListAllCandidateDevices() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Executor executor = new DefaultExecutor(); - executor.setStreamHandler(new PumpStreamHandler(baos, null)); - - try { - CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType"); - executor.execute(toDevicePath); - return new String(baos.toByteArray()); - } catch (Throwable e) { - return super.preListAllCandidateDevices(); - } - } - @Override public java.util.List filterPorts(java.util.List ports, boolean showAll) { if (showAll) { diff --git a/arduino-core/src/processing/app/windows/Platform.java b/arduino-core/src/processing/app/windows/Platform.java index c2f7bf710..1783a1760 100644 --- a/arduino-core/src/processing/app/windows/Platform.java +++ b/arduino-core/src/processing/app/windows/Platform.java @@ -183,43 +183,6 @@ public class Platform extends processing.app.Platform { return PConstants.platformNames[PConstants.WINDOWS]; } - @Override - public Map resolveDeviceAttachedTo(String serial, Map packages, String devicesListOutput) { - assert packages != null; - if (devicesListOutput == null) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - - try { - String vidPid = new ListComPortsParser().extractVIDAndPID(devicesListOutput, serial); - - if (vidPid == null) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - - return super.resolveDeviceByVendorIdProductId(packages, vidPid); - } catch (IOException e) { - return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput); - } - } - - @Override - public String preListAllCandidateDevices() { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Executor executor = new DefaultExecutor(); - executor.setStreamHandler(new PumpStreamHandler(baos, null)); - - try { - String listComPorts = BaseNoGui.getContentFile("hardware/tools/listComPorts.exe").getCanonicalPath(); - - CommandLine toDevicePath = CommandLine.parse(listComPorts); - executor.execute(toDevicePath); - return new String(baos.toByteArray()); - } catch (Throwable e) { - return super.preListAllCandidateDevices(); - } - } - @Override public void fixPrefsFilePermissions(File prefsFile) throws IOException { //noop diff --git a/build/build.xml b/build/build.xml index 9e955d92c..e7d8cf3f2 100644 --- a/build/build.xml +++ b/build/build.xml @@ -393,6 +393,15 @@ + + + + + + + + + @@ -585,6 +594,16 @@ + + + + + + + + + + @@ -845,13 +864,14 @@ - - - - - - - + + + + + + + + diff --git a/build/liblistSerials-1.0.4.zip.sha b/build/liblistSerials-1.0.4.zip.sha new file mode 100644 index 000000000..998f2872e --- /dev/null +++ b/build/liblistSerials-1.0.4.zip.sha @@ -0,0 +1 @@ +4e8ef727d7dc3903c37002f38f8aba87796b787c From 2a677b4bcd20f7b245067ceebd4f821591e243f9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 4 Jan 2016 16:06:36 +0100 Subject: [PATCH 4/4] avoid NPE if serial port gets discovered too early --- .../src/cc/arduino/packages/uploaders/SerialUploader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java index 75acaa9d0..d7fc02b77 100644 --- a/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java +++ b/arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java @@ -154,8 +154,10 @@ public class SerialUploader extends Uploader { } BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port")); - if (boardPort.getPrefs().get("iserial") != null) { + try { prefs.put("serial.port.iserial", boardPort.getPrefs().get("iserial")); + } catch (Exception e) { + // if serial port does not contain an iserial field } prefs.put("build.path", buildPath);