QCanFrameProcessor Class | Qt Serial Bus | Qt 6.10.2
Description: The QCanFrameProcessor class can be used to decode a QCanBusFrame or to convert the input data into a QCanBusFrame that is ready to be sent to the receiver.

- Qt 6.10
- Qt Serial Bus
- C++ Classes
- QCanFrameProcessor
- Qt 6.10.2 Reference Documentation

# QCanFrameProcessor Class

The QCanFrameProcessor class can be used to decode a QCanBusFrame or to convert the input data into a QCanBusFrame that is ready to be sent to the receiver. More...

Header: | `#include <QCanFrameProcessor>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS SerialBus)` `target_link_libraries(mytarget PRIVATE Qt6::SerialBus)`
qmake: | `QT += serialbus`
Since: | Qt 6.5
Status: | Preliminary

This class is under development and is subject to change.

- List of all members, including inherited members

## Public Types

`(since 6.5)` struct | ParseResult
enum class | Error { None, InvalidFrame, UnsupportedFrameFormat, Decoding, Encoding }

## Public Functions

| ~QCanFrameProcessor()
Q_DECL_IMPORT | addMessageDescriptions(const int &descriptions)
Q_DECL_IMPORT | clearMessageDescriptions()
Q_DECL_IMPORT | setMessageDescriptions(const int &descriptions)
Q_DECL_IMPORT | setUniqueIdDescription(const class QCanUniqueIdDescription &description)

## Detailed Description

The QCanFrameProcessor class operates on the CAN message descriptions (represented by the QCanMessageDescription and QCanSignalDescription classes) and a unique identifier description (represented by QCanUniqueIdDescription). It uses the descriptions to decode the incoming QCanBusFrame or to encode the user-specified data into the proper payload.

Before doing any decoding or encoding, the QCanFrameProcessor instance must be initialized properly. The following data needs to be provided:

- A valid unique identifier description. Use the setUniqueIdDescription() method to provide a proper description.
- At least one message description. Use the addMessageDescriptions() or setMessageDescriptions() method to provide message descriptions. All message descriptions must have distinct unique identifiers. Each message can contain multiple signal descriptions, but signal names within one message must be unique as well.

The parseFrame() method can be used to process the incoming QCanBusFrame. The method returns a ParseResult structure which contains the unique identifier and the signal values map. The keys of the map are the signal names, and the values of the map are signal values.

The prepareFrame() method can be used to generate a QCanBusFrame object for a specific unique identifier, using the provided signal names and desired values.

Errors can occur during the encoding or decoding process. In such cases the error() and errorString() methods can be used to get the information about the error.

Some non-critical problems may occur as well. Such problems will be logged, but the process will not be stopped. After the process is completed, the warnings() method can be used to access the list of all the warnings.

Note: The last error and error description, as well as the warnings, are reset once the decoding or encoding is started.

See also QCanMessageDescription and QCanSignalDescription.

## Member Type Documentation

### enum class QCanFrameProcessor::Error

This enum represents the possible errors that can occur while encoding or decoding the QCanBusFrame.

Constant | Value | Description
--- | --- | ---
`QCanFrameProcessor::Error::None` | `0` | No error occurred.
`QCanFrameProcessor::Error::InvalidFrame` | `1` | The received frame is invalid and cannot be parsed.
`QCanFrameProcessor::Error::UnsupportedFrameFormat` | `2` | The format of the received frame is not supported and cannot be parsed.
`QCanFrameProcessor::Error::Decoding` | `3` | An error occurred during decoding. Use errorString() to get a string representation of the error.
`QCanFrameProcessor::Error::Encoding` | `4` | An error occurred during encoding. Use errorString() to get a string representation of the error.

## Member Function Documentation

### `[noexcept]` QCanFrameProcessor::~QCanFrameProcessor()

Destroys this frame processor.

### Q_DECL_IMPORT QCanFrameProcessor::addMessageDescriptions(const int &descriptions)

Adds new message descriptions descriptions to the available message descriptions.

All message descriptions should have distinct unique ids.

If some message descriptions have repeated unique ids, only the last description will be used.

If the parser already had a message description with the same unique id, it will be overwritten.

See also messageDescriptions(), setMessageDescriptions(), and clearMessageDescriptions().

### Q_DECL_IMPORT QCanFrameProcessor::clearMessageDescriptions()

Removes all message descriptions for this frame processor.

See also messageDescriptions(), addMessageDescriptions(), and setMessageDescriptions().

### Q_DECL_IMPORT QCanFrameProcessor::setMessageDescriptions(const int &descriptions)

Replaces current message descriptions used by this frame processor with the new message descriptions descriptions.

See also messageDescriptions(), addMessageDescriptions(), and clearMessageDescriptions().

### Q_DECL_IMPORT QCanFrameProcessor::setUniqueIdDescription(const class QCanUniqueIdDescription &description)

Sets the unique identifier description to description.

The unique identifier description must be valid in order to encode or decode the CAN bus frames. See the QCanUniqueIdDescription class documentation for more details.

See also uniqueIdDescription() and QCanUniqueIdDescription.