24#ifndef LELY_IO2_VCAN_HPP_
25#define LELY_IO2_VCAN_HPP_
41 int nominal = 0,
int data = 0,
46 if (!ctrl) util::throw_errc(
"VirtualCanController");
56 VirtualCanController& operator=(
const VirtualCanController&) =
delete;
59 operator=(VirtualCanController&&
other)
noexcept {
61 swap(ctrl,
other.ctrl);
76 write(
const can_msg& msg,
int timeout, ::std::error_code& ec)
noexcept {
82 ec = util::make_error_code();
90 write(msg, timeout, ec);
91 if (ec) throw ::std::system_error(ec,
"write");
96 write(
const can_err& err,
int timeout, ::std::error_code& ec)
noexcept {
102 ec = util::make_error_code();
109 ::std::error_code ec;
110 write(err, timeout, ec);
111 if (ec) throw ::std::system_error(ec,
"write");
121 if (!chan) util::throw_errc(
"VirtualCanChannel");
128 other.chan =
nullptr;
132 VirtualCanChannel& operator=(
const VirtualCanChannel&) =
delete;
135 operator=(VirtualCanChannel&&
other)
noexcept {
137 swap(chan,
other.chan);
138 swap(dev,
other.dev);
A reference to an abstract CAN channel.
A reference to an abstract CAN controller.
void open(const io_can_ctrl_t *ctrl) noexcept
VirtualCanChannel(io_ctx_t *ctx, ev_exec_t *exec, size_t rxlen=0)
bool is_open() const noexcept
CanControllerBase get_ctrl() const noexcept
A virtual CAN controller.
void write(const can_msg &msg, int timeout, ::std::error_code &ec) noexcept
VirtualCanController(io_clock_t *clock, CanBusFlag flags=CanBusFlag::MASK, int nominal=0, int data=0, CanState state=CanState::ACTIVE)
void write(const can_err &err, int timeout=-1)
void write(const can_msg &msg, int timeout=-1)
void write(const can_err &err, int timeout, ::std::error_code &ec) noexcept
void set_state(CanState state)
const struct io_clock_vtbl *const io_clock_t
An abstract clock.
This header file is part of the I/O library; it contains the C++ interface for the abstract clock.
CanState
The states of a CAN node, depending on the TX/RX error count.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
const struct io_can_ctrl_vtbl *const io_can_ctrl_t
An abstract CAN controller.
This header file is part of the I/O library; it contains the C++ interface for the abstract CAN bus.
CanBusFlag
The CAN bus flags.
A CAN or CAN FD format frame.
This header file is part of the I/O library; it contains the virtual CAN bus declarations.
void io_vcan_chan_destroy(io_can_chan_t *chan)
Destroys a virtual CAN channel.
void io_vcan_ctrl_set_state(io_can_ctrl_t *ctrl, int state)
Sets the state of a virtual CAN bus: one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE, CAN_STATE_BUSOFF,...
io_can_ctrl_t * io_vcan_ctrl_create(io_clock_t *clock, int flags, int nominal, int data, int state)
Creates a new virtual CAN controller.
void io_vcan_chan_close(io_can_chan_t *chan)
Closes a virtual CAN channel.
int io_vcan_ctrl_write_err(io_can_ctrl_t *ctrl, const struct can_err *err, int timeout)
Writes a CAN error frame to a all virtual CAN channels registered with a virtual CAN controller.
void io_vcan_chan_open(io_can_chan_t *chan, io_can_ctrl_t *ctrl)
Opens a virtual CAN channel by registering it with the specified virtual CAN controller.
int io_vcan_chan_is_open(const io_can_chan_t *chan)
Returns 1 if the CAN channel is open and 0 if not.
int io_vcan_ctrl_write_msg(io_can_ctrl_t *ctrl, const struct can_msg *msg, int timeout)
Writes a CAN frame to a all virtual CAN channels registered with a virtual CAN controller.
io_can_chan_t * io_vcan_chan_create(io_ctx_t *ctx, ev_exec_t *exec, size_t rxlen)
Creates a new virtual CAN channel.
io_can_ctrl_t * io_vcan_chan_get_ctrl(const io_can_chan_t *chan)
Returns a pointer to the virtual CAN controller with which a virtual CAN channel is registered,...
void io_vcan_ctrl_destroy(io_can_ctrl_t *ctrl)
Destroys a virtual CAN controller.