QCanBusFrame is a container class representing a single CAN frame. More...
Header: | #include <QCanBusFrame> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
class | TimeStamp |
enum | FrameError { NoError, TransmissionTimeoutError, LostArbitrationError, ControllerError, ..., AnyError } |
flags | FrameErrors |
enum | FrameType { UnknownFrame, DataFrame, ErrorFrame, RemoteRequestFrame, InvalidFrame } |
QCanBusFrame(QCanBusFrame::FrameType type = ...) | |
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 error) |
void | setErrorStateIndicator(bool errorStateIndicator) |
void | setExtendedFrameFormat(bool isExtended) |
void | setFlexibleDataRateFormat(bool isFlexibleData) |
void | setFrameId(quint32 newFrameId) |
void | setFrameType(QCanBusFrame::FrameType newType) |
void | setLocalEcho(bool echo) |
void | setPayload(const QByteArray &data) |
void | setTimeStamp(QCanBusFrame::TimeStamp ts) |
QCanBusFrame::TimeStamp | timeStamp() const |
QString | toString() const |
QDataStream & | operator<<(QDataStream &out, const QCanBusFrame &frame) |
QDataStream & | operator>>(QDataStream &in, QCanBusFrame &frame) |
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.
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.
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().
Constructs a CAN frame of the specified type.
Constructs a CAN frame using identifier as the frame identifier and data as the payload.
Returns the error of the current error frame. If the frame is not an ErrorFrame, this function returns NoError.
See also setError().
Returns the CAN frame identifier. If the CAN frame uses the extended frame format, the identifier has a maximum of 29 bits; otherwise 11 bits.
If the frame is of ErrorFrame type, this ID is always 0.
See also setFrameId() and hasExtendedFrameFormat().
Returns the type of the frame.
See also setFrameType().
Returns true
if the CAN uses Flexible Data-Rate with Bitrate Switch, to transfer the payload data at a higher data bitrate.
This function was introduced in Qt 5.9.
See also setBitrateSwitch() and QCanBusDevice::DataBitRateKey.
Returns true
if the CAN uses Flexible Data-Rate with Error State Indicator set.
This flag is set by the transmitter's CAN FD hardware to indicate the transmitter's error state.
This function was introduced in Qt 5.9.
See also setErrorStateIndicator().
Returns true
if the CAN frame uses a 29bit identifier; otherwise false
, implying an 11bit identifier.
See also setExtendedFrameFormat() and frameId().
Returns true
if the CAN frame uses Flexible Data-Rate which allows up to 64 data bytes, otherwise false
, implying at most 8 byte of payload.
See also setFlexibleDataRateFormat() and payload().
Returns true
if the frame is a local echo frame, i.e. a frame that is received as echo when the frame with the same content was successfully sent to the CAN bus. This flag is set for frames sent by the
application itself as well as for frames sent by other applications running on the same system.
QCanBusDevice::ReceiveOwnKey must be set to true to receive echo frames.
This function was introduced in Qt 5.10.
See also setLocalEcho(), QCanBusDevice::ReceiveOwnKey, and QCanBusDevice::LoopbackKey.
Returns false
if the frameType() is InvalidFrame, the hasExtendedFrameFormat() is not set although frameId() is longer than 11 bit or the payload is longer than the maximal permitted
payload length of 64 byte if Flexible Data-Rate mode is enabled or 8 byte if it is disabled. If frameType() is RemoteRequestFrame and the Flexible Data-Rate mode is enabled at the same time false
is also returned.
Otherwise this function returns true
.
Returns the data payload of the frame.
See also setPayload().
Set the Flexible Data-Rate flag Bitrate Switch flag to bitrateSwitch. The data field of frames with this flag is transferred at a higher data bitrate.
This function was introduced in Qt 5.9.
See also hasBitrateSwitch() and QCanBusDevice::DataBitRateKey.
Sets the frame's error type. This function does nothing if frameType() is not an ErrorFrame.
See also error().
Set the Flexible Data-Rate flag Error State Indicator flag to errorStateIndicator.
When sending CAN FD frames, this flag is automatically set by the CAN FD hardware. QCanBusFrame::setErrorStateIndicator()
should only be used for application testing, e.g. on virtual CAN FD busses.
This function was introduced in Qt 5.9.
See also hasErrorStateIndicator().
Sets the extended frame format flag to isExtended.
See also hasExtendedFrameFormat().
Sets the Flexible Data-Rate flag to isFlexibleData. Those frames can be sent using a higher speed on supporting controllers. Additionally the payload length limit is raised to 64 byte.
See also hasFlexibleDataRateFormat().
Sets the identifier of the CAN frame to newFrameId. The maximum size of a CAN frame identifier is 11 bits, which can be extended up to 29 bits by supporting the CAN extended frame format. The CAN extended frame format setting is automatically adapted to match newFrameId.
See also frameId() and hasExtendedFrameFormat().
Sets the type of the frame to newType.
See also frameType().
Set the Local Echo flag to echo.
When sending CAN bus frames with QCanBusDevice::ReceiveOwnKey enabled, all successfully sent frames are echoed to the receive queue and marked as local echo frames.
QCanBusFrame::setLocalEcho
should therefore only be used for application testing, e.g. on virtual CAN busses.
This function was introduced in Qt 5.10.
See also hasLocalEcho().
Sets data as the payload for the CAN frame. The maximum size of payload is 8 bytes, which can be extended up to 64 bytes by supporting Flexible Data-Rate. If data contains more than 8 byte the Flexible Data-Rate flag is automatically set. Flexible Data-Rate has to be enabled on the QCanBusDevice by setting the QCanBusDevice::CanFdKey.
Frames of type RemoteRequestFrame (RTR) do not have a payload. However they have to provide an indication of the responses expected payload length. To set the length expection it is necessary to set a fake payload whose length matches the expected payload length of the response. One way of doing this might be as follows:
QCanBusFrame frame(QCanBusFrame::RemoteRequestFrame); int expectedResponseLength = ...; frame.setPayload(QByteArray(expectedResponseLength, 0));
See also payload() and hasFlexibleDataRateFormat().
Sets ts as the timestamp for the CAN frame. Usually, this function is not needed, because the timestamp is created during the read operation and not needed during the write operation.
See also timeStamp() and QCanBusFrame::TimeStamp.
Returns the timestamp of the frame.
See also QCanBusFrame::TimeStamp and QCanBusFrame::setTimeStamp().
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
Writes a frame to the stream (out) and returns a reference to the it.
Reads a frame from the stream (in) and returns a reference to the it.