summaryrefslogtreecommitdiffstats
path: root/tools/runonphone
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2010-12-20 16:02:37 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2010-12-20 16:03:07 (GMT)
commit11ea9609129205cd08dc5fbeb889cc60f4f84f65 (patch)
tree9aa96fea91f6d856693890602e58a99c233eb0f0 /tools/runonphone
parent7747e8864db4518e35d5a472cec37697b85b3b15 (diff)
downloadQt-11ea9609129205cd08dc5fbeb889cc60f4f84f65.zip
Qt-11ea9609129205cd08dc5fbeb889cc60f4f84f65.tar.gz
Qt-11ea9609129205cd08dc5fbeb889cc60f4f84f65.tar.bz2
reword: Make the USB serial device enumeration work on OS X, too
Tested on OS X Snow Leopard with libusb-0.1.12. The devices are named /dev/cu.usbmodem<opaque id><interface number>, where the opaque id doesn't seem to be available via the current libusb interface, but finding it would require usage of native OS X APIs. The interface number is available at least, and searching for cu\.usbmodem.*<interface number> as a regexp finds the right devices as long as not too many devices are connected. Merge-request: 834 Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'tools/runonphone')
-rw-r--r--tools/runonphone/serenum_unix.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/tools/runonphone/serenum_unix.cpp b/tools/runonphone/serenum_unix.cpp
index f65497e..93d8c67 100644
--- a/tools/runonphone/serenum_unix.cpp
+++ b/tools/runonphone/serenum_unix.cpp
@@ -158,6 +158,10 @@ QList<SerialPortId> enumerateSerialPorts(int loglevel)
<< "device" << device->filename
<< "interface" << descriptor.bInterfaceNumber;
}
+#ifdef Q_OS_MAC
+ eligibleInterfaces << QString("^cu\\.usbmodem.*%1$")
+ .arg(QString("%1").arg(descriptor.bInterfaceNumber, 1, 16).toUpper());
+#else
// ### manufacturer and product strings are only readable as root :(
if (!manufacturerString.isEmpty() && !productString.isEmpty()) {
eligibleInterfaces << QString("usb-%1_%2-if%3")
@@ -167,6 +171,7 @@ QList<SerialPortId> enumerateSerialPorts(int loglevel)
} else {
eligibleInterfaces << QString("if%1").arg(i, 2, 16, QChar('0')); // fix!
}
+#endif
eligibleInterfacesInfo << InterfaceInfo(manufacturerString, productString, device->descriptor.idVendor, device->descriptor.idProduct);
}
}
@@ -179,14 +184,24 @@ QList<SerialPortId> enumerateSerialPorts(int loglevel)
if (loglevel > 1)
qDebug() << " searching for interfaces:" << eligibleInterfaces;
+#ifdef Q_OS_MAC
+ QDir dir("/dev/");
+ bool allowAny = false;
+#else
QDir dir("/dev/serial/by-id/");
- foreach (const QFileInfo &info, dir.entryInfoList()) {
+ bool allowAny = eligibleInterfaces.isEmpty();
+#endif
+ foreach (const QFileInfo &info, dir.entryInfoList(QDir::System)) {
if (!info.isDir()) {
- bool usable = eligibleInterfaces.isEmpty();
+ bool usable = allowAny;
+ QString friendlyName = info.fileName();
foreach (const QString &iface, eligibleInterfaces) {
- if (info.fileName().contains(iface)) {
+ if (info.fileName().contains(QRegExp(iface))) {
if (loglevel > 1)
qDebug() << " found device file:" << info.fileName() << endl;
+#ifdef Q_OS_MAC
+ friendlyName = eligibleInterfacesInfo[eligibleInterfaces.indexOf(iface)].product;
+#endif
usable = true;
break;
}
@@ -195,7 +210,7 @@ QList<SerialPortId> enumerateSerialPorts(int loglevel)
continue;
SerialPortId id;
- id.friendlyName = info.fileName();
+ id.friendlyName = friendlyName;
id.portName = info.canonicalFilePath();
list << id;
}