libautomotive/
lib.rs

1//! # libautomotive
2//!
3//! `libautomotive` is a comprehensive Rust library for automotive protocol implementations,
4//! following the OSI layer model for clear separation of concerns. It provides support for
5//! various automotive protocols including CAN, CAN-FD, ISO-TP, J1939, UDS, and OBD-II.
6//!
7//! ## Architecture
8//!
9//! The library is organized according to the OSI layer model:
10//!
11//! - Physical Layer: CAN and CAN-FD implementations
12//! - Data Link Layer: Raw CAN frame handling
13//! - Network Layer: J1939 protocol implementation
14//! - Transport Layer: ISO-TP (ISO 15765-2) implementation
15//! - Application Layer: UDS (ISO 14229) and OBD-II implementations
16//!
17//! ## Features
18//!
19//! - Complete automotive protocol stack
20//! - Modular and extensible design
21//! - High-performance implementations
22//! - Strong type safety and error handling
23//! - Easy-to-use abstractions
24//!
25//! ## Example
26//!
27//! ```text
28//! # Complete usage example (conceptual, not actual code)
29//! use libautomotive::physical::can;
30//! use libautomotive::transport::isotp;
31//! use libautomotive::application::uds;
32//!
33//! # 1. Set up physical layer (CAN)
34//! let can_config = can::CustomConfig {
35//!     bitrate: 500_000,
36//!     sample_point: 0.75
37//! };
38//! let mut can = can::CustomInterface::new(can_config);
39//! can.open();
40//!
41//! # 2. Set up transport layer (ISO-TP)
42//! let isotp_config = isotp::CustomConfig {
43//!     tx_id: 0x7E0,
44//!     rx_id: 0x7E8,
45//!     block_size: 8,
46//!     st_min: 10
47//! };
48//! let mut isotp = isotp::CustomInterface::new_with_can(isotp_config, can);
49//! isotp.open();
50//!
51//! # 3. Set up application layer (UDS)
52//! let uds_config = uds::CustomConfig {
53//!     timeout_ms: 1000,
54//!     p2_timeout_ms: 5000
55//! };
56//! let mut uds = uds::CustomInterface::new_with_isotp(uds_config, isotp);
57//! uds.open();
58//!
59//! # 4. Use UDS services
60//! uds.change_session(uds::SESSION_EXTENDED);
61//! let vin = uds.read_data_by_id(0xF190);  // Read Vehicle Identification Number
62//! ```
63//!
64//! ## Credits and Acknowledgments
65//!
66//! This library draws inspiration from and acknowledges the following open-source projects:
67//!
68//! - [esp32-isotp-ble-bridge](https://github.com/bri3d/esp32-isotp-ble-bridge) - ESP32-IDF based BLE<->ISO-TP bridge
69//! - [Open-SAE-J1939](https://github.com/DanielMartensson/Open-SAE-J1939) - Open source SAE J1939 implementation
70//! - [uds-c](https://github.com/openxc/uds-c) - Unified Diagnostic Services (UDS) C library
71//! - [obdii](https://github.com/ejvaughan/obdii) - OBD-II diagnostic protocol implementation
72//! - [canis-can-sdk](https://github.com/kentindell/canis-can-sdk) - CAN protocol stack implementation
73//! - [AgIsoStack++](https://github.com/Open-Agriculture/AgIsoStack-plus-plus) - Open-source C++ ISOBUS library
74//! - [open-LIN-c](https://github.com/open-LIN/open-LIN-c) - Implementation of Local Interconnect Network in C
75//! - [doip-library](https://github.com/doip/doip-library) - Diagnostic over IP (DoIP) protocol implementation
76//!
77//! These projects have provided valuable insights and reference implementations for various
78//! automotive protocols. We are grateful to their authors and contributors for making their
79//! work available to the community.
80
81// OSI Layer modules
82/// Application layer protocols including UDS and OBD-II
83pub mod application;
84/// Data link layer handling raw CAN frames
85pub mod data_link; // Raw CAN frame handling
86/// Network layer implementing J1939 protocol
87pub mod network; // J1939 implementation
88/// Physical layer implementations for CAN and CAN-FD
89pub mod physical; // CAN, CANFD implementations
90/// Transport layer implementing ISO-TP (ISO 15765-2)
91pub mod transport; // ISO-TP implementation // UDS and OBD-II implementations
92
93// Re-exports for convenience
94pub use application::{obdii, uds};
95pub use network::j1939;
96pub use physical::{can, canfd};
97pub use transport::isotp;
98
99// Common types and traits
100/// Common error types and error handling functionality
101pub mod error;
102/// Common types used across the library
103pub mod types;
104
105// Version information
106/// Current version of the library
107pub const VERSION: &str = env!("CARGO_PKG_VERSION");
108
109#[cfg(test)]
110mod tests {
111    use super::*;
112
113    #[test]
114    fn version_is_valid() {
115        assert!(!VERSION.is_empty());
116    }
117}