Struct WaterInjection

Source
pub struct WaterInjection {
    refill_increment: f64,
    additional_refill_volume: f64,
    max_refill_volume: f64,
    spin_sleeper: SpinSleeper,
    sleep_duration_hundred_milli_sec: Duration,
    sleep_interval_seconds: f64,
    pub lock_warn_max_mutex_access_duration: bool,
    pub max_mutex_access_duration: Duration,
}
Expand description

Implementation of the WaterInjectionTrait which contains the code for executing the refill once the main control has detected that the water level is low. Thread communication is as follows:

graph LR water_injection[Water Injection] --> relay_manager[Relay Manager] relay_manager --> water_injection water_injection --> data_logger[Data Logger] data_logger --> water_injection tank_level_switch[TankLevelSwitch] -.-> water_injection signal_handler[Signal Handler] --> water_injection

Fields§

§refill_increment: f64

The volume of water (in Liters) injected during a single control loop cycle. This value is calculated at initialization from the pump’s flow rate and the loop’s sleep interval.

§additional_refill_volume: f64

The extra volume of water to add after the tank level switch first reports high. This acts as a hysteresis to prevent the pump from cycling too frequently.

§max_refill_volume: f64

The maximum total volume of water (in Liters) allowed for a single refill operation. This serves as a safety cutoff to prevent overfilling if the level switch fails.

§spin_sleeper: SpinSleeper

A high-precision sleeper utility to pause the control loop for a consistent duration.

§sleep_duration_hundred_milli_sec: Duration

The Duration for which the control loop sleeps on each iteration (e.g., 100 ms).

§sleep_interval_seconds: f64

The sleep interval of the control loop, expressed in seconds as a floating-point number for use in volume calculations.

§lock_warn_max_mutex_access_duration: bool

An inhibition flag to prevent flooding the log file with repeated warnings about excessive mutex access times.

§max_mutex_access_duration: Duration

The maximum permissible duration for a mutex lock to be held before a warning is issued.

Implementations§

Source§

impl WaterInjection

Source

pub fn new(config: &RefillConfig) -> WaterInjection

Creates a new WaterInjection instance.

This constructor initializes the water injection module, setting up parameters crucial for controlling the refill pump during a water injection operation. It calculates the refill_increment based on pump flow, copies refill limits from the configuration, and sets up internal timing mechanisms. All internal “lock” flags (used to prevent log flooding) are initialized to false.

§Arguments
  • config - A reference to the RefillConfig struct, which contains essential parameters such as refill_pump_flow, additional_refill_volume, and max_refill_volume.
§Returns

A new WaterInjection struct, ready to perform water injection operations.

Trait Implementations§

Source§

impl CheckMutexAccessDurationTrait for WaterInjection

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 WaterInjection

Source§

fn process_external_request( &mut self, rx_from_signal_handler: &mut AquaReceiver<InternalCommand>, _: Option<&mut AquaReceiver<InternalCommand>>, ) -> (bool, bool, bool)

Checks for and processes new commands relevant to the Water Injection module from external channels.

This is the specialized implementation of ProcessExternalRequestTrait for WaterInjection. It delegates directly to process_external_request_without_messaging, indicating that the WaterInjection module only processes commands from the signal handler and ignores any input from a messaging channel.

§Arguments
  • rx_from_signal_handler - A reference to the receiver end of the channel for commands originating from the signal handler.
  • _ - This parameter is ignored, as the WaterInjection module does not process messages from a messaging channel.
§Returns

A tuple (bool, bool, bool) indicating the status of commands received:

  • The first bool is true if a Quit command was received; otherwise false.
  • The second bool is always false (no “Start” commands processed).
  • The third bool is always false (no “Stop” commands processed).
Source§

impl WaterInjectionTrait for WaterInjection

Source§

fn inject_water( &mut self, refill_channels: &mut RefillChannels, refill_errors: &mut RefillErrorStates, sql_interface_refill: &mut Box<dyn DatabaseInterfaceRefillTrait + Sync + Send>, mutex_tank_level_switch_signals: &Arc<Mutex<TankLevelSwitchSignals>>, ) -> bool

Executes the freshwater refill operation, controlling the refill pump and monitoring tank level.

This function orchestrates the physical water injection. It first switches on the refill pump, then enters a loop to continuously monitor the tank level switch and check for various termination conditions:

  • Water level reaching high (plus additional_refill_volume).
  • Tank level switch signal becoming invalid.
  • Total refilled volume exceeding max_refill_volume (safety timeout).
  • A Quit command being received from the signal handler.

During the refill, it periodically communicates the pump status to the DataLogger and logs the final refill event details (timestamp, duration, volume, error code) to the database.

§Arguments
  • refill_channels - A mutable reference to a struct containing all necessary communication channels with RelayManager, DataLogger, and SignalHandler.
  • refill_errors - A mutable reference to a RefillErrors struct, where specific error flags (e.g., error_switch_stuck_low, error_sql_update_failed) will be set if issues occur during injection.
  • sql_interface_refill - A mutable reference to the SQL database interface for refill control, used to log the refill event.
  • mutex_tank_level_switch_signals - A mutable reference to the Arc<Mutex<TankLevelSwitchSignals>> for reading the current tank level switch position and validity.
§Returns

true if the refill operation was aborted due to a Quit command received from the signal handler; false otherwise (meaning it completed normally or aborted due to other conditions like level reached or errors).

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