diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2019-07-15 15:44:50 +0200 |
---|---|---|
committer | Andre Hartmann <aha_1980@gmx.de> | 2019-07-24 10:57:36 +0200 |
commit | 9f5b8ba590d424f82498fca5f2cc8594b1757ff0 (patch) | |
tree | 5489ac4be297bb4576f37d5d0c401529e5398297 /src/plugins/canbus/socketcan/socketcanbackend.cpp | |
parent | e39d9396428c3d078313b50fa1ff65662096debc (diff) |
SocketCAN: Allow specifying the protocol to use
So far, only CAN_RAW was allowed, but there might be
cases where other protocols are useful too.
The default value is still CAN_RAW, so all existing
applications will continue working.
[ChangeLog][SocketCAN] Added the configuration parameter
QCanBusDevice::ProtocolKey to use another protocol
inside the protocol family PF_CAN.
Fixes: QTBUG-75204
Change-Id: I8323ab8d77a569f51d3cd8c296b433352a3f5609
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/canbus/socketcan/socketcanbackend.cpp')
-rw-r--r-- | src/plugins/canbus/socketcan/socketcanbackend.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/plugins/canbus/socketcan/socketcanbackend.cpp b/src/plugins/canbus/socketcan/socketcanbackend.cpp index 27fa326..2ed1310 100644 --- a/src/plugins/canbus/socketcan/socketcanbackend.cpp +++ b/src/plugins/canbus/socketcan/socketcanbackend.cpp @@ -389,7 +389,7 @@ bool SocketCanBackend::connectSocket() { struct ifreq interface; - if (Q_UNLIKELY((canSocket = socket(PF_CAN, SOCK_RAW | SOCK_NONBLOCK, CAN_RAW)) < 0)) { + if (Q_UNLIKELY((canSocket = socket(PF_CAN, SOCK_RAW | SOCK_NONBLOCK, protocol)) < 0)) { setError(qt_error_string(errno), QCanBusDevice::CanBusError::ConnectionError); return false; @@ -464,6 +464,16 @@ void SocketCanBackend::setConfigurationParameter(int key, const QVariant &value) return; } } + } else if (key == QCanBusDevice::ProtocolKey) { + bool ok = false; + const int newProtocol = value.toInt(&ok); + if (Q_UNLIKELY(!ok || (newProtocol < 0))) { + const QString errorString = tr("Cannot set protocol to value %1.").arg(value.toString()); + setError(errorString, QCanBusDevice::ConfigurationError); + qCWarning(QT_CANBUS_PLUGINS_SOCKETCAN, "%ls", qUtf16Printable(errorString)); + return; + } + protocol = newProtocol; } // connected & params not applyable/invalid if (canSocket != -1 && !applyConfigurationParameter(key, value)) |