diff options
Diffstat (limited to 'src')
75 files changed, 314 insertions, 168 deletions
diff --git a/src/plugins/canbus/canbus.pro b/src/plugins/canbus/canbus.pro index 7d70bb9..37db8a3 100644 --- a/src/plugins/canbus/canbus.pro +++ b/src/plugins/canbus/canbus.pro @@ -6,5 +6,7 @@ qtConfig(socketcan) { SUBDIRS += socketcan } -SUBDIRS += peakcan tinycan -win32:SUBDIRS += systeccan vectorcan +qtConfig(library) { + SUBDIRS += peakcan tinycan + win32:SUBDIRS += systeccan vectorcan +} diff --git a/src/plugins/canbus/peakcan/main.cpp b/src/plugins/canbus/peakcan/main.cpp index 453124b..7444f6d 100644 --- a/src/plugins/canbus/peakcan/main.cpp +++ b/src/plugins/canbus/peakcan/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -43,12 +43,11 @@ QT_BEGIN_NAMESPACE -class PeakCanBusPlugin : public QObject, public QCanBusFactory +class PeakCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactory) - + Q_INTERFACES(QCanBusFactoryV2) public: QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override diff --git a/src/plugins/canbus/peakcan/peakcan_symbols_p.h b/src/plugins/canbus/peakcan/peakcan_symbols_p.h index a265383..7c91750 100644 --- a/src/plugins/canbus/peakcan/peakcan_symbols_p.h +++ b/src/plugins/canbus/peakcan/peakcan_symbols_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp index 7d4e123..b6eb30e 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.cpp +++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -400,7 +400,7 @@ void PeakCanBackendPrivate::startRead() QVector<QCanBusFrame> newFrames; - forever { + for (;;) { TPCANMsg message; ::memset(&message, 0, sizeof(message)); TPCANTimestamp timestamp; diff --git a/src/plugins/canbus/peakcan/peakcanbackend.h b/src/plugins/canbus/peakcan/peakcanbackend.h index f806d05..7f7083e 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend.h +++ b/src/plugins/canbus/peakcan/peakcanbackend.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/peakcan/peakcanbackend_p.h b/src/plugins/canbus/peakcan/peakcanbackend_p.h index 8ecbe57..a6c6458 100644 --- a/src/plugins/canbus/peakcan/peakcanbackend_p.h +++ b/src/plugins/canbus/peakcan/peakcanbackend_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/socketcan/main.cpp b/src/plugins/canbus/socketcan/main.cpp index d1e9115..92e759b 100644 --- a/src/plugins/canbus/socketcan/main.cpp +++ b/src/plugins/canbus/socketcan/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -45,12 +45,11 @@ QT_BEGIN_NAMESPACE //! [SocketCanFactory] -class SocketCanBusPlugin : public QObject, public QCanBusFactory +class SocketCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactory) - + Q_INTERFACES(QCanBusFactoryV2) public: QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override diff --git a/src/plugins/canbus/socketcan/socketcanbackend.cpp b/src/plugins/canbus/socketcan/socketcanbackend.cpp index bf6a164..27a847d 100644 --- a/src/plugins/canbus/socketcan/socketcanbackend.cpp +++ b/src/plugins/canbus/socketcan/socketcanbackend.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -138,6 +138,11 @@ QList<QCanBusDeviceInfo> SocketCanBackend::interfaces() result.append(info); } + std::sort(result.begin(), result.end(), + [](const QCanBusDeviceInfo &a, const QCanBusDeviceInfo &b) { + return a.name() < b.name(); + }); + return result; } @@ -631,7 +636,7 @@ void SocketCanBackend::readSocket() { QVector<QCanBusFrame> newFrames; - while (true) { + for (;;) { struct canfd_frame frame; int bytesReceived; diff --git a/src/plugins/canbus/socketcan/socketcanbackend.h b/src/plugins/canbus/socketcan/socketcanbackend.h index 3caddd8..70c47c8 100644 --- a/src/plugins/canbus/socketcan/socketcanbackend.h +++ b/src/plugins/canbus/socketcan/socketcanbackend.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/systeccan/main.cpp b/src/plugins/canbus/systeccan/main.cpp index d81072d..fcb76a3 100644 --- a/src/plugins/canbus/systeccan/main.cpp +++ b/src/plugins/canbus/systeccan/main.cpp @@ -42,11 +42,11 @@ QT_BEGIN_NAMESPACE -class SystecCanBusPlugin : public QObject, public QCanBusFactory +class SystecCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactory) + Q_INTERFACES(QCanBusFactoryV2) public: QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override diff --git a/src/plugins/canbus/tinycan/main.cpp b/src/plugins/canbus/tinycan/main.cpp index 55c5590..c73d81e 100644 --- a/src/plugins/canbus/tinycan/main.cpp +++ b/src/plugins/canbus/tinycan/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -43,12 +43,11 @@ QT_BEGIN_NAMESPACE -class TinyCanBusPlugin : public QObject, public QCanBusFactory +class TinyCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactory) - + Q_INTERFACES(QCanBusFactoryV2) public: QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override diff --git a/src/plugins/canbus/tinycan/tinycan_symbols_p.h b/src/plugins/canbus/tinycan/tinycan_symbols_p.h index 6e05b92..36580ed 100644 --- a/src/plugins/canbus/tinycan/tinycan_symbols_p.h +++ b/src/plugins/canbus/tinycan/tinycan_symbols_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/tinycan/tinycanbackend.cpp b/src/plugins/canbus/tinycan/tinycanbackend.cpp index cea1cd6..6405308 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.cpp +++ b/src/plugins/canbus/tinycan/tinycanbackend.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -373,7 +373,7 @@ void TinyCanBackendPrivate::startRead() QVector<QCanBusFrame> newFrames; - forever { + for (;;) { if (!::CanReceiveGetCount(channelIndex)) break; diff --git a/src/plugins/canbus/tinycan/tinycanbackend.h b/src/plugins/canbus/tinycan/tinycanbackend.h index 3726a71..5f504ca 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend.h +++ b/src/plugins/canbus/tinycan/tinycanbackend.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/tinycan/tinycanbackend_p.h b/src/plugins/canbus/tinycan/tinycanbackend_p.h index 680a559..905175c 100644 --- a/src/plugins/canbus/tinycan/tinycanbackend_p.h +++ b/src/plugins/canbus/tinycan/tinycanbackend_p.h @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2015 Denis Shienkov <denis.shienkov@gmail.com> -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/vectorcan/main.cpp b/src/plugins/canbus/vectorcan/main.cpp index a606ae7..07c30bc 100644 --- a/src/plugins/canbus/vectorcan/main.cpp +++ b/src/plugins/canbus/vectorcan/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -42,11 +42,11 @@ QT_BEGIN_NAMESPACE -class VectorCanBusPlugin : public QObject, public QCanBusFactory +class VectorCanBusPlugin : public QObject, public QCanBusFactoryV2 { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json") - Q_INTERFACES(QCanBusFactory) + Q_INTERFACES(QCanBusFactoryV2) public: QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override @@ -60,8 +60,8 @@ public: QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override { QString errorReason; - if (!VectorCanBackend::canCreate(&errorReason)) { - qWarning("%s", qPrintable(errorReason)); + if (Q_UNLIKELY(!VectorCanBackend::canCreate(&errorReason))) { + qWarning("%ls", qUtf16Printable(errorReason)); if (errorMessage) *errorMessage = errorReason; return nullptr; diff --git a/src/plugins/canbus/vectorcan/vectorcan_symbols_p.h b/src/plugins/canbus/vectorcan/vectorcan_symbols_p.h index 4238fae..7bfb3c6 100644 --- a/src/plugins/canbus/vectorcan/vectorcan_symbols_p.h +++ b/src/plugins/canbus/vectorcan/vectorcan_symbols_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -214,7 +214,7 @@ typedef HANDLE XLhandle; //current version #define XL_INTERFACE_VERSION XL_INTERFACE_VERSION_V3 -#define XL_CAN_EXT_MSG_ID 0x80000000 +#define XL_CAN_EXT_MSG_ID 0x80000000U #define XL_CAN_MSG_FLAG_ERROR_FRAME 0x01 #define XL_CAN_MSG_FLAG_OVERRUN 0x02 // Overrun in Driver or CAN Controller, previous msgs have been lost. @@ -461,7 +461,11 @@ GENERATE_SYMBOL_VARIABLE(char *, xlGetErrorString, XLstatus) inline bool resolveSymbols(QLibrary *vectorcanLibrary) { if (!vectorcanLibrary->isLoaded()) { +#ifdef Q_PROCESSOR_X86_64 + vectorcanLibrary->setFileName(QStringLiteral("vxlapi64")); +#else vectorcanLibrary->setFileName(QStringLiteral("vxlapi")); +#endif if (!vectorcanLibrary->load()) return false; } diff --git a/src/plugins/canbus/vectorcan/vectorcanbackend.cpp b/src/plugins/canbus/vectorcan/vectorcanbackend.cpp index f1035e4..47662a6 100644 --- a/src/plugins/canbus/vectorcan/vectorcanbackend.cpp +++ b/src/plugins/canbus/vectorcan/vectorcanbackend.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -240,6 +240,9 @@ bool VectorCanBackendPrivate::setConfigurationParameter(int key, const QVariant switch (key) { case QCanBusDevice::BitRateKey: return setBitRate(value.toUInt()); + case QCanBusDevice::ReceiveOwnKey: + transmitEcho = value.toBool(); + return true; default: q->setError(VectorCanBackend::tr("Unsupported configuration key"), QCanBusDevice::ConfigurationError); @@ -348,8 +351,11 @@ void VectorCanBackendPrivate::startRead() const s_xl_can_msg &msg = event.tagData.msg; - QCanBusFrame frame(msg.id, QByteArray(reinterpret_cast<const char *>(msg.data), - int(msg.dlc))); + if ((msg.flags & XL_CAN_MSG_FLAG_TX_COMPLETED) && !transmitEcho) + continue; + + QCanBusFrame frame(msg.id & ~XL_CAN_EXT_MSG_ID, + QByteArray(reinterpret_cast<const char *>(msg.data), int(msg.dlc))); frame.setTimeStamp(QCanBusFrame::TimeStamp::fromMicroSeconds(event.timeStamp / 1000)); frame.setExtendedFrameFormat(msg.id & XL_CAN_EXT_MSG_ID); frame.setFrameType((msg.flags & XL_CAN_MSG_FLAG_REMOTE_FRAME) @@ -452,7 +458,7 @@ bool VectorCanBackend::open() const bool success = d->setConfigurationParameter(key, param); if (!success) { qWarning("Cannot apply parameter: %d with value: %ls", - key, param.toString()); + key, qUtf16Printable(param.toString())); } } diff --git a/src/plugins/canbus/vectorcan/vectorcanbackend.h b/src/plugins/canbus/vectorcan/vectorcanbackend.h index ff8fcfe..165d369 100644 --- a/src/plugins/canbus/vectorcan/vectorcanbackend.h +++ b/src/plugins/canbus/vectorcan/vectorcanbackend.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/plugins/canbus/vectorcan/vectorcanbackend_p.h b/src/plugins/canbus/vectorcan/vectorcanbackend_p.h index 141aca8..3eafb0c 100644 --- a/src/plugins/canbus/vectorcan/vectorcanbackend_p.h +++ b/src/plugins/canbus/vectorcan/vectorcanbackend_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Denis Shienkov <denis.shienkov@gmail.com> +** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com> ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -84,6 +84,7 @@ public: VectorCanBackend * const q_ptr; + bool transmitEcho = false; long portHandle = XL_INVALID_PORTHANDLE; quint64 channelMask = 0; HANDLE readHandle = INVALID_HANDLE_VALUE; diff --git a/src/serialbus/doc/snippets/snippetmain.cpp b/src/serialbus/doc/snippets/snippetmain.cpp index a833454..44f213c 100644 --- a/src/serialbus/doc/snippets/snippetmain.cpp +++ b/src/serialbus/doc/snippets/snippetmain.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/doc/src/qtcanbus-backends.qdoc b/src/serialbus/doc/src/qtcanbus-backends.qdoc index 522c6f2..c04cdd1 100644 --- a/src/serialbus/doc/src/qtcanbus-backends.qdoc +++ b/src/serialbus/doc/src/qtcanbus-backends.qdoc @@ -95,7 +95,7 @@ \endcode This key must be passed to \l {QCanBus::createDevice()} together with the interface name of - the CAN bus adapter. QCanBus loads and instantiates the plugin using the QCanBusFactory + the CAN bus adapter. QCanBus loads and instantiates the plugin using the QCanBusFactoryV2 interface which each plugin must implement as central entry point. The interface acts as a factory and its sole purpose is to return a \l QCanBusDevice instance. The above mentioned interface name is passed on via the factory's \l QCanBusFactory::createDevice() method. diff --git a/src/serialbus/doc/src/socketcan.qdoc b/src/serialbus/doc/src/socketcan.qdoc index f5aec83..74a8dab 100644 --- a/src/serialbus/doc/src/socketcan.qdoc +++ b/src/serialbus/doc/src/socketcan.qdoc @@ -58,6 +58,7 @@ the following command can be used: \code sudo ip link set up can0 type can bitrate 250000 restart-ms 100 + \endcode \section3 CAN FD settings diff --git a/src/serialbus/doc/src/vectorcan.qdoc b/src/serialbus/doc/src/vectorcan.qdoc index 8163207..f95f956 100644 --- a/src/serialbus/doc/src/vectorcan.qdoc +++ b/src/serialbus/doc/src/vectorcan.qdoc @@ -88,5 +88,11 @@ \row \li QCanBusDevice::BitRateKey \li Determines the bit rate of the CAN bus connection. + \row + \li QCanBusDevice::ReceiveOwnKey + \li The reception of the CAN frames on the same device that was sending the CAN frame + is disabled by default. When enabling this option, all CAN frames sent to the CAN + bus immediately appear in the receive buffer. This can be used to check if sending + was successful. \endtable */ diff --git a/src/serialbus/qcanbus.cpp b/src/serialbus/qcanbus.cpp index 3189c09..6b74bd7 100644 --- a/src/serialbus/qcanbus.cpp +++ b/src/serialbus/qcanbus.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -37,15 +37,13 @@ #include "qcanbus.h" #include "qcanbusfactory.h" -#include <QtCore/qobject.h> -#include <QtCore/qpluginloader.h> -#include <QtCore/qdebug.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qglobalstatic.h> #include <QtCore/qlist.h> +#include <QtCore/qobject.h> +#include <QtCore/qpluginloader.h> #include <private/qfactoryloader_p.h> -#include <private/qlibrary_p.h> #define QCanBusFactory_iid "org.qt-project.Qt.QCanBusFactory" @@ -55,9 +53,10 @@ class QCanBusPrivate { public: QCanBusPrivate() { } + QCanBusPrivate(int index, const QJsonObject &meta) : meta(meta), index(index) {} QJsonObject meta; - QCanBusFactory *factory = nullptr; + QObject *factory = nullptr; int index = -1; }; @@ -73,14 +72,11 @@ static void loadPlugins() { const QList<QJsonObject> meta = qFactoryLoader()->metaData(); for (int i = 0; i < meta.count(); i++) { - const QJsonObject obj = meta.at(i).value(QStringLiteral("MetaData")).toObject(); + const QJsonObject obj = meta.at(i).value(QLatin1String("MetaData")).toObject(); if (obj.isEmpty()) continue; - QCanBusPrivate d; - d.index = i; - d.meta = obj; - qCanBusPlugins()->insert(obj.value(QStringLiteral("Key")).toString(), d); + qCanBusPlugins()->insert(obj.value(QLatin1String("Key")).toString(), {i, obj}); } } @@ -122,7 +118,7 @@ static void setErrorMessage(QString *result, const QString &message) *result = message; } -static QCanBusFactory *canBusFactory(const QString &plugin, QString *errorMessage) +static QObject *canBusFactory(const QString &plugin, QString *errorMessage) { if (Q_UNLIKELY(!qCanBusPlugins()->contains(plugin))) { setErrorMessage(errorMessage, QCanBus::tr("No such plugin: '%1'").arg(plugin)); @@ -131,7 +127,7 @@ static QCanBusFactory *canBusFactory(const QString &plugin, QString *errorMessag QCanBusPrivate d = qCanBusPlugins()->value(plugin); if (!d.factory) { - d.factory = qobject_cast<QCanBusFactory *>(qFactoryLoader->instance(d.index)); + d.factory = qFactoryLoader->instance(d.index); if (d.factory) qCanBusPlugins()->insert(plugin, d); @@ -155,12 +151,19 @@ static QCanBusFactory *canBusFactory(const QString &plugin, QString *errorMessag */ QList<QCanBusDeviceInfo> QCanBus::availableDevices(const QString &plugin, QString *errorMessage) const { - const QCanBusFactory *factory = canBusFactory(plugin, errorMessage); - if (Q_UNLIKELY(!factory)) + const QObject *obj = canBusFactory(plugin, errorMessage); + if (Q_UNLIKELY(!obj)) return QList<QCanBusDeviceInfo>(); + const QCanBusFactoryV2 *factoryV2 = qobject_cast<QCanBusFactoryV2 *>(obj); + if (Q_UNLIKELY(!factoryV2)) { + setErrorMessage(errorMessage, + tr("The plugin '%1' does not provide this function.").arg(plugin)); + return QList<QCanBusDeviceInfo>(); + } + QString errorString; - QList<QCanBusDeviceInfo> result = factory->availableDevices(&errorString); + QList<QCanBusDeviceInfo> result = factoryV2->availableDevices(&errorString); setErrorMessage(errorMessage, errorString); return result; @@ -191,11 +194,21 @@ QList<QCanBusDeviceInfo> QCanBus::availableDevices(const QString &plugin, QStrin QCanBusDevice *QCanBus::createDevice(const QString &plugin, const QString &interfaceName, QString *errorMessage) const { - const QCanBusFactory *factory = canBusFactory(plugin, errorMessage); - if (Q_UNLIKELY(!factory)) + const QObject *obj = canBusFactory(plugin, errorMessage); + if (Q_UNLIKELY(!obj)) return nullptr; - return factory->createDevice(interfaceName, errorMessage); + const QCanBusFactoryV2 *factoryV2 = qobject_cast<QCanBusFactoryV2 *>(obj); + if (Q_LIKELY(factoryV2)) + return factoryV2->createDevice(interfaceName, errorMessage); + + const QCanBusFactory *factory = qobject_cast<QCanBusFactory *>(obj); + if (factory) + return factory->createDevice(interfaceName, errorMessage); + + setErrorMessage(errorMessage, + tr("The plugin '%1' does not provide this function.").arg(plugin)); + return nullptr; } QCanBus::QCanBus(QObject *parent) : diff --git a/src/serialbus/qcanbus.h b/src/serialbus/qcanbus.h index 2ed1877..695d312 100644 --- a/src/serialbus/qcanbus.h +++ b/src/serialbus/qcanbus.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -44,8 +44,6 @@ QT_BEGIN_NAMESPACE -class QSerialBusBackendFactory; - class Q_SERIALBUS_EXPORT QCanBus : public QObject { Q_OBJECT diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp index 19984e8..70778a7 100644 --- a/src/serialbus/qcanbusdevice.cpp +++ b/src/serialbus/qcanbusdevice.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qcanbusdevice.h b/src/serialbus/qcanbusdevice.h index 0b9d91d..3a644c6 100644 --- a/src/serialbus/qcanbusdevice.h +++ b/src/serialbus/qcanbusdevice.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qcanbusdevice_p.h b/src/serialbus/qcanbusdevice_p.h index 666cb29..faeae65 100644 --- a/src/serialbus/qcanbusdevice_p.h +++ b/src/serialbus/qcanbusdevice_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qcanbusdeviceinfo.cpp b/src/serialbus/qcanbusdeviceinfo.cpp index 418e4f0..fac1e9f 100644 --- a/src/serialbus/qcanbusdeviceinfo.cpp +++ b/src/serialbus/qcanbusdeviceinfo.cpp @@ -44,14 +44,14 @@ QT_BEGIN_NAMESPACE \inmodule QtSerialBus \since 5.9 - \brief The QCanBusDeviceInfo provides information about CAN interfaces. + \brief The QCanBusDeviceInfo provides information about CAN bus interfaces. Each plugin may support one or more interfaces with different capabilities. This class provides information about available functions. */ /*! - Constructs a new empty QCanBusDeviceInfo. + Constructs an empty QCanBusDeviceInfo. */ QCanBusDeviceInfo::QCanBusDeviceInfo() : d_ptr(new QCanBusDeviceInfoPrivate) @@ -59,7 +59,7 @@ QCanBusDeviceInfo::QCanBusDeviceInfo() : } /*! - Constructs a new QCanBusDeviceInfo from \a other. + Constructs a copy of \a other. */ QCanBusDeviceInfo::QCanBusDeviceInfo(const QCanBusDeviceInfo &other) : d_ptr(other.d_ptr) @@ -67,7 +67,7 @@ QCanBusDeviceInfo::QCanBusDeviceInfo(const QCanBusDeviceInfo &other) : } /*! - Constructs a new QCanBusDeviceInfo from the QCanBusDeviceInfoPrivate \a dd. + Constructs a CAN bus device info from QCanBusDeviceInfoPrivate \a dd. \internal */ QCanBusDeviceInfo::QCanBusDeviceInfo(QCanBusDeviceInfoPrivate &dd) : @@ -76,25 +76,22 @@ QCanBusDeviceInfo::QCanBusDeviceInfo(QCanBusDeviceInfoPrivate &dd) : } /*! - Destroys the QCanBusDeviceInfo object. References to the values in the - object become invalid. + Destroys the CAN bus device info. */ QCanBusDeviceInfo::~QCanBusDeviceInfo() { } /*! - Swap this instance's shared data pointer with the shared data pointer in - \a other. - \internal + \fn void QCanBusDeviceInfo::swap(QCanBusDeviceInfo &other) + Swaps this CAN bus device info with \a other. This operation is very fast + and never fails. */ -void QCanBusDeviceInfo::swap(QCanBusDeviceInfo other) -{ - d_ptr.swap(other.d_ptr); -} + /*! - Sets the QCanBusDeviceInfo object to be equal to \a other. + Assigns \a other to this CAN bus device info and returns a reference to this + CAN bus device info. */ QCanBusDeviceInfo &QCanBusDeviceInfo::operator=(const QCanBusDeviceInfo &other) { diff --git a/src/serialbus/qcanbusdeviceinfo.h b/src/serialbus/qcanbusdeviceinfo.h index 33bf1c8..b21a4b3 100644 --- a/src/serialbus/qcanbusdeviceinfo.h +++ b/src/serialbus/qcanbusdeviceinfo.h @@ -53,8 +53,17 @@ public: QCanBusDeviceInfo(const QCanBusDeviceInfo &other); ~QCanBusDeviceInfo(); - void swap(QCanBusDeviceInfo other); + void swap(QCanBusDeviceInfo &other) Q_DECL_NOTHROW + { + qSwap(d_ptr, other.d_ptr); + } + QCanBusDeviceInfo &operator=(const QCanBusDeviceInfo &other); + QCanBusDeviceInfo &operator=(QCanBusDeviceInfo &&other) Q_DECL_NOTHROW + { + swap(other); + return *this; + } QString name() const; @@ -63,13 +72,14 @@ public: private: friend class QCanBusDevice; - friend class GenericBusPlugin; - QCanBusDeviceInfo(QCanBusDeviceInfoPrivate &dd); + explicit QCanBusDeviceInfo(QCanBusDeviceInfoPrivate &dd); QSharedDataPointer<QCanBusDeviceInfoPrivate> d_ptr; }; +Q_DECLARE_SHARED(QCanBusDeviceInfo) + QT_END_NAMESPACE #endif // QCANBUSDEVICEINFO_H diff --git a/src/serialbus/qcanbusfactory.cpp b/src/serialbus/qcanbusfactory.cpp index db6c294..508741b 100644 --- a/src/serialbus/qcanbusfactory.cpp +++ b/src/serialbus/qcanbusfactory.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -42,39 +42,72 @@ QT_BEGIN_NAMESPACE \class QCanBusFactory \inmodule QtSerialBus \since 5.8 + \deprecated \brief The QCanBusFactory class is a factory class used as the plugin interface for CAN bus plugins. All plugins must implement the functions provided by this factory class. + + This class is deprecated, you should use QCanBusFactoryV2 instead. + + \sa QCanBusFactoryV2 */ /*! - \fn QList<QCanBusDeviceInfo> QCanBusFactory::availableDevices(QString *errorMessage) const + \fn QCanBusDevice *QCanBusFactory::createDevice(const QString &interfaceName, + QString *errorMessage) const - Returns the list of available devices and their capabilities for the QCanBusDevice. + Creates a new QCanBusDevice. The caller must take ownership of the returned pointer. + \a interfaceName is the CAN interface name and \a errorMessage contains an error description in case of failure. + If the factory cannot create a plugin, it returns \c nullptr. +*/ + +/*! + \internal + + \fn QCanBusFactory::~QCanBusFactory() +*/ + +/*! + \class QCanBusFactoryV2 + \inmodule QtSerialBus \since 5.9 + + \brief The QCanBusFactoryV2 class is a factory class used as the + plugin interface for CAN bus plugins. + + All plugins must implement the functions provided by this factory class. */ /*! - \fn QCanBusDevice *QCanBusFactory::createDevice(const QString &interfaceName, + \fn QCanBusDevice *QCanBusFactoryV2::createDevice(const QString &interfaceName, QString *errorMessage) const Creates a new QCanBusDevice. The caller must take ownership of the returned pointer. - \a interfaceName is the network/CAN interface name. + \a interfaceName is the CAN interface name and \a errorMessage contains an error description in case of failure. If the factory cannot create a plugin, it returns \c nullptr. */ /*! - \internal + \fn QList<QCanBusDeviceInfo> QCanBusFactoryV2::availableDevices(QString *errorMessage) const - \fn QCanBusFactory::~QCanBusFactory() + Returns the list of available devices and their capabilities for the QCanBusDevice. + + \a errorMessage contains an error description in case of failure. */ +/*! + * \internal + */ +QCanBusFactoryV2::~QCanBusFactoryV2() +{ +} + QT_END_NAMESPACE diff --git a/src/serialbus/qcanbusfactory.h b/src/serialbus/qcanbusfactory.h index 2ab9862..d74903c 100644 --- a/src/serialbus/qcanbusfactory.h +++ b/src/serialbus/qcanbusfactory.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -47,7 +47,6 @@ QT_BEGIN_NAMESPACE class Q_SERIALBUS_EXPORT QCanBusFactory { public: - virtual QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const = 0; virtual QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const = 0; protected: @@ -56,6 +55,19 @@ protected: Q_DECLARE_INTERFACE(QCanBusFactory, "org.qt-project.Qt.QCanBusFactory") +class Q_SERIALBUS_EXPORT QCanBusFactoryV2 : public QCanBusFactory +{ +public: + virtual QCanBusDevice *createDevice(const QString &interfaceName, + QString *errorMessage) const = 0; + virtual QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const = 0; + +protected: + virtual ~QCanBusFactoryV2(); +}; + +Q_DECLARE_INTERFACE(QCanBusFactoryV2, "org.qt-project.Qt.QCanBusFactoryV2") + QT_END_NAMESPACE #endif // QCANBUSFACTORY_H diff --git a/src/serialbus/qcanbusframe.cpp b/src/serialbus/qcanbusframe.cpp index f700595..6ef0f11 100644 --- a/src/serialbus/qcanbusframe.cpp +++ b/src/serialbus/qcanbusframe.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qcanbusframe.h b/src/serialbus/qcanbusframe.h index 9ca766b..5e285c1 100644 --- a/src/serialbus/qcanbusframe.h +++ b/src/serialbus/qcanbusframe.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbus_symbols_p.h b/src/serialbus/qmodbus_symbols_p.h index 20ec329..b678ff0 100644 --- a/src/serialbus/qmodbus_symbols_p.h +++ b/src/serialbus/qmodbus_symbols_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusadu_p.h b/src/serialbus/qmodbusadu_p.h index b95fd38..846466d 100644 --- a/src/serialbus/qmodbusadu_p.h +++ b/src/serialbus/qmodbusadu_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusclient.cpp b/src/serialbus/qmodbusclient.cpp index fcbad8b..7f63afa 100644 --- a/src/serialbus/qmodbusclient.cpp +++ b/src/serialbus/qmodbusclient.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusclient.h b/src/serialbus/qmodbusclient.h index 1a22d3b..3b6785d 100644 --- a/src/serialbus/qmodbusclient.h +++ b/src/serialbus/qmodbusclient.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusclient_p.h b/src/serialbus/qmodbusclient_p.h index da01500..50d73b2 100644 --- a/src/serialbus/qmodbusclient_p.h +++ b/src/serialbus/qmodbusclient_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbuscommevent_p.h b/src/serialbus/qmodbuscommevent_p.h index 4cf730a..47967e7 100644 --- a/src/serialbus/qmodbuscommevent_p.h +++ b/src/serialbus/qmodbuscommevent_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdataunit.cpp b/src/serialbus/qmodbusdataunit.cpp index 0f8821f..6a07bba 100644 --- a/src/serialbus/qmodbusdataunit.cpp +++ b/src/serialbus/qmodbusdataunit.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdataunit.h b/src/serialbus/qmodbusdataunit.h index 9b767c5..fcad4ac 100644 --- a/src/serialbus/qmodbusdataunit.h +++ b/src/serialbus/qmodbusdataunit.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdevice.cpp b/src/serialbus/qmodbusdevice.cpp index 08718d6..4aaae87 100644 --- a/src/serialbus/qmodbusdevice.cpp +++ b/src/serialbus/qmodbusdevice.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdevice.h b/src/serialbus/qmodbusdevice.h index f65f42e..20fa1b3 100644 --- a/src/serialbus/qmodbusdevice.h +++ b/src/serialbus/qmodbusdevice.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdevice_p.h b/src/serialbus/qmodbusdevice_p.h index f9d46e2..52ace00 100644 --- a/src/serialbus/qmodbusdevice_p.h +++ b/src/serialbus/qmodbusdevice_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdeviceidentification.cpp b/src/serialbus/qmodbusdeviceidentification.cpp index 3aa54fb..77c2663 100644 --- a/src/serialbus/qmodbusdeviceidentification.cpp +++ b/src/serialbus/qmodbusdeviceidentification.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusdeviceidentification.h b/src/serialbus/qmodbusdeviceidentification.h index e7217e5..63d7ee3 100644 --- a/src/serialbus/qmodbusdeviceidentification.h +++ b/src/serialbus/qmodbusdeviceidentification.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbuspdu.cpp b/src/serialbus/qmodbuspdu.cpp index 32a3b43..e1ce0c6 100644 --- a/src/serialbus/qmodbuspdu.cpp +++ b/src/serialbus/qmodbuspdu.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbuspdu.h b/src/serialbus/qmodbuspdu.h index 65a3247..28b1f8a 100644 --- a/src/serialbus/qmodbuspdu.h +++ b/src/serialbus/qmodbuspdu.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusreply.cpp b/src/serialbus/qmodbusreply.cpp index f88a3bd..297724b 100644 --- a/src/serialbus/qmodbusreply.cpp +++ b/src/serialbus/qmodbusreply.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusreply.h b/src/serialbus/qmodbusreply.h index a41daa3..9b54687 100644 --- a/src/serialbus/qmodbusreply.h +++ b/src/serialbus/qmodbusreply.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusrtuserialmaster.cpp b/src/serialbus/qmodbusrtuserialmaster.cpp index 5a9555e..457372e 100644 --- a/src/serialbus/qmodbusrtuserialmaster.cpp +++ b/src/serialbus/qmodbusrtuserialmaster.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -144,10 +144,8 @@ bool QModbusRtuSerialMaster::open() */ void QModbusRtuSerialMaster::close() { - if (state() == QModbusDevice::UnconnectedState || - state() == QModbusDevice::ClosingState) { + if (state() == QModbusDevice::UnconnectedState) return; - } setState(QModbusDevice::ClosingState); diff --git a/src/serialbus/qmodbusrtuserialmaster.h b/src/serialbus/qmodbusrtuserialmaster.h index c5e2bf7..5c607e2 100644 --- a/src/serialbus/qmodbusrtuserialmaster.h +++ b/src/serialbus/qmodbusrtuserialmaster.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusrtuserialmaster_p.h b/src/serialbus/qmodbusrtuserialmaster_p.h index c698ebc..e1e4287 100644 --- a/src/serialbus/qmodbusrtuserialmaster_p.h +++ b/src/serialbus/qmodbusrtuserialmaster_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusrtuserialslave.cpp b/src/serialbus/qmodbusrtuserialslave.cpp index 87698d3..899bd8d 100644 --- a/src/serialbus/qmodbusrtuserialslave.cpp +++ b/src/serialbus/qmodbusrtuserialslave.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusrtuserialslave.h b/src/serialbus/qmodbusrtuserialslave.h index d9c8a84..2194bce 100644 --- a/src/serialbus/qmodbusrtuserialslave.h +++ b/src/serialbus/qmodbusrtuserialslave.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusrtuserialslave_p.h b/src/serialbus/qmodbusrtuserialslave_p.h index 32a4dc2..385fb0d 100644 --- a/src/serialbus/qmodbusrtuserialslave_p.h +++ b/src/serialbus/qmodbusrtuserialslave_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusserver.cpp b/src/serialbus/qmodbusserver.cpp index c119e21..815cb0c 100644 --- a/src/serialbus/qmodbusserver.cpp +++ b/src/serialbus/qmodbusserver.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. @@ -1254,7 +1254,7 @@ QModbusResponse QModbusServerPrivate::processEncapsulatedInterfaceTransportReque objectData[1] = quint8(object.size()); objectData += object; if (payload.size() + objectData.size() > 253) { - payload[3] = quint8(0xff); // more follows + payload[3] = char(0xff); // more follows payload[4] = id; // next object id break; } diff --git a/src/serialbus/qmodbusserver.h b/src/serialbus/qmodbusserver.h index ec45629..0f513d8 100644 --- a/src/serialbus/qmodbusserver.h +++ b/src/serialbus/qmodbusserver.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbusserver_p.h b/src/serialbus/qmodbusserver_p.h index 2618ccf..a527317 100644 --- a/src/serialbus/qmodbusserver_p.h +++ b/src/serialbus/qmodbusserver_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpclient.cpp b/src/serialbus/qmodbustcpclient.cpp index a34c241..c897390 100644 --- a/src/serialbus/qmodbustcpclient.cpp +++ b/src/serialbus/qmodbustcpclient.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpclient.h b/src/serialbus/qmodbustcpclient.h index c41f10c..481d558 100644 --- a/src/serialbus/qmodbustcpclient.h +++ b/src/serialbus/qmodbustcpclient.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpclient_p.h b/src/serialbus/qmodbustcpclient_p.h index bb3bc74..e4dfa9e 100644 --- a/src/serialbus/qmodbustcpclient_p.h +++ b/src/serialbus/qmodbustcpclient_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpserver.cpp b/src/serialbus/qmodbustcpserver.cpp index 9232bb3..39aeda8 100644 --- a/src/serialbus/qmodbustcpserver.cpp +++ b/src/serialbus/qmodbustcpserver.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpserver.h b/src/serialbus/qmodbustcpserver.h index a4dea66..57276a5 100644 --- a/src/serialbus/qmodbustcpserver.h +++ b/src/serialbus/qmodbustcpserver.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qmodbustcpserver_p.h b/src/serialbus/qmodbustcpserver_p.h index d502be9..90d1eaf 100644 --- a/src/serialbus/qmodbustcpserver_p.h +++ b/src/serialbus/qmodbustcpserver_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/serialbus/qserialbusglobal.h b/src/serialbus/qserialbusglobal.h index 3ebafe1..736c4a8 100644 --- a/src/serialbus/qserialbusglobal.h +++ b/src/serialbus/qserialbusglobal.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialBus module of the Qt Toolkit. diff --git a/src/tools/canbusutil/canbusutil.cpp b/src/tools/canbusutil/canbusutil.cpp index d614583..0a0a6df 100644 --- a/src/tools/canbusutil/canbusutil.cpp +++ b/src/tools/canbusutil/canbusutil.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. @@ -50,6 +50,11 @@ void CanBusUtil::setShowTimeStamp(bool showTimeStamp) m_readTask->setShowTimeStamp(showTimeStamp); } +void CanBusUtil::setShowFdFlags(bool showFdFlags) +{ + m_readTask->setShowFdFlags(showFdFlags); +} + bool CanBusUtil::start(const QString &pluginName, const QString &deviceName, const QString &data) { if (!m_canBus) { @@ -66,6 +71,8 @@ bool CanBusUtil::start(const QString &pluginName, const QString &deviceName, con return false; if (m_listening) { + if (m_readTask->isShowFdFlags()) + m_canDevice->setConfigurationParameter(QCanBusDevice::CanFdKey, true); connect(m_canDevice.data(), &QCanBusDevice::framesReceived, m_readTask, &ReadTask::checkMessages); } else { if (!sendData()) @@ -83,6 +90,20 @@ void CanBusUtil::printPlugins() m_output << plugins.at(i) << endl; } +int CanBusUtil::printDevices(const QString &pluginName) +{ + QString errorMessage; + const QList<QCanBusDeviceInfo> devices = m_canBus->availableDevices(pluginName, &errorMessage); + if (!errorMessage.isEmpty()) { + m_output << "Error: " << errorMessage << endl; + return 1; + } + + for (const QCanBusDeviceInfo &info : devices) + m_output << info.name() << endl; + return 0; +} + bool CanBusUtil::parseDataField(qint32 &id, QString &payload) { int hashMarkPos = m_data.indexOf('#'); @@ -128,17 +149,25 @@ bool CanBusUtil::setFrameFromPayload(QString payload, QCanBusFrame *frame) payload = payload.mid(1); } - if (payload.size() % 2 != 0) { - m_output << "Data field invalid: Size is not multiple of two." << endl; - return false; - } - const QRegularExpression re(QStringLiteral("^[0-9A-Fa-f]*$")); if (!re.match(payload).hasMatch()) { m_output << "Data field invalid: Only hex numbers allowed." << endl; return false; } + if (payload.size() % 2 != 0) { + if (frame->hasFlexibleDataRateFormat()) { + enum { BitrateSwitchFlag = 1, ErrorStateIndicatorFlag = 2 }; + const int flags = payload.left(1).toInt(nullptr, 16); + frame->setBitrateSwitch(flags & BitrateSwitchFlag); + frame->setErrorStateIndicator(flags & ErrorStateIndicatorFlag); + payload.remove(0, 1); + } else { + m_output << "Data field invalid: Size is not multiple of two." << endl; + return false; + } + } + QByteArray bytes = QByteArray::fromHex(payload.toLatin1()); const int maxSize = frame->hasFlexibleDataRateFormat() ? 64 : 8; diff --git a/src/tools/canbusutil/canbusutil.h b/src/tools/canbusutil/canbusutil.h index e17fe7b..e9e7d2b 100644 --- a/src/tools/canbusutil/canbusutil.h +++ b/src/tools/canbusutil/canbusutil.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. @@ -57,14 +57,15 @@ public: explicit CanBusUtil(QTextStream &output, QCoreApplication &app, QObject *parent = nullptr); void setShowTimeStamp(bool showTimeStamp); + void setShowFdFlags(bool showFdFlags); bool start(const QString &pluginName, const QString &deviceName, const QString &data = QString()); void printPlugins(); + int printDevices(const QString &pluginName); private: bool parseDataField(qint32 &id, QString &payload); bool setFrameFromPayload(QString payload, QCanBusFrame *frame); bool connectCanDevice(); - bool startListeningOnCanDevice(); bool sendData(); private: diff --git a/src/tools/canbusutil/main.cpp b/src/tools/canbusutil/main.cpp index c760c31..1304f22 100644 --- a/src/tools/canbusutil/main.cpp +++ b/src/tools/canbusutil/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. @@ -63,7 +63,7 @@ int main(int argc, char *argv[]) QCommandLineParser parser; parser.setApplicationDescription(CanBusUtil::tr( "Sends arbitrary CAN bus frames.\n" - "If the -l option is set, all received CAN bus packages are dumped.")); + "If the -l option is set, all received CAN bus frames are dumped.")); parser.addHelpOption(); parser.addVersionOption(); @@ -76,10 +76,12 @@ int main(int argc, char *argv[]) parser.addPositionalArgument(QStringLiteral("data"), CanBusUtil::tr( "Data to send if -l is not specified. Format:\n" - "\t\t<id>#{payload} (CAN 2.0 data frames),\n" - "\t\t<id>#Rxx (CAN 2.0 RTR frames with xx bytes data length),\n" - "\t\t<id>##{payload} (CAN FD data frames),\n" + "\t\t<id>#{payload} (CAN 2.0 data frames),\n" + "\t\t<id>#Rxx (CAN 2.0 RTR frames with xx bytes data length),\n" + "\t\t<id>##[flags]{payload} (CAN FD data frames),\n" "where {payload} has 0..8 (0..64 CAN FD) ASCII hex-value pairs, " + "and flags is one optional ASCII hex char for CAN FD flags: " + "1 = Bitrate Switch, 2 = Error State Indicator\n" "e.g. 1#1a2b3c\n"), QStringLiteral("[data]")); const QCommandLineOption listeningOption({"l", "listen"}, @@ -91,9 +93,17 @@ int main(int argc, char *argv[]) parser.addOption(listOption); const QCommandLineOption showTimeStampOption({"t", "timestamp"}, - CanBusUtil::tr("Show timestamp for each received message.")); + CanBusUtil::tr("Show timestamp for each received CAN bus frame.")); parser.addOption(showTimeStampOption); + const QCommandLineOption showFdFlagsOption({"i", "info"}, + CanBusUtil::tr("Show extra info (CAN FD flags) for each received CAN bus frame.")); + parser.addOption(showFdFlagsOption); + + const QCommandLineOption listDevicesOption({"d", "devices"}, + CanBusUtil::tr("Show available CAN bus devices for the given plugin.")); + parser.addOption(listDevicesOption); + parser.process(app); if (parser.isSet(listOption)) { @@ -103,15 +113,19 @@ int main(int argc, char *argv[]) QString data; const QStringList args = parser.positionalArguments(); - if (!parser.isSet(listeningOption) && args.size() == 3) { + if (parser.isSet(listeningOption)) { + util.setShowTimeStamp(parser.isSet(showTimeStampOption)); + util.setShowFdFlags(parser.isSet(showFdFlagsOption)); + } else if (args.size() == 3) { data = args[2]; - } else if (!parser.isSet(listeningOption) || args.size() != 2) { + } else if (args.size() == 1 && parser.isSet(listDevicesOption)) { + return util.printDevices(args[0]); + } else if (args.size() != 2) { fprintf(stderr, "Invalid number of arguments (%d given).\n\n%s", args.size(), qPrintable(parser.helpText())); return 1; } - util.setShowTimeStamp(parser.isSet(showTimeStampOption)); if (!util.start(args[0], args[1], data)) return -1; diff --git a/src/tools/canbusutil/readtask.cpp b/src/tools/canbusutil/readtask.cpp index 93fcae1..fb159b7 100644 --- a/src/tools/canbusutil/readtask.cpp +++ b/src/tools/canbusutil/readtask.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. @@ -45,6 +45,16 @@ void ReadTask::setShowTimeStamp(bool showTimeStamp) m_showTimeStamp = showTimeStamp; } +bool ReadTask::isShowFdFlags() const +{ + return m_showFdFlags; +} + +void ReadTask::setShowFdFlags(bool showFlags) +{ + m_showFdFlags = showFlags; +} + void ReadTask::checkMessages() { auto canDevice = qobject_cast<QCanBusDevice *>(QObject::sender()); if (canDevice == nullptr) { @@ -63,6 +73,15 @@ void ReadTask::checkMessages() { .arg(frame.timeStamp().microSeconds() / 100, 4, 10, QLatin1Char('0')); } + if (m_showFdFlags) { + QString flags = QLatin1String("- - "); + if (frame.hasBitrateSwitch()) + flags[0] = QLatin1Char('B'); + if (frame.hasErrorStateIndicator()) + flags[2] = QLatin1Char('E'); + view += flags; + } + if (frame.frameType() == QCanBusFrame::ErrorFrame) view += canDevice->interpretErrorFrame(frame); else diff --git a/src/tools/canbusutil/readtask.h b/src/tools/canbusutil/readtask.h index 7f7613b..e00440a 100644 --- a/src/tools/canbusutil/readtask.h +++ b/src/tools/canbusutil/readtask.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. @@ -47,9 +47,8 @@ class ReadTask : public QObject public: explicit ReadTask(QTextStream &output, QObject *parent = nullptr); void setShowTimeStamp(bool showStamp); - -signals: - void sigTermSignal(); + bool isShowFdFlags() const; + void setShowFdFlags(bool isShowFdFlags); public slots: void checkMessages(); @@ -58,6 +57,7 @@ public slots: private: QTextStream &output; bool m_showTimeStamp = false; + bool m_showFdFlags = false; }; #endif // READTASK_H diff --git a/src/tools/canbusutil/sigtermhandler.cpp b/src/tools/canbusutil/sigtermhandler.cpp index bf6f6ba..8611916 100644 --- a/src/tools/canbusutil/sigtermhandler.cpp +++ b/src/tools/canbusutil/sigtermhandler.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. diff --git a/src/tools/canbusutil/sigtermhandler.h b/src/tools/canbusutil/sigtermhandler.h index b2c09b3..1d72f0a 100644 --- a/src/tools/canbusutil/sigtermhandler.h +++ b/src/tools/canbusutil/sigtermhandler.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the tools applications of the QtSerialBus module. |