using System.Xml.Linq;
namespace HC_APTBS.Models
{
///
/// Represents a single relay or solenoid output on the test bench.
/// Each relay is mapped to a specific bit position within a CAN message.
/// The bench controller reads a bitmask from CAN message ID
/// and asserts the corresponding output.
///
public class Relay
{
///
/// True when the relay is energised (output ON); false when de-energised.
///
public const bool On = true;
/// False indicates the relay is de-energised (output OFF).
public const bool Off = false;
/// Human-readable relay name (see ).
public string Name { get; set; } = string.Empty;
/// CAN message identifier that carries this relay's bitmask.
public uint MessageId { get; set; }
/// Bit position within the 64-bit relay bitmask sent in the CAN payload.
public int Bit { get; set; }
/// Current output state: true = energised, false = de-energised.
public bool State { get; set; }
/// Parameterless constructor for deserialisation.
public Relay() { }
/// Relay name constant from .
/// CAN message ID carrying the relay bitmask.
/// Bit position in the 64-bit bitmask.
public Relay(string name, uint messageId, int bit)
{
Name = name;
MessageId = messageId;
Bit = bit;
}
/// Serialises this relay definition to XML for persistence.
public XElement ToXml()
=> new XElement("Rele",
new XAttribute("name", Name),
new XAttribute("id", MessageId.ToString("X")),
new XAttribute("bit", Bit));
}
/// Pump rotation direction constants.
public static class RotationDirection
{
/// CAN value for counter-clockwise (left) rotation.
public const short Left = 2;
/// CAN value for clockwise (right) rotation.
public const short Right = 1;
public const string LeftName = "left";
public const string RightName = "right";
}
/// Encoder operating mode constants.
public static class EncoderMode
{
public const double ModeOn = 1;
public const double ModeOff = 0;
/// 4-cylinder pulse-per-revolution mode.
public const double Pumps4 = 1;
/// 6-cylinder pulse-per-revolution mode.
public const double Pumps6 = 0;
public const double PositionRelative = 0;
public const double PositionAbsolute = 1;
}
/// CAN baudrate selector values sent to the bench firmware.
public static class BaudrateSelection
{
/// Select 500 kbps.
public const double Val500K = 1;
/// Select 250 kbps.
public const double Val250K = 0;
}
}