Struct Ventilation

Source
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:

graph LR atlas_scientific[Atlas Scientific] --> ventilation ventilation --> relay_manager[Relay Manager] relay_manager --> ventilation ventilation --> signal_handler[Signal Handler] signal_handler --> ventilation ventilation --> data_logger[Data Logger] data_logger --> ventilation ventilation --> schedule_check[Schedule Check] schedule_check --> ventilation messaging[Messaging] --> ventilation

Fields§

§config: VentilationConfig§lock_error_channel_send_schedule_check: bool

inhibition 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: bool

inhibition 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: bool

inhibition flag to avoid flooding the log file with repeated messages about excessive access time to mutex

§lock_error_ventilation_set_value_read_failure: bool

inhibition flag to avoid flooding the log file about failure to update the set values

§lock_warn_inapplicable_command_signal_handler: bool

inhibition flag to avoid flooding the log file with repeated messages about having received inapplicable command via the channel

§lock_error_channel_receive_termination: bool

inhibition flag to avoid flooding the log file with repeated messages about the channel being disconnected

§max_mutex_access_duration: Duration

Maximum permissible access duration for Mutex

Implementations§

Source§

impl Ventilation

Source

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.

Source

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.

Source

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. If true, the function attempts to switch the ventilation ON; if false, it attempts to switch it OFF.
  • ventilation_state - A mutable reference to the ActuatorState representing 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 the VentilationChannels struct for communication with the relay manager.
  • mutex_was_blocked_during_actuation - A mutable flag indicating if the device scheduler mutex was blocked.
Source

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 - An Arc<Mutex<i32>> used for coordinating device actuation, preventing parallel operations, and tracking actuation counts.
  • ventilation_channels - A mutable reference to VentilationChannels struct containing all mpsc channels for communication with other threads (e.g., relay manager, data logger, schedule checker, signal handler).
  • mutex_sensor_manager_channels - An Arc<Mutex<SensorManagerSignals>> from which the latest water temperature reading will be retrieved.
  • mutex_ventilation_status - An Arc<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

Source§

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)

Method connects the default trait implementation with the specific implementation setting the warn-lock.

Source§

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

inform the location of the warning for logging purposes

Source§

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

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)

Checks for and processes new commands received from the signal handler and an optional messaging channel. Read more
Source§

impl WaitForTerminationTrait for Ventilation

Source§

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

Method connects the default trait implementation with the specific implementation for accessing the error-lock.

Source§

fn wait_for_termination( &mut self, rx_waiting_thread_from_signal_handler: &mut AquaReceiver<InternalCommand>, sleep_duration: Duration, origin: &str, )

Implements the graceful shutdown wait loop for several threads (default implementation). Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T