CAn BaudRate & Mask Calculator

Hi All,
Firstly, Great work done by the pixies.
Arduino does make it "Easy".

The Word "Arduino" should be added to the dictionary.

Anyway I was playing with Some Can work using an ESP8266 and 2 x MCP2515 controllers.

All fine and dandy, but during my ventures I generated a small HTML/javascript page to make it easy to calculate Any baudrate and also a tool to make calculating the Masks & filters a breeze. As the ESP serves up the page you can also use it to Set the config.
Say good bye to the predefined CAN Speeds and go freestyle.
It enables you to program almost any Baud rate (within tolerances) on the Fly.
That along with the Masks and Filters.

The Masks and Filters had me puzzeled for a bit and then the Penny dropped.
Not sure if it landed the right way up but this was the easy way to think of them if You too are out of small change.

SO..>

Just forget about the Masks for a moment and just look at the Filters.
Filter1 and Filter2 are grouped together and use MASK1
Filters 3,4,5,6 are also in their own group using MASK2.

So for example you want to trap for ID's 0x180 and 0x506.

Remember that for 11bit headers (what I am using mostly right now)
the first two bytes of the candata are also part of the filtering function.
Lets not care about the first two bytes at this point. Just ALL 180 & 506 message ID's
As we are not caring about the first two bytes just pack the end of our number with zeros.

So you calculate the Mask = (0x1800000 | 0x5060000) (180 'ored' 506)
we end up with a Mask of 0x05860000

Remember that you will get any packets matching the bit patterns
This MAY include other messages depending on the numbers used.
If you want exact matching use the same single filter value in both filters.

Now if you wanted to do the same but also only filter certain message headers within those ID's.
Get your data bytes and drop them into ya 'OR calculations.

so for example you want only packets starting [0x180,0xFE,0xED] and [0x506,0xBE,0xEF]
Filter1 = 0x180FEED
Filter2 = 0x506BEEF
Mask1 = (0x180FEED | 0x506BEEF)
Mask1 = 0x586FEEF.

Remember that you will get any packets matching the bit patterns
This MAY include other messages depending on the numbers.
If you want exact matching use the same single filter value in both filters.

If memory serves me right,
to test what message may also pass the filter use.
if((ANYNUMBER & MASK) == ANYNUMBER){willpass=true;}

Exactly the same applies to the 2nd Mask & filters 3-6.

so for example , set the filters with the ID + the two start bytes.
? = any, don't care, use 0 in calc
@ = any, 0 to F, use F in calc

Filter3 = 0x46c4802
Filter4 = 0x683?5??
Filter5 = 0x2b08103
Filter6 = 0x188371?
Mask2 = (0x46c4802 | 0x6830500 | 0x2b08103 | 0x1883710)
Mask2 = 0x07FFFF13.

Remember:
if you don't want the filter to include the first two data bytes on 11bit messages then set the lower 8 or 16bits of the MASK to 0.

This is by no means a full explanation, it may not even be correct, but happy to discuss it further if needed.

No doubt I shall edit this a little as we go.

Hv.