diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-26 12:45:10 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-26 12:45:10 +0200 |
commit | 88554d068d287870740b842864a50604f53e8509 (patch) | |
tree | a5ab19d45570ad111b7b9ee60613d9f01247b584 /src | |
parent | eba0e3f243da949789871c3884c0ba158a3f6948 (diff) | |
parent | 36b24743ccecd56b132cd81f05842943ff716943 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
src/plugins/canbus/peakcan/peakcanbackend.cpp
One side renamed a member.
The other changed some code using it.
Change-Id: I14131122835ab9014894eadf4b529bdfd413e436
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend.cpp | 32 | ||||
-rw-r--r-- | src/plugins/canbus/tinycan/tinycanbackend.cpp | 49 | ||||
-rw-r--r-- | src/serialbus/doc/src/peakcan.qdoc | 17 | ||||
-rw-r--r-- | src/serialbus/doc/src/qtcanbus-backends.qdoc | 4 | ||||
-rw-r--r-- | src/serialbus/doc/src/socketcan.qdoc | 16 | ||||
-rw-r--r-- | src/serialbus/doc/src/tinycan.qdoc | 17 | ||||
-rw-r--r-- | src/serialbus/qcanbusdevice.cpp | 18 | ||||
-rw-r--r-- | src/tools/canbusutil/readtask.cpp | 19 |
8 files changed, 101 insertions, 71 deletions
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index ca666cf..920b2c0 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -208,13 +208,15 @@ bool PeakCanBackendPrivate::open() const int bitrate = q->configurationParameter(QCanBusDevice::BitRateKey).toInt(); const int bitrateCode = bitrateCodeFromBitrate(bitrate); - if (TPCANStatus st = ::CAN_Initialize(channelIndex, bitrateCode, 0, 0, 0) != PCAN_ERROR_OK) { + const TPCANStatus st = ::CAN_Initialize(channelIndex, bitrateCode, 0, 0, 0); + if (st != PCAN_ERROR_OK) { q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); return false; } if (!acquireReadNotification()) { - if (TPCANStatus st = ::CAN_Uninitialize(channelIndex) != PCAN_ERROR_OK) + const TPCANStatus st = ::CAN_Uninitialize(channelIndex); + if (st != PCAN_ERROR_OK) q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); return false; } @@ -235,8 +237,9 @@ void PeakCanBackendPrivate::close() writeNotifier = nullptr; } - if (TPCANStatus st = ::CAN_Uninitialize(channelIndex) != PCAN_ERROR_OK) - emit q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); + const TPCANStatus st = ::CAN_Uninitialize(channelIndex); + if (st != PCAN_ERROR_OK) + q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); isOpen = false; } @@ -249,7 +252,8 @@ bool PeakCanBackendPrivate::setConfigurationParameter(int key, const QVariant &v case QCanBusDevice::BitRateKey: return verifyBitRate(value.toInt()); default: - q->setError(PeakCanBackend::tr("Unsupported configuration key"), QCanBusDevice::ConfigurationError); + q->setError(PeakCanBackend::tr("Unsupported configuration key: %1").arg(key), + QCanBusDevice::ConfigurationError); return false; } } @@ -355,7 +359,8 @@ void PeakCanBackendPrivate::startWrite() else ::memcpy(message.DATA, payload.constData(), sizeof(message.DATA)); - if (TPCANStatus st = ::CAN_Write(channelIndex, &message) != PCAN_ERROR_OK) + const TPCANStatus st = ::CAN_Write(channelIndex, &message); + if (st != PCAN_ERROR_OK) q->setError(systemErrorString(st), QCanBusDevice::WriteError); else emit q->framesWritten(qint64(1)); @@ -378,8 +383,9 @@ bool PeakCanBackendPrivate::acquireReadNotification() } #endif - if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle)) - != PCAN_ERROR_OK) { + const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, + &readHandle, sizeof(readHandle)); + if (st != PCAN_ERROR_OK) { q->setError(systemErrorString(st), QCanBusDevice::ReadError); return false; } @@ -397,7 +403,8 @@ void PeakCanBackendPrivate::releaseReadNotification() Q_Q(PeakCanBackend); quint32 value = 0; - if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)) != PCAN_ERROR_OK) + const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)); + if (st != PCAN_ERROR_OK) q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); if (readNotifier) { @@ -428,7 +435,8 @@ void PeakCanBackendPrivate::startRead() TPCANTimestamp timestamp; ::memset(×tamp, 0, sizeof(timestamp)); - if (TPCANStatus st = ::CAN_Read(channelIndex, &message, ×tamp) != PCAN_ERROR_OK) { + const TPCANStatus st = ::CAN_Read(channelIndex, &message, ×tamp); + if (st != PCAN_ERROR_OK) { if (st != PCAN_ERROR_XMTFULL) q->setError(systemErrorString(st), QCanBusDevice::ReadError); break; @@ -489,10 +497,8 @@ bool PeakCanBackend::open() Q_D(PeakCanBackend); if (!d->isOpen) { - if (!d->open()) { - close(); // sets UnconnectedState + if (!d->open()) return false; - } // apply all stored configurations except bitrate, because // the bitrate can not be applied after opening of device diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp index 43640cc..f1d7c5c 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.cpp +++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp @@ -171,21 +171,30 @@ bool TinyCanBackendPrivate::open() { Q_Q(TinyCanBackend); - char options[] = "AutoConnect=1;AutoReopen=0"; - if (int ret = ::CanSetOptions(options) < 0) { - q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); - return false; + { + char options[] = "AutoConnect=1;AutoReopen=0"; + const int ret = ::CanSetOptions(options); + if (ret < 0) { + q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); + return false; + } } - if (int ret = ::CanDeviceOpen(channelIndex, nullptr) < 0) { - q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); - return false; + { + const int ret = ::CanDeviceOpen(channelIndex, nullptr); + if (ret < 0) { + q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); + return false; + } } - if (int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR) < 0) { - q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); - ::CanDeviceClose(channelIndex); - return false; + { + const int ret = ::CanSetMode(channelIndex, OP_CAN_START, CAN_CMD_ALL_CLEAR); + if (ret < 0) { + q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); + ::CanDeviceClose(channelIndex); + return false; + } } isOpen = true; @@ -196,7 +205,8 @@ void TinyCanBackendPrivate::close() { Q_Q(TinyCanBackend); - if (int ret = ::CanDeviceClose(channelIndex) < 0) + const int ret = ::CanDeviceClose(channelIndex); + if (ret < 0) q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); isOpen = false; @@ -210,7 +220,8 @@ bool TinyCanBackendPrivate::setConfigurationParameter(int key, const QVariant &v case QCanBusDevice::BitRateKey: return setBitRate(value.toInt()); default: - q->setError(TinyCanBackend::tr("Unsupported configuration key"), QCanBusDevice::ConfigurationError); + q->setError(TinyCanBackend::tr("Unsupported configuration key: %1").arg(key), + QCanBusDevice::ConfigurationError); return false; } } @@ -354,7 +365,8 @@ void TinyCanBackendPrivate::startWrite() const qint32 messagesToWrite = 1; ::memcpy(message.Data.Bytes, payload.constData(), sizeof(message.Data.Bytes)); - if (int ret = ::CanTransmit(channelIndex, &message, messagesToWrite) < 0) + const int ret = ::CanTransmit(channelIndex, &message, messagesToWrite); + if (ret < 0) q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::WriteError); else emit q->framesWritten(messagesToWrite); @@ -387,7 +399,8 @@ void TinyCanBackendPrivate::startRead() ::memset(&message, 0, sizeof(message)); const int messagesToRead = 1; - if (int ret = ::CanReceive(channelIndex, &message, messagesToRead) < 0) { + const int ret = ::CanReceive(channelIndex, &message, messagesToRead); + if (ret < 0) { q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ReadError); TDeviceStatus status; @@ -429,7 +442,8 @@ void TinyCanBackendPrivate::startupDriver() Q_Q(TinyCanBackend); if (driverRefCount == 0) { - if (int ret = ::CanInitDriver(nullptr) < 0) { + const int ret = ::CanInitDriver(nullptr); + if (ret < 0) { q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); return; } @@ -469,7 +483,8 @@ bool TinyCanBackendPrivate::setBitRate(int bitrate) } if (isOpen) { - if (int ret = ::CanSetSpeed(channelIndex, bitrateCode) < 0) { + const int ret = ::CanSetSpeed(channelIndex, bitrateCode); + if (ret < 0) { q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConfigurationError); return false; } diff --git a/src/serialbus/doc/src/peakcan.qdoc b/src/serialbus/doc/src/peakcan.qdoc index 4ab8760..3b18393 100644 --- a/src/serialbus/doc/src/peakcan.qdoc +++ b/src/serialbus/doc/src/peakcan.qdoc @@ -31,7 +31,7 @@ \brief Overview of how to use the PeakCAN backend. The PeakCAN backend encapsulates the low-level API to work with the - \l{http://www.peak-system.com/}{PCAN} adapters. + \l{http://www.peak-system.com/}{PEAK-System} CAN adapters. \section1 Creating CAN Bus Devices @@ -46,23 +46,22 @@ } \endcode - Where, \e peakcan is the backend name. + Where \e peakcan is the backend name. - Further, it is necessary to request from QCanBus the device with the active PeakCan - interface: + Next, a connection to a specific interface can be established: \code QCanBusDevice *device = QCanBus::instance()->createDevice("peakcan", QStringLiteral("usbbus1")); device->connectDevice(); \endcode - Where, \e usbbus1 is the active CAN interface name. The PCAN API support eight USB - interfaces from \e usbbus1 to \e usbbus8 and eight PCI interfaces from \e pcibus1 to - \e pcibus8. + Where \e usbbus1 is the active CAN interface name. The PeakCAN backend supports + eight USB interfaces from \e usbbus1 to \e usbbus8 and eight PCI interfaces from + \e pcibus1 to \e pcibus8. \note Only the USB and PCI adapters are currently supported by this backend. - The device is now open and can be written and read: + The device is now open for writing and reading CAN frames: \code QCanBusFrame frame; @@ -88,7 +87,7 @@ \li Configuration parameter key \li Description \row - \li QDCanBusDevice::BitRateKey + \li QCanBusDevice::BitRateKey \li Determines the bit rate of the CAN bus connection. The following bit rates are supported: 5000, 10000, 20000, 33000, 47000, 50000, 83000, 95000, 100000, 125000, 250000, 500000, 800000, 1000000. Note that this configuration diff --git a/src/serialbus/doc/src/qtcanbus-backends.qdoc b/src/serialbus/doc/src/qtcanbus-backends.qdoc index 6f32c5e..a2f504e 100644 --- a/src/serialbus/doc/src/qtcanbus-backends.qdoc +++ b/src/serialbus/doc/src/qtcanbus-backends.qdoc @@ -60,11 +60,11 @@ \row \li PEAK-System \li \l {Using PeakCAN Backend}{PeakCAN} (\c peakcan) - \li CAN bus backend using the PCAN adapters. + \li CAN bus backend using the PEAK CAN adapters. \row \li MHS Elektronik \li \l {Using TinyCAN Backend}{TinyCAN} (\c tinycan) - \li CAN bus backend using the Tiny-CAN adapters. + \li CAN bus backend using the MHS CAN adapters. \endtable \section1 Implementing a Custom CAN Plugin diff --git a/src/serialbus/doc/src/socketcan.qdoc b/src/serialbus/doc/src/socketcan.qdoc index 4a10ac7..a979103 100644 --- a/src/serialbus/doc/src/socketcan.qdoc +++ b/src/serialbus/doc/src/socketcan.qdoc @@ -47,20 +47,19 @@ } \endcode - Where, \e socketcan is the backend name. + Where \e socketcan is the backend name. - Further, it is necessary to request from QCanBus the device with the active SocketCAN - interface: + Next, a connection to a specific interface can be established: \code QCanBusDevice *device = QCanBus::instance()->createDevice("socketcan", QStringLiteral("can0")); device->connectDevice(); \endcode - Where, \e can0 is the active CAN interface name. CAN interfaces act like regular network interfaces - on Linux systems and can be discovered using \c ifconfig. + Where \e can0 is the active CAN interface name. CAN interfaces act like regular + network interfaces on Linux systems and can be discovered using \c ifconfig. - The device is now open and can be written and read: + The device is now open for writing and reading CAN frames: \code QCanBusFrame frame; @@ -106,7 +105,8 @@ \row \li QCanBusDevice::BitRateKey \li This configuration is not supported by the socketcan backend. However - it is possible to set the rate when configuring the CAN network interface using the \c {ip link} command. + it is possible to set the rate when configuring the CAN network interface using + the \c {ip link} command. \row \li QCanBusDevice::CanFdKey \li This configuration option determines whether CANFD frames may be sent or received. @@ -118,5 +118,5 @@ \snippet snippetmain.cpp SocketCan Filter Example - Efficient frame format and flexible data-rate are supported in SocketCAN. + Extended frame format and flexible data-rate are supported in SocketCAN. */ diff --git a/src/serialbus/doc/src/tinycan.qdoc b/src/serialbus/doc/src/tinycan.qdoc index c5156e4..da45775 100644 --- a/src/serialbus/doc/src/tinycan.qdoc +++ b/src/serialbus/doc/src/tinycan.qdoc @@ -31,7 +31,7 @@ \brief Overview of how to use the TinyCAN backend. The TinyCAN backend encapsulates the low-level API to work with the - \l{http://www.mhs-elektronik.de/}{Tiny-CAN} adapters. + \l{http://www.mhs-elektronik.de/}{MHS Elektronik} CAN adapters. \section1 Creating CAN Bus Devices @@ -46,22 +46,21 @@ } \endcode - Where, \e tinycan is the backend name. + Where \e tinycan is the backend name. - Further, it is necessary to request from QCanBus the device with the active Tiny-CAN - interface: + Next, a connection to a specific interface can be established: \code QCanBusDevice *device = QCanBus::instance()->createDevice("tinycan", QStringLiteral("channela")); device->connectDevice(); \endcode - Where, \e channela is the active CAN interface name. The Tiny-CAN API provides only two - interfaces \e channela and \e channelb. + Where \e channela is the active CAN interface name. The TinyCAN backend + provides two interfaces, \e channela and \e channelb. \note Only the USB adapters are currently supported by this backend. - The device is now open and can be written and read: + The device is now open for writing and reading CAN frames: \code QCanBusFrame frame; @@ -79,7 +78,7 @@ QCanBusFrame frame = device->readFrame(); \endcode - Tiny-CAN supports the following configurations that can be controlled through + TinyCAN supports the following configurations that can be controlled through \l {QCanBusDevice::}{setConfigurationParameter()}: \table @@ -87,7 +86,7 @@ \li Configuration parameter key \li Description \row - \li QDCanBusDevice::BitRateKey + \li QCanBusDevice::BitRateKey \li Determines the bit rate of the CAN bus connection. The following bit rates are supported: 10000, 20000, 50000, 100000, 125000, 250000, 500000, 800000, 1000000. \endtable diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp index a08a339..00505bf 100644 --- a/src/serialbus/qcanbusdevice.cpp +++ b/src/serialbus/qcanbusdevice.cpp @@ -42,8 +42,6 @@ #include <QtCore/qdebug.h> #include <QtCore/qdatastream.h> -#define SOCKET_CAN_MTU 72 - QT_BEGIN_NAMESPACE /*! @@ -298,8 +296,7 @@ bool QCanBusDevice::hasOutgoingFrames() const \sa configurationParameter() */ -void QCanBusDevice::setConfigurationParameter(int key, - const QVariant &value) +void QCanBusDevice::setConfigurationParameter(int key, const QVariant &value) { Q_D(QCanBusDevice); @@ -523,8 +520,11 @@ bool QCanBusDevice::connectDevice() { Q_D(QCanBusDevice); - if (d->state != QCanBusDevice::UnconnectedState) + if (d->state != QCanBusDevice::UnconnectedState) { + setError(tr("Can not connect an already connected device"), + QCanBusDevice::ConnectionError); return false; + } setState(ConnectingState); @@ -545,6 +545,14 @@ bool QCanBusDevice::connectDevice() */ void QCanBusDevice::disconnectDevice() { + Q_D(QCanBusDevice); + + if (d->state == QCanBusDevice::UnconnectedState + || d->state == QCanBusDevice::ClosingState) { + qWarning("Can not disconnect an unconnected device"); + return; + } + setState(QCanBusDevice::ClosingState); //Unconnected is set by backend -> might be delayed by event loop diff --git a/src/tools/canbusutil/readtask.cpp b/src/tools/canbusutil/readtask.cpp index bb9b344..a83586e 100644 --- a/src/tools/canbusutil/readtask.cpp +++ b/src/tools/canbusutil/readtask.cpp @@ -58,16 +58,19 @@ void ReadTask::checkMessages() { if (frame.frameType() == QCanBusFrame::ErrorFrame) { view = canDevice->interpretErrorFrame(frame); } else { - view += QLatin1String("Id: "); - view += QString::number(id, 16); + const char *format = + frame.hasExtendedFrameFormat() ? "Id: %08X" : "Id: %03X"; + view += QString::asprintf(format, static_cast<uint>(id)); view += QLatin1String(" bytes: "); view += QString::number(dataLength, 10); - view += QLatin1String(" data:"); - QByteArray array = frame.payload(); - for (int i=0; i < array.size(); i++) { - view += QLatin1String(" 0x"); - quint8 number = array[i]; - view += QString::number(number, 16); + if (frame.frameType() != QCanBusFrame::RemoteRequestFrame) { + view += QLatin1String(" data:"); + QByteArray array = frame.payload(); + for (int i=0; i < array.size(); i++) { + view += QLatin1String(" 0x"); + quint8 number = array[i]; + view += QString::number(number, 16); + } } } |