11

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?

Erik Nyquist
  • 1,267
  • 2
  • 12
  • 26
  • pre-empting as I suspect someone will post this.... http://www.mailbrowse.com/linux-can/3494.html This unfortunately did not help me much.... the explanations offered are pretty scant. – Erik Nyquist Sep 30 '15 at 16:10

2 Answers2

11

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:~$
MByD
  • 135,866
  • 28
  • 264
  • 277
2

(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)

Erik Nyquist
  • 1,267
  • 2
  • 12
  • 26
  • hi, the 32bit mask is a mistake, sorry for that :) anyway, re- the filtering itself - what you posted won't work, and I'd like to see what was the problem with my suggestion, please update. Also, please comment to me next time as well, so I will be notified. – MByD Sep 30 '15 at 18:10
  • well, I don't know if it is a problem or not- your suggestion might well work. Hang on, let me set up vcan on my linux box and I'll get back to you once I've tested it. – Erik Nyquist Sep 30 '15 at 18:29
  • `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:~$ – Erik Nyquist Sep 30 '15 at 18:56
  • Sorry... I'll see if I can figure out how to show code samples in a comment. Anyway that was just showing that it does work as expected using 00200200:1fffffff,255:755. If you change you answer to use a 29 bit mask then I'll mark as answered. thanks for the help! – Erik Nyquist Sep 30 '15 at 18:58
  • Glad to hear :) I changed my answer after you previous comment. And no need to repost the log, already parsed it myself :P – MByD Sep 30 '15 at 19:00
  • could you post the log in your answer, in a code block? already marked as answered, but that would be a nice extra anyway :) – Erik Nyquist Sep 30 '15 at 19:09
  • also, I'm not exactly sure why I thought 00200200:1fffffff,255:7ff didn't work the first time I tried it, maybe I typed one too many or two few f's by mistake. – Erik Nyquist Sep 30 '15 at 19:17