1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Message filtering module (FR-005 to FR-009)
//!
//! This module provides message filtering functionality for CAN messages,
//! supporting both hardware and software filtering.
//!
//! # Overview
//!
//! The filtering system allows you to selectively receive CAN messages based on
//! their IDs. This is useful for reducing CPU load and focusing on relevant messages.
//!
//! # Filter Types
//!
//! - [`IdFilter`]: Match messages by exact ID or ID with mask
//! - [`RangeFilter`]: Match messages within an ID range
//! - [`FilterChain`]: Combine multiple filters with OR logic
//!
//! # Hardware vs Software Filtering
//!
//! Filters can be marked as hardware filters using the [`MessageFilter::is_hardware()`]
//! method. Hardware filters are applied by the CAN controller itself, reducing CPU load.
//! When hardware filter slots are exhausted, filters automatically fall back to software
//! filtering.
//!
//! # Example
//!
//! ```rust
//! use canlink_hal::filter::{FilterChain, IdFilter, RangeFilter, MessageFilter};
//! use canlink_hal::CanMessage;
//!
//! // Create a filter chain
//! let mut chain = FilterChain::new(8); // 8 hardware filter slots
//!
//! // Add filters (OR logic - message passes if ANY filter matches)
//! chain.add_filter(Box::new(IdFilter::new(0x123)));
//! chain.add_filter(Box::new(RangeFilter::new(0x200, 0x2FF)));
//!
//! // Test messages
//! let msg1 = CanMessage::new_standard(0x123, &[1, 2, 3]).unwrap();
//! let msg2 = CanMessage::new_standard(0x250, &[4, 5, 6]).unwrap();
//! let msg3 = CanMessage::new_standard(0x400, &[7, 8, 9]).unwrap();
//!
//! assert!(chain.matches(&msg1)); // Matches IdFilter
//! assert!(chain.matches(&msg2)); // Matches RangeFilter
//! assert!(!chain.matches(&msg3)); // No match
//! ```
//!
//! # Performance
//!
//! Software filtering is highly optimized with latency < 10 μs per message
//! (typically 3-20 ns). See SC-003 in the specification for details.
pub use FilterChain;
pub use FilterConfig;
pub use IdFilter;
pub use RangeFilter;
pub use MessageFilter;