Lely core libraries  2.2.5
err.hpp
Go to the documentation of this file.
1 
24 #ifndef LELY_IO2_CAN_ERR_HPP_
25 #define LELY_IO2_CAN_ERR_HPP_
26 
27 #include <lely/io2/can/err.h>
28 
29 namespace lely {
30 namespace io {
31 
33 enum class CanState : int {
35  ACTIVE = CAN_STATE_ACTIVE,
37  PASSIVE = CAN_STATE_PASSIVE,
39  BUSOFF = CAN_STATE_BUSOFF,
41  SLEEPING = CAN_STATE_SLEEPING,
43  STOPPED = CAN_STATE_STOPPED
44 };
45 
47 enum class CanError : int {
49  BIT = CAN_ERROR_BIT,
51  STUFF = CAN_ERROR_STUFF,
53  CRC = CAN_ERROR_CRC,
55  FORM = CAN_ERROR_FORM,
57  ACK = CAN_ERROR_ACK,
59  OTHER = CAN_ERROR_OTHER,
60  NONE = 0
61 };
62 
63 constexpr CanError
64 operator~(CanError rhs) {
65  return static_cast<CanError>(~static_cast<int>(rhs));
66 }
67 
68 constexpr CanError operator&(CanError lhs, CanError rhs) {
69  return static_cast<CanError>(static_cast<int>(lhs) & static_cast<int>(rhs));
70 }
71 
72 constexpr CanError
73 operator^(CanError lhs, CanError rhs) {
74  return static_cast<CanError>(static_cast<int>(lhs) ^ static_cast<int>(rhs));
75 }
76 
77 constexpr CanError
78 operator|(CanError lhs, CanError rhs) {
79  return static_cast<CanError>(static_cast<int>(lhs) | static_cast<int>(rhs));
80 }
81 
82 inline CanError&
83 operator&=(CanError& lhs, CanError rhs) {
84  return lhs = lhs & rhs;
85 }
86 
87 inline CanError&
88 operator^=(CanError& lhs, CanError rhs) {
89  return lhs = lhs ^ rhs;
90 }
91 
92 inline CanError&
93 operator|=(CanError& lhs, CanError rhs) {
94  return lhs = lhs | rhs;
95 }
96 
97 } // namespace io
98 } // namespace lely
99 
100 #endif // !LELY_IO2_CAN_ERR_HPP_
err.h
CAN_STATE_BUSOFF
@ CAN_STATE_BUSOFF
The bus off state (TX/RX error count >= 256).
Definition: err.h:34
CAN_STATE_ACTIVE
@ CAN_STATE_ACTIVE
The error active state (TX/RX error count < 128).
Definition: err.h:30
CAN_ERROR_BIT
@ CAN_ERROR_BIT
A single bit error.
Definition: err.h:44
CAN_STATE_PASSIVE
@ CAN_STATE_PASSIVE
The error passive state (TX/RX error count < 256).
Definition: err.h:32
CAN_ERROR_ACK
@ CAN_ERROR_ACK
An acknowledgment error.
Definition: err.h:52
CAN_ERROR_OTHER
@ CAN_ERROR_OTHER
One or more other errors.
Definition: err.h:54
CAN_ERROR_FORM
@ CAN_ERROR_FORM
A form error.
Definition: err.h:50
lely::io::CanError
CanError
The error flags of a CAN bus, which are not mutually exclusive.
Definition: err.hpp:47
lely::io::CanState
CanState
The states of a CAN node, depending on the TX/RX error count.
Definition: err.hpp:33
CAN_STATE_STOPPED
@ CAN_STATE_STOPPED
The device is stopped.
Definition: err.h:38
CAN_ERROR_STUFF
@ CAN_ERROR_STUFF
A bit stuffing error.
Definition: err.h:46
CAN_ERROR_CRC
@ CAN_ERROR_CRC
A CRC sequence error.
Definition: err.h:48
CAN_STATE_SLEEPING
@ CAN_STATE_SLEEPING
The device is in sleep mode.
Definition: err.h:36