mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
made parser aware of that now vid & pid have 0x
This commit is contained in:
parent
8ba3533a7a
commit
11db302b3e
@ -10,7 +10,7 @@ public class UDevAdmParser {
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.load(new StringReader(output));
|
properties.load(new StringReader(output));
|
||||||
|
|
||||||
return properties.get("ID_VENDOR_ID").toString().toUpperCase() + "_" + properties.get("ID_MODEL_ID").toString().toUpperCase();
|
return ("0x" + properties.get("ID_VENDOR_ID").toString() + "_0x" + properties.get("ID_MODEL_ID").toString()).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,26 +10,34 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class SystemProfilerParser {
|
public class SystemProfilerParser {
|
||||||
|
|
||||||
|
private static final String DEVICE_PATH = "device_path";
|
||||||
|
private static final String VID = "vid";
|
||||||
|
private static final String PID = "pid";
|
||||||
|
private static final String SERIAL_NUMBER = "serial_number";
|
||||||
|
private static final String DEV_TTY = "/dev/tty.";
|
||||||
|
private static final String DEV_TTY_USBMODEM = "/dev/tty.usbmodem";
|
||||||
|
private static final String DEV_CU_USBMODEM = "/dev/cu.usbmodem";
|
||||||
|
|
||||||
private final Pattern vidRegex;
|
private final Pattern vidRegex;
|
||||||
private final Pattern serialNumberRegex;
|
private final Pattern serialNumberRegex;
|
||||||
private final Pattern locationRegex;
|
private final Pattern locationRegex;
|
||||||
private final Pattern pidRegex;
|
private final Pattern pidRegex;
|
||||||
|
|
||||||
public SystemProfilerParser() {
|
public SystemProfilerParser() {
|
||||||
serialNumberRegex = Pattern.compile("^Serial Number: (.+)$");
|
this.serialNumberRegex = Pattern.compile("^Serial Number: (.+)$");
|
||||||
locationRegex = Pattern.compile("^Location ID: (.+)$");
|
this.locationRegex = Pattern.compile("^Location ID: (.+)$");
|
||||||
pidRegex = Pattern.compile("^Product ID: (.+)$");
|
this.pidRegex = Pattern.compile("^Product ID: (.+)$");
|
||||||
vidRegex = Pattern.compile("^Vendor ID: (.+)$");
|
this.vidRegex = Pattern.compile("^Vendor ID: (.+)$");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String extractVIDAndPID(String output, String serial) throws IOException {
|
public String extractVIDAndPID(String output, String serial) throws IOException {
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(output));
|
BufferedReader reader = new BufferedReader(new StringReader(output));
|
||||||
|
|
||||||
String devicePrefix;
|
String devicePrefix;
|
||||||
if (serial.startsWith("/dev/tty.")) {
|
if (serial.startsWith(DEV_TTY)) {
|
||||||
devicePrefix = "/dev/tty.usbmodem";
|
devicePrefix = DEV_TTY_USBMODEM;
|
||||||
} else {
|
} else {
|
||||||
devicePrefix = "/dev/cu.usbmodem";
|
devicePrefix = DEV_CU_USBMODEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> device = new HashMap<String, String>();
|
Map<String, String> device = new HashMap<String, String>();
|
||||||
@ -41,16 +49,16 @@ public class SystemProfilerParser {
|
|||||||
line = line.replaceAll("\\s+", " ");
|
line = line.replaceAll("\\s+", " ");
|
||||||
|
|
||||||
if ((matcher = serialNumberRegex.matcher(line)).matches()) {
|
if ((matcher = serialNumberRegex.matcher(line)).matches()) {
|
||||||
device.put("serial_number", matcher.group(1));
|
device.put(SERIAL_NUMBER, matcher.group(1));
|
||||||
} else if ((matcher = locationRegex.matcher(line)).matches()) {
|
} else if ((matcher = locationRegex.matcher(line)).matches()) {
|
||||||
device.put("device_path", devicePrefix + matcher.group(1).substring(2, 6) + "1");
|
device.put(DEVICE_PATH, devicePrefix + matcher.group(1).substring(2, 6) + "1");
|
||||||
} else if ((matcher = pidRegex.matcher(line)).matches()) {
|
} else if ((matcher = pidRegex.matcher(line)).matches()) {
|
||||||
device.put("pid", matcher.group(1));
|
device.put(PID, matcher.group(1));
|
||||||
} else if ((matcher = vidRegex.matcher(line)).matches()) {
|
} else if ((matcher = vidRegex.matcher(line)).matches()) {
|
||||||
device.put("vid", matcher.group(1));
|
device.put(VID, matcher.group(1));
|
||||||
} else if (line.equals("")) {
|
} else if (line.equals("")) {
|
||||||
if (device.containsKey("serial_number") && device.get("device_path").equals(serial)) {
|
if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) {
|
||||||
return device.get("vid").substring(2).toUpperCase() + "_" + device.get("pid").substring(2).toUpperCase();
|
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
|
||||||
}
|
}
|
||||||
device = new HashMap<String, String>();
|
device = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class ListComPortsParser {
|
|||||||
Matcher vidMatcher = vidRegExp.matcher(line);
|
Matcher vidMatcher = vidRegExp.matcher(line);
|
||||||
Matcher pidMatcher = pidRegExp.matcher(line);
|
Matcher pidMatcher = pidRegExp.matcher(line);
|
||||||
if (vidMatcher.find() && pidMatcher.find()) {
|
if (vidMatcher.find() && pidMatcher.find()) {
|
||||||
return vidMatcher.group(1).toUpperCase() + "_" + pidMatcher.group(1).toUpperCase();
|
return ("0x" + vidMatcher.group(1) + "_0x" + pidMatcher.group(1)).toUpperCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import org.junit.BeforeClass;
|
|||||||
public abstract class AbstractWithPreferencesTest {
|
public abstract class AbstractWithPreferencesTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void init() throws Exception {
|
||||||
Base.initPlatform();
|
Base.initPlatform();
|
||||||
Preferences.init(null);
|
Preferences.init(null);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package processing.app.debug;
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import processing.app.AbstractWithPreferencesTest;
|
import processing.app.AbstractWithPreferencesTest;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -11,11 +13,16 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
||||||
|
|
||||||
|
private TargetPackage targetPackage;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
targetPackage = new TargetPackage("arduino", new File(".", "hardware/arduino/"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateAnInstanceOfHttpUploader() throws Exception {
|
public void shouldCreateAnInstanceOfHttpUploader() throws Exception {
|
||||||
Map<String, String> prefs = new HashMap<String, String>();
|
TargetBoard board = targetPackage.getPlatforms().get("avr").getBoards().get("dogstick");
|
||||||
prefs.put("upload.via_http", "true");
|
|
||||||
TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
|
|
||||||
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
|
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
|
||||||
|
|
||||||
assertTrue(uploader instanceof HttpUploader);
|
assertTrue(uploader instanceof HttpUploader);
|
||||||
@ -23,8 +30,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateAnInstanceOfBasicUploaderWhenHTTPIsUnsupported() throws Exception {
|
public void shouldCreateAnInstanceOfBasicUploaderWhenHTTPIsUnsupported() throws Exception {
|
||||||
Map<String, String> prefs = new HashMap<String, String>();
|
TargetBoard board = targetPackage.getPlatforms().get("avr").getBoards().get("uno");
|
||||||
TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
|
|
||||||
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
|
Uploader uploader = new UploaderFactory().newUploader(board, "192.168.0.1 (mydogstick)");
|
||||||
|
|
||||||
assertTrue(uploader instanceof BasicUploader);
|
assertTrue(uploader instanceof BasicUploader);
|
||||||
@ -32,8 +38,7 @@ public class UploaderFactoryTest extends AbstractWithPreferencesTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateAnInstanceOfBasicUploaderWhenPortIsSerial() throws Exception {
|
public void shouldCreateAnInstanceOfBasicUploaderWhenPortIsSerial() throws Exception {
|
||||||
Map<String, String> prefs = new HashMap<String, String>();
|
TargetBoard board = targetPackage.getPlatforms().get("avr").getBoards().get("uno");
|
||||||
TargetBoard board = new TargetBoard("dummy", new PreferencesMap(prefs), null);
|
|
||||||
Uploader uploader = new UploaderFactory().newUploader(board, "/dev/ttyACM0 (Arduino Leonardo)");
|
Uploader uploader = new UploaderFactory().newUploader(board, "/dev/ttyACM0 (Arduino Leonardo)");
|
||||||
|
|
||||||
assertTrue(uploader instanceof BasicUploader);
|
assertTrue(uploader instanceof BasicUploader);
|
||||||
|
@ -11,6 +11,6 @@ public class UDevAdmParserTest {
|
|||||||
public void shouldCorrectlyParse() throws Exception {
|
public void shouldCorrectlyParse() throws Exception {
|
||||||
String output = TestHelper.inputStreamToString(UDevAdmParserTest.class.getResourceAsStream("udev_output.txt"));
|
String output = TestHelper.inputStreamToString(UDevAdmParserTest.class.getResourceAsStream("udev_output.txt"));
|
||||||
|
|
||||||
assertEquals("2341_0036", new UDevAdmParser().extractVIDAndPID(output));
|
assertEquals("0X2341_0X0036", new UDevAdmParser().extractVIDAndPID(output));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,12 @@ public class SystemProfilerParserTest {
|
|||||||
public void shouldCorrectlyParse() throws Exception {
|
public void shouldCorrectlyParse() throws Exception {
|
||||||
String output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output.txt"));
|
String output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output.txt"));
|
||||||
|
|
||||||
assertEquals("2341_0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfa121"));
|
assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfa121"));
|
||||||
assertEquals("2341_0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfa121"));
|
assertEquals("0X2341_0X0044", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfa121"));
|
||||||
|
|
||||||
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output2.txt"));
|
output = TestHelper.inputStreamToString(SystemProfilerParserTest.class.getResourceAsStream("system_profiler_output2.txt"));
|
||||||
|
|
||||||
assertEquals("2341_8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd131"));
|
|
||||||
assertEquals("2341_8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd131"));
|
|
||||||
|
|
||||||
|
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/cu.usbmodemfd131"));
|
||||||
|
assertEquals("0X2341_0X8036", new SystemProfilerParser().extractVIDAndPID(output, "/dev/tty.usbmodemfd131"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,8 @@ public class ListComPortsParserTest {
|
|||||||
public void shouldFindVIDPID() throws Exception {
|
public void shouldFindVIDPID() throws Exception {
|
||||||
String listComPortsOutput = "COM26 - FTDI - FTDIBUS\\VID_0403+PID_6001+A6004CCFA\\0000\nCOM24 - PJRC.COM, LLC. - USB\\VID_16C0&PID_0483\\12345";
|
String listComPortsOutput = "COM26 - FTDI - FTDIBUS\\VID_0403+PID_6001+A6004CCFA\\0000\nCOM24 - PJRC.COM, LLC. - USB\\VID_16C0&PID_0483\\12345";
|
||||||
|
|
||||||
ListComPortsParser parser = new ListComPortsParser();
|
assertEquals("0X0403_0X6001", new ListComPortsParser().extractVIDAndPID(listComPortsOutput, "COM26"));
|
||||||
|
assertEquals("0X16C0_0X0483", new ListComPortsParser().extractVIDAndPID(listComPortsOutput, "COM24"));
|
||||||
assertEquals("0403_6001", parser.extractVIDAndPID(listComPortsOutput, "COM26"));
|
|
||||||
assertEquals("16C0_0483", parser.extractVIDAndPID(listComPortsOutput, "COM24"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user