Function get_relay_command

Source
pub fn get_relay_command(
    internal_command: &InternalCommand,
    device: AquariumDevice,
    config: &ActuateControllinoConfig,
) -> Result<InternalCommand, RelayError>
Expand description

Creates a Controllino-specific message from a high-level internal command.

This private helper function translates a generic InternalCommand (like SwitchOn, SwitchOff, or Pulse) into the precise ControllinoMessage format required for serial communication with the Controllino hardware. It uses the provided configuration to map AquariumDevice types to their corresponding relay IDs and to determine the correct relay actuation logic (e.g., SetRelay vs. UnsetRelay).

§Arguments

  • internal_command - The InternalCommand enum value representing the desired action (e.g., switching a device on/off or pulsing a relay).
  • config - A reference to the ActuateControllinoConfig, which provides device-to-relay ID mappings and other settings.

§Returns

A Result containing the low-level InternalCommand (e.g., SetRelay, PulseRelay) on success.

§Errors

This function will return a RelayError if:

  • The internal_command is not one that this function can translate for Controllino actuation (e.g., ResetAllErrors), resulting in IrrelevantCommand.
  • A Pulse command is issued for a device that does not support pulsing, resulting in PulseNotAllowedForDevice.