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. 更多...
头: | #include <QCanFrameProcessor> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS SerialBus)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus) |
qmake: | QT += serialbus |
Since: | Qt 6.5 |
该类在开发且可能改变。
struct | ParseResult |
enum class | Error { None, InvalidFrame, UnsupportedFrameFormat, Decoding, Encoding } |
QCanFrameProcessor () | |
~QCanFrameProcessor () | |
void | addMessageDescriptions (const QList<QCanMessageDescription> & descriptions ) |
void | clearMessageDescriptions () |
QCanFrameProcessor::Error | error () const |
QString | errorString () const |
QList<QCanMessageDescription> | messageDescriptions () const |
QCanFrameProcessor::ParseResult | parseFrame (const QCanBusFrame & frame ) |
QCanBusFrame | prepareFrame (QtCanBus::UniqueId uniqueId , const QVariantMap & signalValues ) |
void | setMessageDescriptions (const QList<QCanMessageDescription> & descriptions ) |
void | setUniqueIdDescription (const QCanUniqueIdDescription & description ) |
QCanUniqueIdDescription | uniqueIdDescription () const |
QStringList | warnings () const |
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:
The parseFrame () method can be used to process the incoming QCanBusFrame . The method returns a ParseResult structure which contains the unique identifier 和 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 () 和 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.
注意: The last error and error description, as well as the warnings, are reset once the decoding or encoding is started.
另请参阅 QCanMessageDescription and QCanSignalDescription .
This enum represents the possible errors that can occur while encoding or decoding the QCanBusFrame .
常量 | 值 | 描述 |
---|---|---|
QCanFrameProcessor::Error::None
|
0
|
没有出现错误。 |
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. |
Creates a CAN frame processor.
Destroys this frame processor.
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.
另请参阅 messageDescriptions (), setMessageDescriptions (),和 clearMessageDescriptions ().
Removes all message descriptions for this frame processor.
另请参阅 messageDescriptions (), addMessageDescriptions (),和 setMessageDescriptions ().
Returns the last error.
另请参阅 errorString (), prepareFrame (),和 parseFrame ().
Returns the text description of the last error.
另请参阅 error (), prepareFrame (),和 parseFrame ().
Returns all the message descriptions that are currently used by this frame processor.
另请参阅 addMessageDescriptions (), setMessageDescriptions (),和 clearMessageDescriptions ().
Parses the frame frame using the specified message descriptions.
The process of parsing is as follows:
This method returns a QCanFrameProcessor::ParseResult , which contains both the extracted unique identifier and a QVariantMap with the signals and their values. The keys of the map are the signal names , and the values of the map are signal values.
If an error occurred during the decoding, a result with empty signalValues is returned. In such cases, the error () 和 errorString () methods can be used to get information about the errors.
注意: Calling this method clears all previous errors and warnings.
另请参阅 addMessageDescriptions (), error (), errorString (),和 warnings ().
Constructs a CAN data frame, using uniqueId and signalValues and returns the constructed QCanBusFrame .
The signalValues 参数 must contain signal names as keys, and expected signal values as values.
The process of creating the frame is as follows:
If an error occurred during the encoding, an invalid QCanBusFrame is returned. In such cases, the error () 和 errorString () methods can be used to get information about the errors.
注意: Calling this method clears all previous errors and warnings.
另请参阅 addMessageDescriptions (), error (), errorString (),和 warnings ().
Replaces current message descriptions used by this frame processor with the new message descriptions descriptions .
另请参阅 messageDescriptions (), addMessageDescriptions (),和 clearMessageDescriptions ().
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.
另请参阅 uniqueIdDescription () 和 QCanUniqueIdDescription .
Returns the unique identifier 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.
另请参阅 setUniqueIdDescription () 和 QCanUniqueIdDescription .
Returns the list of warnings generated during the last encoding or decoding call.
另请参阅 error (), errorString (), prepareFrame (),和 parseFrame ().