summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp32
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.cpp49
2 files changed, 51 insertions, 30 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(&timestamp, 0, sizeof(timestamp));
- if (TPCANStatus st = ::CAN_Read(channelIndex, &message, &timestamp) != PCAN_ERROR_OK) {
+ const TPCANStatus st = ::CAN_Read(channelIndex, &message, &timestamp);
+ 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
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;
}