Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: Add filtering of incoming CAN frames #25703

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

EosBandi
Copy link
Contributor

@EosBandi EosBandi commented Dec 5, 2023

Add filters to the CAN buffer; mask is bitwise ANDed with the frame ID and compared to value. If not match, frame is not put to the receiving buffer
-- By default, no filters are added, and all frames are buffered, writing is not affected by filters
-- Maximum number of filters is 8 per buffer.
-- You can open as many buffers per driver as you want (every get_device() call creates a new buffer)

Usage : - driver:add_filter(mask, value) add a generic filted
- driver:add_DroneCAN_filter(message ID) to add filter for a DroneCan message.

Peter Hall rewrote my original version to a fully configurable, multi-buffer filter, so it is basically his code...

Use cases:

On a shared bus non-handled frames can be filtered out, making processing relevant frames easier and requiring less buffer and slower script update.
Can add script driver for composite DroneCAN devices with custom or experimental messages without the need for processing the frames that a non-script driver already handles. (Processing a single 1Hz custom message from a GPS/MAG device with maximum buffer size requires 5ms update time without filtering. A slower update or smaller buffer causes drop of messages)

Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used sizeof when I should have used ARRAY_SIZE.

libraries/AP_Scripting/AP_Scripting_CANSensor.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/AP_Scripting_CANSensor.cpp Outdated Show resolved Hide resolved
@IamPete1 IamPete1 force-pushed the Scripting_can_filtering branch from 416a3d7 to 149640d Compare December 5, 2023 14:00
@tridge
Copy link
Contributor

tridge commented Dec 6, 2023

nice idea!
I'll wait for @IamPete1 to approve, this is really his area

@IamPete1 IamPete1 removed the DevCallEU label Dec 6, 2023
@IamPete1 IamPete1 force-pushed the Scripting_can_filtering branch from 2c9ee46 to a957ca2 Compare December 6, 2023 13:18
@tridge tridge merged commit 782605e into ArduPilot:master Dec 12, 2023
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants