From 64fcc716c9e43bb4b19f2c0a04a491b9a4201fba Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Fri, 12 Jun 2015 13:54:46 +0200 Subject: [PATCH] MacOSX: SystemProfilerParser nows claims to have found the device even if the name is not exactly the same --- .../app/macosx/SystemProfilerParserTest.java | 4 + .../app/macosx/system_profiler_output8.txt | 96 +++++++++++++++++++ .../app/macosx/SystemProfilerParser.java | 17 +++- 3 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 app/test/processing/app/macosx/system_profiler_output8.txt diff --git a/app/test/processing/app/macosx/SystemProfilerParserTest.java b/app/test/processing/app/macosx/SystemProfilerParserTest.java index 30c6f6b63..1476822c4 100644 --- a/app/test/processing/app/macosx/SystemProfilerParserTest.java +++ b/app/test/processing/app/macosx/SystemProfilerParserTest.java @@ -74,5 +74,9 @@ public class SystemProfilerParserTest { assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131")); assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV")); assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV")); + + output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt")); + + assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132")); } } diff --git a/app/test/processing/app/macosx/system_profiler_output8.txt b/app/test/processing/app/macosx/system_profiler_output8.txt new file mode 100644 index 000000000..13a2d7f8e --- /dev/null +++ b/app/test/processing/app/macosx/system_profiler_output8.txt @@ -0,0 +1,96 @@ +USB: + + USB Hi-Speed Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBEHCI + PCI Device ID: 0x1c2d + PCI Revision ID: 0x0005 + PCI Vendor ID: 0x8086 + Bus Number: 0xfa + + Hub: + + Product ID: 0x2513 + Vendor ID: 0x0424 (SMSC) + Version: b.b3 + Speed: Up to 480 Mb/sec + Location ID: 0xfa100000 / 2 + Current Available (mA): 500 + Current Required (mA): 2 + + Arduino Leonardo: + + Product ID: 0x8036 + Vendor ID: 0x2341 + Version: 1.00 + Speed: Up to 12 Mb/sec + Manufacturer: Arduino LLC + Location ID: 0xfa120000 / 5 + Current Available (mA): 500 + Current Required (mA): 500 + + BRCM20702 Hub: + + Product ID: 0x4500 + Vendor ID: 0x0a5c (Broadcom Corp.) + Version: 1.00 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0xfa110000 / 3 + Current Available (mA): 500 + Current Required (mA): 94 + + Bluetooth USB Host Controller: + + Product ID: 0x8281 + Vendor ID: 0x05ac (Apple Inc.) + Version: 1.25 + Speed: Up to 12 Mb/sec + Manufacturer: Apple Inc. + Location ID: 0xfa113000 / 4 + Current Available (mA): 500 + Current Required (mA): 0 + + USB Hi-Speed Bus: + + Host Controller Location: Built-in USB + Host Controller Driver: AppleUSBEHCI + PCI Device ID: 0x1c26 + PCI Revision ID: 0x0005 + PCI Vendor ID: 0x8086 + Bus Number: 0xfd + + Hub: + + Product ID: 0x2513 + Vendor ID: 0x0424 (SMSC) + Version: b.b3 + Speed: Up to 480 Mb/sec + Location ID: 0xfd100000 / 2 + Current Available (mA): 500 + Current Required (mA): 2 + + EDBG CMSIS-DAP: + + Product ID: 0x2157 + Vendor ID: 0x03eb (Atmel Corporation) + Version: 1.01 + Serial Number: 00000000AZE000000310 + Speed: Up to 480 Mb/sec + Manufacturer: Atmel Corp. + Location ID: 0xfd130000 / 4 + Current Available (mA): 500 + Current Required (mA): 500 + + IR Receiver: + + Product ID: 0x8242 + Vendor ID: 0x05ac (Apple Inc.) + Version: 0.16 + Speed: Up to 1.5 Mb/sec + Manufacturer: Apple Computer, Inc. + Location ID: 0xfd110000 / 3 + Current Available (mA): 500 + Current Required (mA): 100 + diff --git a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java index bef99387c..2e1d77462 100644 --- a/arduino-core/src/processing/app/macosx/SystemProfilerParser.java +++ b/arduino-core/src/processing/app/macosx/SystemProfilerParser.java @@ -55,7 +55,7 @@ public class SystemProfilerParser { if ((matcher = serialNumberRegex.matcher(line)).matches()) { device.put(SERIAL_NUMBER, matcher.group(1)); - if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) { + if (serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL)) { String devicePath = devicePrefix + matcher.group(1); device.put(DEVICE_PATH, devicePath); } @@ -65,17 +65,24 @@ public class SystemProfilerParser { device.put(DEVICE_PATH, devicePath); } else if ((matcher = pidRegex.matcher(line)).matches()) { String pid = matcher.group(1); - if (pid.indexOf(" ") > 0) + if (pid.indexOf(" ") > 0) { pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number + } device.put(PID, pid); } else if ((matcher = vidRegex.matcher(line)).matches()) { String vid = matcher.group(1); - if (vid.indexOf(" ") > 0) + if (vid.indexOf(" ") > 0) { vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number + } device.put(VID, vid); } else if (line.equals("")) { - if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) { - return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); + if (device.containsKey(DEVICE_PATH)) { + String computedDevicePath = device.get(DEVICE_PATH); + String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1); + String serialMinusChar = serial.substring(0, serial.length() - 1); + if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) { + return (device.get(VID) + "_" + device.get(PID)).toUpperCase(); + } } device = new HashMap(); }