From 0efc71b7af2818f2f40438b2807efe361352f7a9 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 9 Jul 2010 14:31:04 +0200 Subject: Linux runonphone - tell the user which driver to load The linux usbserial driver doesn't attach to devices automatically, to avoid conflicts with the real driver (if there is one). So the user must run modprobe to load the driver before runonphone can be used. Since runonphone has found the correct device(s) using libusb, this patch will tell the user the modprobe command that is required to load the generic usbserial driver. Reviewed-By: Gareth Stockwell --- tools/runonphone/serenum_unix.cpp | 51 ++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/tools/runonphone/serenum_unix.cpp b/tools/runonphone/serenum_unix.cpp index 4c90d7a..db6375e 100644 --- a/tools/runonphone/serenum_unix.cpp +++ b/tools/runonphone/serenum_unix.cpp @@ -48,9 +48,32 @@ #include +class InterfaceInfo +{ +public: + InterfaceInfo(const QString &mf, const QString &pr, int mfid, int prid); + QString manufacturer; + QString product; + int manufacturerid; + int productid; +}; + +InterfaceInfo::InterfaceInfo(const QString &mf, const QString &pr, int mfid, int prid) : + manufacturer(mf), + product(pr), + manufacturerid(mfid), + productid(prid) +{ + if(mf.isEmpty()) + manufacturer = QString("[%1]").arg(mfid, 4, 16, QChar('0')); + if(pr.isEmpty()) + product = QString("[%1]").arg(prid, 4, 16, QChar('0')); +} + QList enumerateSerialPorts(int loglevel) { - QList eligableInterfaces; + QList eligibleInterfaces; + QList eligibleInterfacesInfo; QList list; usb_init(); @@ -137,13 +160,14 @@ QList enumerateSerialPorts(int loglevel) } // ### manufacturer and product strings are only readable as root :( if (!manufacturerString.isEmpty() && !productString.isEmpty()) { - eligableInterfaces << QString("usb-%1_%2-if%3") + eligibleInterfaces << QString("usb-%1_%2-if%3") .arg(manufacturerString.replace(QChar(' '), QChar('_'))) .arg(productString.replace(QChar(' '), QChar('_'))) .arg(i, 2, 16, QChar('0')); } else { - eligableInterfaces << QString("if%1").arg(i, 2, 16, QChar('0')); // fix! + eligibleInterfaces << QString("if%1").arg(i, 2, 16, QChar('0')); // fix! } + eligibleInterfacesInfo << InterfaceInfo(manufacturerString, productString, device->descriptor.idVendor, device->descriptor.idProduct); } } } @@ -153,13 +177,13 @@ QList enumerateSerialPorts(int loglevel) } if (loglevel > 1) - qDebug() << " searching for interfaces:" << eligableInterfaces; + qDebug() << " searching for interfaces:" << eligibleInterfaces; QDir dir("/dev/serial/by-id/"); foreach (const QFileInfo &info, dir.entryInfoList()) { if (!info.isDir()) { - bool usable = eligableInterfaces.isEmpty(); - foreach (const QString &iface, eligableInterfaces) { + bool usable = eligibleInterfaces.isEmpty(); + foreach (const QString &iface, eligibleInterfaces) { if (info.fileName().contains(iface)) { if (loglevel > 1) qDebug() << " found device file:" << info.fileName() << endl; @@ -176,6 +200,21 @@ QList enumerateSerialPorts(int loglevel) list << id; } } + + if (list.isEmpty() && !eligibleInterfacesInfo.isEmpty() && loglevel > 0) { + qDebug() << "Possible USB devices found, but without serial drivers:"; + foreach(const InterfaceInfo &iface, eligibleInterfacesInfo) { + qDebug() << " Manufacturer:" + << iface.manufacturer + << "Product:" + << iface.product + << endl + << " Load generic driver using:" + << QString("sudo modprobe usbserial vendor=0x%1 product=0x%2") + .arg(iface.manufacturerid, 4, 16, QChar('0')) + .arg(iface.productid, 4, 16, QChar('0')); + } + } return list; } -- cgit v0.12