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 QCANDBCFILEPARSER_H
5#define QCANDBCFILEPARSER_H
6
7#include <QtCore/QList>
8
9#include <QtSerialBus/qcancommondefinitions.h>
10#include <QtSerialBus/qtserialbusglobal.h>
11
12#include <memory>
13
14QT_BEGIN_NAMESPACE
15
16class QCanDbcFileParserPrivate;
17class QCanMessageDescription;
18class QCanUniqueIdDescription;
19
20class QCanDbcFileParser
21{
22public:
23 enum class Error : quint8 {
24 None = 0,
25 FileReading,
26 Parsing
27 };
28
29 // The DBC protocol uses unsigned_integer to describe the supported values.
30 // Do we need to use QVariant instead of quint32? Or qint64 for better BC
31 // guarantees?
32 using ValueDescriptions = QHash<quint32, QString>;
33 using SignalValueDescriptions = QHash<QString, ValueDescriptions>;
34 using MessageValueDescriptions = QHash<QtCanBus::UniqueId, SignalValueDescriptions>;
35
36 Q_SERIALBUS_EXPORT QCanDbcFileParser();
37 Q_SERIALBUS_EXPORT ~QCanDbcFileParser();
38
39 Q_SERIALBUS_EXPORT bool parse(const QString &fileName);
40 Q_SERIALBUS_EXPORT bool parse(const QStringList &fileNames);
41
42 Q_SERIALBUS_EXPORT QList<QCanMessageDescription> messageDescriptions() const;
43 Q_SERIALBUS_EXPORT MessageValueDescriptions messageValueDescriptions() const;
44
45 Q_SERIALBUS_EXPORT Error error() const;
46 Q_SERIALBUS_EXPORT QString errorString() const;
47 Q_SERIALBUS_EXPORT QStringList warnings() const;
48
49 Q_SERIALBUS_EXPORT static QCanUniqueIdDescription uniqueIdDescription();
50
51private:
52 std::unique_ptr<QCanDbcFileParserPrivate> d;
53 friend class QCanDbcFileParserPrivate;
54
55 Q_DISABLE_COPY_MOVE(QCanDbcFileParser)
56};
57
58QT_END_NAMESPACE
59
60#endif // QCANDBCFILEPARSER_H
61

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