diff options
Diffstat (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp')
-rw-r--r-- | src/plugins/canbus/peakcan/peakcanbackend.cpp | 32 |
1 files changed, 19 insertions, 13 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 |