Lely core libraries  2.2.5
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 
29 int
30 can_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 }
can_msg::flags
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
can_msg::data
uint_least8_t data[CAN_MSG_MAX_LEN]
The frame payload (in case of a data frame).
Definition: msg.h:102
string.h
can_msg
A CAN or CAN FD format frame.
Definition: msg.h:87
can_msg::len
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
msg.h
can_msg_cmp
int can_msg_cmp(const void *p1, const void *p2)
Compares two CAN or CAN FD format frames.
Definition: msg.c:30
can_msg::id
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
Definition: msg.h:89