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:
frameReference to a canfd_frame to store the received data.timeoutTimeout duration.
Returns:
True if a frame was received, false if timeout occurred.
Exception:
- SocketError if poll or read fails.
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:
frameThe CAN frame to send.
Exception:
- SocketError if the write fails or is incomplete.
function send_fd
Send a CAN FD frame.
inline void nebula::drivers::connections::CanSocket::send_fd (
const canfd_frame & frame
)
Parameters:
frameThe CAN FD frame to send.
Exception:
- SocketError if the write fails or is incomplete.
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:
enableTrue to enable, false to disable.
Exception:
- SocketError if setsockopt fails.
function set_filters
Set CAN raw filters.
inline void nebula::drivers::connections::CanSocket::set_filters (
const std::vector< can_filter > & filters
)
Parameters:
filtersVector of can_filter structures.
Exception:
- SocketError if setsockopt fails.
function set_timestamping
Enable or disable kernel socket timestamping (SO_TIMESTAMP).
inline void nebula::drivers::connections::CanSocket::set_timestamping (
bool enable
)
Parameters:
enableTrue to enable, false to disable.
Exception:
- SocketError if setsockopt fails.
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:
callbackThe 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