Veethree D7 SDK
Loading...
Searching...
No Matches
can_socket.h
Go to the documentation of this file.
1
5#ifndef CAN_SOCKET_H
6#define CAN_SOCKET_H
7
8#include "can_adapter.h"
10#include <chrono>
11#include <memory>
12
13namespace vsdk::comms {
18
23public:
29 can_socket(can_socket&&) = default;
30 can_socket(const can_socket&) = default;
31 can_socket& operator=(const can_socket&) = default;
34
35 ~can_socket() noexcept = default;
36
37#if __linux__
41 can_socket_interface::native_handle handle();
42#elif !defined(_WIN32) // Windows will be supported later
43#error "Unsupported OS"
44#endif
45
52 std::errc bind(const can_adapter& adapter);
53
59 std::optional<can_adapter> adapter() const;
60
67 std::errc close();
68
75 bool is_open();
76
83 std::errc send(const can_msg_frame& frame) const;
84
90 std::errc set_nonblocking();
91
97 std::errc set_blocking();
98
105
112
120
132 can_msg_frame& frame,
133 std::chrono::milliseconds timeout = std::chrono::milliseconds::zero()) const;
134
147 static select_result_can select_receive_timeout(const std::vector<can_socket>& sockets,
148 std::chrono::milliseconds timeout);
149
150private:
151 friend class can_socket_impl;
152 std::shared_ptr<can_socket_interface> _impl;
153};
154
155
156} // namespace vsdk::comms
157
158#endif // CAN_SOCKET_H
CAN Adapter.
CAN Socket Interface.
The CAN interface setup class.
Definition can_adapter.h:47
void set_receive_callback(const can_socket_recv_callback &cb)
Set the receive callback object. See can_socket::receive.
std::errc bind(const can_adapter &adapter)
Open the socket and bind to an adapter.
std::errc set_nonblocking()
Make the socket non-blocking.
can_socket & operator=(can_socket &&)=default
Constructors and assignment operators.
receive_result receive(can_msg_frame &frame, std::chrono::milliseconds timeout=std::chrono::milliseconds::zero()) const
Receive a CAN frame.
std::errc send(const can_msg_frame &frame) const
Send a CAN frame.
std::errc close()
Close the socket.
bool is_open()
Check if the socket is open.
can_socket()
Constructors and assignment operators.
std::errc set_blocking()
Make the socket blocking.
std::errc enable_error_frames()
Allow CAN Error Frames to pass up to the application via this socket.
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.
std::errc disable_error_frames()
Filter out Error CAN frames.
std::optional< can_adapter > adapter() const
Get the adapter this socket is bound to.
can_socket & operator=(const can_socket &)=default
Constructors and assignment operators.
can_socket(const can_socket &)=default
Constructors and assignment operators.
can_socket(can_socket &&)=default
Constructors and assignment operators.
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
Result to receive a message on multiple sockets at once.
Definition can_socket_interface.h:39