feat(settings): add modbus and relay configuration structs
Add ModbusSettings with host, port, slave_id, and timeout_secs fields. Add RelaySettings with label_max_length field. Integrate both into Settings struct and load from settings/base.yaml with test Modbus TCP configuration. Ref: T003 (specs/001-modbus-relay-control)
This commit is contained in:
@@ -6,3 +6,12 @@ rate_limit:
|
||||
enabled: true
|
||||
burst_size: 10
|
||||
per_seconds: 60
|
||||
|
||||
modbus:
|
||||
host: "192.168.0.200"
|
||||
port: 502
|
||||
slave_id: 0
|
||||
timeout_secs: 5
|
||||
|
||||
relay:
|
||||
label_max_length: 8
|
||||
|
||||
@@ -22,16 +22,16 @@
|
||||
- **Test**: Module declarations compile without errors
|
||||
- **Complexity**: Low | **Uncertainty**: Low
|
||||
|
||||
- [ ] **T003** [P] [Setup] [TDD] Update settings.rs with Modbus configuration
|
||||
- [x] **T003** [P] [Setup] [TDD] Update settings.rs with Modbus configuration
|
||||
- Add ModbusSettings struct with `host`, `port`, `slave_id`, `timeout_secs` fields
|
||||
- Add RelaySettings struct with `label_max_length` field
|
||||
- Update Settings struct to include modbus and relay fields
|
||||
- **Test**: Settings loads from settings/base.yaml with test Modbus config
|
||||
- **Complexity**: Low | **Uncertainty**: Low
|
||||
|
||||
- [ ] **T004** [P] [Setup] [TDD] Create settings/base.yaml with Modbus defaults
|
||||
- Add modbus section: host: "192.168.0.200", port: 502, slave_id: 0, timeout_secs: 5
|
||||
- Add relay section: label_max_length: 8
|
||||
- [x] **T004** [P] [Setup] [TDD] Create settings/base.yaml with Modbus defaults
|
||||
- Add modbus section: `host: "192.168.0.200"`, `port: 502`, `slave_id: 0`, `timeout_secs: 5`
|
||||
- Add relay section: `label_max_length: 8`
|
||||
- **Test**: Settings::new() loads config without errors
|
||||
- **Complexity**: Low | **Uncertainty**: Low
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//! - YAML configuration files (base.yaml and environment-specific files)
|
||||
//! - Environment variables (prefixed with APP__)
|
||||
//!
|
||||
//! Settings include application details, email server configuration, and environment settings.
|
||||
//! Settings include application details, Modbus connection parameters, relay configuration,
|
||||
//! rate limiting, and environment settings.
|
||||
|
||||
/// Application configuration settings.
|
||||
///
|
||||
@@ -20,6 +21,10 @@ pub struct Settings {
|
||||
/// Rate limiting configuration
|
||||
#[serde(default)]
|
||||
pub rate_limit: RateLimitSettings,
|
||||
/// Modbus configuration
|
||||
pub modbus: ModbusSettings,
|
||||
/// Relay configuration
|
||||
pub relay: RelaySettings,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
@@ -156,6 +161,50 @@ const fn default_per_seconds() -> u64 {
|
||||
60
|
||||
}
|
||||
|
||||
/// Modbus TCP connection configuration.
|
||||
///
|
||||
/// Configures the connection parameters for communicating with the Modbus relay device
|
||||
/// using Modbus RTU over TCP protocol.
|
||||
#[derive(Debug, serde::Deserialize, Clone)]
|
||||
pub struct ModbusSettings {
|
||||
/// IP address or hostname of the Modbus device
|
||||
pub host: String,
|
||||
/// TCP port for Modbus communication (standard Modbus TCP port is 502)
|
||||
pub port: u16,
|
||||
/// Modbus slave/device ID (unit identifier)
|
||||
pub slave_id: u8,
|
||||
/// Operation timeout in seconds
|
||||
pub timeout_secs: u8,
|
||||
}
|
||||
|
||||
impl Default for ModbusSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
host: "192.168.0.200".to_string(),
|
||||
port: 502,
|
||||
slave_id: 0,
|
||||
timeout_secs: 5,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Relay control configuration.
|
||||
///
|
||||
/// Configures parameters for relay management and labeling.
|
||||
#[derive(Debug, serde::Deserialize, Clone)]
|
||||
pub struct RelaySettings {
|
||||
/// Maximum length for custom relay labels (in characters)
|
||||
pub label_max_length: u8,
|
||||
}
|
||||
|
||||
impl Default for RelaySettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
label_max_length: 8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -181,6 +181,8 @@ mod tests {
|
||||
burst_size: 100,
|
||||
per_seconds: 60,
|
||||
},
|
||||
modbus: crate::settings::ModbusSettings::default(),
|
||||
relay: crate::settings::RelaySettings::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user