summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/tinycan
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2018-10-02 11:41:16 +0200
committerAndré Hartmann <aha_1980@gmx.de>2019-05-02 11:15:05 +0000
commita88ecda86028228174a1ec4e53df235ebac33dcc (patch)
tree9a39dfe2e0e85310c0450fef9be15120f9dd7ba1 /src/plugins/canbus/tinycan
parent4a7f051247b05e1e298ffabc00e8ce3dc3e216a0 (diff)
Add QCanBusDevice::resetController() for CAN controller reset
Currently missing: * VectorCAN: no information in the documentation found * PassthroughCAN: no documentation [ChangeLog][QCanBus][QCanBusDevice] Added the function QCanBusDevice::resetController() to reset a CAN controller from bus off state, as far as supported by the various plugins. Fixes: QTBUG-54943 Change-Id: Ic098054b012726c0c69970c0ae84f434c2b3964a Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/plugins/canbus/tinycan')
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.cpp24
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend.h2
-rw-r--r--src/plugins/canbus/tinycan/tinycanbackend_p.h1
3 files changed, 25 insertions, 2 deletions
diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp
index 882cb47..411b917 100644
--- a/src/plugins/canbus/tinycan/tinycanbackend.cpp
+++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp
@@ -405,8 +405,7 @@ void TinyCanBackendPrivate::startRead()
} else {
if (status.CanStatus == CAN_STATUS_BUS_OFF) {
qCWarning(QT_CANBUS_PLUGINS_TINYCAN, "CAN bus is in off state, trying to reset the bus.");
- if (::CanSetMode(channelIndex, OP_CAN_RESET, CAN_CMD_NONE) < 0)
- q->setError(systemErrorString(ret), QCanBusDevice::CanBusError::ReadError);
+ resetController();
}
}
@@ -468,6 +467,18 @@ void TinyCanBackendPrivate::cleanupDriver()
}
}
+void TinyCanBackendPrivate::resetController()
+{
+ Q_Q(TinyCanBackend);
+ qint32 ret = ::CanSetMode(channelIndex, OP_CAN_RESET, CAN_CMD_NONE);
+ if (Q_UNLIKELY(ret < 0)) {
+ const QString errorString = systemErrorString(ret);
+ qCWarning(QT_CANBUS_PLUGINS_TINYCAN, "Cannot perform hardware reset: %ls",
+ qUtf16Printable(errorString));
+ q->setError(errorString, QCanBusDevice::CanBusError::ConfigurationError);
+ }
+}
+
bool TinyCanBackendPrivate::setBitRate(int bitrate)
{
Q_Q(TinyCanBackend);
@@ -498,6 +509,9 @@ TinyCanBackend::TinyCanBackend(const QString &name, QObject *parent)
d->setupChannel(name);
d->setupDefaultConfigurations();
+
+ std::function<void()> f = std::bind(&TinyCanBackend::resetController, this);
+ setResetControllerFunction(f);
}
TinyCanBackend::~TinyCanBackend()
@@ -591,4 +605,10 @@ QString TinyCanBackend::interpretErrorFrame(const QCanBusFrame &errorFrame)
return QString();
}
+void TinyCanBackend::resetController()
+{
+ Q_D(TinyCanBackend);
+ d->resetController();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/canbus/tinycan/tinycanbackend.h b/src/plugins/canbus/tinycan/tinycanbackend.h
index 5f504ca..428e9bc 100644
--- a/src/plugins/canbus/tinycan/tinycanbackend.h
+++ b/src/plugins/canbus/tinycan/tinycanbackend.h
@@ -72,6 +72,8 @@ public:
static QList<QCanBusDeviceInfo> interfaces();
private:
+ void resetController();
+
TinyCanBackendPrivate * const d_ptr;
};
diff --git a/src/plugins/canbus/tinycan/tinycanbackend_p.h b/src/plugins/canbus/tinycan/tinycanbackend_p.h
index 905175c..25316a2 100644
--- a/src/plugins/canbus/tinycan/tinycanbackend_p.h
+++ b/src/plugins/canbus/tinycan/tinycanbackend_p.h
@@ -75,6 +75,7 @@ public:
void startRead();
void startupDriver();
void cleanupDriver();
+ void resetController();
bool setBitRate(int bitrate);