From 464eb11843cabfecf108724688fe172de250782e Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 10 Jul 2016 19:15:31 +0300 Subject: Fix logic with the wrong priority of operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assignment '=' operator has a lower priority, than the comparison '==, !=' operators. Thus, the result of logical statements is wrong. Change-Id: Iab281f1f3dd95b59da94379fd68a45f75e2dd5ac Reviewed-by: Marc Mutz Reviewed-by: AndrĂ© Hartmann Reviewed-by: Alex Blasche --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 98c8117..7d54e18 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -205,13 +205,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; } @@ -232,7 +234,8 @@ void PeakCanBackendPrivate::close() outgoingEventNotifier = nullptr; } - if (TPCANStatus st = ::CAN_Uninitialize(channelIndex) != PCAN_ERROR_OK) + const TPCANStatus st = ::CAN_Uninitialize(channelIndex); + if (st != PCAN_ERROR_OK) emit q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); isOpen = false; @@ -352,7 +355,8 @@ void PeakCanBackendPrivate::canWriteNotification() 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)); @@ -375,8 +379,9 @@ bool PeakCanBackendPrivate::acquireReadNotification() } #endif - if (TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &incomingEventHandle, sizeof(incomingEventHandle)) - != PCAN_ERROR_OK) { + const TPCANStatus st = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, + &incomingEventHandle, sizeof(incomingEventHandle)); + if (st != PCAN_ERROR_OK) { q->setError(systemErrorString(st), QCanBusDevice::ReadError); return false; } @@ -394,7 +399,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 (incomingEventNotifier) { @@ -425,7 +431,8 @@ void PeakCanBackendPrivate::canReadNotification() 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; -- cgit v1.2.3 From 30710cce8f5c4babba0582bfa2ec751afa8e90b4 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sun, 17 Jul 2016 17:21:50 +0200 Subject: PeakCAN: Do not close interface when open fails Trying to close an interface that is not open leads to errors which fill the internal error message buffer with unrelated errors like "full write buffer". Instead, the error should indicate that open failed. As QCanBusDevice::connectDevice() already sets UnconnectedState, this does not need to be done here. Change-Id: I61c73c9d51e05eb5ea80a13e1c706e4a3eca98c0 Reviewed-by: Alex Blasche Reviewed-by: Denis Shienkov --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 7d54e18..5b06007 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -493,10 +493,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 -- cgit v1.2.3 From 11cdcd8c7bc53b40f87c934f00b384536a5008d2 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Mon, 18 Jul 2016 19:17:51 +0200 Subject: CAN: More information when configuration fails ... for PEAK and TINY backends. Change-Id: I0285107616bbfbaa91df266e2116f5d7460d60ca Reviewed-by: Alex Blasche --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 5b06007..f717111 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -249,7 +249,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; } } -- cgit v1.2.3 From 56ee21cdd66d72f7f858d72f731636e9903795dc Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 20 Jul 2016 06:33:19 +0200 Subject: PeakCAN: Remove unneeded emit QCanBusDevice::setError() is no SIGNAL, but a protected member function. Change-Id: I10e83d189d3df93504b759729d0c4fc5caa682b0 Reviewed-by: Alex Blasche Reviewed-by: Denis Shienkov --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/canbus/peakcan/peakcanbackend.cpp') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index f717111..7e954c2 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -236,7 +236,7 @@ void PeakCanBackendPrivate::close() const TPCANStatus st = ::CAN_Uninitialize(channelIndex); if (st != PCAN_ERROR_OK) - emit q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); + q->setError(systemErrorString(st), QCanBusDevice::ConnectionError); isOpen = false; } -- cgit v1.2.3