22#ifndef LELY_CAN_MSG_H_
23#define LELY_CAN_MSG_H_
31#define CAN_MASK_BID UINT32_C(0x000007ff)
34#define CAN_MASK_EID UINT32_C(0x1fffffff)
76#define CANFD_MAX_LEN 64
81#define CAN_MSG_MAX_LEN CAN_MAX_LEN
83#define CAN_MSG_MAX_LEN CANFD_MAX_LEN
107#define CAN_MSG_INIT \
109 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } \
113#define CAN_MSG_INIT \
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
120 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
201 uint_least16_t crc,
const void *ptr,
int off,
size_t bits);
@ 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_FDF
The FD Format (FDF) flag, formerly known as Extended Data Length (EDL).
@ 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).
int snprintf_can_msg(char *s, size_t n, const struct can_msg *msg)
Prints the contents of a CAN or CAN FD format frame to a string buffer.
#define CAN_MSG_MAX_LEN
The maximum number of bytes in the payload of a can_msg struct.
int asprintf_can_msg(char **ps, const struct can_msg *msg)
Equivalent to snprintf_can_msg(), except that it allocates a string large enough to hold the output,...
int can_msg_bits(const struct can_msg *msg, enum can_msg_bits_mode mode)
Computes the size (in bits) of the specified CAN format frame on the CAN bus.
uint_least16_t can_crc(uint_least16_t crc, const void *ptr, int off, size_t bits)
Computes a bitwise CRC-15-CAN checksum, based on the 0x4599 generator polynomial.
can_msg_bits_mode
The method used to compute te size (in bits) of a CAN frame.
@ CAN_MSG_BITS_MODE_WORST
Simple worst case estimate.
@ CAN_MSG_BITS_MODE_EXACT
Exact calculation based of frame content and CRC.
@ CAN_MSG_BITS_MODE_NO_STUFF
Simple calculation assuming no bit stuffing.
This header file is part of the Lely libraries; it contains the compiler feature definitions.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
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).