Expand description
Contains the trait implementation for the execution of the feed Implements the physical execution of a feed pattern, controlling pumps and the feeder.
This module provides the FoodInjectionTrait and its concrete implementation,
FoodInjection. Its core responsibility is to translate a logical Feedpattern
into a sequence of physical actions by communicating with the RelayManager. It
manages the state of individual actuators, handles precise timing, and allows for
graceful interruption.
§Key Components
-
FoodInjectionTrait: An abstraction for the food injection process. This is a critical design element that decouples the mainFeedcontroller from the concrete implementation, enabling the use of mock injectors for unit testing. -
FoodInjectionStruct: The primary implementation of the trait. It maintains the current known state of all relevant actuators (pumps, skimmer, feeder) to avoid sending redundant commands to theRelayManager. -
inject_food()Method: The main entry point. It iterates through eachFeedPhaseof a givenFeedpattern, orchestrating the complex sequence of pausing pumps, running the feeder, and waiting for specified durations. -
switch_skimmer_pumps_feeder()Method: A private helper that compares the current actuator states with the target states for a given phase. If a state mismatch is found, it sends the appropriateSwitchOn/SwitchOffcommand and waits for confirmation.
§Design and Architecture
The module is designed for robustness and safe operation in a concurrent environment.
-
Stateful Execution: By tracking the state of each device (
skimmer_state,main_pump1_state, etc.), theFoodInjectionstruct ensures that it only sends commands when a state change is actually required. -
Interruptible Loops: The waiting periods within
inject_foodare not simplesleepcalls. They are implemented as tight loops that frequently check for aQuitcommand from theSignalHandler. This ensures that the entire feeding process can be aborted gracefully and quickly at any point. -
Guaranteed Cleanup: Regardless of whether the feed pattern completes, is interrupted, or encounters an error, a final cleanup step is always executed. This step ensures that all pumps are returned to their active state and the feeder is turned off, preventing the system from being left in a hazardous or undesirable state.
-
Comprehensive Error Collection: Instead of failing on the first error, the
inject_foodmethod collects all errors encountered during the process into aVec<FoodInjectionError>. This provides a complete picture of all failures that occurred during a single injection attempt, which is invaluable for diagnostics.
Structs§
- Food
Injection - Struct implements the FoodInjectionTrait for executing the feed pattern. It also contains state attributes for the actuators. Thread communication is as follows:
- Food
Injection Target Actuator States - Struct collects the target actuator states for switch_skimmer_pumps_feeder
Traits§
- Food
Injection Trait - Trait for the execution of the feed pattern. This trait allows running the main control with a mock implementation for testing.