CAN bus error status
Kheirlb opened this issue · 4 comments
Is there a way for me to check bus status? ERROR_ACTIVE vs PASSIVE?
We didn't implement getting the link state yet, but you can just listed to error frames (check 'err' variable of each frame and than interpret the payload as defined by SocketCAN).
Nevertheless would be cool to have an API to retrieve the current bus state.
@sebi2k1 Do you have an example on how to listen for the error state? My can controller got into the ERROR_ACTIVE
state and I'm trying handle this my application.
I don't have a hardware here with me to play around with, so I can give only some general advise.
Default state of your controller is error active, where it detects and reports error. If it detects to many issues it enters passive state (still transmit) and finally (depending on the error) bus off state (no rx/tx anymore).
Everytime the controller detects an error it raises the event to the host. In SocketCAN this is translated into an error frame (check if received frame has an 'err' member), if yes you can evaluate the exact error state by looking into the bytes of the frame. The mapping is defined in error.h. The first byte for example tells you the current bus state of the controller.
By default we enabled all error types, but you can change that via setErrorFilters(), parameter is a bit mask of the error class (see error.h again).
I found a nice illustration of the behaviour of a CAN controller online.