Auto: ablegacy-3 — sub-element bit semantics

Closes #246
This commit is contained in:
Joseph Doherty
2026-04-25 13:41:52 -04:00
parent 07235d3b66
commit c89f5bb3b9
6 changed files with 350 additions and 5 deletions

View File

@@ -102,4 +102,96 @@ public sealed class AbLegacyDriverTests
AbLegacyDataType.String.ToDriverDataType().ShouldBe(DriverDataType.String);
AbLegacyDataType.TimerElement.ToDriverDataType().ShouldBe(DriverDataType.Int32);
}
[Theory]
[InlineData(AbLegacyDataType.TimerElement, "EN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.TimerElement, "TT", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.TimerElement, "DN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.TimerElement, "PRE", DriverDataType.Int32)]
[InlineData(AbLegacyDataType.TimerElement, "ACC", DriverDataType.Int32)]
[InlineData(AbLegacyDataType.CounterElement, "CU", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.CounterElement, "CD", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.CounterElement, "DN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.CounterElement, "OV", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.CounterElement, "UN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.CounterElement, "PRE", DriverDataType.Int32)]
[InlineData(AbLegacyDataType.CounterElement, "ACC", DriverDataType.Int32)]
[InlineData(AbLegacyDataType.ControlElement, "EN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "EU", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "DN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "EM", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "ER", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "UL", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "IN", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "FD", DriverDataType.Boolean)]
[InlineData(AbLegacyDataType.ControlElement, "LEN", DriverDataType.Int32)]
[InlineData(AbLegacyDataType.ControlElement, "POS", DriverDataType.Int32)]
public void EffectiveDriverDataType_resolves_subelements(
AbLegacyDataType dataType, string subElement, DriverDataType expected)
{
AbLegacyDataTypeExtensions.EffectiveDriverDataType(dataType, subElement).ShouldBe(expected);
}
[Fact]
public void EffectiveDriverDataType_unknown_subelement_falls_back_to_base()
{
// Permissive — keeps the driver from refusing tags whose sub-element we don't catalogue.
AbLegacyDataTypeExtensions.EffectiveDriverDataType(AbLegacyDataType.TimerElement, "BOGUS")
.ShouldBe(DriverDataType.Int32);
AbLegacyDataTypeExtensions.EffectiveDriverDataType(AbLegacyDataType.TimerElement, null)
.ShouldBe(DriverDataType.Int32);
AbLegacyDataTypeExtensions.EffectiveDriverDataType(AbLegacyDataType.Int, "DN")
.ShouldBe(DriverDataType.Int32);
}
[Theory]
[InlineData(AbLegacyDataType.TimerElement, "DN", 13)]
[InlineData(AbLegacyDataType.TimerElement, "TT", 14)]
[InlineData(AbLegacyDataType.TimerElement, "EN", 15)]
[InlineData(AbLegacyDataType.CounterElement, "UN", 10)]
[InlineData(AbLegacyDataType.CounterElement, "OV", 11)]
[InlineData(AbLegacyDataType.CounterElement, "DN", 12)]
[InlineData(AbLegacyDataType.CounterElement, "CD", 13)]
[InlineData(AbLegacyDataType.CounterElement, "CU", 14)]
[InlineData(AbLegacyDataType.ControlElement, "FD", 8)]
[InlineData(AbLegacyDataType.ControlElement, "IN", 9)]
[InlineData(AbLegacyDataType.ControlElement, "UL", 10)]
[InlineData(AbLegacyDataType.ControlElement, "ER", 11)]
[InlineData(AbLegacyDataType.ControlElement, "EM", 12)]
[InlineData(AbLegacyDataType.ControlElement, "DN", 13)]
[InlineData(AbLegacyDataType.ControlElement, "EU", 14)]
[InlineData(AbLegacyDataType.ControlElement, "EN", 15)]
public void StatusBitIndex_maps_to_standard_pccc_positions(
AbLegacyDataType dataType, string subElement, int expectedBit)
{
AbLegacyDataTypeExtensions.StatusBitIndex(dataType, subElement).ShouldBe(expectedBit);
}
[Fact]
public void StatusBitIndex_for_word_subelements_is_null()
{
AbLegacyDataTypeExtensions.StatusBitIndex(AbLegacyDataType.TimerElement, "PRE").ShouldBeNull();
AbLegacyDataTypeExtensions.StatusBitIndex(AbLegacyDataType.CounterElement, "ACC").ShouldBeNull();
AbLegacyDataTypeExtensions.StatusBitIndex(AbLegacyDataType.ControlElement, "LEN").ShouldBeNull();
AbLegacyDataTypeExtensions.StatusBitIndex(AbLegacyDataType.TimerElement, null).ShouldBeNull();
AbLegacyDataTypeExtensions.StatusBitIndex(AbLegacyDataType.Int, "DN").ShouldBeNull();
}
[Theory]
[InlineData(AbLegacyDataType.TimerElement, "DN", true)]
[InlineData(AbLegacyDataType.TimerElement, "TT", true)]
[InlineData(AbLegacyDataType.TimerElement, "EN", false)] // operator-controllable
[InlineData(AbLegacyDataType.CounterElement, "DN", true)]
[InlineData(AbLegacyDataType.CounterElement, "OV", true)]
[InlineData(AbLegacyDataType.CounterElement, "UN", true)]
[InlineData(AbLegacyDataType.CounterElement, "CU", false)]
[InlineData(AbLegacyDataType.ControlElement, "DN", true)]
[InlineData(AbLegacyDataType.ControlElement, "ER", true)]
[InlineData(AbLegacyDataType.ControlElement, "EM", true)]
[InlineData(AbLegacyDataType.ControlElement, "EN", false)]
public void IsPlcSetStatusBit_classifies_writable_vs_status_bits(
AbLegacyDataType dataType, string subElement, bool expected)
{
AbLegacyDataTypeExtensions.IsPlcSetStatusBit(dataType, subElement).ShouldBe(expected);
}
}