2

I would like to detect the number of frame dropped on a CAN socket implemented using linux socketCAN. When the command ip -details -statistics link show can0 is given on terminal I can get the number of dropped frame in the dropped column for both Rx and Tx.

2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can  promiscuity 0 
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
  bitrate 250000 sample-point 0.866 
  tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
  flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
  clock 30000000
  re-started bus-errors arbit-lost error-warn error-pass bus-off
  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
RX: bytes  packets  errors  dropped overrun mcast   
1860       356      0       0       0       0       
TX: bytes  packets  errors  dropped carrier collsns 
13789      1843     0       0       0       0       

How can I get/detect the dropped number for Rx and Tx using C code?. Thanks for the time and answer in advance.

curosity
  • 19
  • 5
  • What exactly is "dropped frames"? CAN is CSMA/CA not CSMA/CD. You can't lose frames. You can however get error frames. See https://www.kvaser.com/about-can/the-can-protocol/can-error-handling/ – Lundin Mar 01 '21 at 11:24
  • The dropped frame is observed when there are too many interrupts in a system. I think it is more related to socket rather than CAN frame error. The `candump` command can already detect such dropped frames. – curosity Mar 01 '21 at 11:50
  • Did you `strace` that `ip` command to see where it's getting its data from? – Toby Speight Mar 01 '21 at 12:05

0 Answers0