4 releases
0.2.2 | Oct 18, 2022 |
---|---|
0.2.1 | Apr 12, 2022 |
0.2.0 | Oct 31, 2021 |
0.1.0 | Jul 11, 2021 |
#2194 in Embedded development
51 downloads per month
Used in 5 crates
(4 directly)
17KB
327 lines
Cyphal acceptance filter configuration
This library implements the automatic hardware acceptance filter configuration described in section 4.2.4.4 of the Cyphal specification.
To reduce the amount of CPU time spent processing messages, a Cyphal device can use hardware acceptance filters to ignore CAN messages that it is not interested in. When the application is interested in more message IDs than the number of filters that the hardware supports, this library can find a quasi-optimal set of filters that accepts all interesting message IDs and the minimum number of non-interesting message IDs.
Basic operation
- Find the set of message IDs the application is interested in, based on the topics, requests, and responses it wants to receive
- For each interesting message ID, create a filter that matches exactly that ID. Optimize those filters down to the number of filters the hardware supports:
use canadensis_filter_config::{optimize, Filter};
let interesting_message_ids = [0x107d552a, 0x11733775, 0x136b957b, 0x126bbdaa, 0x1073373b];
let mut ideal_filters = [
Filter::exact_match(interesting_message_ids[0]),
Filter::exact_match(interesting_message_ids[1]),
Filter::exact_match(interesting_message_ids[2]),
Filter::exact_match(interesting_message_ids[3]),
Filter::exact_match(interesting_message_ids[4]),
];
// Using an imaginary CAN peripheral that supports only 2 receive filters
let max_hardware_filters = 2;
let optimized_filters = optimize(&mut ideal_filters, max_hardware_filters);
assert_eq!(optimized_filters.len(), 2);
// Each interesting message ID will be accepted by at least one of the optimized filters
for &id in interesting_message_ids.iter() {
assert!(optimized_filters.iter().any(|filter| filter.accepts(id)));
}
- Apply the resulting filters to the CAN hardware