1// Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com>
2// Copyright (C) 2017 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef PEAKCANBACKEND_H
6#define PEAKCANBACKEND_H
7
8#include <QtSerialBus/qcanbusdevice.h>
9#include <QtSerialBus/qcanbusdeviceinfo.h>
10#include <QtSerialBus/qcanbusframe.h>
11
12#include <QtCore/qlist.h>
13#include <QtCore/qvariant.h>
14
15QT_BEGIN_NAMESPACE
16
17class PeakCanBackendPrivate;
18
19class PeakCanBackend : public QCanBusDevice
20{
21 Q_OBJECT
22 Q_DECLARE_PRIVATE(PeakCanBackend)
23 Q_DISABLE_COPY(PeakCanBackend)
24public:
25 explicit PeakCanBackend(const QString &name, QObject *parent = nullptr);
26 ~PeakCanBackend();
27
28 bool open() override;
29 void close() override;
30
31 void setConfigurationParameter(ConfigurationKey key, const QVariant &value) override;
32
33 bool writeFrame(const QCanBusFrame &newData) override;
34
35 QString interpretErrorFrame(const QCanBusFrame &errorFrame) override;
36
37 static bool canCreate(QString *errorReason);
38 static QList<QCanBusDeviceInfo> interfaces();
39
40 void resetController() override;
41 bool hasBusStatus() const override;
42 CanBusStatus busStatus() override;
43 QCanBusDeviceInfo deviceInfo() const override;
44
45private:
46 enum class Availability {
47 Available = 1U, // matches PCAN_CHANNEL_AVAILABLE
48 Occupied = 2U // matches PCAN_CHANNEL_OCCUPIED
49 };
50 static QList<QCanBusDeviceInfo> interfacesByChannelCondition(Availability available);
51 static QList<QCanBusDeviceInfo> interfacesByAttachedChannels(Availability available, bool *ok);
52 static QList<QCanBusDeviceInfo> attachedInterfaces(Availability available);
53
54 PeakCanBackendPrivate * const d_ptr;
55};
56
57QT_END_NAMESPACE
58
59#endif // PEAKCANBACKEND_H
60

source code of qtserialbus/src/plugins/canbus/peakcan/peakcanbackend.h