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:
2026-01-01 14:54:35 +01:00
parent c06407d8d3
commit e6619acba0
4 changed files with 65 additions and 5 deletions

View File

@@ -6,3 +6,12 @@ rate_limit:
enabled: true enabled: true
burst_size: 10 burst_size: 10
per_seconds: 60 per_seconds: 60
modbus:
host: "192.168.0.200"
port: 502
slave_id: 0
timeout_secs: 5
relay:
label_max_length: 8

View File

@@ -22,16 +22,16 @@
- **Test**: Module declarations compile without errors - **Test**: Module declarations compile without errors
- **Complexity**: Low | **Uncertainty**: Low - **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 ModbusSettings struct with `host`, `port`, `slave_id`, `timeout_secs` fields
- Add RelaySettings struct with `label_max_length` field - Add RelaySettings struct with `label_max_length` field
- Update Settings struct to include modbus and relay fields - Update Settings struct to include modbus and relay fields
- **Test**: Settings loads from settings/base.yaml with test Modbus config - **Test**: Settings loads from settings/base.yaml with test Modbus config
- **Complexity**: Low | **Uncertainty**: Low - **Complexity**: Low | **Uncertainty**: Low
- [ ] **T004** [P] [Setup] [TDD] Create settings/base.yaml with Modbus defaults - [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 modbus section: `host: "192.168.0.200"`, `port: 502`, `slave_id: 0`, `timeout_secs: 5`
- Add relay section: label_max_length: 8 - Add relay section: `label_max_length: 8`
- **Test**: Settings::new() loads config without errors - **Test**: Settings::new() loads config without errors
- **Complexity**: Low | **Uncertainty**: Low - **Complexity**: Low | **Uncertainty**: Low

View File

@@ -4,7 +4,8 @@
//! - YAML configuration files (base.yaml and environment-specific files) //! - YAML configuration files (base.yaml and environment-specific files)
//! - Environment variables (prefixed with APP__) //! - 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. /// Application configuration settings.
/// ///
@@ -20,6 +21,10 @@ pub struct Settings {
/// Rate limiting configuration /// Rate limiting configuration
#[serde(default)] #[serde(default)]
pub rate_limit: RateLimitSettings, pub rate_limit: RateLimitSettings,
/// Modbus configuration
pub modbus: ModbusSettings,
/// Relay configuration
pub relay: RelaySettings,
} }
impl Settings { impl Settings {
@@ -156,6 +161,50 @@ const fn default_per_seconds() -> u64 {
60 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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@@ -181,6 +181,8 @@ mod tests {
burst_size: 100, burst_size: 100,
per_seconds: 60, per_seconds: 60,
}, },
modbus: crate::settings::ModbusSettings::default(),
relay: crate::settings::RelaySettings::default(),
} }
} }