#cyphal #uavcan #uav #can

no-std bin+lib canadensis_filter_config

Automatic receive filter configuration for Cyphal

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

Download history 16/week @ 2024-03-24 36/week @ 2024-03-31 13/week @ 2024-04-07 32/week @ 2024-04-14 22/week @ 2024-04-21 6/week @ 2024-04-28 8/week @ 2024-05-05 8/week @ 2024-05-12 12/week @ 2024-05-19 5/week @ 2024-05-26 10/week @ 2024-06-02 11/week @ 2024-06-09 17/week @ 2024-06-16 22/week @ 2024-06-23 3/week @ 2024-06-30 7/week @ 2024-07-07

51 downloads per month
Used in 5 crates (4 directly)

MIT/Apache

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

  1. Find the set of message IDs the application is interested in, based on the topics, requests, and responses it wants to receive
  2. 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)));
}
  1. Apply the resulting filters to the CAN hardware

No runtime deps