4 个版本
0.2.2 | 2022年10月18日 |
---|---|
0.2.1 | 2022年4月12日 |
0.2.0 | 2021年10月31日 |
0.1.0 | 2021年7月11日 |
#2194 在 嵌入式开发 中
每月 51 次下载
在 5 个crate中(4 个直接) 使用
17KB
327 行
Cyphal 接受过滤器配置
该库实现了Cyphal规范第4.2.4.4节中描述的自动硬件接受过滤器配置。
为了减少处理消息所花费的CPU时间,Cyphal设备可以使用硬件接受过滤器来忽略它不感兴趣的消息。当应用程序感兴趣的消息ID数量超过硬件支持的过滤器数量时,该库可以找到一组近似最优的过滤器,这些过滤器接受所有感兴趣的消息ID和尽可能少的不感兴趣的消息ID。
基本操作
- 根据应用程序想要接收的主题、请求和响应,找到感兴趣的消息ID集合
- 对于每个感兴趣的消息ID,创建一个与该ID完全匹配的过滤器。将这些过滤器优化到硬件支持的过滤器数量
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)));
}
- 将生成的过滤器应用于CAN硬件