-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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 frames #25700
Conversation
// Check if frame matches any filters | ||
bool find = false; | ||
for (int i=0;i<MAX_FILTERS;i++) { | ||
if (filter_mask[i] == UINT32_MAX) { | ||
break; | ||
} | ||
if ((frame.id & filter_mask[i]) == filter_value[i]) { | ||
find = true; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be down one level in the handle_frame
method before we do buffer.push(frame);
. Here it will filter everything so you could not have two different sets of filters on the same bus.
uint32_t filter_mask[MAX_FILTERS]; | ||
uint32_t filter_value[MAX_FILTERS]; | ||
|
||
void add_filter(uint32_t mask, uint32_t value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should return false if there are no more filters left.
filter_mask[i] = UINT32_MAX; | ||
filter_value[i] = UINT32_MAX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely the default value would be zeros? Anything & 0 == 0, so it would pass everything?
Might also want a way to clear filters, although I guess you could just delete the object in the script and get a new one. |
Add filters to the CAN buffer; mask is bitwise ANDed with the frame ID and compared to value if not match frame is not buffered
-- By default, no filters are added, and all frames are buffered, writing is not affected by filters
-- Maximum number of filters is 8
Usage : driver:add_filter(mask, value)
Why?