From a7a49d057613e88aba3ca98a0d8e52805f7d5bcf Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 26 Aug 2017 14:52:23 +0200 Subject: SocketCAN: Fix Clang semantic warning about old-style cast Semantic Issue -Wold-style-cast 433:17: warning: use of old-style cast Change-Id: I45ba127193a65ccca1bdf5453320fd4129666b20 Reviewed-by: Rolf Eike Beer Reviewed-by: Denis Shienkov Reviewed-by: Alex Blasche --- src/plugins/canbus/socketcan/socketcanbackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/socketcan/socketcanbackend.cpp b/src/plugins/canbus/socketcan/socketcanbackend.cpp index 021c309..14a4cde 100644 --- a/src/plugins/canbus/socketcan/socketcanbackend.cpp +++ b/src/plugins/canbus/socketcan/socketcanbackend.cpp @@ -430,7 +430,7 @@ bool SocketCanBackend::writeFrame(const QCanBusFrame &newData) if (newData.frameType() == QCanBusFrame::RemoteRequestFrame) { canId |= CAN_RTR_FLAG; } else if (newData.frameType() == QCanBusFrame::ErrorFrame) { - canId = (uint)(newData.error() & QCanBusFrame::AnyError); + canId = static_cast((newData.error() & QCanBusFrame::AnyError)); canId |= CAN_ERR_FLAG; } -- cgit v1.2.3 From a7cac26249c70519d381636a667e1c57ab90caca Mon Sep 17 00:00:00 2001 From: Marcell Varga Date: Mon, 25 Sep 2017 18:52:09 +0200 Subject: PeakCAN: Fix connect() always returning false under Linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was impossible to open a Peak CAN device under Linux, because CAN_SetValue (which is needed for the Windows implementation) always returned with error. Task-number: QTBUG-63428 Change-Id: I353bf44a7bdea4a18ef84d8037a3a9fd86d47d89 Reviewed-by: Denis Shienkov Reviewed-by: André Hartmann --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index b6eb30e..ca751cf 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -272,7 +272,6 @@ bool PeakCanBackendPrivate::open() return false; } } -#endif const TPCANStatus err = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle)); if (Q_UNLIKELY(err != PCAN_ERROR_OK)) { @@ -280,6 +279,14 @@ bool PeakCanBackendPrivate::open() return false; } +#else + const TPCANStatus err = ::CAN_GetValue(channelIndex, PCAN_RECEIVE_EVENT, &readHandle, sizeof(readHandle)); + if (Q_UNLIKELY(err != PCAN_ERROR_OK)) { + q->setError(systemErrorString(err), QCanBusDevice::ConnectionError); + return false; + } +#endif + writeNotifier = new WriteNotifier(this, q); writeNotifier->setInterval(0); -- cgit v1.2.3 From 344e9644317fe569363b15d13f8c1d4715bfc255 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Fri, 29 Sep 2017 18:07:31 +0200 Subject: PeakCAN: Avoid turning PeakCAN status frames into random data frames [ChangeLog][CanBus][PeakCAN] Peak CAN status frames are no longer converted into QCanBusFrame::DataFrame, they are simply dropped for now. In a later Qt version they might by converted into proper QCanBusFrame::ErrorFrame, together with an interpretErrorFrame() implementation. Change-Id: I673ef2c8d312a96de192def831036ad10d5f2c01 Reviewed-by: Denis Shienkov Reviewed-by: Marcell Varga Reviewed-by: Alex Blasche --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index ca751cf..075cd5d 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -420,6 +420,11 @@ void PeakCanBackendPrivate::startRead() break; } + // Filter out PCAN status frames, to avoid turning them + // into QCanBusFrame::DataFrames with random canId + if (Q_UNLIKELY(message.MSGTYPE & PCAN_MESSAGE_STATUS)) + continue; + QCanBusFrame frame(message.ID, QByteArray(reinterpret_cast(message.DATA), int(message.LEN))); const quint64 millis = timestamp.millis + Q_UINT64_C(0xFFFFFFFF) * timestamp.millis_overflow; const quint64 micros = Q_UINT64_C(1000) * millis + timestamp.micros; -- cgit v1.2.3 From a28b034aa3985571a8dc73f6a322e5b41a60992a Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Thu, 12 Oct 2017 18:28:14 +0200 Subject: PeakCAN: Remove unneeded emit Found by clazy. Change-Id: Ie04fadd3adacde9739c5cba7f566caac78f1d696 Reviewed-by: Denis Shienkov Reviewed-by: Alex Blasche --- src/plugins/canbus/peakcan/peakcanbackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index b6eb30e..8f47343 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -303,7 +303,7 @@ void PeakCanBackendPrivate::close() quint32 value = 0; const TPCANStatus err = ::CAN_SetValue(channelIndex, PCAN_RECEIVE_EVENT, &value, sizeof(value)); if (Q_UNLIKELY(err != PCAN_ERROR_OK)) - emit q->setError(systemErrorString(err), QCanBusDevice::ConnectionError); + q->setError(systemErrorString(err), QCanBusDevice::ConnectionError); const TPCANStatus st = ::CAN_Uninitialize(channelIndex); if (Q_UNLIKELY(st != PCAN_ERROR_OK)) -- cgit v1.2.3 From 9cfcc2f9868759dc679c0cf4532fb1c0883451d0 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 18 Oct 2017 21:52:21 +0200 Subject: SystecCAN: Fix device number assignment in availableDevices() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QCanBus][SystecCAN] The function availableDevices() returned the wrong device number in some cases. In turn, it was not possible to connect to the correct device afterwards. Task-number: QTBUG-63833 Change-Id: I37cc250d144596af00aec9f743f0016e5634abe7 Reviewed-by: Alex Blasche Reviewed-by: André Hartmann Reviewed-by: Denis Shienkov --- src/plugins/canbus/systeccan/systeccanbackend.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/systeccan/systeccanbackend.cpp b/src/plugins/canbus/systeccan/systeccanbackend.cpp index 652c8cb..ca63e86 100644 --- a/src/plugins/canbus/systeccan/systeccanbackend.cpp +++ b/src/plugins/canbus/systeccan/systeccanbackend.cpp @@ -67,13 +67,13 @@ static void DRV_CALLBACK_TYPE ucanEnumCallback(DWORD index, BOOL isUsed, { auto result = static_cast(args); + Q_UNUSED(index); Q_UNUSED(isUsed); - Q_UNUSED(hardwareInfo); Q_UNUSED(initInfo); - result->append(QString::fromLatin1("can%1.0").arg(index)); + result->append(QString::fromLatin1("can%1.0").arg(hardwareInfo->m_bDeviceNr)); if (USBCAN_CHECK_SUPPORT_TWO_CHANNEL(hardwareInfo)) - result->append(QString::fromLatin1("can%1.1").arg(index)); + result->append(QString::fromLatin1("can%1.1").arg(hardwareInfo->m_bDeviceNr)); } QList SystecCanBackend::interfaces() -- cgit v1.2.3 From a24e76d16ab3c3b18180e3dce554bc7696ea91c0 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Thu, 12 Oct 2017 18:34:05 +0200 Subject: TinyCAN: Fix usage of global static non-POD variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by clazy. Change-Id: Ic935fd2e9e351b1fd1399223f38afef840b623fc Reviewed-by: André Hartmann Reviewed-by: Denis Shienkov Reviewed-by: Thiago Macieira Reviewed-by: Alex Blasche --- src/plugins/canbus/tinycan/tinycanbackend.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp index 6405308..2d3488a 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.cpp +++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp @@ -73,9 +73,16 @@ QList TinyCanBackend::interfaces() return { createDeviceInfo(QStringLiteral("can0.0")), createDeviceInfo(QStringLiteral("can0.1")) }; } -Q_GLOBAL_STATIC(QList, qChannels) +namespace { -static QMutex channelsGuard(QMutex::NonRecursive); +struct TinyCanGlobal { + QList channels; + QMutex mutex; +}; + +} // namespace + +Q_GLOBAL_STATIC(TinyCanGlobal, gTinyCan) class WriteNotifier : public QTimer { @@ -108,8 +115,8 @@ static void DRV_CALLBACK_TYPE canRxEventCallback(quint32 index, TCanMsg *frame, Q_UNUSED(frame); Q_UNUSED(count); - QMutexLocker lock(&channelsGuard); - for (TinyCanBackendPrivate *p : qAsConst(*qChannels())) { + QMutexLocker lock(&gTinyCan->mutex); + for (TinyCanBackendPrivate *p : qAsConst(gTinyCan->channels)) { if (p->channelIndex == int(index)) { p->startRead(); return; @@ -122,16 +129,16 @@ TinyCanBackendPrivate::TinyCanBackendPrivate(TinyCanBackend *q) { startupDriver(); - QMutexLocker lock(&channelsGuard); - qChannels()->append(this); + QMutexLocker lock(&gTinyCan->mutex); + gTinyCan->channels.append(this); } TinyCanBackendPrivate::~TinyCanBackendPrivate() { cleanupDriver(); - QMutexLocker lock(&channelsGuard); - qChannels()->removeAll(this); + QMutexLocker lock(&gTinyCan->mutex); + gTinyCan->channels.removeAll(this); } struct BitrateItem -- cgit v1.2.3 From 60c0114e846a593895503a78d13b006f93e95675 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Wed, 25 Oct 2017 12:58:09 +0200 Subject: SystecCAN: Fix availableDevices() for more than one device initInfo->m_fTryNext is set to false when the callback is entered but must be set to true to continue with the next device. [ChangeLog][QCanBus][SystecCAN] Fixed that the function availableDevices() only returned the first device. Change-Id: I689564c2379a1db28cb7c623425aa261e44fdd4d Reviewed-by: Denis Shienkov Reviewed-by: Alex Blasche --- src/plugins/canbus/systeccan/systeccanbackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/plugins/canbus') diff --git a/src/plugins/canbus/systeccan/systeccanbackend.cpp b/src/plugins/canbus/systeccan/systeccanbackend.cpp index ca63e86..2662c42 100644 --- a/src/plugins/canbus/systeccan/systeccanbackend.cpp +++ b/src/plugins/canbus/systeccan/systeccanbackend.cpp @@ -69,11 +69,12 @@ static void DRV_CALLBACK_TYPE ucanEnumCallback(DWORD index, BOOL isUsed, Q_UNUSED(index); Q_UNUSED(isUsed); - Q_UNUSED(initInfo); result->append(QString::fromLatin1("can%1.0").arg(hardwareInfo->m_bDeviceNr)); if (USBCAN_CHECK_SUPPORT_TWO_CHANNEL(hardwareInfo)) result->append(QString::fromLatin1("can%1.1").arg(hardwareInfo->m_bDeviceNr)); + + initInfo->m_fTryNext = true; // continue enumerating with next device } QList SystecCanBackend::interfaces() -- cgit v1.2.3