Skip to main content

canlink_hal/
lib.rs

1//! # `CANLink` HAL
2//! <a id="en"></a>
3//! [English](#en) | [中文](#zh)
4//!
5//! `CANLink` HAL is the core hardware abstraction layer of `CANLink`. It defines the
6//! `CanBackend` trait, message types, and the backend registry used by real
7//! hardware backends.
8//!
9//! ## Quick Start
10//!
11//! ```rust,ignore
12//! use canlink_hal::{BackendConfig, CanBackend, CanMessage};
13//! use canlink_tscan::TSCanBackend;
14//!
15//! # fn main() -> Result<(), canlink_hal::CanError> {
16//! let mut backend = TSCanBackend::new();
17//! let config = BackendConfig::new("tscan");
18//!
19//! backend.initialize(&config)?;
20//! backend.open_channel(0)?;
21//!
22//! let msg = CanMessage::new_standard(0x123, &[1, 2, 3, 4])?;
23//! backend.send_message(&msg)?;
24//!
25//! backend.close_channel(0)?;
26//! backend.close()?;
27//! # Ok(())
28//! # }
29//! ```
30//!
31//! ## Scope
32//!
33//! This crate is hardware-agnostic. The only real-hardware backend currently
34//! landed in this repository is `canlink-tscan` (`LibTSCAN`).
35//!
36//! ## Related Crates
37//!
38//! - [`canlink-tscan-sys`](https://docs.rs/canlink-tscan-sys) - `LibTSCAN` FFI
39//! - [`canlink-tscan`](https://docs.rs/canlink-tscan) - `LibTSCAN` backend
40//! - [`canlink-cli`](https://docs.rs/canlink-cli) - CLI tool
41//!
42//! <a id="zh"></a>
43//! [中文](#zh) | [English](#en)
44//!
45//! `CANLink` HAL 是 `CANLink` 的核心硬件抽象层,定义 `CanBackend` trait、消息类型以及后端注册表。
46//!
47//! ## 快速开始
48//!
49//! ```rust,ignore
50//! use canlink_hal::{BackendConfig, CanBackend, CanMessage};
51//! use canlink_tscan::TSCanBackend;
52//!
53//! # fn main() -> Result<(), canlink_hal::CanError> {
54//! let mut backend = TSCanBackend::new();
55//! let config = BackendConfig::new("tscan");
56//!
57//! backend.initialize(&config)?;
58//! backend.open_channel(0)?;
59//!
60//! let msg = CanMessage::new_standard(0x123, &[1, 2, 3, 4])?;
61//! backend.send_message(&msg)?;
62//!
63//! backend.close_channel(0)?;
64//! backend.close()?;
65//! # Ok(())
66//! # }
67//! ```
68//!
69//! ## 定位
70//!
71//! 本 crate 与具体硬件无关。当前仓库唯一已落地的真实硬件后端是 `canlink-tscan`(`LibTSCAN`)。
72//!
73//! ## 相关包
74//!
75//! - [`canlink-tscan-sys`](https://docs.rs/canlink-tscan-sys) - `LibTSCAN` FFI 绑定
76//! - [`canlink-tscan`](https://docs.rs/canlink-tscan) - `LibTSCAN` 后端
77//! - [`canlink-cli`](https://docs.rs/canlink-cli) - 命令行工具
78//!
79#![deny(missing_docs)]
80#![warn(clippy::all)]
81#![warn(clippy::pedantic)]
82#![allow(clippy::module_name_repetitions)]
83
84// Core modules
85pub mod backend;
86pub mod capability;
87pub mod config;
88pub mod error;
89pub mod message;
90pub mod registry;
91pub mod state;
92pub mod version;
93
94// New modules introduced in v0.2.0 (003-async-and-filtering)
95pub mod filter;
96pub mod monitor;
97pub mod queue;
98
99// Conditional modules
100#[cfg(feature = "tracing")]
101pub mod logging;
102
103#[cfg(feature = "hot-reload")]
104pub mod hot_reload;
105
106// Periodic message sending (004 spec FR-001 to FR-006)
107#[cfg(feature = "periodic")]
108pub mod periodic;
109
110// ISO-TP protocol support (004 spec FR-007 to FR-019)
111#[cfg(feature = "isotp")]
112pub mod isotp;
113
114// Resource management documentation
115pub mod resource;
116
117// Re-exports
118#[cfg(feature = "async")]
119pub use backend::CanBackendAsync;
120pub use backend::{
121    retry_initialize, switch_backend, BackendFactory, CanBackend, MessageRateMonitor,
122};
123pub use capability::{HardwareCapability, TimestampPrecision};
124pub use config::{BackendConfig, CanlinkConfig};
125pub use error::{BusErrorKind, CanError, CanResult};
126pub use error::{FilterError, FilterResult};
127pub use error::{MonitorError, MonitorResult};
128pub use error::{QueueError, QueueResult};
129pub use message::{CanId, CanMessage, MessageFlags, Timestamp};
130pub use registry::{BackendInfo, BackendRegistry};
131pub use state::BackendState;
132pub use version::BackendVersion;
133
134// Periodic message sending re-exports (004 spec)
135#[cfg(feature = "periodic")]
136pub use periodic::{
137    run_scheduler, PeriodicMessage, PeriodicScheduler, PeriodicStats, SchedulerCommand,
138};
139
140// ISO-TP protocol re-exports (004 spec)
141#[cfg(feature = "isotp")]
142pub use isotp::{
143    AddressingMode, FlowStatus, FrameSize, IsoTpConfig, IsoTpConfigBuilder, IsoTpError, IsoTpFrame,
144    IsoTpState, RxState, StMin, TxState,
145};