• Home • Files • Structures         • Download

cp_msg.h File Reference

CANpie message access. More...

Include dependency graph for cp_msg.h:


Functions

void CpMsgClrRemote (_TsCpCanMsg *ptsCanMsgV)
void CpMsgClear (_TsCpCanMsg *ptsCanMsgV)
_U08 CpMsgGetData (_TsCpCanMsg *ptsCanMsgV, _U08 ubPosV)
_U08 CpMsgGetDlc (_TsCpCanMsg *ptsCanMsgV)
_U32 CpMsgGetExtId (_TsCpCanMsg *ptsCanMsgV)
_U16 CpMsgGetStdId (_TsCpCanMsg *ptsCanMsgV)
_U08 CpMsgIsExtended (_TsCpCanMsg *ptsCanMsgV)
_U08 CpMsgIsRemote (_TsCpCanMsg *ptsCanMsgV)
void CpMsgSetData (_TsCpCanMsg *ptsCanMsgV, _U08 ubPosV, _U08 ubValueV)
void CpMsgSetDlc (_TsCpCanMsg *ptsCanMsgV, _U08 ubDlcV)
void CpMsgSetExtId (_TsCpCanMsg *ptsCanMsgV, _U32 ulExtIdV)
void CpMsgSetRemote (_TsCpCanMsg *ptsCanMsgV)
void CpMsgSetStdId (_TsCpCanMsg *ptsCanMsgV, _U16 uwStdIdV)
void CpMsgSetTime (_TsCpCanMsg *ptsCanMsgV, _TsCpTime *ptsTimeV)

Detailed Description

 

In order to create small and fast code, CANpie supplies a set of macros to access the CAN message structure (_TsCpCanMsg). 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 consistence. Usage of macros is enabled via the symbol CP_CAN_MSG_MACRO.

Example

 //--- setup a CAN message ----------------------------------------
 _TsCpCanMsg   myMessage;
 CpMsgClear(&myMessage);                // clear the message
 CpMsgSetStdId(&myMessage, 100, 0);     // identifier is 100 dec, no RTR
 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 -----------------------
 _TsCpCanMsg   receiveMsg;
 //... receive the stuff ....

 if(CpMsgIsExtended(&receiveMsg))
 {
    //--- this is an Extended Frame ---------------------
    DoExtendedMessageService();
    return;
 }

 if(CpMsgIsRemote(&receiveMsg))
 {
    //... do something with RTR frames
 }

Function Documentation

void CpMsgClear ( _TsCpCanMsg ptsCanMsgV  ) 

Clear message structure.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
This macro 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.

void CpMsgClrRemote ( _TsCpCanMsg ptsCanMsgV  ) 

Clear RTR bit.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
See also:
CpMsgSetRemote()
This function clears the Remote Transmission bit (RTR).

_U08 CpMsgGetData ( _TsCpCanMsg ptsCanMsgV,
_U08  ubPosV 
)

Get Data.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
ubPosV Zero based index of byte position
Returns:
Value of data at position ubPosV
This functions retrieves the data of a CAN message. The parameter ubPosV must be within the range 0 .. 7. Please note that the macro implementation does not check the value range of the parameter ubPosV.

_U08 CpMsgGetDlc ( _TsCpCanMsg ptsCanMsgV  ) 

Get Data Length Code.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg 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.

_U32 CpMsgGetExtId ( _TsCpCanMsg ptsCanMsgV  ) 

Get 29 Bit Identifier Value.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg 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.

_U16 CpMsgGetStdId ( _TsCpCanMsg ptsCanMsgV  ) 

Get 11 Bit Identifier Value.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg 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.

_U08 CpMsgIsExtended ( _TsCpCanMsg ptsCanMsgV  ) 

Check the frame type.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
Returns:
0 for CAN 2.0A, 1 for CAN 2.0B
This function checks the frame type. If the frame is CAN 2.0A (Standard Frame), the value 0 is returned. If the frame is CAN 2.0B (Extended Frame), the value 1 is returned.

_U08 CpMsgIsRemote ( _TsCpCanMsg ptsCanMsgV  ) 

Check for remote frame.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg 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.

void CpMsgSetData ( _TsCpCanMsg ptsCanMsgV,
_U08  ubPosV,
_U08  ubValueV 
)

Set Data.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
ubPosV Zero based index of byte position
ubValueV Value 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. Please note that the macro implementation does not check the value range of the parameter ubPosV.

void CpMsgSetDlc ( _TsCpCanMsg ptsCanMsgV,
_U08  ubDlcV 
)

Set Data Length Code.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
ubDlcV Data 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.

void CpMsgSetExtId ( _TsCpCanMsg ptsCanMsgV,
_U32  ulExtIdV 
)

Set 29 Bit Identifier Value.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
ulExtIdV Identifier value
See also:
CpMsgSetStdFrame()
This function sets the identifer 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.

void CpMsgSetRemote ( _TsCpCanMsg ptsCanMsgV  ) 

Set RTR bit.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
This function sets the Remote Transmission bit (RTR).

void CpMsgSetStdId ( _TsCpCanMsg ptsCanMsgV,
_U16  uwStdIdV 
)

Set 11 Bit Identifier Value.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
uwStdIdV Identifier value
See also:
CpMsgSetExtFrame()
This function sets the identifer value for a Standard frame (CAN 2.0A). The value of uwStdIdV is limited to CP_MASK_STD_FRAME.

void CpMsgSetTime ( _TsCpCanMsg ptsCanMsgV,
_TsCpTime *  ptsTimeV 
)

Set timestamp value.

Parameters:
ptsCanMsgV Pointer to a _TsCpCanMsg message
ptsTimeV Pointer to timestamp structure
This function sets the timestamp value for a CAN frame.


 

© MicroControl GmbH & Co. KG

CANpie - V2.00