26 #ifdef LELY_HAVE_SOCKET_CAN
35 #ifdef HAVE_LINUX_CAN_H
38 #ifdef HAVE_LINUX_CAN_ERROR_H
39 #include <linux/can/error.h>
48 if (!(frame->can_id & CAN_ERR_FLAG))
52 enum can_error error = perror ? *perror : 0;
54 #ifdef HAVE_LINUX_CAN_ERROR_H
55 if (frame->can_dlc != CAN_ERR_DLC) {
60 if (frame->can_id & CAN_ERR_RESTARTED)
63 if (frame->can_id & CAN_ERR_TX_TIMEOUT)
66 if (frame->can_id & CAN_ERR_CRTL) {
67 #ifdef CAN_ERR_CRTL_ACTIVE
68 if (frame->data[1] & CAN_ERR_CRTL_ACTIVE)
72 if (frame->data[1] & (CAN_ERR_CRTL_RX_PASSIVE
73 | CAN_ERR_CRTL_TX_PASSIVE))
78 if (frame->can_id & CAN_ERR_PROT) {
79 if (frame->data[2] & CAN_ERR_PROT_BIT)
81 if (frame->data[2] & CAN_ERR_PROT_FORM)
83 if (frame->data[2] & CAN_ERR_PROT_STUFF)
86 if (frame->data[2] & (CAN_ERR_PROT_BIT0 | CAN_ERR_PROT_BIT1
87 | CAN_ERR_PROT_OVERLOAD))
90 if (frame->data[2] & CAN_ERR_PROT_ACTIVE)
92 if (frame->data[3] & CAN_ERR_PROT_LOC_CRC_SEQ)
96 if ((frame->can_id & CAN_ERR_TRX) && frame->data[4])
99 if (frame->can_id & CAN_ERR_ACK)
102 if (frame->can_id & CAN_ERR_BUSOFF)
121 if (src->can_id & CAN_ERR_FLAG) {
126 memset(dst, 0,
sizeof(*dst));
128 if (src->can_id & CAN_EFF_FLAG) {
129 dst->
id = src->can_id & CAN_EFF_MASK;
132 dst->
id = src->can_id & CAN_SFF_MASK;
134 if (src->can_id & CAN_RTR_FLAG)
139 memcpy(dst->
data, src->data, dst->
len);
150 #ifndef LELY_NO_CANFD
151 if (src->
flags & CAN_FLAG_EDL) {
157 memset(dst, 0,
sizeof(*dst));
158 dst->can_id = src->
id;
160 dst->can_id &= CAN_EFF_MASK;
161 dst->can_id |= CAN_EFF_FLAG;
163 dst->can_id &= CAN_SFF_MASK;
167 dst->can_id |= CAN_RTR_FLAG;
169 memcpy(dst->data, src->
data, dst->can_dlc);
174 #if !defined(LELY_NO_CANFD) && defined(CANFD_MTU)
182 if (src->can_id & CAN_ERR_FLAG) {
187 memset(dst, 0,
sizeof(*dst));
188 dst->
flags = CAN_FLAG_EDL;
189 if (src->can_id & CAN_EFF_FLAG) {
190 dst->
id = src->can_id & CAN_EFF_MASK;
193 dst->
id = src->can_id & CAN_SFF_MASK;
195 if (src->flags & CANFD_BRS)
197 if (src->flags & CANFD_ESI)
200 memcpy(dst->
data, src->data, dst->
len);
211 if (!(src->
flags & CAN_FLAG_EDL)) {
216 memset(dst, 0,
sizeof(*dst));
217 dst->can_id = src->
id;
219 dst->can_id &= CAN_EFF_MASK;
220 dst->can_id |= CAN_EFF_FLAG;
222 dst->can_id &= CAN_SFF_MASK;
226 dst->flags |= CANFD_BRS;
228 dst->flags |= CANFD_ESI;
230 memcpy(dst->data, src->
data, dst->len);
can_error
The error flags of a CAN bus, which are not mutually exclusive.
@ CAN_ERROR_FORM
A form error.
@ CAN_ERROR_BIT
A single bit error.
@ CAN_ERROR_STUFF
A bit stuffing error.
@ CAN_ERROR_ACK
An acknowledgment error.
@ CAN_ERROR_CRC
A CRC sequence error.
@ CAN_ERROR_OTHER
One or more other errors.
can_state
The states of a CAN node, depending on the TX/RX error count.
@ CAN_STATE_BUSOFF
The bus off state (TX/RX error count >= 256).
@ CAN_STATE_PASSIVE
The error passive state (TX/RX error count < 256).
@ CAN_STATE_ACTIVE
The error active state (TX/RX error count < 128).
@ CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
@ CAN_FLAG_RTR
The Remote Transmission Request (RTR) flag (unavailable in CAN FD format frames).
@ CAN_FLAG_BRS
The Bit Rate Switch (BRS) flag (only available in CAN FD format frames).
@ CAN_FLAG_ESI
The Error State Indicator (ESI) flag (only available in CAN FD format frames).
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
#define CANFD_MAX_LEN
The maximum number of bytes in the payload of a CAN FD format frame.
This header file is part of the utilities library; it contains the native and platform-independent er...
@ ERRNUM_INVAL
Invalid argument.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
This header file is part of the I/O library; it contains the CAN bus declarations for Linux.
This is the public header file of the utilities library.
#define MIN(a, b)
Returns the minimum of a and b.
int can_frame2can_msg(const struct can_frame *src, struct can_msg *dst)
Converts a SocketCAN CAN frame to a can_msg frame.
int can_frame_is_error(const struct can_frame *frame, enum can_state *pstate, enum can_error *perror)
Checks if a SocketCAN CAN frame is an error frame and parses the bus state and error flags if it is.
int can_msg2can_frame(const struct can_msg *src, struct can_frame *dst)
Converts a can_msg frame to a SocketCAN CAN frame.
This header file is part of the CAN library; it contains the SocketCAN interface declarations.
int can_msg2canfd_frame(const struct can_msg *src, struct canfd_frame *dst)
Converts a can_msg frame to a SocketCAN CAN FD frame.
int canfd_frame2can_msg(const struct canfd_frame *src, struct can_msg *dst)
Converts a SocketCAN CAN FD frame to a can_msg frame.
This is the internal header file of the CAN bus operation queue functions.
This header file is part of the C11 and POSIX compatibility library; it includes <string....
A CAN or CAN FD format frame.
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
uint_least8_t flags
The flags (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR, CAN_FLAG_FDF, CAN_FLAG_BRS and CAN_FLAG_ESI...
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).