CANopenNode
CAN errors & Log

Files

file  CO_error.h
 CANopenNode Linux socketCAN Error handling.
 

Data Structures

struct  CO_CANinterfaceErrorhandler_t
 socketCAN interface error handling More...
 

Macros

#define CO_CANerror_NOACK_MAX   16
 This is how many NO-ACKs need to be received in a row to assume that no other nodes are connected to a bus and therefore are assuming listen-only.
 
#define CO_CANerror_LISTEN_ONLY   10
 This is how long we are going to block transmission if listen-only mode is active. More...
 

Enumerations

enum  CO_CANinterfaceState_t { CO_INTERFACE_ACTIVE, CO_INTERFACE_LISTEN_ONLY, CO_INTERFACE_BUS_OFF }
 driver interface state More...
 

Functions

void log_printf (int priority, const char *format,...)
 Message logging function. More...
 
void CO_CANerror_init (CO_CANinterfaceErrorhandler_t *CANerrorhandler, int fd, const char *ifname)
 Initialize CAN error handler. More...
 
void CO_CANerror_disable (CO_CANinterfaceErrorhandler_t *CANerrorhandler)
 Reset CAN error handler. More...
 
void CO_CANerror_rxMsg (CO_CANinterfaceErrorhandler_t *CANerrorhandler)
 Message received event. More...
 
CO_CANinterfaceState_t CO_CANerror_txMsg (CO_CANinterfaceErrorhandler_t *CANerrorhandler)
 Check if interface is ready for message transmission. More...
 
CO_CANinterfaceState_t CO_CANerror_rxMsgError (CO_CANinterfaceErrorhandler_t *CANerrorhandler, const struct can_frame *msg)
 Error message received event. More...
 

Detailed Description

CANopen Errors and System message log

Macro Definition Documentation

◆ CO_CANerror_LISTEN_ONLY

#define CO_CANerror_LISTEN_ONLY   10

This is how long we are going to block transmission if listen-only mode is active.

Time is in seconds.

Enumeration Type Documentation

◆ CO_CANinterfaceState_t

driver interface state

CAN hardware can be in the followning states:

  • error active (OK)
  • error passive (Can't generate error flags)
  • bus off (no influence on bus)
Enumerator
CO_INTERFACE_ACTIVE 

CAN error passive/active.

CO_INTERFACE_LISTEN_ONLY 

CAN error passive/active, but currently no other device on bus.

CO_INTERFACE_BUS_OFF 

CAN bus off.

Function Documentation

◆ log_printf()

void log_printf ( int  priority,
const char *  format,
  ... 
)

Message logging function.

Function must be defined by application. It should record log message to some place, for example syslog() call in Linux or logging functionality in CANopen gateway Gateway ASCII mapping.

By default system stores messages in /var/log/syslog file. Log can optionally be configured before, for example to filter out less critical errors than LOG_NOTICE, specify program name, print also process PID and print also to standard error, set 'user' type of program, use:

setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("exampleprog", LOG_PID | LOG_PERROR, LOG_USER);
Parameters
priorityone of LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG
formatformat string as in printf

◆ CO_CANerror_init()

void CO_CANerror_init ( CO_CANinterfaceErrorhandler_t CANerrorhandler,
int  fd,
const char *  ifname 
)

Initialize CAN error handler.

We need one error handler per interface

Parameters
CANerrorhandlerThis object will be initialized.
fdinterface file descriptor
ifnameinterface name as string

◆ CO_CANerror_disable()

void CO_CANerror_disable ( CO_CANinterfaceErrorhandler_t CANerrorhandler)

Reset CAN error handler.

Parameters
CANerrorhandlerCAN error object.

◆ CO_CANerror_rxMsg()

void CO_CANerror_rxMsg ( CO_CANinterfaceErrorhandler_t CANerrorhandler)

Message received event.

When a message is received at least one other CAN module is connected. Function clears listenOnly and noackCounter error flags.

Parameters
CANerrorhandlerCAN error object.

◆ CO_CANerror_txMsg()

CO_CANinterfaceState_t CO_CANerror_txMsg ( CO_CANinterfaceErrorhandler_t CANerrorhandler)

Check if interface is ready for message transmission.

Message mustn't be transmitted if not ready.

Parameters
CANerrorhandlerCAN error object.
Returns
CO_INTERFACE_ACTIVE message transmission ready

◆ CO_CANerror_rxMsgError()

CO_CANinterfaceState_t CO_CANerror_rxMsgError ( CO_CANinterfaceErrorhandler_t CANerrorhandler,
const struct can_frame *  msg 
)

Error message received event.

This handles all received error messages.

Parameters
CANerrorhandlerCAN error object.
msgreceived error message
Returns
CO_CANinterfaceState_t