fix(driver-galaxy): resolve Medium code-review finding (Driver.Galaxy-004)
Add StatusCodeMap.ToQualityCategoryByte(uint) so the StatusCode → quality-byte mapping lives in one place next to its inverse (FromQualityByte). GalaxyDriver OnPumpDataChange now delegates to the helper instead of duplicating the shift+switch inline; a future edit to the OPC UA bit layout cannot silently desync the probe-health decode. Unit tests in StatusCodeMapTests pin all three category buckets and the round-trip invariant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -112,4 +112,29 @@ public sealed class StatusCodeMapTests
|
||||
((StatusCodeMap.BadNotConnected >> 30) & 0x3u).ShouldBe(2u);
|
||||
((StatusCodeMap.BadOutOfService >> 30) & 0x3u).ShouldBe(2u);
|
||||
}
|
||||
|
||||
// ===== Driver.Galaxy-004 regression: ToQualityCategoryByte lives next to its inverse =====
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x00000000u, (byte)192)] // Good
|
||||
[InlineData(0x00D80000u, (byte)192)] // GoodLocalOverride — still Good category
|
||||
[InlineData(0x40000000u, (byte)64)] // Uncertain
|
||||
[InlineData(0x408F0000u, (byte)64)] // UncertainSubNormal — still Uncertain category
|
||||
[InlineData(0x80000000u, (byte)0)] // Bad
|
||||
[InlineData(0x808A0000u, (byte)0)] // BadNotConnected — still Bad category
|
||||
[InlineData(0x80020000u, (byte)0)] // BadInternalError — still Bad category
|
||||
public void ToQualityCategoryByte_ExtractsTopTwoBitsAsOpcDaByte(uint statusCode, byte expected)
|
||||
{
|
||||
StatusCodeMap.ToQualityCategoryByte(statusCode).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQualityCategoryByte_IsRightInverseOfFromQualityByte_ForCategoryBytes()
|
||||
{
|
||||
// The category bytes the probe watcher uses are 0, 64, 192. Round-trip: a value
|
||||
// that came FROM those bytes should map back to the same byte.
|
||||
StatusCodeMap.ToQualityCategoryByte(StatusCodeMap.FromQualityByte(0)).ShouldBe((byte)0);
|
||||
StatusCodeMap.ToQualityCategoryByte(StatusCodeMap.FromQualityByte(64)).ShouldBe((byte)64);
|
||||
StatusCodeMap.ToQualityCategoryByte(StatusCodeMap.FromQualityByte(192)).ShouldBe((byte)192);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user