43#define CO_WTM_MAX_NIF 127
168 co_wtm_t *wtm, uint_least32_t ac,
void *data);
180 co_wtm_t *wtm,
const void *buf,
size_t nbytes);
188 return "Diagnostic protocol timed out limit reached";
192 return "Data cannot be transferred or stored to the application";
194 return "Data cannot be transferred or stored to the application because of local control";
196 return "Data cannot be transferred or stored to the application because of the present device state";
200 case CO_WTM_AC_DIAG:
return "Diagnostic data generation not supported";
202 return "Diagnostic data generation for requested CAN interface not supported";
204 return "Diagnostic data generation for requested WTM interface not supported";
207 case CO_WTM_AC_SEQ:
return "Invalid sequence counter in generic frame";
211 case CO_WTM_AC_CAN:
return "CAN telegram essentials invalid";
212 default:
return "Unknown abort code";
219 void *ptr = malloc(
sizeof(
struct __co_wtm));
228__co_wtm_free(
void *ptr)
252 can->recv_time = (
struct timespec){ 0, 0 };
253 can->send_time = (
struct timespec){ 0, 0 };
254 can->send_next = (
struct timespec){ 0, 0 };
301 goto error_alloc_wtm;
304 if (!__co_wtm_init(wtm)) {
352 uint_least8_t err, uint_least8_t load, uint_least16_t ec,
353 uint_least16_t foc, uint_least16_t coc)
406 if (quality > 100 && quality != 0xff) {
528 for (
const uint_least8_t *bp = buf; nbytes;) {
529 uint_least32_t ac = 0;
556 uint_least8_t len = wtm->
recv_buf[1];
576 uint_least8_t seq = wtm->
recv_buf[2];
584 uint_least8_t type = wtm->
recv_buf[3];
608 if (nif != 0x80 + wtm->
nif)
647 if (nif != 0x80 + wtm->
nif) {
664 if (!nif || nif == 0x80) {
675 uint_least8_t
st = 0xf;
676 switch ((wtm->
recv_buf[5] >> 4) & 0xf) {
681 uint_least8_t
err = 0xf;
701 uint_least8_t quality = wtm->
recv_buf[5];
733 if (nif != 0x80 + wtm->
nif) {
758 if (nif != 0x80 + wtm->
nif)
823 if (!
can->send_time.tv_sec && !
can->send_time.tv_nsec)
824 can->send_time = *tp;
826 can->send_next = *tp;
857 if (msg->
flags & CAN_FLAG_EDL) {
883 uint_least8_t dlc = msg->
len | 0x40;
910 memcpy(bp, msg->
data, msg->
len);
916 stle_u16(bp, (uint_least16_t)(usec / 100));
1034 uint_least8_t len = (uint_least8_t)(wtm->
send_nbytes - 4);
1134static uint_least32_t
1141 uint_least32_t ac = 0;
1142 for (
const uint_least8_t *bp = buf; nbytes;) {
1145 uint_least8_t dlc = *bp;
1148 msg.
len = dlc & 0x0f;
1156 uint_least8_t nif = 1;
1186 if (nbytes < msg.
len) {
1190 memcpy(msg.
data, bp, msg.
len);
1194 uint_least16_t ts = 0;
1208 struct timespec *tp = NULL;
This header file is part of the CAN library; it contains CAN bus error definitions.
@ 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_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).
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
#define CAN_MAX_LEN
The maximum number of bytes in the payload of a CAN format frame.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
#define CAN_MSG_INIT
The static initializer for can_msg.
This header file is part of the CANopen library; it contains the Cyclic Redundancy Check (CRC) declar...
uint_least16_t co_crc(uint_least16_t crc, const uint_least8_t *bp, size_t n)
Computes a CRC-16 checksum.
This header file is part of the utilities library; it contains the diagnostic declarations.
void diag(enum diag_severity severity, int errc, const char *format,...)
Emits a diagnostic message.
This header file is part of the utilities library; it contains the byte order (endianness) function d...
uint_least32_t ldle_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in little-endian byte order.
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
void stle_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
void stle_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
@ ERRNUM_NOSYS
Function not supported.
@ ERRNUM_NOMEM
Not enough space.
@ ERRNUM_INVAL
Invalid argument.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
errnum_t get_errnum(void)
Returns the last (thread-specific) platform-independent error number set by a system call or library ...
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
#define MIN(a, b)
Returns the minimum of a and b.
#define MAX(a, b)
Returns the maximum of a and b.
This is the internal header file of the CANopen library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
This header file is part of the C11 and POSIX compatibility library; it includes <string....
A CANopen Wireless Transmission Media (WTM) interface.
co_wtm_diag_can_ind_t * diag_can_ind
A pointer to the indication function invoked when a CAN communication quality reset message is receiv...
uint_least8_t send_buf[CO_WTM_MAX_LEN]
The buffer used to send byte streams.
size_t send_nbytes
The number of bytes in send_buf.
void * diag_wtm_con_data
A pointer to the user-specified data for diag_wtm_con.
co_wtm_diag_ac_ind_t * diag_ac_ind
A pointer to the callback function invoked when an abort code is generated or received.
co_wtm_diag_can_con_t * diag_can_con
A pointer to the confirmation function invoked when a CAN communication quality response is received.
struct co_wtm_can can[CO_WTM_MAX_NIF]
The CAN interfaces.
void * diag_ac_data
A pointer to the user-specified data for diag_ac_ind.
uint_least8_t quality
The link quality percentage (in the range [0..100], or 0xff if the information is not available).
void * recv_data
A pointer to the user-specified data for recv_func.
size_t recv_nbytes
The number of bytes in recv_buf.
void * diag_can_ind_data
A pointer to the user-specified data for diag_can_ind.
co_wtm_recv_func_t * recv_func
A pointer to the callback function invoked by co_wtm_recv().
co_wtm_diag_wtm_con_t * diag_wtm_con
A pointer to the confirmation function invoked when a WTM communication quality response is received.
void * send_data
A pointer to the user-specified data for send_func.
co_wtm_diag_wtm_ind_t * diag_wtm_ind
A pointer to the indication function invoked when a WTM communication quality reset message is receiv...
co_wtm_send_func_t * send_func
A pointer to the callback function invoked by co_wtm_send().
void * diag_wtm_ind_data
A pointer to the user-specified data for diag_wtm_ind.
uint_least8_t recv_buf[CO_WTM_MAX_LEN]
The buffer used to receive byte streams.
void * diag_can_con_data
A pointer to the user-specified data for diag_can_con.
uint_least8_t send_nseq
The sequence number for sent generic frames.
uint_least8_t nif
The WTM interface indicator.
uint_least8_t recv_nseq
The sequence number for received generic frames.
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).
A CANopen WTM CAN interface.
struct timespec send_time
The current time of the CAN frame sender.
uint_least8_t err
The last detected error (0 if no error was detected, one of CAN_ERROR_BIT, CAN_ERROR_STUFF,...
struct timespec recv_time
The current time of the CAN frame receiver.
uint_least8_t st
The current CAN controller status (one of CAN_STATE_ACTIVE, CAN_STATE_PASSIVE or CAN_STATE_BUSOFF,...
struct timespec send_next
The time at which the next frame is sent.
uint_least16_t foc
The FIFO overrun counter (in the range [0..0xfffe], or 0xffff if the information is not available).
uint_least8_t load
The current busload percentage (in the range [0..100], or 0xff if the information is not available).
uint_least16_t coc
The CAN controller overrun counter (in the range [0..0xfffe], or 0xffff if the information is not ava...
uint_least16_t ec
The number of detected errors that led to the increase of one of the CAN controller internal error co...
This header file is part of the utilities library; it contains the time function declarations.
void timespec_add_usec(struct timespec *tp, uint_least64_t usec)
Adds usec microseconds to the time at tp.
int_least64_t timespec_diff_usec(const struct timespec *t1, const struct timespec *t2)
Returns the time difference (in microseconds) between *t1 and *t2.
void co_wtm_get_diag_ac_ind(const co_wtm_t *wtm, co_wtm_diag_ac_ind_t **pind, void **pdata)
Retrieves the indication function invoked when an abort code is generated or received by a CANopen WT...
int co_wtm_set_diag_wtm(co_wtm_t *wtm, uint_least8_t quality)
Sets the diagnostic parameters of a WTM interface.
int co_wtm_send_diag_wtm_rst(co_wtm_t *wtm, uint_least8_t nif)
Sends a WTM communication quality reset message.
void co_wtm_get_diag_can_ind(const co_wtm_t *wtm, co_wtm_diag_can_ind_t **pcon, void **pdata)
Retrieves the indication function invoked when a CAN communication quality reset message is received ...
void co_wtm_set_diag_wtm_ind(co_wtm_t *wtm, co_wtm_diag_wtm_ind_t *con, void *data)
Sets the indication function invoked when a WTM communication quality reset message is received by a ...
int co_wtm_get_time(const co_wtm_t *wtm, uint_least8_t nif, struct timespec *tp)
Retrieves the current time of a CANopen WTM interface.
void co_wtm_destroy(co_wtm_t *wtm)
Destroys a CANopen Wireless Transmission Media (WTM) interface.
static uint_least32_t co_wtm_recv_can(co_wtm_t *wtm, const void *buf, size_t nbytes)
Processes a generic frame containing CAN messages.
static void default_wtm_diag_ac_ind(co_wtm_t *wtm, uint_least32_t ac, void *data)
The default diagnostic indication function.
int co_wtm_send_alive(co_wtm_t *wtm)
Sends a keep-alive message from a CANopen WTM interface.
void co_wtm_get_diag_wtm_con(const co_wtm_t *wtm, co_wtm_diag_wtm_con_t **pcon, void **pdata)
Retrieves the confirmation function invoked when a WTM communication quality response is received by ...
void co_wtm_get_diag_wtm_ind(const co_wtm_t *wtm, co_wtm_diag_wtm_ind_t **pcon, void **pdata)
Retrieves the indication function invoked when a WTM communication quality reset message is received ...
int co_wtm_send_diag_ac(co_wtm_t *wtm, uint_least32_t ac)
Sends a diagnostic abort message from a CANopen WTM interface.
void co_wtm_set_diag_can_ind(co_wtm_t *wtm, co_wtm_diag_can_ind_t *con, void *data)
Sets the indication function invoked when a CAN communication quality reset message is received by a ...
co_wtm_t * co_wtm_create(void)
Creates a new CANopen Wireless Transmission Media (WTM) interface.
int co_wtm_send_diag_can_req(co_wtm_t *wtm, uint_least8_t nif)
Sends a CAN communication quality request.
void co_wtm_set_diag_ac_ind(co_wtm_t *wtm, co_wtm_diag_ac_ind_t *ind, void *data)
Sets the indication function invoked when an abort code is generated or received by a CANopen WTM int...
void co_wtm_set_recv_func(co_wtm_t *wtm, co_wtm_recv_func_t *func, void *data)
Sets the callback function invoked when a CAN frame is received by a CANopen WTM interface.
static int co_wtm_send_diag_wtm_res(co_wtm_t *wtm)
Sends a communication quality response for a WTM interface.
static int co_wtm_send_diag_can_res(co_wtm_t *wtm, uint_least8_t nif)
Sends a communication quality response for a CAN interface.
void co_wtm_set_send_func(co_wtm_t *wtm, co_wtm_send_func_t *func, void *data)
Sets the callback function used to send byte streams from a CANopen WTM interface.
void co_wtm_recv(co_wtm_t *wtm, const void *buf, size_t nbytes)
Receives and processes a byte stream with a CANopen WTM interface.
#define CO_WTM_MAX_NIF
The maximum value of a CAN/WTM interface indicator.
void co_wtm_get_diag_can_con(const co_wtm_t *wtm, co_wtm_diag_can_con_t **pcon, void **pdata)
Retrieves the confirmation function invoked when a CAN communication quality response is received by ...
void co_wtm_get_recv_func(const co_wtm_t *wtm, co_wtm_recv_func_t **pfunc, void **pdata)
Retrieves the callback function invoked when a CAN frame is received by a CANopen WTM interface.
static void co_wtm_diag_ac(co_wtm_t *wtm, uint_least32_t ac)
Invokes the diagnostic indication function.
int co_wtm_send(co_wtm_t *wtm, uint_least8_t nif, const struct can_msg *msg)
Sends a CAN frame from a CANopen WTM interface.
int co_wtm_send_diag_wtm_req(co_wtm_t *wtm, uint_least8_t nif)
Sends a WTM communication quality request.
int co_wtm_send_diag_can_rst(co_wtm_t *wtm, uint_least8_t nif)
Sends a CAN communication quality reset message.
int co_wtm_flush(co_wtm_t *wtm)
Flushes the current send buffer of a CANopen WTM interface.
void co_wtm_set_diag_can_con(co_wtm_t *wtm, co_wtm_diag_can_con_t *con, void *data)
Sets the confirmation function invoked when a CAN communication quality response is received by a CAN...
void co_wtm_get_send_func(const co_wtm_t *wtm, co_wtm_send_func_t **pfunc, void **pdata)
Retrieves the callback function used to send byte streams from a CANopen WTM interface.
int co_wtm_set_diag_can(co_wtm_t *wtm, uint_least8_t nif, uint_least8_t st, uint_least8_t err, uint_least8_t load, uint_least16_t ec, uint_least16_t foc, uint_least16_t coc)
Sets the diagnostic parameters of a CAN interface.
uint_least8_t co_wtm_get_nif(const co_wtm_t *wtm)
Returns the interface indicator of a CANopen WTM interface.
int co_wtm_set_nif(co_wtm_t *wtm, uint_least8_t nif)
Sets the interface indicator of a CANopen WTM interface.
int co_wtm_set_time(co_wtm_t *wtm, uint_least8_t nif, const struct timespec *tp)
Sets the current time of a CANopen WTM interface.
void co_wtm_set_diag_wtm_con(co_wtm_t *wtm, co_wtm_diag_wtm_con_t *con, void *data)
Sets the confirmation function invoked when a WTM communication quality response is received by a CAN...
const char * co_wtm_ac_str(uint_least32_t ac)
Returns a string describing a CANopen WTM abort code.
This header file is part of the CANopen library; it contains the Wireless Transmission Media (WTM) de...
#define CO_WTM_AC_DATA_CTL
CANopen WTM abort code: Data cannot be transferred or stored to the application because of local cont...
void co_wtm_diag_can_con_t(co_wtm_t *wtm, uint_least8_t nif, uint_least8_t st, uint_least8_t err, uint_least8_t load, uint_least16_t ec, uint_least16_t foc, uint_least16_t coc, void *data)
The type of a CANopen WTM diagnostic confirmation function, invoked when a CAN communication quality ...
#define CO_WTM_AC_DATA
CANopen WTM abort code: Data cannot be transferred or stored to the application.
void co_wtm_diag_can_ind_t(co_wtm_t *wtm, uint_least8_t nif, void *data)
The type of a CANopen WTM diagnostic indication function, invoked when a CAN communication quality re...
void co_wtm_diag_wtm_ind_t(co_wtm_t *wtm, void *data)
The type of a CANopen WTM diagnostic indication function, invoked when a WTM communication quality re...
#define CO_WTM_AC_TYPE
CANopen WTM abort code: Message type not valid or unknown.
#define CO_WTM_AC_DATA_DEV
CANopen WTM abort code: Data cannot be transferred or stored to the application because of the presen...
#define CO_WTM_AC_DIAG_CAN
CANopen WTM abort code: Diagnostic data generation for requested CAN interface not supported.
#define CO_WTM_AC_DIAG
CANopen WTM abort code: Diagnostic data generation not supported.
#define CO_WTM_AC_DIAG_WTM
CANopen WTM abort code: Diagnostic data generation for requested WTM interface not supported.
int co_wtm_send_func_t(co_wtm_t *wtm, const void *buf, size_t nbytes, void *data)
The type of a CANopen WTM send callback function, invoked when a byte stream needs to be sent.
#define CO_WTM_AC_HARDWARE
CANopen WTM abort code: Access failed due to a hardware error.
#define CO_WTM_AC_NO_DATA
CANopen WTM abort code: No data available.
#define CO_WTM_AC_IF_DOWN
CANopen WTM abort code: Requested interface disabled.
#define CO_WTM_AC_NO_IF
CANopen WTM abort code: Requested interface not implemented.
#define CO_WTM_AC_ERROR
CANopen WTM abort code: General error.
#define CO_WTM_AC_PREAMBLE
CANopen WTM abort code: Invalid generic frame preamble.
#define CO_WTM_AC_SEQ
CANopen WTM abort code: Invalid sequence counter in generic frame.
#define CO_WTM_AC_NO_MEM
CANopen WTM abort code: Out of memory.
void co_wtm_diag_ac_ind_t(co_wtm_t *wtm, uint_least32_t ac, void *data)
The type of a CANopen WTM diagnostic indication function, invoked when an abort code is generated or ...
#define CO_WTM_AC_CRC
CANopen WTM abort code: CRC error (Generic frame).
#define CO_WTM_AC_CAN
CANopen WTM abort code: CAN telegram essentials invalid.
int co_wtm_recv_func_t(co_wtm_t *wtm, uint_least8_t nif, const struct timespec *tp, const struct can_msg *msg, void *data)
The type of a CANopen WTM receive callback function, invoked when a CAN frame is received.
void co_wtm_diag_wtm_con_t(co_wtm_t *wtm, uint_least8_t nif, uint_least8_t quality, void *data)
The type of a CANopen WTM diagnostic confirmation function, invoked when a WTM communication quality ...
#define CO_WTM_AC_TIMEOUT
CANopen WTM abort code: Diagnostic protocol timed out limit reached.
#define CO_WTM_AC_FRAME
CANopen WTM abort code: General generic frame error.
#define CO_WTM_AC_PAYLOAD
CANopen WTM abort code: Payload field in generic frame invalid.
#define CO_WTM_MAX_LEN
The maximum size of a CANopen WTM generic frame (4 (header) + 255 (payload) + 2 (CRC checksum) = 261)...