QCanDbcFileParser Class

The QCanDbcFileParser class can be used to parse DBC files. 更多...

头: #include <QCanDbcFileParser>
CMake: find_package(Qt6 REQUIRED COMPONENTS SerialBus)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus)
qmake: QT += serialbus
Since: Qt 6.5
状态: Preliminary

该类在开发且可能改变。

公共类型

enum class Error { None, FileReading, Parsing }
MessageValueDescriptions
SignalValueDescriptions
ValueDescriptions

公共函数

QCanDbcFileParser ()
~QCanDbcFileParser ()
QCanDbcFileParser::Error error () const
QString errorString () const
QList<QCanMessageDescription> messageDescriptions () const
QCanDbcFileParser::MessageValueDescriptions messageValueDescriptions () const
bool parse (const QString & fileName )
bool parse (const QStringList & fileNames )
(从 6.7 起) bool parseData (QStringView data )
QStringList warnings () const

静态公共成员

QCanUniqueIdDescription uniqueIdDescription ()

详细描述

A CAN database or CAN DBC file is an ASCII text file that contains information on how to decode and interpret raw CAN bus data. Some more details about the format can be found here or here .

The QCanDbcFileParser class takes the input DBC file, parses it, and provides a list of QCanMessageDescription s as an output. These message descriptions can be forwarded to QCanFrameProcessor , and later used as rules to encode or decode QCanBusFrame

Use one of parse () overloads to specify a file or a list of files that will be processed. Both overloads return true if the parsing completes successfully and false 否则。

调用 error () method to get the error which occurred during the parsing. If the parsing completes successfully, this method will return None . Otherwise, you can use an errorString () method to get the string representation of an error.

During the parsing some non-critical problems may occur as well. Such problems will be logged, but the parsing process will not be aborted. You can use the warnings () method to get the full list of such problems after the parsing is completed.

If the parsing completes successfully, call messageDescriptions () to get a list of the message descriptions that were extracted during the last parse () call. Call messageValueDescriptions () to get the textual descriptions of signal raw values, if they are available.

Use the static uniqueIdDescription () function to get a QCanUniqueIdDescription for the DBC format.

QCanDbcFileParser fileParser;
const bool result = fileParser.parse(u"path/to/file.dbc"_s);
// Check result, call error() and warnings() if needed
// Prepare a QCanFrameProcessor to decode or encode DBC frames
QCanFrameProcessor frameProcessor;
frameProcessor.setUniqueIdDescription(QCanDbcFileParser::uniqueIdDescription());
frameProcessor.setMessageDescriptions(fileParser.messageDescriptions());
					

注意: The parser is stateful, which means that all the results (like extracted message descriptions, error code, or warnings) are reset once the next parsing starts.

Supported Keywords

The current implementation supports only a subset of keywords that you can find in a DBC file:

  • BO_ - message description.
  • SG_ - signal description.
  • SIG_VALTYPE_ - signal type description.
  • SG_MUL_VAL_ - extended multiplexing description.
  • CM_ - comments (only for message and signal descriptions).
  • VAL_ - textual descriptions for raw signal values.

Lines starting from other keywords are simply ignored.

另请参阅 QCanMessageDescription and QCanFrameProcessor .

成员类型文档编制

enum class QCanDbcFileParser:: Error

This enum represents the possible errors that can happen during the parsing of a DBC file.

常量 描述
QCanDbcFileParser::Error::None 0 没有出现错误。
QCanDbcFileParser::Error::FileReading 1 An error occurred while opening or reading the file.
QCanDbcFileParser::Error::Parsing 2 An error occurred while parsing the content of the file.

[alias] QCanDbcFileParser:: MessageValueDescriptions

This is a type alias for QHash<QtCanBus::UniqueId, SignalValueDescriptions> .

The keys of the hash represent message unique ids, and the values of the hash contain the corresponding QCanDbcFileParser::SignalValueDescriptions 条目。

另请参阅 QCanDbcFileParser::SignalValueDescriptions .

[alias] QCanDbcFileParser:: SignalValueDescriptions

This is a type alias for QHash<QString, ValueDescriptions> .

The keys of the hash represent signal names, and the values of the hash contain the corresponding QCanDbcFileParser::ValueDescriptions 条目。

另请参阅 QCanDbcFileParser::ValueDescriptions .

[alias] QCanDbcFileParser:: ValueDescriptions

This is a type alias for QHash<quint32, QString> .

The keys of the hash represent raw signal values, and the values of the hash represent corresponding string descriptions.

成员函数文档编制

QCanDbcFileParser:: QCanDbcFileParser ()

Constructs a DBC file parser.

[noexcept] QCanDbcFileParser:: ~QCanDbcFileParser ()

Destroys this DBC file parser.

QCanDbcFileParser::Error QCanDbcFileParser:: error () const

Returns the last error which occurred during the parsing.

另请参阅 errorString () 和 parse ().

QString QCanDbcFileParser:: errorString () const

Returns the text representation of the last error which occurred during the parsing or an empty string if there was no error.

另请参阅 error ().

QList < QCanMessageDescription > QCanDbcFileParser:: messageDescriptions () const

Returns the list of message descriptions that were extracted during the last parse () 调用。

另请参阅 parse () 和 error ().

QCanDbcFileParser::MessageValueDescriptions QCanDbcFileParser:: messageValueDescriptions () const

Returns the textual descriptions for signal raw values.

DBC supports the possibility to provide textual descriptions to signal raw values. If such data exists in the parsed DBC file(s), it can be accessed using this function.

The textual descriptions are unique for a certain signal within a specific message, so the returned structure contains the information about the message unique id and the signal name, as well as the actual value descriptions.

另请参阅 QCanDbcFileParser::MessageValueDescriptions , QCanDbcFileParser::SignalValueDescriptions ,和 QCanDbcFileParser::ValueDescriptions .

bool QCanDbcFileParser:: parse (const QString & fileName )

Parses the file fileName 。返回 true if the parsing completed successfully or false 否则。

If the parsing completed successfully, call the messageDescriptions () method to get the list of all extracted message descriptions.

If the parsing failed, call the error () 和 errorString () methods to get the information about the error.

调用 warnings () method to get the list of warnings that were logged during the parsing.

注意: This method expects the file contents to be encoded in UTF-8. If the file has a different encoding, decode it first, and use parseData () to extract the DBC information.

另请参阅 messageDescriptions (), error (), warnings (),和 parseData ().

bool QCanDbcFileParser:: parse (const QStringList & fileNames )

这是重载函数。

Parses a list of files fileNames 。返回 true if the parsing completed successfully or false 否则。

If the parsing completed successfully, call the messageDescriptions () method to get the list of all extracted message descriptions.

The parsing stops at the first error. Call the error () 和 errorString () methods to get the information about the error.

调用 warnings () method to get the list of warnings that were logged during the parsing.

注意: This method expects the file contents to be encoded in UTF-8. If the file has a different encoding, decode it first, and use parseData () to extract the DBC information.

另请参阅 messageDescriptions (), error (), warnings (),和 parseData ().

[since 6.7] bool QCanDbcFileParser:: parseData ( QStringView data )

Parses the input data data 并返回 true if the parsing completed successfully or false 否则。

If the parsing completed successfully, call the messageDescriptions () method to get the list of all extracted message descriptions.

If the parsing failed, call the error () 和 errorString () methods to get the information about the error.

调用 warnings () method to get the list of warnings that were logged during the parsing.

The method expects that data is the content of a valid DBC file, properly converted to QStringView .

Use this method when the input file has an encoding different from UTF-8.

// Read the data from a DBC file with custom encoding
const QByteArray initialData = ...;
// Convert to UTF-16 using QStringDecoder or some other way
const QString decodedData = ...;
QCanDbcFileParser parser;
const bool result = parser.parseData(decodedData);
					

该函数在 Qt 6.7 引入。

另请参阅 messageDescriptions (), error (), warnings (),和 parse ().

[static] QCanUniqueIdDescription QCanDbcFileParser:: uniqueIdDescription ()

Returns a unique identifier description. DBC protocol always uses the Frame Id as an identifier, and therefore the unique identifier description is always the same.

Use this method to get an instance of QCanUniqueIdDescription and pass it to QCanFrameProcessor .

另请参阅 QCanFrameProcessor::setUniqueIdDescription ().

QStringList QCanDbcFileParser:: warnings () const

Returns the list of non-critical problems which occurred during the parsing.

A typical problem can be a malformed message or signal description. In such cases the malformed message or signal is skipped, but the rest of the file can be processed as usual.

另请参阅 error () 和 parse ().