CANpie FD
CAN programming interface environment - Version 3.08
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions
QCanFrame Class Reference

Detailed Description

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.

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.

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()).

QCanFrame clErrorFrameT;
//--------------------------------------------------------------------------
// set frame type to error frame
//
clErrorFrameT.setErrorCounterReceive(32);
clErrorFrameT.setErrorCounterTransmit(64);

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
 

Member Enumeration Documentation

◆ 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 classical 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

Constructor & Destructor Documentation

◆ QCanFrame() [1/3]

QCanFrame::QCanFrame ( )

Constructs an empty classic standard CAN frame (frame format QCanFrame::eFORMAT_CAN_STD) with a DLC value of 0.

◆ QCanFrame() [2/3]

QCanFrame::QCanFrame ( const FrameType_e ubTypeR)
Parameters
[in]ubTypeRFrame type

Constructs an empty data structure with a frame type of QCanFrame::FrameType_e.

◆ QCanFrame() [3/3]

QCanFrame::QCanFrame ( const FrameFormat_e ubFormatR,
const uint32_t &  ulIdentifierR = 0,
const uint8_t &  ubDlcR = 0 
)
Parameters
[in]ubFormatRCAN frame format
[in]ulIdentifierRCAN frame identifier
[in]ubDlcRCAN frame data length code

Constructs a CAN frame of type ubTypeR with an identifier value of ulIdentifierR and a DLC value of ubDlcR.

Member Function Documentation

◆ 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]ubPosRIndex 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.

QCanFrame clCanFrameT;
..
for (uint8_t ubPosT = 0; ubPosT < clCanFrameT.dataSize(); ubPosT++)
{
//------------------------------------------------
// print payload of CAN frame
//
cout << hex << clCanFrameT.data(ubPosT);
}

◆ 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]ubPosRIndex of payload
[in]btMsbFirstRByte 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]ubPosRIndex of payload
[in]btMsbFirstRByte 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
Returns
Value of receive error counter
See also
setErrorCounterReceive()

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.

◆ errorCounterTransmit()

uint8_t QCanFrame::errorCounterTransmit ( void  ) const
Returns
Value of transmit error counter
See also
setErrorCounterTransmit()

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).

◆ errorState()

CAN_State_e QCanFrame::errorState ( void  ) const
Returns
Current error state
See also
setErrorState()

This functions returns the current error state, defined by the enumeration QCan::CAN_State_e.

◆ 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()

ErrorType_e QCanFrame::errorType ( void  ) const
Returns
Error type
See also
setErrorType()

This functions returns the error type which caused the last error condition.

◆ frameFormat()

FrameFormat_e QCanFrame::frameFormat ( void  ) const
Returns
Frame format
See also
setFrameFormat()

The function returns the CAN frame format, defined by the FrameFormat_e enumeration.

◆ frameType()

FrameType_e QCanFrame::frameType ( void  ) const
Returns
Frame type
See also
setFrameType()

The function returns the frame type defined by FrameType_e.

◆ fromByteArray()

bool QCanFrame::fromByteArray ( const QByteArray &  clByteArrayR)
Parameters
[in]clByteArrayRByte 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]ptsCanMsgVPointer 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
Returns
true if Extended CAN frame
See also
frameType()

The function returns true if the frame type is either eFORMAT_CAN_EXT or eFORMAT_FD_EXT, otherwise it will return false;

◆ 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.

◆ setBitrateSwitch()

void QCanFrame::setBitrateSwitch ( const bool &  btBrsR = true)
Parameters
[in]btBrsRValue 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]ubPosRIndex of payload
[in]ubValueRData 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]ubSizeVSize 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]ubPosRIndex of payload
[in]uwValueR16-bit value
[in]btMsbFirstRByte 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]ubPosRIndex of payload
[in]ulValueR32-bit value
[in]btMsbFirstRByte 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
[in]ubDlcVDLC value
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)
Parameters
[in]ubErrorCntRReceive error counter value
See also
errorCounterReceive()

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).

◆ setErrorCounterTransmit()

void QCanFrame::setErrorCounterTransmit ( const uint8_t &  ubErrorCntR)
Parameters
[in]ubErrorCntRTransmit error counter value
See also
errorCounterTransmit()

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).

◆ setErrorState()

void QCanFrame::setErrorState ( CAN_State_e  ubStateV)
Parameters
[in]ubStateVError 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]btEsiRValue 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()

void QCanFrame::setErrorType ( ErrorType_e  ubTypeV)
Parameters
[in]ubTypeVError 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]ubFormatRCAN 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]ubTypeRCAN 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]ulIdentifierVCAN 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]ulMarkerValueRMarker 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]btRtrRValue 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]clTimeStampRTime-stamp
See also
timeStamp()

The function sets the time-stamp of the CAN frame.

◆ setUser()

void QCanFrame::setUser ( const uint32_t &  ulUserValueR)
Parameters
[in]ulUserValueRUser value
See also
user()

The function sets a user-defined value inside the CAN frame. The purpose of the field is application specific.

◆ timeStamp()

QCanTimeStamp QCanFrame::timeStamp ( void  ) const
inline
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]ptsCanMsgVPointer 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]btShowTimeRPrint time-stamp
[in]btShowDataSizeRPrint 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
QCanFrame::setErrorCounterReceive
void setErrorCounterReceive(const uint8_t &ubErrorCntR)
QCanFrame::setFrameType
void setFrameType(const FrameType_e &ubTypeR)
QCanFrame
Definition: qcan_frame.hpp:164
QCanFrame::dataSize
uint8_t dataSize(void) const
QCanFrame::setErrorCounterTransmit
void setErrorCounterTransmit(const uint8_t &ubErrorCntR)
QCanFrame::data
uint8_t data(const uint8_t &ubPosR) const
QCanFrame::eFRAME_TYPE_ERROR
@ eFRAME_TYPE_ERROR
Definition: qcan_frame.hpp:236