Skip to content

Commit a396f2a

Browse files
committed
Merge pull request #4006 from cmaglie/sys_prof_parse_fix
SystemProfilerParse fix for OSX El Capitan
2 parents 9f5efe2 + 2ae3694 commit a396f2a

File tree

4 files changed

+168
-53
lines changed

4 files changed

+168
-53
lines changed

app/test/processing/app/macosx/SystemProfilerParserTest.java

+44-39
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,55 @@
3333
import processing.app.TestHelper;
3434

3535
import static org.junit.Assert.assertEquals;
36+
import static processing.app.macosx.SystemProfilerParser.extractVIDAndPID;
37+
38+
import java.io.IOException;
39+
import java.io.InputStream;
3640

3741
public class SystemProfilerParserTest {
3842

3943
@Test
4044
public void shouldCorrectlyParse() throws Exception {
41-
String output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output.txt"));
42-
43-
assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfa121"));
44-
assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfa121"));
45-
46-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output2.txt"));
47-
48-
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd131"));
49-
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd131"));
50-
51-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output3.txt"));
52-
53-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd121"));
54-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd121"));
55-
56-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output4.txt"));
57-
58-
assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem411"));
59-
assertEquals("0X2341_0X0041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem411"));
60-
61-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output5.txt"));
62-
63-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem621"));
64-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem621"));
65-
66-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output6.txt"));
67-
68-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem1421"));
69-
assertEquals("0X2341_0X8041", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem1421"));
70-
71-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output7.txt"));
72-
73-
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodem24131"));
74-
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodem24131"));
75-
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV"));
76-
assertEquals("0X0403_0X6015", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV"));
77-
78-
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output8.txt"));
45+
String output = getFileContent("system_profiler_output.txt");
46+
assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/cu.usbmodemfa121"));
47+
assertEquals("0X2341_0X0044", extractVIDAndPID(output, "/dev/tty.usbmodemfa121"));
48+
49+
output = getFileContent("system_profiler_output2.txt");
50+
assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodemfd131"));
51+
assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemfd131"));
52+
53+
output = getFileContent("system_profiler_output3.txt");
54+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodemfd121"));
55+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodemfd121"));
56+
57+
output = getFileContent("system_profiler_output4.txt");
58+
assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/cu.usbmodem411"));
59+
assertEquals("0X2341_0X0041", extractVIDAndPID(output, "/dev/tty.usbmodem411"));
60+
61+
output = getFileContent("system_profiler_output5.txt");
62+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem621"));
63+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem621"));
64+
65+
output = getFileContent("system_profiler_output6.txt");
66+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/cu.usbmodem1421"));
67+
assertEquals("0X2341_0X8041", extractVIDAndPID(output, "/dev/tty.usbmodem1421"));
68+
69+
output = getFileContent("system_profiler_output7.txt");
70+
assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/cu.usbmodem24131"));
71+
assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodem24131"));
72+
assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/cu.usbserial-DN0031EV"));
73+
assertEquals("0X0403_0X6015", extractVIDAndPID(output, "/dev/tty.usbserial-DN0031EV"));
74+
75+
output = getFileContent("system_profiler_output8.txt");
76+
assertEquals("0X03EB_0X2157", extractVIDAndPID(output, "/dev/tty.usbmodemfd132"));
77+
78+
// OSX El Capitan
79+
output = getFileContent("system_profiler_output9.txt");
80+
assertEquals("0X2341_0X8036", extractVIDAndPID(output, "/dev/tty.usbmodemFA121"));
81+
}
7982

80-
assertEquals("0X03EB_0X2157", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd132"));
83+
private String getFileContent(String filename) throws IOException {
84+
InputStream resource = SystemProfilerParserTest.class.getResourceAsStream(filename);
85+
return TestHelper.inputStreamToString(resource);
8186
}
8287
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
USB:
2+
3+
USB 2.0 Bus:
4+
5+
Host Controller Driver: AppleUSBEHCIPCI
6+
PCI Device ID: 0x1c2d
7+
PCI Revision ID: 0x0005
8+
PCI Vendor ID: 0x8086
9+
10+
Hub:
11+
12+
Product ID: 0x2513
13+
Vendor ID: 0x0424 (SMSC)
14+
Version: b.b3
15+
Speed: Up to 480 Mb/sec
16+
Location ID: 0xfa100000 / 1
17+
Current Available (mA): 1000
18+
Current Required (mA): 2
19+
Extra Operating Current (mA): 0
20+
Built-In: Yes
21+
22+
Arduino Leonardo:
23+
24+
Product ID: 0x8036
25+
Vendor ID: 0x2341
26+
Version: 1.00
27+
Speed: Up to 12 Mb/sec
28+
Manufacturer: Arduino LLC
29+
Location ID: 0xfa120000 / 3
30+
Current Available (mA): 1000
31+
Current Required (mA): 500
32+
Extra Operating Current (mA): 0
33+
34+
BRCM20702 Hub:
35+
36+
Product ID: 0x4500
37+
Vendor ID: 0x0a5c (Broadcom Corp.)
38+
Version: 1.00
39+
Speed: Up to 12 Mb/sec
40+
Manufacturer: Apple Inc.
41+
Location ID: 0xfa110000 / 4
42+
Current Available (mA): 1000
43+
Current Required (mA): 94
44+
Extra Operating Current (mA): 0
45+
Built-In: Yes
46+
47+
Bluetooth USB Host Controller:
48+
49+
Product ID: 0x8281
50+
Vendor ID: 0x05ac (Apple Inc.)
51+
Version: 1.51
52+
Speed: Up to 12 Mb/sec
53+
Manufacturer: Apple Inc.
54+
Location ID: 0xfa113000 / 2
55+
Current Available (mA): 1000
56+
Current Required (mA): 0
57+
Extra Operating Current (mA): 0
58+
Built-In: Yes
59+
60+
USB 2.0 Bus:
61+
62+
Host Controller Driver: AppleUSBEHCIPCI
63+
PCI Device ID: 0x1c26
64+
PCI Revision ID: 0x0005
65+
PCI Vendor ID: 0x8086
66+
67+
Hub:
68+
69+
Product ID: 0x2513
70+
Vendor ID: 0x0424 (SMSC)
71+
Version: b.b3
72+
Speed: Up to 480 Mb/sec
73+
Location ID: 0xfd100000 / 1
74+
Current Available (mA): 1000
75+
Current Required (mA): 2
76+
Extra Operating Current (mA): 0
77+
Built-In: Yes
78+
79+
USB Keyboard:
80+
81+
Product ID: 0x2000
82+
Vendor ID: 0x040b (Weltrend Semiconductor)
83+
Version: 2.05
84+
Speed: Up to 1.5 Mb/sec
85+
Manufacturer: Generic
86+
Location ID: 0xfd130000 / 4
87+
Current Available (mA): 1000
88+
Current Required (mA): 100
89+
Extra Operating Current (mA): 0
90+
91+
USB OPTICAL MOUSE:
92+
93+
Product ID: 0x2510
94+
Vendor ID: 0x093a (Pixart Imaging, Inc.)
95+
Version: 1.00
96+
Speed: Up to 1.5 Mb/sec
97+
Manufacturer: PIXART
98+
Location ID: 0xfd120000 / 3
99+
Current Available (mA): 1000
100+
Current Required (mA): 100
101+
Extra Operating Current (mA): 0
102+
103+
IR Receiver:
104+
105+
Product ID: 0x8242
106+
Vendor ID: 0x05ac (Apple Inc.)
107+
Version: 0.16
108+
Speed: Up to 1.5 Mb/sec
109+
Manufacturer: Apple Computer, Inc.
110+
Location ID: 0xfd110000 / 2
111+
Current Available (mA): 1000
112+
Current Required (mA): 100
113+
Extra Operating Current (mA): 0
114+
Built-In: Yes
115+
116+
117+

arduino-core/src/processing/app/macosx/Platform.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, Ta
172172
}
173173

174174
try {
175-
String vidPid = new SystemProfilerParser().extractVIDAndPID(devicesListOutput, serial);
175+
String vidPid = SystemProfilerParser.extractVIDAndPID(devicesListOutput, serial);
176176

177177
if (vidPid == null) {
178178
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);

arduino-core/src/processing/app/macosx/SystemProfilerParser.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ public class SystemProfilerParser {
1919
private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem";
2020
private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem";
2121

22-
private final Pattern vidRegex;
23-
private final Pattern serialNumberRegex;
24-
private final Pattern locationRegex;
25-
private final Pattern pidRegex;
22+
private static final Pattern serialNumberRegex = Pattern.compile("^Serial Number: (.+)$");
23+
private static final Pattern locationRegex = Pattern.compile("^Location ID: (.+)$");
24+
private static final Pattern pidRegex = Pattern.compile("^Product ID: (.+)$");
25+
private static final Pattern vidRegex = Pattern.compile("^Vendor ID: (.+)$");
2626

27-
public SystemProfilerParser() {
28-
this.serialNumberRegex = Pattern.compile("^Serial Number: (.+)$");
29-
this.locationRegex = Pattern.compile("^Location ID: (.+)$");
30-
this.pidRegex = Pattern.compile("^Product ID: (.+)$");
31-
this.vidRegex = Pattern.compile("^Vendor ID: (.+)$");
32-
}
33-
34-
public String extractVIDAndPID(String output, String serial) throws IOException {
27+
public synchronized static String extractVIDAndPID(String output, String serial) throws IOException {
3528
BufferedReader reader = new BufferedReader(new StringReader(output));
3629

3730
String devicePrefix;
@@ -80,7 +73,7 @@ public String extractVIDAndPID(String output, String serial) throws IOException
8073
String computedDevicePath = device.get(DEVICE_PATH);
8174
String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1);
8275
String serialMinusChar = serial.substring(0, serial.length() - 1);
83-
if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) {
76+
if (computedDevicePath.equalsIgnoreCase(serial) || computedDevicePathMinusChar.equalsIgnoreCase(serialMinusChar)) {
8477
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
8578
}
8679
}

0 commit comments

Comments
 (0)