Libsockcanpp
A complete C++ wrapper around socketcan.
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
sockcanpp::CanMessage Class Reference

Represents a CAN message that was received. More...

#include <CanMessage.hpp>

Collaboration diagram for sockcanpp::CanMessage:
Collaboration graph
[legend]

Public Member Functions

 CanMessage (const struct can_frame frame)
 
 CanMessage (const CanId canId, const string &frameData)
 
virtual ~CanMessage ()
 
const CanId getCanId () const
 
const string getFrameData () const
 
const can_frame getRawFrame () const
 
 CanMessage (const struct canxl_frame frame)
 
 CanMessage (const CanId &priorityField, const CanId &acceptanceField, const string &frameData)
 
virtual ~CanMessage ()=default
 

Private Attributes

CanId _canIdentifier
 
string _frameData
 
struct can_frame _rawFrame
 
struct canxl_frame _rawFrame
 

Detailed Description

Represents a CAN message that was received.

Definition at line 53 of file CanMessage.hpp.

Constructor & Destructor Documentation

◆ CanMessage() [1/4]

sockcanpp::CanMessage::CanMessage ( const struct can_frame  frame)
inline

Definition at line 55 of file CanMessage.hpp.

55 :
56 _canIdentifier(frame.can_id), _frameData((const char*)frame.data, frame.can_dlc), _rawFrame(frame) { }
struct can_frame _rawFrame

References _canIdentifier, _frameData, _rawFrame, and sockcanpp::CanId::CanId().

Referenced by sockcanpp::CanDriver::readMessageLock().

◆ CanMessage() [2/4]

sockcanpp::CanMessage::CanMessage ( const CanId  canId,
const string &  frameData 
)
inline

Definition at line 58 of file CanMessage.hpp.

58 : _canIdentifier(canId), _frameData(frameData) {
59 if (frameData.size() > CAN_MAX_DLEN) {
60 throw system_error(error_code(0xbadd1c, generic_category()), "Payload too big!");
61 }
62
63 struct can_frame rawFrame{};
64 rawFrame.can_id = canId;
65 std::copy(frameData.begin(), frameData.end(), rawFrame.data);
66 rawFrame.can_dlc = frameData.size();
67
68 _rawFrame = rawFrame;
69 }

References _canIdentifier, _frameData, and _rawFrame.

◆ ~CanMessage() [1/2]

virtual sockcanpp::CanMessage::~CanMessage ( )
inlinevirtual

Definition at line 71 of file CanMessage.hpp.

71{}

◆ CanMessage() [3/4]

sockcanpp::CanMessage::CanMessage ( const struct canxl_frame  frame)
inline

Definition at line 54 of file CanXLMessage.hpp.

54: _rawFrame(frame) { }

References _rawFrame.

◆ CanMessage() [4/4]

sockcanpp::CanMessage::CanMessage ( const CanId priorityField,
const CanId acceptanceField,
const string &  frameData 
)
inline

Definition at line 56 of file CanXLMessage.hpp.

56 {
57 if (frameData.size() > CANXL_MAX_DLEN) {
58 throw system_error(error_code(0xbadd1c, generic_category()), "Payload too big!");
59 }
60
61 struct canxl_frame rawFrame{};
62
63 std::copy(frameData.begin(), frameData.end(), rawFrame.data);
64
65 rawFrame.len = frameData.size();
66 rawFrame.prio = static_cast<uint16_t>(priorityField); // Ensure the CanId is truncated to 11 bits
67 rawFrame.af = static_cast<uint32_t>(acceptanceField); // Ensure the CanId is truncated to 32 bits
68 rawFrame.flags |= CANXL_XLF; // Set the mandatory CAN XL frame flag
69 rawFrame.sdt = 0; // Set the SDU type to 0 (default)
70 }

◆ ~CanMessage() [2/2]

virtual sockcanpp::CanMessage::~CanMessage ( )
virtualdefault

Member Function Documentation

◆ getCanId()

const CanId sockcanpp::CanMessage::getCanId ( ) const
inline

Definition at line 74 of file CanMessage.hpp.

74{ return this->_canIdentifier; }

References _canIdentifier.

Referenced by sockcanpp::CanDriver::sendMessage().

◆ getFrameData()

const string sockcanpp::CanMessage::getFrameData ( ) const
inline

Definition at line 75 of file CanMessage.hpp.

75{ return this->_frameData; }

References _frameData.

Referenced by sockcanpp::CanDriver::sendMessage().

◆ getRawFrame()

const can_frame sockcanpp::CanMessage::getRawFrame ( ) const
inline

Definition at line 76 of file CanMessage.hpp.

76{ return this->_rawFrame; }

References _rawFrame.

Referenced by sockcanpp::CanDriver::sendMessage().

Field Documentation

◆ _canIdentifier

CanId sockcanpp::CanMessage::_canIdentifier
private

Definition at line 79 of file CanMessage.hpp.

Referenced by CanMessage(), CanMessage(), and getCanId().

◆ _frameData

string sockcanpp::CanMessage::_frameData
private

Definition at line 81 of file CanMessage.hpp.

Referenced by CanMessage(), CanMessage(), and getFrameData().

◆ _rawFrame [1/2]

struct can_frame sockcanpp::CanMessage::_rawFrame
private

Definition at line 83 of file CanMessage.hpp.

Referenced by CanMessage(), CanMessage(), CanMessage(), and getRawFrame().

◆ _rawFrame [2/2]

struct canxl_frame sockcanpp::CanMessage::_rawFrame
private

Definition at line 77 of file CanXLMessage.hpp.


The documentation for this class was generated from the following files: