diff options
author | Sergey Belyashov <Sergey.Belyashov@gmail.com> | 2014-05-15 11:11:56 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-24 19:49:54 +0200 |
commit | c711f3870605d58218e0ca9a52a7aac296ecd396 (patch) | |
tree | 222b98523588e641321a7d429c7d60782e16df2e /src/serialport/qserialportinfo_unix.cpp | |
parent | 63d3fc0c0679a801da54cf390728120338fbd187 (diff) |
Add support for PCI vendor/device information
Tested on Linux x86_64 with Qt 5.1.1
Change-Id: Ibea1204ece921c2c18ee37992380fbc33897be8d
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialportinfo_unix.cpp')
-rw-r--r-- | src/serialport/qserialportinfo_unix.cpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp index 783105eb..4fc66508 100644 --- a/src/serialport/qserialportinfo_unix.cpp +++ b/src/serialport/qserialportinfo_unix.cpp @@ -192,6 +192,17 @@ QList<QSerialPortInfo> availablePortsBySysfs() } while (targetDir.cdUp()); } else if (targetPath.contains(QStringLiteral("pci"))) { + QDir targetDir(targetPath + QStringLiteral("/device")); + QFile vendorIdentifier(QFileInfo(targetDir, QStringLiteral("vendor")).absoluteFilePath()); + if (vendorIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { + serialPortInfo.d_ptr->vendorIdentifier = QString::fromLatin1(vendorIdentifier.readAll()) + .toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + } + QFile productIdentifier(QFileInfo(targetDir, QStringLiteral("device")).absoluteFilePath()); + if (productIdentifier.open(QIODevice::ReadOnly | QIODevice::Text)) { + serialPortInfo.d_ptr->productIdentifier = QString::fromLatin1(productIdentifier.readAll()) + .toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + } // TODO: Obtain more information about the device } else { continue; @@ -217,6 +228,12 @@ struct ScopedPointerUdevDeleter Q_GLOBAL_STATIC(QLibrary, udevLibrary) #endif +static +QString getUdevPropertyValue(struct ::udev_device *dev, const char *name) +{ + return QString::fromLatin1(::udev_device_get_property_value(dev, name)); +} + QList<QSerialPortInfo> availablePortsByUdev() { #ifndef LINK_LIBUDEV @@ -263,28 +280,36 @@ QList<QSerialPortInfo> availablePortsByUdev() if (subsys == QStringLiteral("usb-serial") || subsys == QStringLiteral("usb")) { - serialPortInfo.d_ptr->description = QString::fromLatin1(::udev_device_get_property_value(dev.data(), - "ID_MODEL")).replace(QLatin1Char('_'), QLatin1Char(' ')); - serialPortInfo.d_ptr->manufacturer = QString::fromLatin1(::udev_device_get_property_value(dev.data(), - "ID_VENDOR")).replace(QLatin1Char('_'), QLatin1Char(' ')); + serialPortInfo.d_ptr->description = + getUdevPropertyValue(dev.data(), "ID_MODEL").replace(QLatin1Char('_'), QLatin1Char(' ')); + + serialPortInfo.d_ptr->manufacturer = + getUdevPropertyValue(dev.data(), "ID_VENDOR").replace(QLatin1Char('_'), QLatin1Char(' ')); - serialPortInfo.d_ptr->serialNumber = QString( - QLatin1String(::udev_device_get_property_value(dev.data(), "ID_SERIAL_SHORT"))); + serialPortInfo.d_ptr->serialNumber = getUdevPropertyValue(dev.data(),"ID_SERIAL_SHORT"); serialPortInfo.d_ptr->vendorIdentifier = - QString::fromLatin1(::udev_device_get_property_value(dev.data(), - "ID_VENDOR_ID")).toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + getUdevPropertyValue(dev.data(), "ID_VENDOR_ID").toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); serialPortInfo.d_ptr->productIdentifier = - QString::fromLatin1(::udev_device_get_property_value(dev.data(), - "ID_MODEL_ID")).toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); + getUdevPropertyValue(dev.data(), "ID_MODEL_ID").toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); } else if (subsys == QStringLiteral("pnp")) { // TODO: Obtain more information } else if (subsys == QStringLiteral("platform")) { continue; } else if (subsys == QStringLiteral("pci")) { - // TODO: Obtain more information about the device + serialPortInfo.d_ptr->description = + getUdevPropertyValue(dev.data(), "ID_MODEL"); + + serialPortInfo.d_ptr->manufacturer = + getUdevPropertyValue(dev.data(), "ID_VENDOR"); + + serialPortInfo.d_ptr->vendorIdentifier = + getUdevPropertyValue(dev.data(), "ID_VENDOR_ID").toInt(&serialPortInfo.d_ptr->hasVendorIdentifier, 16); + + serialPortInfo.d_ptr->productIdentifier = + getUdevPropertyValue(dev.data(), "ID_MODEL_ID").toInt(&serialPortInfo.d_ptr->hasProductIdentifier, 16); } else { // FIXME: Obtain more information } |