Struct RelayManager

Source
pub struct RelayManager {
    config: RelayManagerConfig,
    lock_error_channel_send_refill: bool,
    lock_error_channel_receive_refill: bool,
    lock_error_channel_send_feed: bool,
    lock_error_channel_receive_feed: bool,
    lock_error_channel_send_ventilation: bool,
    lock_error_channel_receive_ventilation: bool,
    lock_error_channel_send_heating: bool,
    lock_error_channel_receive_heating: bool,
    lock_error_channel_send_balling: bool,
    lock_error_channel_receive_balling: bool,
    execution_config: ExecutionConfig,
}
Expand description

Contains the configuration and the implementation of the relay manager. Thread communication of this component is as follows:

graph LR relay_manager[Relay manager] --> tcp_communication[TCP communication] relay_manager --> refill[Refill control] refill --> relay_manager relay_manager --> heating[Heating control] heating --> relay_manager relay_manager --> balling[Balling dosing control] balling --> relay_manager relay_manager --> feed[Feed control] feed --> relay_manager relay_manager --> signal_handler[Signal handler] signal_handler --> relay_manager relay_manager --> ventilation[Ventilation control] ventilation --> relay_manager

Fields§

§config: RelayManagerConfig

configuration data for relay manager

§lock_error_channel_send_refill: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to send to refill control via the channel

§lock_error_channel_receive_refill: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to receive from refill control via the channel

§lock_error_channel_send_feed: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to send to feed control via the channel

§lock_error_channel_receive_feed: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to receive from feed control via the channel

§lock_error_channel_send_ventilation: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to send to ventilation control via the channel

§lock_error_channel_receive_ventilation: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to receive from ventilation control via the channel

§lock_error_channel_send_heating: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to send to heating control via the channel

§lock_error_channel_receive_heating: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to receive from heating control via the channel

§lock_error_channel_send_balling: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to send to balling mineral dosing via the channel

§lock_error_channel_receive_balling: bool

inhibition flag to avoid flooding the log file with repeated messages of failure to receive from balling mineral dosing via the channel

§execution_config: ExecutionConfig

information about which threads have been started

Implementations§

Source§

impl RelayManager

Source

pub fn new( config: RelayManagerConfig, execution_config: ExecutionConfig, ) -> RelayManager

Creates a new RelayManager instance.

This constructor initializes the relay management module with its configuration. It sets up various internal lock flags to false, which are used to prevent repetitive error and warning messages from flooding the log file during operation, especially concerning channel communication and actuation errors.

§Arguments
  • config - Configuration data for the relay manager, loaded from a TOML file.
§Returns

A new RelayManager struct, ready to handle relay actuation commands and communicate with other modules.

Source

fn actuate_with_retries( &mut self, actuator: &mut impl RelayActuationTrait, command: &InternalCommand, actuation_name: &str, spin_sleeper: &mut SpinSleeper, sleep_duration: Duration, ) -> Result<(), RelayError>

Attempts to actuate a given command, with retries on failure.

This helper function encapsulates the retry logic for actuator commands. It will attempt the actuation at least once, and if it fails, it will retry up to the number of times specified by self.config.actuation_retries. If a failure is due to an IncorrectChecksum, it will attempt to flush the buffer before retrying.

§Arguments
  • actuator - A mutable reference to an object implementing RelayActuationTrait.
  • command - The InternalCommand to be executed.
  • actuation_name - A descriptive name for the action (e.g., “refill pump”) for logging.
  • spin_sleeper - A SpinSleeper to pause between retries.
  • sleep_duration - The Duration to wait between retry attempts.
§Returns

An empty Result (Ok(())) if the actuation succeeds, possibly after one or more retries.

§Errors

Returns Err(RelayError::ActuationFailed) if all attempts (the initial one plus all retries) fail. This error is a wrapper that contains detailed context, including

  • The name of the actuation that failed.
  • The total number of attempts made.
  • The specific error from the last attempt, providing the root cause of the final failure.
Source

pub fn execute( &mut self, relay_manager_channels: &mut RelayManagerChannels, actuator: &mut impl RelayActuationTrait, )

Executes the main control loop for the Relay Manager.

This function runs continuously, acting as the central dispatcher for actuation commands received from various control modules (Refill, Heating, etc.). It uses a helper function, process_actuation_request, to handle the logic for each module’s channel pair, keeping the main loop clean and readable.

The loop forwards commands to the provided actuator and handles graceful shutdown when a Quit command is received from the signal handler. It also manages to send periodic heartbeats to the hardware if required.

§Arguments
  • relay_manager_channels - A mutable reference to the struct containing all mpsc channels necessary for communication with other control threads.
  • actuator - A mutable reference to an object implementing the RelayActuationTrait, which handles the actual hardware interaction or simulation.
Source

fn process_actuation_request( &mut self, channels: (&mut AquaReceiver<InternalCommand>, &mut AquaSender<bool>), locks: (bool, bool), actuation_name: &str, actuator: &mut impl RelayActuationTrait, spin_sleeper: &mut SpinSleeper, sleep_duration_between_retries: Duration, ) -> (bool, bool)

Helper function to process an actuation request from a single channel pair.

This function encapsulates the logic for receiving a command, actuating it with retries, and sending a confirmation response. It is used to de-duplicate the main execute loop.

It takes the current state of the log-suppression flags (lock_receive, lock_send) by value and returns their updated state in a tuple. This pattern is used to work around Rust’s borrowing rules, as the flags are fields on RelayManager and cannot be mutably borrowed multiple times in the execute loop.

§Arguments
  • rx - The channel for receiving InternalCommands from a control module.
  • tx - The channel for sending a boolean confirmation back to the control module.
  • lock_receive - The current state of the receive-error lock flag.
  • lock_send - The current state of the send error lock flag.
  • actuation_name - A descriptive name for the action (e.g., “refill”) for logging.
  • actuator - A mutable reference to the hardware actuator.
  • spin_sleeper - A SpinSleeper to pause between retries.
  • sleep_duration_between_retries - The Duration to wait between retry attempts.
§Returns

A tuple (bool, bool) containing the updated state of the lock_receive and lock_send flags, respectively.

Trait Implementations§

Source§

impl ProcessExternalRequestTrait for RelayManager

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 Relay Manager module from external channels.

This is the specialized implementation of ProcessExternalRequestTrait for RelayManager. It delegates directly to process_external_request_without_messaging, indicating that the RelayManager (which often interacts with hardware like Controllino) 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 RelayManager 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).

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