| 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 | |
| 14 | QT_BEGIN_NAMESPACE | 
| 15 | |
| 16 | class QCanDbcFileParserPrivate; | 
| 17 | class QCanMessageDescription; | 
| 18 | class QCanUniqueIdDescription; | 
| 19 | |
| 20 | class QCanDbcFileParser | 
| 21 | { | 
| 22 | public: | 
| 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 | Q_SERIALBUS_EXPORT bool parseData(QStringView data); | 
| 42 | |
| 43 | Q_SERIALBUS_EXPORT QList<QCanMessageDescription> messageDescriptions() const; | 
| 44 | Q_SERIALBUS_EXPORT MessageValueDescriptions messageValueDescriptions() const; | 
| 45 | |
| 46 | Q_SERIALBUS_EXPORT Error error() const; | 
| 47 | Q_SERIALBUS_EXPORT QString errorString() const; | 
| 48 | Q_SERIALBUS_EXPORT QStringList warnings() const; | 
| 49 | |
| 50 | Q_SERIALBUS_EXPORT static QCanUniqueIdDescription uniqueIdDescription(); | 
| 51 | |
| 52 | private: | 
| 53 | std::unique_ptr<QCanDbcFileParserPrivate> d; | 
| 54 | friend class QCanDbcFileParserPrivate; | 
| 55 | |
| 56 | Q_DISABLE_COPY_MOVE(QCanDbcFileParser) | 
| 57 | }; | 
| 58 | |
| 59 | QT_END_NAMESPACE | 
| 60 | |
| 61 | #endif // QCANDBCFILEPARSER_H | 
| 62 | 
