aquarium_control/relays/relay_manager_config.rs
1/* Copyright 2025 Uwe Martin
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8*/
9use serde_derive::Deserialize;
10use std::fmt;
11
12/// Holds the configuration data for the relay manager.
13/// The configuration is loaded from the .toml configuration file.
14/// This struct does not contain any implementation.
15#[derive(Clone, Deserialize, Debug)]
16pub struct RelayManagerConfig {
17 /// Switch for testing purposes enabling main functionalities
18 pub active: bool,
19
20 /// Indicates if the thread shall be started or not
21 pub execute: bool,
22
23 /// Flag to determine if the application shall communicate with hardware directly or via TCP with a simulator
24 pub use_simulator: bool,
25
26 /// Flag to determine if the application shall use GPIO or Controllino
27 pub use_gpio: bool,
28
29 /// The number of retries in case write operation to actuator fails
30 /// Applicable only to Controllino, because GPIO actuation does not execute a write operation
31 pub actuation_retries: u64,
32
33 /// Pause time in milliseconds between retries
34 pub pause_between_retries_millis: u64,
35}
36
37impl fmt::Display for RelayManagerConfig {
38 /// Formats the `RelayManagerConfig` for display purposes.
39 ///
40 /// This implementation provides a clean, multi-line string representation of the
41 /// relay manager's configuration, which is ideal for logging at startup or
42 /// for debugging purposes.
43 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44 writeln!(f, "Relay Manager Configuration:")?;
45 writeln!(f, " Active: {}", self.active)?;
46 writeln!(f, " Use Simulator: {}", self.use_simulator)?;
47 writeln!(f, " Use GPIO: {}", self.use_gpio)?;
48 writeln!(f, " Actuation Retries: {}", self.actuation_retries)?;
49 write!(
50 f,
51 " Pause Between Retries: {} ms",
52 self.pause_between_retries_millis
53 )
54 }
55}