| 1 | // Copyright (C) 2017 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef CANBUSUTIL_H |
| 5 | #define CANBUSUTIL_H |
| 6 | |
| 7 | #include "readtask.h" |
| 8 | |
| 9 | #include <QObject> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | class QCanBusFrame; |
| 14 | class QCoreApplication; |
| 15 | class QTextStream; |
| 16 | |
| 17 | QT_END_NAMESPACE |
| 18 | |
| 19 | class CanBusUtil : public QObject |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | public: |
| 23 | explicit CanBusUtil(QTextStream &output, QCoreApplication &app, QObject *parent = nullptr); |
| 24 | |
| 25 | void setShowTimeStamp(bool showTimeStamp); |
| 26 | void setShowFlags(bool showFlags); |
| 27 | void setConfigurationParameter(QCanBusDevice::ConfigurationKey key, const QVariant &value); |
| 28 | bool start(const QString &pluginName, const QString &deviceName, const QString &data = QString()); |
| 29 | int printPlugins(); |
| 30 | int printDevices(const QString &pluginName); |
| 31 | |
| 32 | private: |
| 33 | bool parseDataField(QCanBusFrame::FrameId &id, QString &payload); |
| 34 | bool setFrameFromPayload(QString payload, QCanBusFrame *frame); |
| 35 | bool connectCanDevice(); |
| 36 | bool sendData(); |
| 37 | |
| 38 | private: |
| 39 | QCanBus *m_canBus = nullptr; |
| 40 | QTextStream &m_output; |
| 41 | QCoreApplication &m_app; |
| 42 | bool m_listening = false; |
| 43 | QString m_pluginName; |
| 44 | QString m_deviceName; |
| 45 | QString m_data; |
| 46 | std::unique_ptr<QCanBusDevice> m_canDevice; |
| 47 | ReadTask *m_readTask = nullptr; |
| 48 | using ConfigurationParameter = QHash<QCanBusDevice::ConfigurationKey, QVariant>; |
| 49 | ConfigurationParameter m_configurationParameter; |
| 50 | }; |
| 51 | |
| 52 | #endif // CANBUSUTIL_H |
| 53 |
