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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Modbus RTU simulation module.
//!
//! This module provides Modbus RTU (Remote Terminal Unit) protocol simulation,
//! including:
//!
//! - **RTU framing**: CRC-16 calculation and frame encoding/decoding
//! - **Virtual serial ports**: PTY-based serial port simulation (Unix)
//! - **Timing simulation**: Baud rate and inter-character delays
//! - **Transport abstraction**: Unified interface for serial and other transports
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │ ModbusRtuServer │
//! │ ┌──────────────────┐ ┌────────────────┐ │
//! │ │ TransportManager │──│ HandlerRegistry│ │
//! │ └────────┬─────────┘ └────────────────┘ │
//! │ │ │
//! │ ┌────────┴─────────────────────────────────┐ │
//! │ │ Transport Trait │ │
//! │ │ VirtualSerial │ TcpBridge │ Custom │ │
//! │ └──────────────────────────────────────────┘ │
//! │ │ │
//! │ ┌───────────────┴───────────────────┐ │
//! │ │ RtuCodec │ │
//! │ │ Frame Detection │ CRC Validation │ │
//! │ └────────────────────────────────────┘ │
//! └─────────────────────────────────────────────────────────────┘
//! ```
//!
//! # RTU Frame Format
//!
//! ```text
//! ┌──────────┬───────────────┬─────────────┬──────────┐
//! │ Unit ID │ Function Code │ Data │ CRC-16 │
//! │ (1 byte) │ (1 byte) │ (N bytes) │ (2 bytes)│
//! └──────────┴───────────────┴─────────────┴──────────┘
//! ```
//!
//! # Timing Requirements
//!
//! According to Modbus specification:
//! - **Inter-frame gap**: 3.5 character times (silence between frames)
//! - **Inter-character gap**: 1.5 character times max (within a frame)
//!
//! For example, at 9600 baud (11 bits per character):
//! - Character time ≈ 1.145 ms
//! - Inter-frame gap ≈ 4 ms
//! - Max inter-character gap ≈ 1.7 ms
//!
//! # Example
//!
//! ```rust,no_run
//! use mabi_modbus::rtu::{RtuServerConfig, ModbusRtuServer};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Configure RTU server
//! let server_config = RtuServerConfig::default()
//! .with_unit_ids(vec![1, 2, 3])
//! .with_broadcast(true);
//!
//! let server = ModbusRtuServer::new(server_config);
//! // server.run().await?; // Would run the server
//! Ok(())
//! }
//! ```
// Re-exports
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;