QCanBusFrame Class
QCanBusFrame is a container class representing a single CAN frame. More...
Header: | #include <QCanBusFrame> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
Public Types
class | TimeStamp |
enum | FrameError { NoError, TransmissionTimeoutError, LostArbitrationError, ControllerError, ..., AnyError } |
flags | FrameErrors |
enum | FrameType { UnknownFrame, DataFrame, ErrorFrame, RemoteRequestFrame, InvalidFrame } |
Public Functions
QCanBusFrame(QCanBusFrame::FrameType type = DataFrame) | |
QCanBusFrame(quint32 identifier, const QByteArray &data) | |
QCanBusFrame::FrameErrors | error() const |
quint32 | frameId() const |
QCanBusFrame::FrameType | frameType() const |
bool | hasBitrateSwitch() const |
bool | hasErrorStateIndicator() const |
bool | hasExtendedFrameFormat() const |
bool | hasFlexibleDataRateFormat() const |
bool | hasLocalEcho() const |
bool | isValid() const |
QByteArray | payload() const |
void | setBitrateSwitch(bool bitrateSwitch) |
void | setError(QCanBusFrame::FrameErrors e) |
void | setErrorStateIndicator(bool errorStateIndicator) |
void | setExtendedFrameFormat(bool isExtended) |
void | setFlexibleDataRateFormat(bool isFlexibleData) |
void | setFrameId(quint32 newFrameId) |
void | setFrameType(QCanBusFrame::FrameType newFormat) |
void | setLocalEcho(bool localEcho) |
void | setPayload(const QByteArray &data) |
void | setTimeStamp(QCanBusFrame::TimeStamp ts) |
QCanBusFrame::TimeStamp | timeStamp() const |
QString | toString() const |
Related Non-Members
QDataStream & | operator<<(QDataStream &out, const QCanBusFrame &frame) |
QDataStream & | operator>>(QDataStream &in, QCanBusFrame &frame) |
Detailed Description
QCanBusFrame is a container class representing a single CAN frame.
QCanBusDevice can use QCanBusFrame for read and write operations. It contains the frame identifier and the data payload. QCanBusFrame contains the timestamp of the moment it was read.
See also QCanBusFrame::TimeStamp.
Member Type Documentation
enum QCanBusFrame::FrameError
flags QCanBusFrame::FrameErrors
This enum describes the possible error types.
Constant | Value | Description |
---|---|---|
QCanBusFrame::NoError | 0 | No error has occurred. |
QCanBusFrame::TransmissionTimeoutError | (1 << 0) | The transmission has timed out. |
QCanBusFrame::LostArbitrationError | (1 << 1) | The frame could not be sent due to lost arbitration on the bus. |
QCanBusFrame::ControllerError | (1 << 2) | The controller encountered an error. |
QCanBusFrame::ProtocolViolationError | (1 << 3) | A protocol violation has occurred. |
QCanBusFrame::TransceiverError | (1 << 4) | A transceiver error occurred |
QCanBusFrame::MissingAcknowledgmentError | (1 << 5) | The transmission received no acknowledgment. |
QCanBusFrame::BusOffError | (1 << 6) | The CAN bus is offline. |
QCanBusFrame::BusError | (1 << 7) | A CAN bus error occurred. |
QCanBusFrame::ControllerRestartError | (1 << 8) | The controller restarted. |
QCanBusFrame::UnknownError | (1 << 9) | An unknown error has occurred. |
QCanBusFrame::AnyError | 0x1FFFFFFFU | Matches every other error type. |
The FrameErrors type is a typedef for QFlags<FrameError>. It stores an OR combination of FrameError values.
enum QCanBusFrame::FrameType
This enum describes the type of the CAN frame.
Constant | Value | Description |
---|---|---|
QCanBusFrame::UnknownFrame | 0x0 | The frame type is unknown. |
QCanBusFrame::DataFrame | 0x1 | This value represents a data frame. |
QCanBusFrame::ErrorFrame | 0x2 | This value represents an error frame. |
QCanBusFrame::RemoteRequestFrame | 0x3 | This value represents a remote request. |
QCanBusFrame::InvalidFrame | 0x4 | This value represents an invalid frame. This type is used for error reporting. |
See also setFrameType().
Member Function Documentation
QCanBusFrame::QCanBusFrame(QCanBusFrame::FrameType type = DataFrame)
Default constructs an instance of QCanBusFrame.
QCanBusFrame::QCanBusFrame(quint32 identifier, const QByteArray &data)
Default constructs an instance of QCanBusFrame.
QCanBusFrame::FrameErrors QCanBusFrame::error() const
See also setError().
quint32 QCanBusFrame::frameId() const
See also setFrameId().
QCanBusFrame::FrameType QCanBusFrame::frameType() const
See also setFrameType().
bool QCanBusFrame::hasBitrateSwitch() const
bool QCanBusFrame::hasErrorStateIndicator() const
bool QCanBusFrame::hasExtendedFrameFormat() const
bool QCanBusFrame::hasFlexibleDataRateFormat() const
bool QCanBusFrame::hasLocalEcho() const
bool QCanBusFrame::isValid() const
QByteArray QCanBusFrame::payload() const
See also setPayload().
void QCanBusFrame::setBitrateSwitch(bool bitrateSwitch)
See also hasBitrateSwitch().
void QCanBusFrame::setError(QCanBusFrame::FrameErrors e)
See also error().
void QCanBusFrame::setErrorStateIndicator(bool errorStateIndicator)
See also hasErrorStateIndicator().
void QCanBusFrame::setExtendedFrameFormat(bool isExtended)
See also hasExtendedFrameFormat().
void QCanBusFrame::setFlexibleDataRateFormat(bool isFlexibleData)
See also hasFlexibleDataRateFormat().
void QCanBusFrame::setFrameId(quint32 newFrameId)
See also frameId().
void QCanBusFrame::setFrameType(QCanBusFrame::FrameType newFormat)
See also frameType().
void QCanBusFrame::setLocalEcho(bool localEcho)
See also hasLocalEcho().
void QCanBusFrame::setPayload(const QByteArray &data)
See also payload().
void QCanBusFrame::setTimeStamp(QCanBusFrame::TimeStamp ts)
See also timeStamp().
QCanBusFrame::TimeStamp QCanBusFrame::timeStamp() const
See also setTimeStamp().
QString QCanBusFrame::toString() const
Returns the CAN frame as a formatted string.
The output contains the CAN identifier in hexadecimal format, right adjusted to 32 bit, followed by the data length in square brackets and the payload in hexadecimal format.
Standard identifiers are filled with spaces while extended identifiers are filled with zeros.
Typical outputs are:
(Error) - error frame 7FF [1] 01 - data frame with standard identifier 1FFFFFFF [8] 01 23 45 67 89 AB CD EF - data frame with extended identifier 400 [10] 01 23 45 67 ... EF 01 23 - CAN FD frame 123 [5] Remote Request - remote frame with standard identifier 00000234 [0] Remote Request - remote frame with extended identifier
Related Non-Members
QDataStream &operator<<(QDataStream &out, const QCanBusFrame &frame)
Writes a frame to the stream (out) and returns a reference to the it.
QDataStream &operator>>(QDataStream &in, QCanBusFrame &frame)
Reads a frame from the stream (in) and returns a reference to the it.