Generates a CAN message containing the given data. This handles the byte-swapping (because of big-endian) automatically.
17{
18
19 CAN_message_t can_msg;
20
21 uint16_t actual_first = first, actual_second = second, actual_third = third, actual_fourth = fourth;
22
23
24
25
26 if (use_little_endian) {
27 actual_first = (uint16_t) ( (0x00FFU & first) << 8U | (0xFF00U & first) >> 8U );
28 actual_second = (uint16_t) ( (0x00FFU & second) << 8U | (0xFF00U & second) >> 8U );
29 actual_third = (uint16_t) ( (0x00FFU & third) << 8U | (0xFF00U & third) >> 8U );
30 actual_fourth = (uint16_t) ( (0x00FFU & fourth) << 8U | (0xFF00U & fourth) >> 8U );
31 }
32
33
34 memcpy(&can_msg.buf, &actual_first, sizeof(uint16_t));
35 memcpy(&can_msg.buf[2], &actual_second, sizeof(uint16_t));
36 memcpy(&can_msg.buf[4], &actual_third, sizeof(uint16_t));
37 memcpy(&can_msg.buf[6], &actual_fourth, sizeof(uint16_t));
38
39 return can_msg;
40
41}