1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef CANBUSUTIL_H
5#define CANBUSUTIL_H
6
7#include "readtask.h"
8
9#include <QObject>
10
11QT_BEGIN_NAMESPACE
12
13class QCanBusFrame;
14class QCoreApplication;
15class QTextStream;
16
17QT_END_NAMESPACE
18
19class CanBusUtil : public QObject
20{
21 Q_OBJECT
22public:
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
32private:
33 bool parseDataField(QCanBusFrame::FrameId &id, QString &payload);
34 bool setFrameFromPayload(QString payload, QCanBusFrame *frame);
35 bool connectCanDevice();
36 bool sendData();
37
38private:
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

source code of qtserialbus/src/tools/canbusutil/canbusutil.h