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/plugins/canbus/tinycan | |
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/plugins/canbus/tinycan')
-rw-r--r-- | src/plugins/canbus/tinycan/tinycanbackend.cpp | 49 |
1 files changed, 32 insertions, 17 deletions
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; } |