CAN bus: Difference between revisions

 
(3 intermediate revisions by the same user not shown)
Line 88: Line 88:


===Error States===
===Error States===
Each ECU maintains an RX Error counter and TX Error Counter (REC/TEC), initialized to 0. Successful operations reduce the appropriate counter by 1, though never below 0. Errors increase the counters (usually TEC by 8, REc by 1). Depending on the values of these counters, each ECU is in one of three error states:
Each ECU maintains an RX Error counter and TX Error Counter (REC/TEC), initialized to 0. Successful operations reduce the appropriate counter by 1, though never below 0. Errors increase the counters (usually TEC by 8, REC by 1). Depending on the values of these counters, each ECU is in one of three error states:
* Error-Active: Both counters are less than 128. The ECU will respond to errors with an Active Error Frame.
* Error-Active: Both counters are less than 128. The ECU will respond to errors with an Active Error Frame.
* Error-Passive: One or both counters are greater than 127. The ECU will respond to errors with (network-transparent) Passive Error Frames.
* Error-Passive: One or both counters are greater than 127. The ECU will respond to errors with (network-transparent) Passive Error Frames.
Line 119: Line 119:
** Also simple timer-based interface for cyclic RX with failure notification
** Also simple timer-based interface for cyclic RX with failure notification


===iproute===
===[[iproute]]===
SocketCAN devices, including virtual interfaces (<tt>vcanX</tt>), are configured with the standard <tt>iproute</tt> tool.
SocketCAN devices, including virtual interfaces (<tt>vcanX</tt>), are configured with the standard <tt>iproute</tt> tool.
* Get statistics: <tt>ip -details -statistics link show canX</tt>
* Get statistics: <tt>ip -details -statistics link show canX</tt>
** Alternatively, look at <tt>/proc/net/can/stats</tt>
** Alternatively, look at <tt>/proc/net/can/stats</tt>
Options for the device include:
Options for the device include:
* <tt>restart-ms</tt>: automatic restart time in milliseconds in the event of bus-off state
* <tt>restart-ms</tt>: automatic restart time in milliseconds in the event of bus-off state (default: disabled)
** <tt>restart</tt> can be used by itself for one-time bus recovery
** <tt>restart</tt> can be used by itself for one-time bus recovery
** A restart will send an error frame
** A restart will send an error frame
* <tt>one-shot</tt>: don't attempt to retransmit when we don't see an ACK
* <tt>one-shot</tt>: don't attempt to retransmit when we don't see an ACK (default: disabled)
** Note: when sniffing a <b>non-virtual</b> CAN interface, you must either (a) see an ACK -- requiring a connected device, or (b) be in one-shot mode, or you will not see your transmitted frames
** Note: when sniffing a <b>non-virtual</b> CAN interface, you must either (a) see an ACK -- requiring a connected device, or (b) be in one-shot mode, or you will not see your transmitted frames
* <tt>bitrate</tt>: bits per second, i.e. "125000".
* <tt>bitrate</tt>: bits per second, i.e. "125000".
Line 144: Line 144:
The tools above all have ISO-TP variants in the [https://github.com/hartkopp/can-isotp can-isotp] project, replacing "can" with "isotp".
The tools above all have ISO-TP variants in the [https://github.com/hartkopp/can-isotp can-isotp] project, replacing "can" with "isotp".


===non-socketcan===
===Non-SocketCAN===
* Can4Linux -- avoid
* Can4Linux -- avoid
* Lincan -- best of a bad lot, might have lower latency than SocketCAN
* Lincan -- best of a bad lot, might have lower latency than SocketCAN