1// Copyright (C) 2022 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 QCANSIGNALDESCRIPTION_H
5#define QCANSIGNALDESCRIPTION_H
6
7#include <QtCore/QDebug>
8#include <QtCore/QExplicitlySharedDataPointer>
9#include <QtCore/QVariant>
10
11#include <QtSerialBus/qcancommondefinitions.h>
12#include <QtSerialBus/qtserialbusglobal.h>
13
14QT_BEGIN_NAMESPACE
15
16class QCanSignalDescriptionPrivate;
17QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QCanSignalDescriptionPrivate, Q_SERIALBUS_EXPORT)
18
19class QCanSignalDescription
20{
21public:
22 struct MultiplexValueRange {
23 QVariant minimum;
24 QVariant maximum;
25 private:
26 friend bool operator==(const MultiplexValueRange &lhs,
27 const MultiplexValueRange &rhs) noexcept
28 {
29 return lhs.minimum == rhs.minimum && lhs.maximum == rhs.maximum;
30 }
31 friend bool operator!=(const MultiplexValueRange &lhs,
32 const MultiplexValueRange &rhs) noexcept
33 {
34 return !(lhs == rhs);
35 }
36 friend size_t qHash(const MultiplexValueRange &, size_t) noexcept = delete;
37#ifndef QT_NO_DEBUG_STREAM
38 friend QDebug operator<<(QDebug dbg, const MultiplexValueRange &range)
39 {
40 return debugStreaming(dbg, range);
41 }
42 Q_SERIALBUS_EXPORT
43 static QDebug debugStreaming(QDebug dbg, const MultiplexValueRange &range);
44#endif // QT_NO_DEBUG_STREAM
45 };
46 using MultiplexValues = QList<MultiplexValueRange>;
47 using MultiplexSignalValues = QHash<QString, MultiplexValues>;
48
49
50 Q_SERIALBUS_EXPORT QCanSignalDescription();
51 Q_SERIALBUS_EXPORT QCanSignalDescription(const QCanSignalDescription &other);
52 QCanSignalDescription(QCanSignalDescription &&other) noexcept = default;
53 ~QCanSignalDescription() = default;
54
55 Q_SERIALBUS_EXPORT QCanSignalDescription &operator=(const QCanSignalDescription &other);
56 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QCanSignalDescription)
57
58 void swap(QCanSignalDescription &other) noexcept { d.swap(other&: other.d); }
59
60 Q_SERIALBUS_EXPORT bool isValid() const;
61
62 Q_SERIALBUS_EXPORT QString name() const;
63 Q_SERIALBUS_EXPORT void setName(const QString &name);
64
65 Q_SERIALBUS_EXPORT QString physicalUnit() const;
66 Q_SERIALBUS_EXPORT void setPhysicalUnit(const QString &unit);
67
68 Q_SERIALBUS_EXPORT QString receiver() const;
69 Q_SERIALBUS_EXPORT void setReceiver(const QString &receiver);
70
71 Q_SERIALBUS_EXPORT QString comment() const;
72 Q_SERIALBUS_EXPORT void setComment(const QString &text);
73
74 Q_SERIALBUS_EXPORT QtCanBus::DataSource dataSource() const;
75 Q_SERIALBUS_EXPORT void setDataSource(QtCanBus::DataSource source);
76
77 Q_SERIALBUS_EXPORT QSysInfo::Endian dataEndian() const;
78 Q_SERIALBUS_EXPORT void setDataEndian(QSysInfo::Endian endian);
79
80 Q_SERIALBUS_EXPORT QtCanBus::DataFormat dataFormat() const;
81 Q_SERIALBUS_EXPORT void setDataFormat(QtCanBus::DataFormat format);
82
83 Q_SERIALBUS_EXPORT quint16 startBit() const;
84 Q_SERIALBUS_EXPORT void setStartBit(quint16 bit);
85
86 Q_SERIALBUS_EXPORT quint16 bitLength() const;
87 Q_SERIALBUS_EXPORT void setBitLength(quint16 length);
88
89 Q_SERIALBUS_EXPORT double factor() const;
90 Q_SERIALBUS_EXPORT void setFactor(double factor);
91
92 Q_SERIALBUS_EXPORT double offset() const;
93 Q_SERIALBUS_EXPORT void setOffset(double offset);
94
95 Q_SERIALBUS_EXPORT double scaling() const;
96 Q_SERIALBUS_EXPORT void setScaling(double scaling);
97
98 Q_SERIALBUS_EXPORT double minimum() const;
99 Q_SERIALBUS_EXPORT double maximum() const;
100 Q_SERIALBUS_EXPORT void setRange(double minimum, double maximum);
101
102 Q_SERIALBUS_EXPORT QtCanBus::MultiplexState multiplexState() const;
103 Q_SERIALBUS_EXPORT void setMultiplexState(QtCanBus::MultiplexState state);
104
105 Q_SERIALBUS_EXPORT MultiplexSignalValues multiplexSignals() const;
106 Q_SERIALBUS_EXPORT void clearMultiplexSignals();
107 Q_SERIALBUS_EXPORT void setMultiplexSignals(const MultiplexSignalValues &multiplexorSignals);
108 Q_SERIALBUS_EXPORT void addMultiplexSignal(const QString &name,
109 const MultiplexValues &ranges);
110 Q_SERIALBUS_EXPORT void addMultiplexSignal(const QString &name, const QVariant &value);
111
112private:
113 QExplicitlySharedDataPointer<QCanSignalDescriptionPrivate> d;
114 friend class QCanSignalDescriptionPrivate;
115
116 friend void qHash(const QCanSignalDescription &desc, size_t seed) noexcept = delete;
117 friend void operator==(const QCanSignalDescription &lhs,
118 const QCanSignalDescription &rhs) noexcept = delete;
119 friend void operator!=(const QCanSignalDescription &lhs,
120 const QCanSignalDescription &rhs) noexcept = delete;
121
122#ifndef QT_NO_DEBUG_STREAM
123 friend QDebug operator<<(QDebug dbg, const QCanSignalDescription &sig)
124 {
125 return debugStreaming(dbg, sig);
126 }
127 Q_SERIALBUS_EXPORT static QDebug debugStreaming(QDebug dbg, const QCanSignalDescription &sig);
128#endif // QT_NO_DEBUG_STREAM
129};
130
131Q_DECLARE_SHARED(QCanSignalDescription)
132
133QT_END_NAMESPACE
134
135#endif // QCANSIGNALDESCRIPTION_H
136

source code of qtserialbus/src/serialbus/qcansignaldescription.h