Trait RelayActuationTrait

Source
pub trait RelayActuationTrait {
    // Required methods
    fn actuate(
        &mut self,
        internal_command: &InternalCommand,
    ) -> Result<(), RelayError>;
    fn get_heartbeat_interval_seconds(&self) -> Option<u64>;
    fn heartbeat(&mut self) -> Result<(), RelayError>;
    fn flush_buffer(&mut self) -> Result<(), RelayError>;
}
Expand description

Trait for the execution of relay actuation on either simulator or real hardware. This trait allows running the main control with a mock implementation for testing.

Required Methods§

Source

fn actuate( &mut self, internal_command: &InternalCommand, ) -> Result<(), RelayError>

Actuates a device based on the given command.

This is the primary method for controlling a hardware device. Implementations should translate the high-level InternalCommand into a hardware-specific action (e.g., sending a serial command, setting a GPIO pin).

§Arguments
  • internal_command - The command specifying the device and action to perform.
§Returns

An empty Result (Ok(())) on successful actuation.

§Errors

Returns a RelayError variant if the actuation fails. This could be due to various reasons depending on the implementation, such as

  • A failure to write to a serial port (WriteError).
  • A corrupt response from the hardware (IncorrectChecksum).
  • An attempt to use an unsupported command for the given hardware.
Source

fn get_heartbeat_interval_seconds(&self) -> Option<u64>

Gets the required interval for the heartbeat signal, if any.

Some hardware (like the Controllino) requires a periodic “keep-alive” signal to ensure the connection is active. This method defines that interval.

§Returns
  • Some(u64): The heartbeat interval in seconds.
  • None: If no heartbeat is required for this actuator (e.g., for direct GPIO control or a simulator).
Source

fn heartbeat(&mut self) -> Result<(), RelayError>

Sends a heartbeat signal to the hardware.

This method should be called periodically according to the interval specified by get_heartbeat_interval_seconds to maintain the hardware connection.

§Returns

An empty Result (Ok(())) if the heartbeat was sent successfully.

§Errors

Returns a RelayError if sending the heartbeat signal fails, for instance, due to a disconnected serial port.

Source

fn flush_buffer(&mut self) -> Result<(), RelayError>

Flushes the communication buffer of the hardware interface.

This method is a recovery mechanism, typically used after a communication error (like an incorrect checksum) to clear any lingering, corrupt data from the input/output buffers and resynchronize communication.

§Returns

An empty Result (Ok(())) if the buffer was flushed successfully.

§Errors

Returns a RelayError if the flush operation fails, which could indicate a deeper issue with the serial port or hardware driver.

Implementors§