Expand description

UAVCAN acceptance filter configuration

This library implements the automatic hardware acceptance filter configuration described in section of the UAVCAN specification.

To reduce the amount of CPU time spent processing messages, a UAVCAN 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 = [
// 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


A generic mask-based filter for extended CAN IDs


Combines a slice of ideal filters down to max_filters filters that will accept a superset of the message IDs of the ideal filters