Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heavily confused by candump (SocketCAN) ID filtering feature

In a nutshell, I want candump to show me ONLY frames with IDs 0x00200200 or 0x255.

So I do this:

candump can0,00200200:0,255:0

But this gives ALL frames, and each frame is shown twice. i.e. the output of:

cansend can0 256#112233

would be this:

can0      256  [3] 11 22 33
can0      256  [3] 11 22 33

Aside from the filter not behaving like I expected and passing through 0x256, the fact that it shows up twice suggests that this frames is actually matched by both filters, which makes even less sense to me. Can anyone explain why this is happening, and perhaps show me the correct way to do it?

like image 703
Erik Nyquist Avatar asked Sep 30 '15 16:09

Erik Nyquist


2 Answers

From the help of candump:

<can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)

Now, when the mask is 0, every CAN ID will match it. So the can_id has no real effect, this is why all messages pass, each required bit in the can id should be set to 1 in the mask.

Regarding the duplication problem, it probably happens because you use two filters, although I am not sure about this.

What you want to do is:

candump can0,00200200:1fffffff,255:7ff

Example (provided by OP):

enyquist:~$ candump vcan0,00200200:1fffffff,255:7ff &
[1] 7339 
enyquist:~$ cansend vcan0 002001fe#1122 
enyquist:~$ cansend vcan0 002001ff#1122 
enyquist:~$ cansend vcan0 00200200#1122
vcan0 00200200 [2] 11 22 
enyquist:~$ cansend vcan0 00200201#1122 
enyquist:~$ cansend vcan0 00200202#1122 
enyquist:~$ 
enyquist:~$ cansend vcan0 253#1122 
enyquist:~$ cansend vcan0 254#1122 
enyquist:~$ cansend vcan0 255#1122
vcan0 255 [2] 11 22 
enyquist:~$ cansend vcan0 256#1122 
enyquist:~$ cansend vcan0 257#1122 
enyquist:~$
like image 72
MByD Avatar answered Oct 21 '22 22:10

MByD


(Response to MByD, too long to fit in a comment)

OK, that almost makes sense to me. The reason I say almost is because I tried this:

candump can0,00200200:1fffffff,255:7ff

With the idea of using a 29 bit mask for the first ID, since it's a 29-bit ID, and likewise an 11 bit mask for the second ID.

However, this didn't work the way I expected either- I don't have the output in front of me and I can't remember what exactly the discrepancy was, but there was one.

You're suggesting to use a 32-bit mask - can you explain why that would work but using a mask with 29 bits set did not work? Or am I just completely misunderstanding it?

(I am away from my system for now, I will be able to test it tomorrow and will report back then)

like image 37
Erik Nyquist Avatar answered Oct 21 '22 21:10

Erik Nyquist