CANpie FD
CAN programming interface environment - Version 3.08
|
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().
The QCanFrame class distinguishes the four message frame formats via the method frameFormat(), possible values are listed by the enumeration QCanFrame::FrameFormat_e.
Classical base frame format (CBFF) | QCanFrame::eFORMAT_CAN_STD |
Classical extended frame format (CEFF) | QCanFrame::eFORMAT_CAN_EXT |
FD base frame format (FBFF) | QCanFrame::eFORMAT_FD_STD |
FD extended frame format (FEFF) | QCanFrame::eFORMAT_FD_EXT |
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.
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()).
Public Types | |
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 } |
Public Member Functions | |
QCanFrame () | |
QCanFrame (const FrameType_e &ubTypeR) | |
QCanFrame (const FrameFormat_e &ubFormatR, const uint32_t &ulIdentifierR=0, const uint8_t &ubDlcR=0) | |
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 |
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 (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 |
The enumeration ErrorType_e defines CAN error types.
QCanFrame::QCanFrame | ( | ) |
Constructs an empty classic standard CAN frame (frame format QCanFrame::eFORMAT_CAN_STD) with a DLC value of 0.
QCanFrame::QCanFrame | ( | const FrameType_e & | ubTypeR | ) |
[in] | ubTypeR | Frame type |
Constructs an empty data structure with a frame type of QCanFrame::FrameType_e.
QCanFrame::QCanFrame | ( | const FrameFormat_e & | ubFormatR, |
const uint32_t & | ulIdentifierR = 0 , |
||
const uint8_t & | ubDlcR = 0 |
||
) |
[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
.
bool QCanFrame::bitrateSwitch | ( | void | ) | const |
true
if bit-rate switch is set 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
.
uint8_t QCanFrame::data | ( | const uint8_t & | ubPosR | ) | const |
[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.
QByteArray QCanFrame::data | ( | void | ) | const |
The function returns the data stored in the CAN frame as QByteArray.
uint8_t QCanFrame::dataSize | ( | void | ) | const |
uint16_t QCanFrame::dataUInt16 | ( | const uint8_t & | ubPosR, |
const bool & | btMsbFirstR = false |
||
) | const |
[in] | ubPosR | Index of payload |
[in] | btMsbFirstR | Byte order |
The function returns an unsigned 16-bit value (uint16_t) starting at position ubPosR of the CAN payload.
uint32_t QCanFrame::dataUInt32 | ( | const uint8_t & | ubPosR, |
const bool & | btMsbFirstR = false |
||
) | const |
[in] | ubPosR | Index of payload |
[in] | btMsbFirstR | Byte order |
The function returns an unsigned 32-bit value (uint32_t) starting at position ubPosR of the CAN payload.
uint8_t QCanFrame::dlc | ( | void | ) | const |
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().
uint8_t QCanFrame::errorCounterReceive | ( | void | ) | const |
The functions returns the current value of the receive error counter for an error frame (frame type QCanFrame::eFRAME_TYPE_ERROR). For a data frame the function returns 0.
uint8_t QCanFrame::errorCounterTransmit | ( | void | ) | const |
This functions returns the current value of the transmit error counter for an error frame (frame type QCanFrame::eFRAME_TYPE_ERROR). For a data frame the function returns 0. A value of 255 leads to a bus-off condition (QCan::eCAN_STATE_BUS_OFF).
CAN_State_e QCanFrame::errorState | ( | void | ) | const |
This functions returns the current error state, defined by the enumeration QCan::CAN_State_e.
bool QCanFrame::errorStateIndicator | ( | void | ) | const |
true
if error state indicator is set 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_e QCanFrame::errorType | ( | void | ) | const |
This functions returns the error type which caused the last error condition.
FrameFormat_e QCanFrame::frameFormat | ( | void | ) | const |
The function returns the CAN frame format, defined by the FrameFormat_e enumeration.
FrameType_e QCanFrame::frameType | ( | void | ) | const |
The function returns the frame type defined by FrameType_e.
bool QCanFrame::fromByteArray | ( | const QByteArray & | clByteArrayR | ) |
[in] | clByteArrayR | Byte array containing CAN frame data |
The function converts a QByteArray object to a QCanFrame object. On success, the function returns true
, otherwise false
.
bool QCanFrame::fromCpCanMsg | ( | const struct CpCanMsg_s * | ptsCanMsgV | ) |
[in] | ptsCanMsgV | Pointer to CANpie message structure |
The function converts a structure of type CpCanMsg_ts to a QCanFrame object. On success, the function returns true
, otherwise false
.
uint32_t QCanFrame::identifier | ( | void | ) | const |
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().
bool QCanFrame::isExtended | ( | void | ) | const |
true
if Extended CAN frame The function returns true
if the frame type is either eFORMAT_CAN_EXT or eFORMAT_FD_EXT, otherwise it will return false
;
bool QCanFrame::isRemote | ( | void | ) | const |
true
if Remote frame 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
.
uint32_t QCanFrame::marker | ( | void | ) | const |
The function returns the message marker of the frame.
void QCanFrame::setBitrateSwitch | ( | const bool & | btBrsR = true | ) |
[in] | btBrsR | Value of BRS bit |
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.
void QCanFrame::setData | ( | const uint8_t & | ubPosR, |
const uint8_t & | ubValueR | ||
) |
[in] | ubPosR | Index of payload |
[in] | ubValueR | Data of payload |
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.
void QCanFrame::setDataSize | ( | uint8_t | ubSizeV | ) |
[in] | ubSizeV | Size of payload |
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.
void QCanFrame::setDataUInt16 | ( | const uint8_t & | ubPosR, |
const uint16_t & | uwValueR, | ||
const bool & | btMsbFirstR = 0 |
||
) |
[in] | ubPosR | Index of payload |
[in] | uwValueR | 16-bit value |
[in] | btMsbFirstR | Byte order |
The function sets an unsigned 16-bit value (uint16_t) uwValueR starting at position ubPosR of the CAN payload.
void QCanFrame::setDataUInt32 | ( | const uint8_t & | ubPosR, |
const uint32_t & | ulValueR, | ||
const bool & | btMsbFirstR = 0 |
||
) |
[in] | ubPosR | Index of payload |
[in] | ulValueR | 32-bit value |
[in] | btMsbFirstR | Byte order |
The function sets an unsigned 32-bit value (uint32_t) ulValueR starting at position ubPosR of the CAN payload.
void QCanFrame::setDlc | ( | uint8_t | ubDlcV | ) |
[in] | ubDlcV | DLC value |
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.
void QCanFrame::setErrorCounterReceive | ( | const uint8_t & | ubErrorCntR | ) |
[in] | ubErrorCntR | Receive error counter value |
The functions sets the receive error counter for an error frame (frame type QCanFrame::eFRAME_TYPE_ERROR). For a data frame the function has no impact. Passing a value greater than 127 will set the error state to error passive (QCan::eCAN_STATE_BUS_PASSIVE).
void QCanFrame::setErrorCounterTransmit | ( | const uint8_t & | ubErrorCntR | ) |
[in] | ubErrorCntR | Transmit error counter value |
The functions sets the transmit error counter for an error frame (frame type QCanFrame::eFRAME_TYPE_ERROR). For a data frame the function has no impact. Passing a value greater than 127 will set the error state to error passive (QCan::eCAN_STATE_BUS_PASSIVE). A value of 255 will set the error state to bus-off (QCan::eCAN_STATE_BUS_OFF).
void QCanFrame::setErrorState | ( | CAN_State_e | ubStateV | ) |
[in] | ubStateV | Error state value |
This functions sets the current error state, defined by the enumeration QCan::CAN_State_e.
void QCanFrame::setErrorStateIndicator | ( | const bool & | btEsiR = true | ) |
[in] | btEsiR | Value of ESI bit |
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.
void QCanFrame::setErrorType | ( | ErrorType_e | ubTypeV | ) |
[in] | ubTypeV | Error type value |
This functions sets the error type which caused the last error condition.
void QCanFrame::setFrameFormat | ( | const FrameFormat_e & | ubFormatR | ) |
[in] | ubFormatR | CAN frame format |
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.
void QCanFrame::setFrameType | ( | const FrameType_e & | ubTypeR | ) |
[in] | ubTypeR | CAN frame type |
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.
void QCanFrame::setIdentifier | ( | uint32_t | ulIdentifierV | ) |
[in] | ulIdentifierV | CAN frame type |
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).
void QCanFrame::setMarker | ( | const uint32_t & | ulMarkerValueR | ) |
[in] | ulMarkerValueR | Marker value |
The function sets a message marker inside the CAN frame. The purpose of the message marker is application specific.
void QCanFrame::setRemote | ( | const bool & | btRtrR = true | ) |
[in] | btRtrR | Value of RTR bit |
The function sets the value of the Remote Transmission Request (RTR) bit of a classic CAN frame.
|
inline |
[in] | clTimeStampR | Time-stamp |
The function sets the time-stamp of the CAN frame.
void QCanFrame::setUser | ( | const uint32_t & | ulUserValueR | ) |
[in] | ulUserValueR | User value |
The function sets a user-defined value inside the CAN frame. The purpose of the field is application specific.
|
inline |
The function returns the time-stamp value of the CAN frame.
QByteArray QCanFrame::toByteArray | ( | void | ) | const |
The function converts a QCanFrame object to a QByteArray. The size of the array is defined by QCAN_FRAME_ARRAY_SIZE.
bool QCanFrame::toCpCanMsg | ( | struct CpCanMsg_s * | ptsCanMsgV | ) | const |
[in] | ptsCanMsgV | Pointer to CANpie message structure |
The function converts a QCanFrame to a structure of type CpCanMsg_ts. On success, the function returns true
, otherwise false
.
|
virtual |
[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()).