5#ifndef CAN_SOCKET_INTERFACE
6#define CAN_SOCKET_INTERFACE
12#include <system_error>
43 std::optional<can_msg_frame>
frame
66 using native_handle = int;
70 virtual native_handle handle() = 0;
72#error "Unsupported OS"
78 virtual std::errc
open() = 0;
97 virtual std::optional<can_adapter>
adapter()
const = 0;
116 can_msg_frame& frame, std::chrono::milliseconds timeout = std::chrono::milliseconds::zero())
158 std::chrono::milliseconds timeout)
const
The CAN interface setup class.
Definition can_adapter.h:47
The can_socket_interface lists the expected interface for a CAN socket implementation that can be use...
Definition can_socket_interface.h:58
virtual std::optional< can_adapter > adapter() const =0
Get the adapter this socket is bound to, if any.
virtual std::errc enable_error_frames()=0
Enable receiving CAN Error Frames on this socket.
virtual std::errc send(const can_msg_frame &frame)=0
Send a CAN frame on this socket.
virtual std::errc bind(const can_adapter &adapter)=0
Bind this socket to an adapter.
virtual select_result_can select_receive_timeout(const std::vector< can_socket > &sockets, std::chrono::milliseconds timeout) const =0
Listen on multiple sockets at the same time for a CAN frame. Returns after receiving a single CAN fra...
virtual bool is_open()=0
Check if the socket is open and bound to an interface.
virtual std::errc set_nonblocking()=0
Make reads and writes on this socket non-blocking.
virtual void set_receive_callback(const can_socket_recv_callback &cb)=0
Set a callback to be run when a CAN frame is received.
virtual bool has_receive_callback()=0
Does the socket have a receive callback set.
virtual void clear_receive_callback()=0
Remove the receive callback.
virtual std::errc open()=0
Native handle for a socket.
virtual receive_result receive(can_msg_frame &frame, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero())=0
Receive a CAN frame on this socket.
virtual std::errc close()=0
Close this socket.
virtual std::errc disable_error_frames()=0
Disable receiving CAN Error Frames on this socket.
virtual std::errc set_blocking()=0
Make reads and writes on this socket blocking.
Convenience wrapper class around a CAN socket.
Definition can_socket.h:22
std::function< std::errc(can_msg_frame)> can_socket_recv_callback
A callback function to be called when a message is successfully ready from a socket.
Definition can_socket_interface.h:50
Any entities that belong to the comms library.
Definition can_adapter.h:11
CAN frame structure.
Definition can_common.h:32
Result to receiving a message on a socket.
Definition can_socket_interface.h:26
std::errc recv_err
The error code for receving the CAN frame.
Definition can_socket_interface.h:27
std::optional< std::errc > callback_err
The error code returned by the callback (if there is one)
Definition can_socket_interface.h:29
Result to receive a message on multiple sockets at once.
Definition can_socket_interface.h:39
std::optional< can_msg_frame > frame
The CAN frame that was read. std::nullopt if an error occurred while reading.
Definition can_socket_interface.h:44
std::optional< can_adapter > adapter
The CAN adapter on which a frame was received. std::nullopt if an error occurred while reading.
Definition can_socket_interface.h:42
receive_result result
The result of the entire operation.
Definition can_socket_interface.h:40