using System.Xml.Linq;
namespace HC_APTBS.Models
{
///
/// Defines a single alarm condition monitored by the bench controller.
/// Alarms are bit-mapped: the bench asserts a bitmask in the Alarms CAN parameter
/// () and each bit corresponds to a named condition.
///
public class Alarm
{
/// Bit position in the alarm bitmask (0-based).
public int Bit { get; set; }
/// Human-readable description of this alarm condition.
public string Description { get; set; } = string.Empty;
///
/// When true, this alarm immediately halts any running test and requires
/// operator acknowledgement before the bench can be restarted.
///
public bool IsCritical { get; set; }
/// True while this alarm condition is currently active.
public bool IsActive { get; set; }
/// Serialises this alarm to XML for persistence in alarms.xml.
public XElement ToXml()
=> new XElement("Alarm",
new XAttribute("bit", Bit),
new XAttribute("desc", Description),
new XAttribute("critical", IsCritical));
/// Deserialises an alarm from an XML element.
public static Alarm FromXml(XElement element)
=> new Alarm
{
Bit = int.Parse(element.Attribute("bit")?.Value ?? "0"),
Description = element.Attribute("desc")?.Value ?? string.Empty,
IsCritical = bool.Parse(element.Attribute("critical")?.Value ?? "false")
};
}
}