Lely core libraries 2.3.4
can.hpp
Go to the documentation of this file.
1
23#ifndef LELY_IO_CAN_HPP_
24#define LELY_IO_CAN_HPP_
25
26#ifndef __cplusplus
27#error "include <lely/io/can.h> for the C interface"
28#endif
29
30#include <lely/io/can.h>
31#include <lely/io/io.hpp>
32
33#include <utility>
34
35namespace lely {
36
38class IOCAN : public IOHandle {
39 public:
40 IOCAN(const char* path) : IOHandle(io_open_can(path)) {
41 if (!operator bool()) throw_or_abort(bad_init());
42 }
43
44 IOCAN(const IOCAN& can) noexcept : IOHandle(can) {}
45
46 IOCAN(IOCAN&& can) noexcept : IOHandle(::std::forward<IOCAN>(can)) {}
47
48 IOCAN&
49 operator=(const IOCAN& can) noexcept {
50 IOHandle::operator=(can);
51 return *this;
52 }
53
54 IOCAN&
55 operator=(IOCAN&& can) noexcept {
56 IOHandle::operator=(::std::forward<IOCAN>(can));
57 return *this;
58 }
59
60 int
61 read(can_msg& msg) noexcept {
62 return io_can_read(*this, &msg);
63 }
64
65 int
66 write(const can_msg& msg) noexcept {
67 return io_can_write(*this, &msg);
68 }
69
70 int
71 start() noexcept {
72 return io_can_start(*this);
73 }
74 int
75 stop() noexcept {
76 return io_can_stop(*this);
77 }
78
79 int
80 getState() noexcept {
81 return io_can_get_state(*this);
82 }
83
84 int
85 getError(int& error) noexcept {
86 return io_can_get_error(*this, &error);
87 }
88
89 int
90 getEC(uint16_t& txec, uint16_t& rxec) noexcept {
91 return io_can_get_ec(*this, &txec, &rxec);
92 }
93
94 int
95 getBitrate(uint32_t& bitrate) noexcept {
96 return io_can_get_bitrate(*this, &bitrate);
97 }
98
99 int
100 setBitrate(uint32_t bitrate) noexcept {
101 return io_can_set_bitrate(*this, bitrate);
102 }
103
104 int
105 getTXQLen(size_t& txqlen) noexcept {
106 return io_can_get_txqlen(*this, &txqlen);
107 }
108
109 int
110 setTXQLen(size_t txqlen) noexcept {
111 return io_can_set_txqlen(*this, txqlen);
112 }
113};
114
115} // namespace lely
116
117#endif // !LELY_IO_CAN_HPP_
A CANopen value.
Definition val.hpp:42
A Controller Area Network (CAN) device handle.
Definition can.hpp:38
An I/O device handle.
Definition io.hpp:35
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
Definition c_type.hpp:38
The type of objects thrown as exceptions to report a system error with an associated error code.
Definition exception.hpp:54
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
Definition exception.hpp:38
This header file is part of the I/O library; it contains the Controller Area Network (CAN) declaratio...
int io_can_get_error(io_handle_t handle, int *perror)
Obtains and clears the current error number of a CAN device, and stores the value (any combination of...
Definition can.c:436
int io_can_set_txqlen(io_handle_t handle, size_t txqlen)
Sets the length of the transmission queue (in number of CAN frames) of a CAN device.
Definition can.c:626
int io_can_stop(io_handle_t handle)
Stops transmission and reception on a CAN device.
Definition can.c:354
int io_can_write(io_handle_t handle, const struct can_msg *msg)
Writes a single CAN or CAN FD frame.
Definition can.c:276
int io_can_get_txqlen(io_handle_t handle, size_t *ptxqlen)
Obtains the length of the transmission queue (in number of CAN frames) of a CAN device and stores the...
Definition can.c:589
io_handle_t io_open_can(const char *path)
Opens a CAN device.
Definition can.c:111
int io_can_read(io_handle_t handle, struct can_msg *msg)
Reads a single CAN or CAN FD frame.
Definition can.c:218
int io_can_get_ec(io_handle_t handle, uint16_t *ptxec, uint16_t *prxec)
Obtains the transmit and/or receive error count of a CAN device and stores the value in *ptxec and/or...
Definition can.c:458
int io_can_start(io_handle_t handle)
Starts transmission and reception on a CAN device.
Definition can.c:322
int io_can_set_bitrate(io_handle_t handle, uint32_t bitrate)
Sets the bitrate (in bit/s) of a CAN device.
Definition can.c:536
int io_can_get_state(io_handle_t handle)
Obtains the state of a CAN device.
Definition can.c:388
int io_can_get_bitrate(io_handle_t handle, uint32_t *pbitrate)
Obtains the bitrate (in bit/s) of a CAN device and stores the value in *pbitrate.
Definition can.c:498
This header file is part of the I/O library; it contains the C++ interface of the I/O device handle.
A CAN or CAN FD format frame.
Definition msg.h:87
A CAN device.
Definition can.c:60