pub struct Ventilation {
config: VentilationConfig,
lock_error_channel_send_schedule_check: bool,
lock_error_channel_receive_schedule_check: bool,
pub lock_warn_max_mutex_access_duration: bool,
lock_error_ventilation_set_value_read_failure: bool,
pub lock_warn_inapplicable_command_signal_handler: bool,
pub lock_error_channel_receive_termination: bool,
pub max_mutex_access_duration: Duration,
}Expand description
Holds the configuration and the implementation for the ventilation control. Thread communication of this component is as follows:
Fields§
§config: VentilationConfig§lock_error_channel_send_schedule_check: boolinhibition flag to avoid flooding the log file with repeated messages to send request via the channel to schedule check
lock_error_channel_receive_schedule_check: boolinhibition flag to avoid flooding the log file with repeated messages to receive request via the channel from schedule check
lock_warn_max_mutex_access_duration: boolinhibition flag to avoid flooding the log file with repeated messages about excessive access time to mutex
lock_error_ventilation_set_value_read_failure: boolinhibition flag to avoid flooding the log file about failure to update the set values
lock_warn_inapplicable_command_signal_handler: boolinhibition flag to avoid flooding the log file with repeated messages about having received inapplicable command via the channel
lock_error_channel_receive_termination: boolinhibition flag to avoid flooding the log file with repeated messages about the channel being disconnected
max_mutex_access_duration: DurationMaximum permissible access duration for Mutex
Implementations§
Source§impl Ventilation
impl Ventilation
Sourcepub fn new(config: VentilationConfig) -> Ventilation
pub fn new(config: VentilationConfig) -> Ventilation
Creates a new Ventilation control instance.
This constructor initializes the ventilation control module with its specific
configuration. It sets all internal “lock” flags to false by default; these
flags are used during operation to prevent log files from being flooded with
repeated error or warning messages.
§Arguments
config- Configuration data for the ventilation control, loaded from a TOML file. This includes parameters such as temperatures for switching on/off, and various behavioral strategies.
§Returns
A new Ventilation struct, ready to manage the aquarium’s ventilation system.
Sourcefn calc_normalized_control_deviation(&self, measured_value: f32) -> f32
fn calc_normalized_control_deviation(&self, measured_value: f32) -> f32
Calculates a normalized control deviation based on the measured temperature and configured thresholds.
This private helper function determines how far the measured_value deviates
from the switch_off_temperature relative to the total temperature control range
(switch_on_temperature to switch_off_temperature). The result is a float
between 0.0 and 1.0. A value of 0.0 means the temperature is at or below
switch_off_temperature, and 1.0 means it’s at or above switch_on_temperature.
§Arguments
measured_value- The current measured temperature (f32).
§Returns
An f32 representing the normalized control deviation, ranging from 0.0 to 1.0.
Returns 0.0 if switch_on_temperature is not greater than switch_off_temperature
(i.e., target_value_delta is not positive), indicating an invalid configuration.
Sourcefn conditional_ventilation_switch(
condition: bool,
ventilation_state: &mut ActuatorState,
mutex_device_scheduler_ventilation: &Arc<Mutex<i32>>,
ventilation_channels: &mut VentilationChannels,
mutex_was_blocked_during_actuation: &mut bool,
)
fn conditional_ventilation_switch( condition: bool, ventilation_state: &mut ActuatorState, mutex_device_scheduler_ventilation: &Arc<Mutex<i32>>, ventilation_channels: &mut VentilationChannels, mutex_was_blocked_during_actuation: &mut bool, )
Conditionally switches the ventilation device ON or OFF based on a boolean condition.
This private helper function encapsulates the logic for changing the ventilation’s
state. It only triggers a switch if the ventilation_state is not already
in the desired condition. It relies on switch_on_ventilation and switch_off_ventilation
to interact with the relay manager.
§Arguments
condition- A boolean value. Iftrue, the function attempts to switch the ventilation ON; iffalse, it attempts to switch it OFF.ventilation_state- A mutable reference to theActuatorStaterepresenting the current state of the ventilation device, which will be updated by this function.mutex_device_scheduler_ventilation- A shared mutex for coordinating device actuation.ventilation_channels- A reference to theVentilationChannelsstruct for communication with the relay manager.mutex_was_blocked_during_actuation- A mutable flag indicating if the device scheduler mutex was blocked.
Sourcepub fn execute(
&mut self,
mutex_device_scheduler_ventilation: Arc<Mutex<i32>>,
ventilation_channels: &mut VentilationChannels,
ventilation_set_val_updater: &mut impl ThermalSetValueUpdaterTrait,
mutex_sensor_manager_signals: Arc<Mutex<SensorManagerSignals>>,
mutex_ventilation_status: Arc<Mutex<bool>>,
)
pub fn execute( &mut self, mutex_device_scheduler_ventilation: Arc<Mutex<i32>>, ventilation_channels: &mut VentilationChannels, ventilation_set_val_updater: &mut impl ThermalSetValueUpdaterTrait, mutex_sensor_manager_signals: Arc<Mutex<SensorManagerSignals>>, mutex_ventilation_status: Arc<Mutex<bool>>, )
Executes the main control loop for the ventilation module.
This function runs continuously, managing the aquarium’s ventilation system. It adjusts ventilation based on water temperature readings, a calculated sawtooth profile (for proportional control), and various external commands and schedule limitations.
The loop periodically reads water temperature, checks schedule permissions, and updates
the ventilation state via the relay manager. It is responsive to Start, Stop, and Quit
commands from external channels. The function maintains a fixed cycle time and ensures
a graceful shutdown upon receiving termination signals.
§Arguments
mutex_device_scheduler_ventilation- AnArc<Mutex<i32>>used for coordinating device actuation, preventing parallel operations, and tracking actuation counts.ventilation_channels- A mutable reference toVentilationChannelsstruct containing allmpscchannels for communication with other threads (e.g., relay manager, data logger, schedule checker, signal handler).mutex_sensor_manager_channels- AnArc<Mutex<SensorManagerSignals>>from which the latest water temperature reading will be retrieved.mutex_ventilation_status- AnArc<Mutex<bool>>for communicating the ventilation status to the data logger.
§Returns
This function does not return a value in the traditional sense, as it is designed
to loop indefinitely. It will only break out of its loop and terminate when a Quit
command is received from the signal handler, after which it performs final cleanup
(switching the ventilation to its configured terminal state) and confirms shutdown.
Trait Implementations§
Source§impl CheckMutexAccessDurationTrait for Ventilation
impl CheckMutexAccessDurationTrait for Ventilation
Source§fn get_warn_lock(&self, _key_opt: &Option<&AquariumSignal>) -> bool
fn get_warn_lock(&self, _key_opt: &Option<&AquariumSignal>) -> bool
Method connects the default trait implementation with the specific implementation reading the warn-lock.
Source§fn set_warn_lock(&mut self, _key_opt: &Option<&AquariumSignal>, value: bool)
fn set_warn_lock(&mut self, _key_opt: &Option<&AquariumSignal>, value: bool)
Method connects the default trait implementation with the specific implementation setting the warn-lock.
Source§fn get_max_mutex_access_duration(&self) -> Duration
fn get_max_mutex_access_duration(&self) -> Duration
Method connects the default trait implementation with the specific implementation for getting maximum permissible access duration
Source§fn get_location(&self) -> &str
fn get_location(&self) -> &str
inform the location of the warning for logging purposes
fn check_mutex_access_duration( &mut self, key_opt: Option<&AquariumSignal>, instant_after_locking_mutex: Instant, instant_before_locking_mutex: Instant, )
Source§impl ProcessExternalRequestTrait for Ventilation
impl ProcessExternalRequestTrait for Ventilation
Source§fn process_external_request(
&mut self,
rx_from_signal_handler: &mut AquaReceiver<InternalCommand>,
rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>,
) -> (bool, bool, bool)
fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, rx_from_messaging_opt: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)
Source§impl WaitForTerminationTrait for Ventilation
impl WaitForTerminationTrait for Ventilation
Source§fn get_warn_lock_mut(&mut self) -> &mut bool
fn get_warn_lock_mut(&mut self) -> &mut bool
Method connects the default trait implementation with the specific implementation accessing the warn-lock.
Source§fn get_error_lock_mut(&mut self) -> &mut bool
fn get_error_lock_mut(&mut self) -> &mut bool
Method connects the default trait implementation with the specific implementation for accessing the error-lock.