The QCanFrame class supports CAN data frames and CAN error frames. The method frameType() is used to distinguish between these formats. The frame type can be selected either by the constructor QCanFrame(const FrameType_e &) or by using setFrameType().
Data Frame
The QCanFrame class distinguishes the four message frame formats via the method frameFormat(), possible values are listed by the enumeration QCanFrame::FrameFormat_e.
The class provides two application specific fields with a size of 32-bit which are compliant are compliant to the CpCanMsg_s structure They can be accessed by the setMarker() and setUser() methods. An optional time-stamp is provided by the setTimeStamp() method.
Error Frame
A frame of type QCanFrame::eFRAME_TYPE_ERROR is used to inform about the actual error state (function errorState()) and the current values of the error counters (functions errorCounterReceive() and errorCounterTransmit()). In addition, it is possible to inform about the last error type which caused the error condition (function errorType()).
Definition qcan_frame.hpp:159
@ eFRAME_TYPE_ERROR
Definition qcan_frame.hpp:229
void setErrorCounterTransmit(const uint8_t &ubErrorCntR)
void setErrorCounterReceive(const uint8_t &ubErrorCntR)
void setFrameType(const FrameType_e &ubTypeR)
#include <qcan_frame.hpp>
|
| enum | ErrorType_e {
eERROR_TYPE_NONE = 0
,
eERROR_TYPE_BIT0
,
eERROR_TYPE_BIT1
,
eERROR_TYPE_STUFF
,
eERROR_TYPE_FORM
,
eERROR_TYPE_CRC
,
eERROR_TYPE_ACK
} |
| |
| enum | FrameFormat_e {
eFORMAT_CAN_STD = 0
,
eFORMAT_CAN_EXT
,
eFORMAT_FD_STD
,
eFORMAT_FD_EXT
} |
| |
| enum | FrameType_e {
eFRAME_TYPE_UNKNOWN = 0
,
eFRAME_TYPE_DATA
,
eFRAME_TYPE_ERROR
} |
| |
|
| | QCanFrame () |
| |
| | QCanFrame (const FrameType_e &ubTypeR) |
| |
| | QCanFrame (const FrameFormat_e &ubFormatR, const uint32_t &ulIdentifierR=0, const uint8_t &ubDlcR=0) |
| |
| | QCanFrame (const QCanFrame &clOtherR) |
| |
| QCanFrame & | operator= (const QCanFrame &clOtherR) |
| |
| bool | bitrateSwitch (void) const |
| |
| uint8_t | data (const uint8_t &ubPosR) const |
| |
| QByteArray | data (void) const |
| |
| uint8_t | dataSize (void) const |
| |
| uint16_t | dataUInt16 (const uint8_t &ubPosR, const bool &btMsbFirstR=false) const |
| |
| uint32_t | dataUInt32 (const uint8_t &ubPosR, const bool &btMsbFirstR=false) const |
| |
| uint8_t | dlc (void) const |
| |
| uint8_t | errorCounterReceive (void) const |
| |
| uint8_t | errorCounterTransmit (void) const |
| |
| QCan::CAN_State_e | errorState (void) const |
| |
| bool | errorStateIndicator (void) const |
| |
| ErrorType_e | errorType (void) const |
| |
| FrameFormat_e | frameFormat (void) const |
| |
| FrameType_e | frameType (void) const |
| |
| bool | fromByteArray (const QByteArray &clByteArrayR) |
| |
| bool | fromCpCanMsg (const struct CpCanMsg_s *ptsCanMsgV) |
| |
| uint32_t | identifier (void) const |
| |
| bool | isExtended (void) const |
| |
| bool | isRemote (void) const |
| |
| uint32_t | marker (void) const |
| |
| void | setBitrateSwitch (const bool &btBrsR=true) |
| |
| void | setData (const uint8_t &ubPosR, const uint8_t &ubValueR) |
| |
| void | setDataSize (uint8_t ubSizeV) |
| |
| void | setDataUInt16 (const uint8_t &ubPosR, const uint16_t &uwValueR, const bool &btMsbFirstR=0) |
| |
| void | setDataUInt32 (const uint8_t &ubPosR, const uint32_t &ulValueR, const bool &btMsbFirstR=0) |
| |
| void | setDlc (uint8_t ubDlcV) |
| |
| void | setErrorCounterReceive (const uint8_t &ubErrorCntR) |
| |
| void | setErrorCounterTransmit (const uint8_t &ubErrorCntR) |
| |
| void | setErrorState (QCan::CAN_State_e ubStateV) |
| |
| void | setErrorType (ErrorType_e ubTypeV) |
| |
| void | setErrorStateIndicator (const bool &btEsiR=true) |
| |
| void | setFrameFormat (const FrameFormat_e &ubFormatR) |
| |
| void | setFrameType (const FrameType_e &ubTypeR) |
| |
| void | setIdentifier (uint32_t ulIdentifierV) |
| |
| void | setMarker (const uint32_t &ulMarkerValueR) |
| |
| void | setRemote (const bool &btRtrR=true) |
| |
| void | setUser (const uint32_t &ulUserValueR) |
| |
| void | setTimeStamp (const QCanTimeStamp &clTimeStampR) |
| |
| QCanTimeStamp | timeStamp (void) const |
| |
| QByteArray | toByteArray (void) const |
| |
| bool | toCpCanMsg (struct CpCanMsg_s *ptsCanMsgV) const |
| |
| virtual QString | toString (const bool &btShowTimeR=false, const bool &btShowDataSizeR=false) const |
| |
◆ ErrorType_e
The enumeration ErrorType_e defines CAN error types.
| Enumerator |
|---|
| eERROR_TYPE_NONE | no error
|
| eERROR_TYPE_BIT0 | Bit 0 error occurred
|
| eERROR_TYPE_BIT1 | Bit 1 error occurred
|
| eERROR_TYPE_STUFF | Stuff error occurred
|
| eERROR_TYPE_FORM | Form error occurred
|
| eERROR_TYPE_CRC | CRC error occurred
|
| eERROR_TYPE_ACK | Acknowledgement error occurred
|
◆ FrameFormat_e
This enumeration defines the CAN frame formats for classic CAN and CAN FD.
| Enumerator |
|---|
| eFORMAT_CAN_STD | Classic CAN, Standard frame format
|
| eFORMAT_CAN_EXT | Classic CAN, Extended frame format
|
| eFORMAT_FD_STD | ISO CAN FD, Standard frame format
|
| eFORMAT_FD_EXT | ISO CAN FD, Extended frame format
|
◆ FrameType_e
The enumeration FrameType_e defines the different CAN frame types.
| Enumerator |
|---|
| eFRAME_TYPE_UNKNOWN | Unknown frame type
|
| eFRAME_TYPE_DATA | Data frame
|
| eFRAME_TYPE_ERROR | Error frame
|
◆ QCanFrame() [1/4]
◆ QCanFrame() [2/4]
◆ QCanFrame() [3/4]
| QCanFrame::QCanFrame |
( |
const FrameFormat_e & | ubFormatR, |
|
|
const uint32_t & | ulIdentifierR = 0, |
|
|
const uint8_t & | ubDlcR = 0 ) |
- Parameters
-
| [in] | ubFormatR | CAN frame format |
| [in] | ulIdentifierR | CAN frame identifier |
| [in] | ubDlcR | CAN frame data length code |
Constructs a CAN frame of type ubTypeR with an identifier value of ulIdentifierR and a DLC value of ubDlcR.
◆ QCanFrame() [4/4]
| QCanFrame::QCanFrame |
( |
const QCanFrame & | clOtherR | ) |
|
- Parameters
-
| [in] | clOtherR | reference to CAN frame |
Constructs a copy of clOtherR.
◆ bitrateSwitch()
| bool QCanFrame::bitrateSwitch |
( |
void | | ) |
const |
- Returns
true if bit-rate switch is set
- See also
- setBitrateSwitch()
The function returns true if the bit-rate switch bit is set for the CAN frame. For classic CAN frames the function always returns false.
◆ data() [1/2]
| uint8_t QCanFrame::data |
( |
const uint8_t & | ubPosR | ) |
const |
- Returns
- Data at payload position ubPosR
- Parameters
-
| [in] | ubPosR | Index of payload |
The function returns the data stored at payload position ubPosR. The first position starts at index 0. If the index position is out of range, the function will return 0. The maximum index position for a CAN frame is dataSize() - 1, as depicted in the following code example.
..
for (uint8_t ubPosT = 0; ubPosT < clCanFrameT.
dataSize(); ubPosT++)
{
cout << hex << clCanFrameT.
data(ubPosT);
}
uint8_t dataSize(void) const
uint8_t data(const uint8_t &ubPosR) const
◆ data() [2/2]
| QByteArray QCanFrame::data |
( |
void | | ) |
const |
- Returns
- Data of CAN frame
The function returns the data stored in the CAN frame as QByteArray.
◆ dataSize()
| uint8_t QCanFrame::dataSize |
( |
void | | ) |
const |
- Returns
- Size of payload in bytes
- See also
- dlc()
The function returns the number of bytes that are valid for the CAN frame. The possible value range is 0 to 8 for classic CAN frames and 0 to 64 for CAN FD frames. In order to obtain the data length code (DLC) use the dlc() function.
◆ dataUInt16()
| uint16_t QCanFrame::dataUInt16 |
( |
const uint8_t & | ubPosR, |
|
|
const bool & | btMsbFirstR = false ) const |
- Returns
- Unsigned 16-bit data
- Parameters
-
| [in] | ubPosR | Index of payload |
| [in] | btMsbFirstR | Byte order |
- See also
- setDataUInt16()
The function returns an unsigned 16-bit value (uint16_t) starting at position ubPosR of the CAN payload.
◆ dataUInt32()
| uint32_t QCanFrame::dataUInt32 |
( |
const uint8_t & | ubPosR, |
|
|
const bool & | btMsbFirstR = false ) const |
- Returns
- Unsigned 32-bit data
- Parameters
-
| [in] | ubPosR | Index of payload |
| [in] | btMsbFirstR | Byte order |
- See also
- setDataUInt32()
The function returns an unsigned 32-bit value (uint32_t) starting at position ubPosR of the CAN payload.
◆ dlc()
| uint8_t QCanFrame::dlc |
( |
void | | ) |
const |
- Returns
- Data length code (DLC)
- See also
- dataSize()
The function returns the DLC value (data length code) for the CAN frame. The possible value range is 0 to 8 for classic CAN frames and 0 to 15 for CAN FD frames. In order to obtain the number of bytes inside the payload use dataSize().
◆ errorCounterReceive()
| uint8_t QCanFrame::errorCounterReceive |
( |
void | | ) |
const |
◆ errorCounterTransmit()
| uint8_t QCanFrame::errorCounterTransmit |
( |
void | | ) |
const |
◆ errorState()
◆ errorStateIndicator()
| bool QCanFrame::errorStateIndicator |
( |
void | | ) |
const |
- Returns
true if error state indicator is set
- See also
- setErrorStateIndicator()
The function returns true if the error state indicator bit is set inside a CAN FD frame. For classic CAN frames the function always returns false.
◆ errorType()
- Returns
- Error type
- See also
- setErrorType()
This functions returns the error type which caused the last error condition.
◆ frameFormat()
◆ frameType()
◆ fromByteArray()
| bool QCanFrame::fromByteArray |
( |
const QByteArray & | clByteArrayR | ) |
|
- Parameters
-
| [in] | clByteArrayR | Byte array containing CAN frame data |
- Returns
- Conversion result
- See also
- toByteArray()
The function converts a QByteArray object to a QCanFrame object. On success, the function returns true, otherwise false.
◆ fromCpCanMsg()
| bool QCanFrame::fromCpCanMsg |
( |
const struct CpCanMsg_s * | ptsCanMsgV | ) |
|
- Parameters
-
| [in] | ptsCanMsgV | Pointer to CANpie message structure |
- Returns
- Conversion result
- See also
- toCpCanMsg()
The function converts a structure of type CpCanMsg_ts to a QCanFrame object. On success, the function returns true, otherwise false.
◆ identifier()
| uint32_t QCanFrame::identifier |
( |
void | | ) |
const |
- Returns
- Identifier of CAN frame
- See also
- setIdentifier()
The function returns the identifier value. In order to distinguish between standard (11 bit) and extended (29 bit) frame formats use either frameFormat() or isExtended().
◆ isExtended()
| bool QCanFrame::isExtended |
( |
void | | ) |
const |
◆ isRemote()
| bool QCanFrame::isRemote |
( |
void | | ) |
const |
- Returns
true if Remote frame
- See also
- setRemote()
The function returns true if the CAN frame is a Remote frame. Please note that only classic CAN frames have this attribute, i.e. a ISO CAN FD frame will always return false.
◆ marker()
| uint32_t QCanFrame::marker |
( |
void | | ) |
const |
- Returns
- Marker of CAN frame
- See also
- setMarker()
The function returns the message marker of the frame.
◆ operator=()
- Parameters
-
| [in] | clOtherR | reference to CAN frame |
- Returns
- Reference to this CAN frame
Assigns clOtherR to this CAN frame and returns a reference to this CAN frame.
◆ setBitrateSwitch()
| void QCanFrame::setBitrateSwitch |
( |
const bool & | btBrsR = true | ) |
|
- Parameters
-
| [in] | btBrsR | Value of BRS bit |
- See also
- bitrateSwitch()
The function sets the value of the bit-rate switch (BRS) bit of a ISO CAN FD frame. The function has no impact on a classic CAN frame.
◆ setData()
| void QCanFrame::setData |
( |
const uint8_t & | ubPosR, |
|
|
const uint8_t & | ubValueR ) |
- Parameters
-
| [in] | ubPosR | Index of payload |
| [in] | ubValueR | Data of payload |
- See also
- data()
This function sets the data in a CAN message. The parameter ubPosR must be within the range 0 .. 7 for classic frames and 0 .. 63 for FD frames.
◆ setDataSize()
| void QCanFrame::setDataSize |
( |
uint8_t | ubSizeV | ) |
|
- Parameters
-
| [in] | ubSizeV | Size of payload |
- See also
- setDlc()
The function sets the number of data bytes that are valid for the CAN frame. The possible value range is 0 to 8 for classic CAN frames and 0 to 64 for CAN FD frames.
◆ setDataUInt16()
| void QCanFrame::setDataUInt16 |
( |
const uint8_t & | ubPosR, |
|
|
const uint16_t & | uwValueR, |
|
|
const bool & | btMsbFirstR = 0 ) |
- Parameters
-
| [in] | ubPosR | Index of payload |
| [in] | uwValueR | 16-bit value |
| [in] | btMsbFirstR | Byte order |
- See also
- dataUInt16()
The function sets an unsigned 16-bit value (uint16_t) uwValueR starting at position ubPosR of the CAN payload.
◆ setDataUInt32()
| void QCanFrame::setDataUInt32 |
( |
const uint8_t & | ubPosR, |
|
|
const uint32_t & | ulValueR, |
|
|
const bool & | btMsbFirstR = 0 ) |
- Parameters
-
| [in] | ubPosR | Index of payload |
| [in] | ulValueR | 32-bit value |
| [in] | btMsbFirstR | Byte order |
- See also
- dataUInt32()
The function sets an unsigned 32-bit value (uint32_t) ulValueR starting at position ubPosR of the CAN payload.
◆ setDlc()
| void QCanFrame::setDlc |
( |
uint8_t | ubDlcV | ) |
|
- Parameters
-
- See also
- setDataSize()
The function sets the DLC value (data length code) for a CAN data frame. The possible value range is 0 to 8 for classic CAN frames and 0 to 15 for CAN FD frames. If the value is out of range it is not stored in the frame object.
◆ setErrorCounterReceive()
| void QCanFrame::setErrorCounterReceive |
( |
const uint8_t & | ubErrorCntR | ) |
|
◆ setErrorCounterTransmit()
| void QCanFrame::setErrorCounterTransmit |
( |
const uint8_t & | ubErrorCntR | ) |
|
◆ setErrorState()
- Parameters
-
| [in] | ubStateV | Error state value |
- See also
- errorState()
This functions sets the current error state, defined by the enumeration QCan::CAN_State_e.
◆ setErrorStateIndicator()
| void QCanFrame::setErrorStateIndicator |
( |
const bool & | btEsiR = true | ) |
|
- Parameters
-
| [in] | btEsiR | Value of ESI bit |
- See also
- errorStateIndicator()
The function sets the value of the Error State Indicator (ESI) bit of a ISO CAN FD frame. The function has no impact on a classic CAN frame.
◆ setErrorType()
- Parameters
-
| [in] | ubTypeV | Error type value |
- See also
- errorType()
This functions sets the error type which caused the last error condition.
◆ setFrameFormat()
| void QCanFrame::setFrameFormat |
( |
const FrameFormat_e & | ubFormatR | ) |
|
- Parameters
-
| [in] | ubFormatR | CAN frame format |
- See also
- frameType()
The function sets the CAN frame format, defined by the FrameFormat_e enumeration. Please note that a change of frame format has an impact on several internal CAN frame bits:
Changing from Classic CAN to ISO CAN FD
In this case the RTR bit is cleared and the FDF bit is set. Both ESI and BRS are cleared by default.
Changing from ISO CAN FD to Classic CAN
In this case the the FDF bit is cleared, also the ESI and BRS bits are cleared. The RTR bit is cleared by default. If the current DLC value exceeds the value 8, the DLC value will be set to 8.
◆ setFrameType()
| void QCanFrame::setFrameType |
( |
const FrameType_e & | ubTypeR | ) |
|
- Parameters
-
| [in] | ubTypeR | CAN frame type |
- See also
- frameType()
The function sets the CAN frame format, defined by the FrameType_e enumeration. Please note that changing the frame type will set all data bytes to 0.
◆ setIdentifier()
| void QCanFrame::setIdentifier |
( |
uint32_t | ulIdentifierV | ) |
|
- Parameters
-
| [in] | ulIdentifierV | CAN frame type |
- See also
- identifier()
The function sets the identifier value of a CAN frame. Depending on the CAN frame type (Standard or Extended) the value is truncated to a 11-bit value (for Standard frames) or a 29-bit value (for Extended frames).
◆ setMarker()
| void QCanFrame::setMarker |
( |
const uint32_t & | ulMarkerValueR | ) |
|
- Parameters
-
| [in] | ulMarkerValueR | Marker value |
- See also
- marker()
The function sets a message marker inside the CAN frame. The purpose of the message marker is application specific.
◆ setRemote()
| void QCanFrame::setRemote |
( |
const bool & | btRtrR = true | ) |
|
- Parameters
-
| [in] | btRtrR | Value of RTR bit |
- See also
- isRemote()
The function sets the value of the Remote Transmission Request (RTR) bit of a classic CAN frame.
◆ setTimeStamp()
| void QCanFrame::setTimeStamp |
( |
const QCanTimeStamp & | clTimeStampR | ) |
|
|
inline |
- Parameters
-
| [in] | clTimeStampR | Time-stamp |
- See also
- timeStamp()
The function sets the time-stamp of the CAN frame.
◆ setUser()
| void QCanFrame::setUser |
( |
const uint32_t & | ulUserValueR | ) |
|
- Parameters
-
| [in] | ulUserValueR | User value |
- See also
- user()
The function sets a user-defined value inside the CAN frame. The purpose of the field is application specific.
◆ timeStamp()
- Returns
- Time-stamp
- See also
- setTimeStamp()
The function returns the time-stamp value of the CAN frame.
◆ toByteArray()
| QByteArray QCanFrame::toByteArray |
( |
void | | ) |
const |
- Returns
- QByteArray
- See also
- fromByteArray()
The function converts a QCanFrame object to a QByteArray. The size of the array is defined by QCAN_FRAME_ARRAY_SIZE.
◆ toCpCanMsg()
| bool QCanFrame::toCpCanMsg |
( |
struct CpCanMsg_s * | ptsCanMsgV | ) |
const |
- Parameters
-
| [in] | ptsCanMsgV | Pointer to CANpie message structure |
- Returns
- Conversion result
- See also
- fromCpCanMsg()
The function converts a QCanFrame to a structure of type CpCanMsg_ts. On success, the function returns true, otherwise false.
◆ toString()
| virtual QString QCanFrame::toString |
( |
const bool & | btShowTimeR = false, |
|
|
const bool & | btShowDataSizeR = false ) const |
|
virtual |
- Returns
- CAN frame as QString object
- Parameters
-
| [in] | btShowTimeR | Print time-stamp |
| [in] | btShowDataSizeR | Print data size instead of DLC value |
The function converts a QCanFrame object to a QString. The output depends on the frame type and frame format. Frame formats are denoted with the abbreviations CBFF, CEFF, FBFF and FEFF. For CAN FD frames the fields bit-rate switch (BRS) and error state indicator (ESI) are shown if set. The parameter btShowDataSizeR defines if the DLC value (dlc()) is shown or the data size (dataSize()).
100 CBFF 2 11 22
18EEFF00 CEFF 3 45 AB 12
200 FBFF BRS,ESI 9 11 22 00 00 00 00 00 00 00 00 00 00
2AFF33 FEFF BRS 10 88 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Error frame ---------- Error passive, Error counter: Rcv=128, Trm=32