Closed jeremy-daily closed 4 years ago
There are no reprocussions of using it in public that I see, it was just never intended to use it the way you are using it. The library managed it itself. However, there is one thing that may not work, which is enhanced filtering, but with single ID and the public function you'll be fine without enhancement anyways (which is for multiID input only)
Thank you. I added an example and submitted a PR.
I worked on multiple ID and distribution for the work you provided here. You can try new functions:
bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t mask);
bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t mask);
bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t mask);
bool setMBUserFilter(FLEXCAN_MAILBOX mb_num, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask);
bool setFIFOUserFilter(uint8_t filter, uint32_t id1, uint32_t mask, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE);
bool setFIFOUserFilter(uint8_t filter, uint32_t id1, uint32_t id2, uint32_t mask, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE);
bool setFIFOUserFilter(uint8_t filter, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t mask, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE);
bool setFIFOUserFilter(uint8_t filter, uint32_t id1, uint32_t id2, uint32_t id3, uint32_t id4, uint32_t mask, const FLEXCAN_IDE &ide, const FLEXCAN_IDE &remote = NONE);
There will be a patch called update7.zip on the forum thread, use that to override the github copy, I don't plan to update the github version until latest build is stable. Theres been a few updates on it :)
This is how I set your 3 IDs to a mailbox:
Can0.setMBUserFilter(MB10, 0x0B, 0x03, 0x0, 0xFF);
You can set up to 4 IDs, using 1ID theres obviously no bleed thru frames, however, with multiple IDs, no worries, after you set the mailbox, run Can0.enhanceFilter(MB10);, and the sub filter will only allow the ones you requested from going to callback.
Same can be done for FIFO, REJECT_ALL the filters, and set them accordingly.
Hello, I have a need to filter based on SAE J1939 source address. The source address is located in the least significant byte of the extended ID. For example, a message id of XXXXX0B would have a source address of 11 and correspond to a brake controller. However, the current filtering setup is hard to mask off the last byte and apply a filter. To remedy this, I suggest moving the function declaration
void setMBFilterProcessing(FLEXCAN_MAILBOX mb_num, uint32_t filter_id, uint32_t calculated_mask);
from the private section of the FlexCAN_T4.h file to the public section. There were two locations for this line. This should enable an external program to call the function.After making this change in the source code header file, I modified the CAN2.0_example_FIFO_with_interrupts.ino sketch to look like this:
Running the example on a fuzzed network, I can get an output on the Arduino Serial Monitor that looks like this:
The input for this case was a fuzzer using Linux SocketCAN running the command
cangen can1 -e -v -i -g 0
, which floods the bus with random extended ID messages. The filter worked and only captured messages with source addresses of 0, 3, and 11 were processed.The ability to filter based on arbitrary masks would be very helpful in the J1939 world.
While this seems to work, are there any checks that I'm missing on the calculated_mask? What's the risk of declaring that function as public?