Fixposition SDK 0.0.0-heads/main-0-gde8559b
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
fpsdk::common::can::RawCan Class Reference

Raw CAN helper class using SocketCAN. More...

#include <can.hpp>

Inheritance diagram for fpsdk::common::can::RawCan:
[legend]
Collaboration diagram for fpsdk::common::can::RawCan:
[legend]

Public Member Functions

 RawCan (const std::string &device)
 Constructor.
 
 ~RawCan ()
 Destructor.
 
bool Open ()
 Open CAN interface.
 
bool SetFilters (const std::vector< struct can_filter > &filters)
 Set filters.
 
void Close ()
 Close CAN interface.
 
bool IsOpen () const
 Check if CAN is open.
 
int GetSocket () const
 Get socket.
 
int GetErrno () const
 Get last error (errno)
 
std::string GetStrerror ()
 Get last error string (strerror)
 
void FlushInput ()
 Flush all pending input data.
 
bool SendFrame (CanFrame &frame)
 Send raw CAN frame (standard, extended and FD, and combinations thereof)
 
bool ReadFrame (struct can_frame &frame, const int timeout=0)
 Read raw classical CAN frame.
 
bool SendFrame (const struct can_frame &frame)
 Send raw classical CAN frame.
 
bool SendFrame (const struct canfd_frame &frame)
 Send raw CAN FD frame.
 
bool ReadFrame (struct canfd_frame &frame, const int timeout=0)
 Read raw CAN FD frame.
 
bool ReadFrame (CanFrame &frame, const int timeout=0)
 Read raw CAN frame (standard, extended and FD, and combinations thereof)
 

Protected Attributes

std::string device_
 Device name.
 
int sock_
 The socket to the CAN inferface.
 
int saved_errno_
 Saved errno.
 

Detailed Description

Raw CAN helper class using SocketCAN.

Definition at line 142 of file can.hpp.

Constructor & Destructor Documentation

◆ RawCan()

fpsdk::common::can::RawCan::RawCan ( const std::string & device)

Constructor.

Parameters
[in]deviceDevice name (e.g. "can0")

Member Function Documentation

◆ Open()

bool fpsdk::common::can::RawCan::Open ( )

Open CAN interface.

Returns
true if device was successfully opened, false otherwise

◆ SetFilters()

bool fpsdk::common::can::RawCan::SetFilters ( const std::vector< struct can_filter > & filters)

Set filters.

Parameters
[in]filtersList of filters to apply to the CAN interface
Returns
true if filters were applied successfully, false othwise

See https://www.kernel.org/doc/html/latest/networking/can.html#raw-socket-option-can-raw-filter and linux/can.h for the can_filter struct documentation (for example, the filter flags).

◆ IsOpen()

bool fpsdk::common::can::RawCan::IsOpen ( ) const

Check if CAN is open.

Returns
true if socket is open, false otherwise

◆ GetSocket()

int fpsdk::common::can::RawCan::GetSocket ( ) const

Get socket.

Returns
the socket, -1 if interface is not opened

◆ GetErrno()

int fpsdk::common::can::RawCan::GetErrno ( ) const

Get last error (errno)

Returns
the last error (errno), 0 = no error

◆ GetStrerror()

std::string fpsdk::common::can::RawCan::GetStrerror ( )

Get last error string (strerror)

Returns
the last error string

◆ SendFrame() [1/3]

bool fpsdk::common::can::RawCan::SendFrame ( CanFrame & frame)

Send raw CAN frame (standard, extended and FD, and combinations thereof)

Parameters
[in,out]frameThe CAN frame to send
Returns
true if sent successfully, false otherwise

◆ ReadFrame() [1/3]

bool fpsdk::common::can::RawCan::ReadFrame ( struct can_frame & frame,
const int timeout = 0 )

Read raw classical CAN frame.

Parameters
[out]frameThe received frame
[in]timeoutTimeout to wait for a frame [ms], use 0 for no wait, < 0 for infinite wait (like poll())
Returns
true if a frame was received, false otherwise

◆ SendFrame() [2/3]

bool fpsdk::common::can::RawCan::SendFrame ( const struct can_frame & frame)

Send raw classical CAN frame.

Parameters
[in]frameThe CAN frame to send
Returns
true if sent successfully, false otherwise

◆ SendFrame() [3/3]

bool fpsdk::common::can::RawCan::SendFrame ( const struct canfd_frame & frame)

Send raw CAN FD frame.

Parameters
[in]frameThe CAN frame to send
Returns
true if sent successfully, false otherwise

◆ ReadFrame() [2/3]

bool fpsdk::common::can::RawCan::ReadFrame ( struct canfd_frame & frame,
const int timeout = 0 )

Read raw CAN FD frame.

Parameters
[out]frameThe received frame
[in]timeoutTimeout to wait for a frame [ms], use 0 for no wait, < 0 for infinite wait (like poll())
Returns
true if a frame was received, false otherwise

◆ ReadFrame() [3/3]

bool fpsdk::common::can::RawCan::ReadFrame ( CanFrame & frame,
const int timeout = 0 )

Read raw CAN frame (standard, extended and FD, and combinations thereof)

Parameters
[out]frameThe received frame
[in]timeoutTimeout to wait for a frame [ms], use 0 for no wait, < 0 for infinite wait (like poll())
Returns
true if a frame was received, false otherwise

Member Data Documentation

◆ device_

std::string fpsdk::common::can::RawCan::device_
protected

Device name.

Definition at line 272 of file can.hpp.

◆ sock_

int fpsdk::common::can::RawCan::sock_
protected

The socket to the CAN inferface.

Definition at line 273 of file can.hpp.

◆ saved_errno_

int fpsdk::common::can::RawCan::saved_errno_
protected

Saved errno.

Definition at line 274 of file can.hpp.


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