Veethree D7 SDK
Loading...
Searching...
No Matches
vsdk::comms::can_socket Class Reference

Detailed Description

Convenience wrapper class around a CAN socket.

#include <can_socket.h>

Public Member Functions

std::errc bind (const can_adapter &adapter)
 Open the socket and bind to an adapter.
std::optional< can_adapter > adapter () const
 Get the adapter this socket is bound to.
std::errc close ()
 Close the socket.
bool is_open ()
 Check if the socket is open.
std::errc send (const can_msg_frame &frame) const
 Send a CAN frame.
std::errc set_nonblocking ()
 Make the socket non-blocking.
std::errc set_blocking ()
 Make the socket blocking.
std::errc disable_error_frames ()
 Filter out Error CAN frames.
std::errc enable_error_frames ()
 Allow CAN Error Frames to pass up to the application via this socket.
void set_receive_callback (const can_socket_recv_callback &cb)
 Set the receive callback object. See can_socket::receive.
receive_result receive (can_msg_frame &frame, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero()) const
 Receive a CAN frame.
 can_socket ()
 Constructors and assignment operators.
 can_socket (can_socket &&)=default
 Constructors and assignment operators.
 can_socket (const can_socket &)=default
 Constructors and assignment operators.
can_socket & operator= (const can_socket &)=default
 Constructors and assignment operators.
can_socket & operator= (can_socket &&)=default
 Constructors and assignment operators.

Static Public Member Functions

static select_result_can select_receive_timeout (const std::vector< can_socket > &sockets, std::chrono::milliseconds timeout)
 Listen on an array of sockets until one of them receives a CAN frame or the timeout expires.

Friends

class can_socket_impl

Detailed Description

Convenience wrapper class around a CAN socket.

Member Function Documentation

◆ adapter()

std::optional< can_adapter > vsdk::comms::can_socket::adapter ( ) const

Get the adapter this socket is bound to.

Returns
The adapter the socket is bound to, or std::nullopt if the socket is not bound yet.

◆ bind()

std::errc vsdk::comms::can_socket::bind ( const can_adapter & adapter)

Open the socket and bind to an adapter.

Parameters
adapterThe adapter to bind the socket on.
Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.

◆ close()

std::errc vsdk::comms::can_socket::close ( )

Close the socket.

Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.
Note
Most of the time it's okay to ignore the return value of this method.

◆ disable_error_frames()

std::errc vsdk::comms::can_socket::disable_error_frames ( )

Filter out Error CAN frames.

Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.

◆ enable_error_frames()

std::errc vsdk::comms::can_socket::enable_error_frames ( )

Allow CAN Error Frames to pass up to the application via this socket.

Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.

◆ is_open()

bool vsdk::comms::can_socket::is_open ( )

Check if the socket is open.

Returns
true when the socket is open and bound to an adapter
false otherwise (never opened or explicitly closed)

◆ receive()

receive_result vsdk::comms::can_socket::receive ( can_msg_frame & frame,
std::chrono::milliseconds timeout = std::chrono::milliseconds::zero() ) const

Receive a CAN frame.

Note
If a callback is set, it will be called before this function returns.
Parameters
[out]frameThe frame that was received.
[in]timeoutThe timeout for receiving a CAN frame. 0 for waiting indefinitely.
Returns
receive_result::recv_err will be std::errc{} (i.e. error code 0) if a CAN frame was successfully received, otherwise contains an error code describing the issue. receive_result::callback_err will contain the callback's return value, if a callback was set on the socket

◆ select_receive_timeout()

select_result_can vsdk::comms::can_socket::select_receive_timeout ( const std::vector< can_socket > & sockets,
std::chrono::milliseconds timeout )
static

Listen on an array of sockets until one of them receives a CAN frame or the timeout expires.

Parameters
socketsThe list of sockets to listen on.
timeoutThe timeout in milliseconds.
Returns
A structure containing the {error code, CAN adapter (optional), CAN frame (optional) }.
Note
Check the return value's error code (select_result_can::err).
  • The error code is guaranteed to be there. If err == std::errc{}, both the CAN adapter and the CAN frame are guaranteed to be set. Otherwise, check if there is a value before accessing the adapter or the frame.
  • If the adapter is missing, no CAN frame will have been read.

◆ send()

std::errc vsdk::comms::can_socket::send ( const can_msg_frame & frame) const

Send a CAN frame.

Parameters
frameThe frame to send.
Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.

◆ set_blocking()

std::errc vsdk::comms::can_socket::set_blocking ( )

Make the socket blocking.

Returns
std::errc{} (i.e. error code 0) if successful, otherwise an error code describing the error.

◆ set_nonblocking()

std::errc vsdk::comms::can_socket::set_nonblocking ( )

Make the socket non-blocking.

Returns
std::errc

◆ set_receive_callback()

void vsdk::comms::can_socket::set_receive_callback ( const can_socket_recv_callback & cb)

Set the receive callback object. See can_socket::receive.

Parameters
cbThe callback function.

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