Skip to content

Class nebula::drivers::connections::CanSocket

ClassList > nebula > drivers > connections > CanSocket

A wrapper around a raw CAN socket (AF_CAN). Supports both standard CAN and CAN FD frames.

  • #include <can.hpp>

Classes

Type Name
class Builder
struct RxMetadata

Public Types

Type Name
typedef std::function< void(const canfd_frame &frame, const RxMetadata &metadata)> callback_t

Public Functions

Type Name
CanSocket (const CanSocket &) = delete
CanSocket (CanSocket && other)
bool is_subscribed ()
Check if the socket is currently subscribed and receiving data.
CanSocket & operator= (const CanSocket &) = delete
CanSocket & operator= (CanSocket &&) = delete
bool receive_fd (canfd_frame & frame, std::chrono::nanoseconds timeout)
Receive a CAN FD frame with a timeout.
bool receive_fd (canfd_frame & frame, std::chrono::nanoseconds timeout, RxMetadata & metadata)
void send (const can_frame & frame)
Close the socket and return the file descriptor to uninitialized state.
void send_fd (const canfd_frame & frame)
Send a CAN FD frame.
void set_fd_mode (bool enable)
Enable or disable CAN FD frame support on the socket.
void set_filters (const std::vector< can_filter > & filters)
Set CAN raw filters.
void set_timestamping (bool enable)
Enable or disable kernel socket timestamping (SO_TIMESTAMP).
CanSocket & subscribe (callback_t && callback)
Register a callback for processing received frames and start the receiver thread.
CanSocket & unsubscribe ()
Gracefully stops the active receiver thread.
~CanSocket ()

Public Types Documentation

typedef callback_t

using nebula::drivers::connections::CanSocket::callback_t =  std::function<void(const canfd_frame & frame, const RxMetadata & metadata)>;

Public Functions Documentation

function CanSocket [2/3]

nebula::drivers::connections::CanSocket::CanSocket (
    const CanSocket &
) = delete

function CanSocket [3/3]

inline nebula::drivers::connections::CanSocket::CanSocket (
    CanSocket && other
) 

function is_subscribed

Check if the socket is currently subscribed and receiving data.

inline bool nebula::drivers::connections::CanSocket::is_subscribed () 

Returns:

True if receiving, false otherwise.


function operator=

CanSocket & nebula::drivers::connections::CanSocket::operator= (
    const CanSocket &
) = delete

function operator=

CanSocket & nebula::drivers::connections::CanSocket::operator= (
    CanSocket &&
) = delete

function receive_fd [1/2]

Receive a CAN FD frame with a timeout.

inline bool nebula::drivers::connections::CanSocket::receive_fd (
    canfd_frame & frame,
    std::chrono::nanoseconds timeout
) 

Parameters:

  • frame Reference to a canfd_frame to store the received data.
  • timeout Timeout duration.

Returns:

True if a frame was received, false if timeout occurred.

Exception:


function receive_fd [2/2]

inline bool nebula::drivers::connections::CanSocket::receive_fd (
    canfd_frame & frame,
    std::chrono::nanoseconds timeout,
    RxMetadata & metadata
) 

function send

Close the socket and return the file descriptor to uninitialized state.

inline void nebula::drivers::connections::CanSocket::send (
    const can_frame & frame
) 

Send a standard CAN frame.

Parameters:

  • frame The CAN frame to send.

Exception:


function send_fd

Send a CAN FD frame.

inline void nebula::drivers::connections::CanSocket::send_fd (
    const canfd_frame & frame
) 

Parameters:

  • frame The CAN FD frame to send.

Exception:


function set_fd_mode

Enable or disable CAN FD frame support on the socket.

inline void nebula::drivers::connections::CanSocket::set_fd_mode (
    bool enable
) 

Parameters:

  • enable True to enable, false to disable.

Exception:


function set_filters

Set CAN raw filters.

inline void nebula::drivers::connections::CanSocket::set_filters (
    const std::vector< can_filter > & filters
) 

Parameters:

  • filters Vector of can_filter structures.

Exception:


function set_timestamping

Enable or disable kernel socket timestamping (SO_TIMESTAMP).

inline void nebula::drivers::connections::CanSocket::set_timestamping (
    bool enable
) 

Parameters:

  • enable True to enable, false to disable.

Exception:


function subscribe

Register a callback for processing received frames and start the receiver thread.

inline CanSocket & nebula::drivers::connections::CanSocket::subscribe (
    callback_t && callback
) 

Parameters:

  • callback The function to be executed for each received frame.

function unsubscribe

Gracefully stops the active receiver thread.

inline CanSocket & nebula::drivers::connections::CanSocket::unsubscribe () 


function ~CanSocket

inline nebula::drivers::connections::CanSocket::~CanSocket () 


The documentation for this class was generated from the following file src/nebula_core/nebula_core_hw_interfaces/include/nebula_core_hw_interfaces/nebula_hw_interfaces_common/connections/can.hpp