Lely core libraries  2.2.5
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 
35 namespace lely {
36 
38 class 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 CAN or CAN FD format frame.
Definition: msg.h:87
int io_can_get_state(io_handle_t handle)
Obtains the state of a CAN device.
Definition: can.c:385
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:533
This header file is part of the I/O library; it contains the C++ interface of the I/O device handle...
io_handle_t io_open_can(const char *path)
Opens a CAN device.
Definition: can.c:108
An I/O device handle.
Definition: io.hpp:35
int io_can_stop(io_handle_t handle)
Stops transmission and reception on a CAN device.
Definition: can.c:351
The type of objects thrown as exceptions to report a system error with an associated error code...
Definition: exception.hpp:54
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:586
int io_can_start(io_handle_t handle)
Starts transmission and reception on a CAN device.
Definition: can.c:319
The type of objects thrown as exceptions to report a failure to initialize an instantiation of a C ty...
Definition: c_type.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:433
A CAN device.
Definition: can.c:57
int io_can_read(io_handle_t handle, struct can_msg *msg)
Reads a single CAN or CAN FD frame.
Definition: can.c:215
int io_can_write(io_handle_t handle, const struct can_msg *msg)
Writes a single CAN or CAN FD frame.
Definition: can.c:273
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:455
Definition: buf.hpp:32
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:495
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:623
A Controller Area Network (CAN) device handle.
Definition: can.hpp:38
#define throw_or_abort(e)
If exceptions are disabled, aborts the process instead of throwing an exception.
Definition: exception.hpp:38