diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-08-02 06:58:40 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2016-08-02 06:58:40 +0000 |
commit | 96107d21b20aa1e6c9d02ea6e592d564f0400a7e (patch) | |
tree | f704d722dedb2be8e9b9f535086a42359aa364ac /src/plugins/canbus | |
parent | f3248db1af9f0c9688c7e8bef4a8333aaedb0d83 (diff) | |
parent | 2a5d0ab81718d4bbb2bad427edb713753ac979b9 (diff) |
Merge "Merge remote-tracking branch 'gerrit/5.7' into dev" into refs/staging/dev
Diffstat (limited to 'src/plugins/canbus')
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend.cpp | 34 | ||||
-rw-r--r-- | src/plugins/canbus/tinycan/tinycanbackend.cpp | 49 |
2 files changed, 50 insertions, 33 deletions
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 4e733fc..06a2d4b 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -208,7 +208,8 @@ 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; } @@ -223,9 +224,9 @@ bool PeakCanBackendPrivate::open() } #endif - if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle)) - != PCAN_ERROR_OK) { - q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); + const TPCANStatus err = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle)); + if (err != PCAN_ERROR_OK) { + q->setError(systemErrorString(err), QCanBusDevice::ConnectionError); return false; } @@ -250,13 +251,13 @@ void PeakCanBackendPrivate::close() writeNotifier = nullptr; quint32 value = 0; - if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)) - != PCAN_ERROR_OK) { - emit q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); - } + const TPCANStatus err = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)); + if (err != PCAN_ERROR_OK) + emit q->setError(systemErrorString(err), QCanBusDevice::ConnectionError); - 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); #if defined(Q_OS_WIN32) if (readHandle && (readHandle != INVALID_HANDLE_VALUE)) { @@ -279,7 +280,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; } } @@ -367,7 +369,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)); @@ -388,7 +391,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; @@ -449,10 +453,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 4a36918..2f9c191 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; + } } writeNotifier = new WriteNotifier(this, q); @@ -202,7 +211,8 @@ void TinyCanBackendPrivate::close() delete writeNotifier; writeNotifier = nullptr; - if (int ret = ::CanDeviceClose(channelIndex) < 0) + const int ret = ::CanDeviceClose(channelIndex); + if (ret < 0) q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ConnectionError); isOpen = false; @@ -216,7 +226,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; } } @@ -342,7 +353,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); @@ -367,7 +379,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; @@ -409,7 +422,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; } @@ -450,7 +464,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; } |