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:
Fields§
§refill_increment: f64The 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: f64The 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: f64The 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: SpinSleeperA high-precision sleeper utility to pause the control loop for a consistent duration.
sleep_duration_hundred_milli_sec: DurationThe Duration for which the control loop sleeps on each iteration (e.g., 100 ms).
sleep_interval_seconds: f64The 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: boolAn inhibition flag to prevent flooding the log file with repeated warnings about excessive mutex access times.
max_mutex_access_duration: DurationThe maximum permissible duration for a mutex lock to be held before a warning is issued.
Implementations§
Source§impl WaterInjection
impl WaterInjection
Sourcepub fn new(config: &RefillConfig) -> WaterInjection
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 theRefillConfigstruct, which contains essential parameters such asrefill_pump_flow,additional_refill_volume, andmax_refill_volume.
§Returns
A new WaterInjection struct, ready to perform water injection operations.
Trait Implementations§
Source§impl CheckMutexAccessDurationTrait for WaterInjection
impl CheckMutexAccessDurationTrait for WaterInjection
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 WaterInjection
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)
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 theWaterInjectionmodule does not process messages from a messaging channel.
§Returns
A tuple (bool, bool, bool) indicating the status of commands received:
- The first
boolistrueif aQuitcommand was received; otherwisefalse. - The second
boolis alwaysfalse(no “Start” commands processed). - The third
boolis alwaysfalse(no “Stop” commands processed).
Source§impl WaterInjectionTrait for WaterInjection
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
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(plusadditional_refill_volume). - Tank level switch signal becoming
invalid. - Total refilled
volumeexceedingmax_refill_volume(safety timeout). - A
Quitcommand 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 withRelayManager,DataLogger, andSignalHandler.refill_errors- A mutable reference to aRefillErrorsstruct, 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 theArc<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).