1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

working on #223: Auto-detection of serial ports. Speeding up mac and windows

This commit is contained in:
Federico Fissore 2013-02-04 15:35:16 +01:00
parent 1445529d1c
commit e650e20760
5 changed files with 54 additions and 27 deletions

View File

@ -994,6 +994,7 @@ public class Editor extends JFrame implements RunnerListener {
try
{
String devicesListOutput = Base.getPlatform().preListAllCandidateDevices();
for (Enumeration enumeration = CommPortIdentifier.getPortIdentifiers(); enumeration.hasMoreElements();)
{
CommPortIdentifier commportidentifier = (CommPortIdentifier)enumeration.nextElement();
@ -1004,7 +1005,7 @@ public class Editor extends JFrame implements RunnerListener {
String curr_port = commportidentifier.getName();
String description = curr_port;
String additionalDescription = Base.getPlatform().resolveDeviceAttachedTo(curr_port, Base.packages);
String additionalDescription = Base.getPlatform().resolveDeviceAttachedTo(curr_port, Base.packages, devicesListOutput);
if (additionalDescription != null) {
description += " (" + additionalDescription + ")";
}

View File

@ -136,7 +136,11 @@ public class Platform {
}
}
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
return null;
}
public String preListAllCandidateDevices() {
return null;
}

View File

@ -129,7 +129,7 @@ public class Platform extends processing.app.Platform {
}
@Override
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new ExternalProcessExecutor(baos);
@ -143,12 +143,12 @@ public class Platform extends processing.app.Platform {
String vidPid = new UDevAdmParser().extractVIDAndPID(new String(baos.toByteArray()));
if (vidPid == null) {
return super.resolveDeviceAttachedTo(serial, packages);
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
}
return super.resolveDeviceByVendorIdProductId(packages, vidPid);
} catch (IOException e) {
return super.resolveDeviceAttachedTo(serial, packages);
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
}
}
}

View File

@ -205,24 +205,35 @@ public class Platform extends processing.app.Platform {
}
@Override
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
if (devicesListOutput == null) {
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
}
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 ExternalProcessExecutor(baos);
try {
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");
executor.execute(toDevicePath);
String output = new String(baos.toByteArray());
String vidPid = new SystemProfilerParser().extractVIDAndPID(output, serial);
if (vidPid == null) {
return super.resolveDeviceAttachedTo(serial, packages);
}
return super.resolveDeviceByVendorIdProductId(packages, vidPid);
return new String(baos.toByteArray());
} catch (IOException e) {
return super.resolveDeviceAttachedTo(serial, packages);
return super.preListAllCandidateDevices();
}
}
}

View File

@ -316,7 +316,26 @@ public class Platform extends processing.app.Platform {
}
@Override
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) {
public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
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 ExternalProcessExecutor(baos);
@ -325,17 +344,9 @@ public class Platform extends processing.app.Platform {
CommandLine toDevicePath = CommandLine.parse(listComPorts);
executor.execute(toDevicePath);
String vidPid = new ListComPortsParser().extractVIDAndPID(new String(baos.toByteArray()), serial);
if (vidPid == null) {
return super.resolveDeviceAttachedTo(serial, packages);
}
return super.resolveDeviceByVendorIdProductId(packages, vidPid);
return new String(baos.toByteArray());
} catch (IOException e) {
return super.resolveDeviceAttachedTo(serial, packages);
return super.preListAllCandidateDevices();
}
}
}