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/tinycan/tinycanbackend.cpp | 46 +++++++++++++++++---------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'src/plugins/canbus/tinycan') diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp index 530959a..b86e5f9 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.cpp +++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp @@ -170,21 +170,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; @@ -195,7 +204,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; @@ -353,7 +363,8 @@ void TinyCanBackendPrivate::canWriteNotification() 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); @@ -386,7 +397,8 @@ void TinyCanBackendPrivate::canReadNotification() ::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; @@ -428,7 +440,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; } @@ -468,7 +481,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; } -- 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/tinycan/tinycanbackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/canbus/tinycan') diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp index b86e5f9..88edf25 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.cpp +++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp @@ -219,7 +219,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; } } -- cgit v1.2.3