Lely core libraries 2.3.4
msg.c
Go to the documentation of this file.
1
24#include "../io2.h"
25#include <lely/io2/can/msg.h>
26
27#include <string.h>
28
29int
30can_msg_cmp(const void *p1, const void *p2)
31{
32 if (p1 == p2)
33 return 0;
34
35 if (!p1)
36 return -1;
37 if (!p2)
38 return 1;
39
40 const struct can_msg *m1 = p1;
41 const struct can_msg *m2 = p2;
42
43 int cmp;
44 if ((cmp = (m2->id < m1->id) - (m1->id < m2->id)))
45 return cmp;
46 if ((cmp = (m2->flags < m1->flags) - (m1->flags < m2->flags)))
47 return cmp;
48 if ((cmp = (m2->len < m1->len) - (m1->len < m2->len)))
49 return cmp;
50
51 return memcmp(m1->data, m2->data, m1->len);
52}
int can_msg_cmp(const void *p1, const void *p2)
Compares two CAN or CAN FD format frames.
Definition msg.c:30
This header file is part of the I/O library; it contains the CAN frame declarations.
This header file is part of the C11 and POSIX compatibility library; it includes <string....
A CAN or CAN FD format frame.
Definition msg.h:87
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
Definition msg.h:102
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
Definition msg.h:89
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...
Definition msg.h:94
uint_least8_t len
The number of bytes in data (or the requested number of bytes in case of a remote frame).
Definition msg.h:100