J1939 Documentation
Version 4.16.00
Loading...
Searching...
No Matches
cp_msg.h File Reference

Detailed Description

In order to create small and fast code, CANpie supplies a set of macros to access the CAN message structure (CpCanMsg_ts). These macros can be used instead of the functions defined in the cp_msg.h header file. However keep in mind that macros can't be used to check for value ranges or parameter consistency. Usage of macros is enabled via the symbol CP_CAN_MSG_MACRO.

Example

//--- setup a CAN message ----------------------------------------
CpCanMsg_ts myMessage;
CpMsgInit(&myMessage, CP_MSG_FORMAT_CBFF); // initialise message
CpMsgSetIdentifier(&myMessage, 100); // identifier is 100 dec.
CpMsgSetDlc(&myMessage, 2); // data length code is 2
CpMsgSetData(&myMessage, 0, 0x11); // byte 0 has the value 0x11
CpMsgSetData(&myMessage, 1, 0x22); // byte 1 has the value 0x22
//... do something with it ....
//--- evaluate a message that was received -----------------------
CpCanMsg_ts receiveMsg;
//... receive the stuff ....
if(CpMsgIsExtended(&receiveMsg))
{
//--- this is an Extended Frame ---------------------
DoExtendedMessageService();
return;
}
if(CpMsgIsRemote(&receiveMsg))
{
//... do something with RTR frames
}
void CpMsgSetDlc(CpCanMsg_ts *ptsCanMsgV, uint8_t ubDlcV)
Set Data Length Code.
void CpMsgInit(CpCanMsg_ts *ptsCanMsgV, uint8_t ubFormatV)
Initialise message structure.
bool_t CpMsgIsRemote(const CpCanMsg_ts *ptsCanMsgV)
Check for remote frame.
void CpMsgSetData(CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV, uint8_t ubValueV)
Set Data.
void CpMsgSetIdentifier(CpCanMsg_ts *ptsCanMsgV, uint32_t ulIdentifierV)
Set Identifier Value.
bool_t CpMsgIsExtended(const CpCanMsg_ts *ptsCanMsgV)
Check for Extended CAN frame.
#define CP_MSG_FORMAT_CBFF
Definition canpie.h:415
CAN message structure.
Definition canpie.h:1005
+ Include dependency graph for cp_msg.h:

Functions

void CpMsgClear (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgClrOverrun (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgClrRemote (CpCanMsg_ts *ptsCanMsgV)
 
uint8_t CpMsgDlcToSize (const uint8_t ubDlcV)
 
uint8_t CpMsgGetData (const CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV)
 
uint8_t CpMsgGetDlc (const CpCanMsg_ts *ptsCanMsgV)
 
uint32_t CpMsgGetExtId (const CpCanMsg_ts *ptsCanMsgV)
 
uint32_t CpMsgGetIdentifier (const CpCanMsg_ts *ptsCanMsgV)
 
uint16_t CpMsgGetStdId (const CpCanMsg_ts *ptsCanMsgV)
 
CpTime_tsCpMsgGetTime (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgInit (CpCanMsg_ts *ptsCanMsgV, uint8_t ubFormatV)
 
bool_t CpMsgIsBitrateSwitchSet (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsExtended (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsFdFrame (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsOverrun (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsRemote (const CpCanMsg_ts *ptsCanMsgV)
 
bool_t CpMsgIsRpc (const CpCanMsg_ts *ptsCanMsgV)
 
uint8_t CpMsgRpcGetCanMode (const CpCanMsg_ts *ptsCanMsgV)
 
int32_t CpMsgRpcGetDataBitrate (const CpCanMsg_ts *ptsCanMsgV)
 
int32_t CpMsgRpcGetNominalBitrate (const CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgRpcSetCanMode (CpCanMsg_ts *ptsCanMsgV, uint8_t ubModeV)
 
void CpMsgRpcSetBitrate (CpCanMsg_ts *ptsCanMsgV, int32_t slNomBitRateV, int32_t slDatBitRateV)
 
uint32_t CpMsgRpcType (const CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetBitrateSwitch (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetData (CpCanMsg_ts *ptsCanMsgV, uint8_t ubPosV, uint8_t ubValueV)
 
void CpMsgSetDlc (CpCanMsg_ts *ptsCanMsgV, uint8_t ubDlcV)
 
void CpMsgSetExtId (CpCanMsg_ts *ptsCanMsgV, uint32_t ulExtIdV)
 
void CpMsgSetIdentifier (CpCanMsg_ts *ptsCanMsgV, uint32_t ulIdentifierV)
 
void CpMsgSetOverrun (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetRemote (CpCanMsg_ts *ptsCanMsgV)
 
void CpMsgSetStdId (CpCanMsg_ts *ptsCanMsgV, uint16_t uwStdIdV)
 
void CpMsgSetTime (CpCanMsg_ts *ptsCanMsgV, const CpTime_ts *ptsTimeV)
 
uint8_t CpMsgSizeToDlc (uint8_t ubSizeV)
 

Function Documentation

◆ CpMsgClear()

void CpMsgClear ( CpCanMsg_ts * ptsCanMsgV)

Clear message structure.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message

This function sets the identifier field and the flags field of a CAN message structure to 0. It is recommended to use this function when a message structure is assigned in memory.

Deprecated
It is advised to use CpMsgInit() for new applications.

◆ CpMsgClrOverrun()

void CpMsgClrOverrun ( CpCanMsg_ts * ptsCanMsgV)

Clear Overrun bit.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
See also
CpMsgSetOverrun()

This function clears the Overrun bit (RTR).

◆ CpMsgClrRemote()

void CpMsgClrRemote ( CpCanMsg_ts * ptsCanMsgV)

Clear RTR bit.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
See also
CpMsgSetRemote()

This function clears the Remote Transmission bit (RTR).

◆ CpMsgDlcToSize()

uint8_t CpMsgDlcToSize ( const uint8_t ubDlcV)

Convert DLC to payload size.

Parameters
ubDlcVData Length Code
Returns
Number of bytes in CAN payload
See also
CpMsgSizeToDlc()

This function converts the DLC value to the corresponding size of the CAN message payload.

◆ CpMsgGetData()

uint8_t CpMsgGetData ( const CpCanMsg_ts * ptsCanMsgV,
uint8_t ubPosV )

Get Data.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ubPosVZero based index of byte position
Returns
Value of data at position ubPosV

This function retrieves the data of a CAN message. The parameter ubPosV must be within the range 0 .. 7 for Classical CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check the value range of the parameter ubPosV.

◆ CpMsgGetDlc()

uint8_t CpMsgGetDlc ( const CpCanMsg_ts * ptsCanMsgV)

Get Data Length Code.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Data Length Code (DLC) of CAN message

This function retrieves the data length code (DLC) of a CAN message. The return value range is between 0 and 8.

◆ CpMsgGetExtId()

uint32_t CpMsgGetExtId ( const CpCanMsg_ts * ptsCanMsgV)

Get 29 Bit Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Extended Identifier value
See also
CpMsgGetStdId()

This function retrieves the value for the identifier of an extended frame (CAN 2.0B). The frame format of the CAN message can be tested with the CpMsgIsExtended() function.

Deprecated
It is advised to use CpMsgGetIdentifier() for new applications.

◆ CpMsgGetIdentifier()

uint32_t CpMsgGetIdentifier ( const CpCanMsg_ts * ptsCanMsgV)

Get Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Identifier value
See also
CpMsgSetIdentifier()

This function retrieves the value for the identifier of a CAN frame. The frame format of the CAN message can be tested with the CpMsgIsExtended() function.

◆ CpMsgGetStdId()

uint16_t CpMsgGetStdId ( const CpCanMsg_ts * ptsCanMsgV)

Get 11 Bit Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Standard Identifier value
See also
CpMsgGetExtId()

This macro retrieves the value for the identifier of an standard frame (CAN 2.0A). The frame format of the CAN message can be tested with the CpMsgIsExtended() function.

Deprecated
It is advised to use CpMsgGetIdentifier() for new applications.

◆ CpMsgGetTime()

CpTime_ts * CpMsgGetTime ( CpCanMsg_ts * ptsCanMsgV)

Get time-stamp value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Pointer to time-stamp structure
See also
CpMsgSetTime

This function returns the time-stamp value for a CAN frame.

◆ CpMsgInit()

void CpMsgInit ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubFormatV )

Initialise message structure.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ubFormatVFrame format

This function sets the identifier field and the DLC field of a CAN message structure to 0. The parameter ubFormatV defines the frame format. Possible value are:

The contents of the data field and all other optional fields (time-stamp, user, message marker) are not altered.

◆ CpMsgIsBitrateSwitchSet()

bool_t CpMsgIsBitrateSwitchSet ( const CpCanMsg_ts * ptsCanMsgV)

Check for bit-rate.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
true if bit-rate switch is set
See also
CpMsgSetBitrateSwitch()

This function checks the frame type. If the frame is a CAN FD frame and the bit-rate switch (BRS) bit is set, the value true is returned.

◆ CpMsgIsExtended()

bool_t CpMsgIsExtended ( const CpCanMsg_ts * ptsCanMsgV)

Check for Extended CAN frame.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
true for Extended CAN frame

This function checks the frame type. If the frame is CAN 2.0A (Standard Frame), the value false is returned. If the frame is CAN 2.0B (Extended Frame), the value true is returned.

◆ CpMsgIsFdFrame()

bool_t CpMsgIsFdFrame ( const CpCanMsg_ts * ptsCanMsgV)

Check for CAN FD frame.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
true for CAN FD frame

This function checks the frame type. If the frame is a CAN FD frame CAN 2.0B (Extended Frame), the value true is returned.

◆ CpMsgIsOverrun()

bool_t CpMsgIsOverrun ( const CpCanMsg_ts * ptsCanMsgV)

Check for message overrun.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
1 for data overrun, else 0

This function checks if a data overrun has occurred for the message.

◆ CpMsgIsRemote()

bool_t CpMsgIsRemote ( const CpCanMsg_ts * ptsCanMsgV)

Check for remote frame.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
0 for data frame, 1 for remote frame

This function checks if the Remote Transmission bit (RTR) is set. If the RTR bit is set, the function will return 1, otherwise 0.

◆ CpMsgIsRpc()

bool_t CpMsgIsRpc ( const CpCanMsg_ts * ptsCanMsgV)

Check for Remote Procedure Call.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
0 for CAN frame, 1 for Remote Procedure Call

This function checks if the Remote Procedure Call bit (RPC) is set. If the RPC bit is set, the function will return 1, otherwise 0.

◆ CpMsgRpcGetCanMode()

uint8_t CpMsgRpcGetCanMode ( const CpCanMsg_ts * ptsCanMsgV)

Get CAN controller mode via RPC.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Mode selection

This function returns the operating mode of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpMode_e enumeration.

◆ CpMsgRpcGetDataBitrate()

int32_t CpMsgRpcGetDataBitrate ( const CpCanMsg_ts * ptsCanMsgV)

Get Data Bit Timing selection via RPC.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Data Bitrate

This function returns the Data Bit Timing selection of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpBitrate_e enumeration.

◆ CpMsgRpcGetNominalBitrate()

int32_t CpMsgRpcGetNominalBitrate ( const CpCanMsg_ts * ptsCanMsgV)

Get Nominal Bit Timing selection via RPC.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Nominal Bitrate

This function returns the Nominal Bit Timing selection of the CAN controller which is provided via a Remote Procedure Call. Possible return values are defined in the CpBitrate_e enumeration.

◆ CpMsgRpcSetBitrate()

void CpMsgRpcSetBitrate ( CpCanMsg_ts * ptsCanMsgV,
int32_t slNomBitRateV,
int32_t slDatBitRateV )

Set bit-rate of CAN controller via RPC.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
[in]slNomBitRateVNominal Bit Timing selection
[in]slDatBitRateVData Bit Timing selection

This function initializes the bit timing registers of a CAN controller to pre-defined values. The values are defined by the enumeration CpBitrate_e.

◆ CpMsgRpcSetCanMode()

void CpMsgRpcSetCanMode ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubModeV )

Set state of CAN controller via RPC.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
[in]ubModeVMode selection

This function changes the operating mode of the CAN controller FSA. Possible values for the parameter ubModeV are defined in the CpMode_e enumeration.

◆ CpMsgRpcType()

uint32_t CpMsgRpcType ( const CpCanMsg_ts * ptsCanMsgV)

Identify Remote Procedure Call.

Parameters
[in]ptsCanMsgVPointer to a CpCanMsg_ts message
Returns
Value from CpRpc_e enumeration

This function returns a value defined inside the CpRpc_e enumeration which identifies the RPC type.

◆ CpMsgSetBitrateSwitch()

void CpMsgSetBitrateSwitch ( CpCanMsg_ts * ptsCanMsgV)

Set bit-rate switch.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
See also
CpMsgIsBitrateSwitch()

This function checks the frame type. If the frame is a CAN FD frame the bit-rate switch (BRS) bit is set, otherwise the bit value in the message control field is not altered.

◆ CpMsgSetData()

void CpMsgSetData ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubPosV,
uint8_t ubValueV )

Set Data.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ubPosVZero based index of byte position
ubValueVValue of data byte in CAN message

This function sets the data in a CAN message. The parameter ubPosV must be within the range 0 .. 7 for Classical CAN frames. For ISO CAN FD frames the valid range is 0 .. 63. Please note that the macro implementation does not check the value range of the parameter ubPosV.

◆ CpMsgSetDlc()

void CpMsgSetDlc ( CpCanMsg_ts * ptsCanMsgV,
uint8_t ubDlcV )

Set Data Length Code.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ubDlcVData Length Code

This function sets the Data Length Code (DLC) of a CAN message. The parameter ubDlcV must be within the range from 0..8. Please note that the macro implementation does not check the value range of the parameter ubDlcV.

◆ CpMsgSetExtId()

void CpMsgSetExtId ( CpCanMsg_ts * ptsCanMsgV,
uint32_t ulExtIdV )

Set 29 Bit Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ulExtIdVIdentifier value
See also
CpMsgSetStdId()

This function sets the identifier value for an Extended Frame (CAN 2.0B) and marks the frame format as accordingly. The value of ulExtIdV is limited to CP_MASK_EXT_FRAME.

Deprecated
It is advised to use CpMsgSetIdentifier() for new applications.

◆ CpMsgSetIdentifier()

void CpMsgSetIdentifier ( CpCanMsg_ts * ptsCanMsgV,
uint32_t ulIdentifierV )

Set Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ulIdentifierVIdentifier value
See also
CpMsgGetIdentifier()

This function sets the identifier value for a CAN frame. The parameter ulIdentifierV is truncated to a 11-bit value (AND operation with CP_MASK_STD_FRAME) when the message uses base frame format. The parameter ulIdentifierV is truncated to a 29-bit value (AND operation with CP_MASK_EXT_FRAME) when the message uses extended frame format.

◆ CpMsgSetOverrun()

void CpMsgSetOverrun ( CpCanMsg_ts * ptsCanMsgV)

Set Overrun bit.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
See also
CpMsgClrOverrun()

This function sets the Overrun bit.

◆ CpMsgSetRemote()

void CpMsgSetRemote ( CpCanMsg_ts * ptsCanMsgV)

Set RTR bit.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
See also
CpMsgClrRemote()

This function sets the Remote Transmission bit (RTR).

◆ CpMsgSetStdId()

void CpMsgSetStdId ( CpCanMsg_ts * ptsCanMsgV,
uint16_t uwStdIdV )

Set 11 Bit Identifier Value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
uwStdIdVIdentifier value
See also
CpMsgSetExtFrame()

This function sets the identifier value for a Standard frame (CAN 2.0A). The value of uwStdIdV is limited to CP_MASK_STD_FRAME.

Deprecated
It is advised to use CpMsgSetIdentifier() for new applications.

◆ CpMsgSetTime()

void CpMsgSetTime ( CpCanMsg_ts * ptsCanMsgV,
const CpTime_ts * ptsTimeV )

Set time-stamp value.

Parameters
ptsCanMsgVPointer to a CpCanMsg_ts message
ptsTimeVPointer to time-stamp structure

This function sets the time-stamp value for a CAN frame.

◆ CpMsgSizeToDlc()

uint8_t CpMsgSizeToDlc ( uint8_t ubSizeV)

Convert CAN payload size to DLC.

Parameters
ubSizeVSize of CAN message payload in bytes
Returns
DLC value
See also
CpMsgDlcToSize()

This function converts the size of the CAN message payload into a DLC value.