summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/tinycan/tinycanbackend.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2016-08-01 10:14:48 +0200
committerAlex Blasche <alexander.blasche@theqtcompany.com>2016-08-01 10:14:48 +0200
commit2a5d0ab81718d4bbb2bad427edb713753ac979b9 (patch)
treebbfcf6103a248feb80f8326c1a5c67fea2a819b1 /src/plugins/canbus/tinycan/tinycanbackend.cpp
parent84c891ce502c2503f8c6cb808d600e88953aeacb (diff)
parent398eda8be9eb3415ca44cc35dad3422311d8e221 (diff)
Merge remote-tracking branch 'gerrit/5.7' into dev
Diffstat (limited to 'src/plugins/canbus/tinycan/tinycanbackend.cpp')
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.cpp49
1 files changed, 32 insertions, 17 deletions
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;
}