|
|
@@ -0,0 +1,74 @@
|
|
|
+using IvfTl.Control.Entity;
|
|
|
+using ivf_tl_SerialHelper.Util;
|
|
|
+using Xunit;
|
|
|
+
|
|
|
+namespace ivf_tl_SerialHelper.Tests
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// M-01/M-02/M-03 合并遗留:control 端 Commander 缺 3 个 E方读写 builder。
|
|
|
+ /// 期望字节 = 合并前 operate 端 ivf_tl_Entity/ComEntitys/Commander.cs 同名方法的黄金真值
|
|
|
+ /// (临时文件/ivf_tl_operate_2.0,该实现真机已用),末位为 CreateORC 累加和校验(对前 n-1 字节求和取低字节)。
|
|
|
+ /// 字节编码是纯逻辑,这里 red→green;ComBin/SerialChannelImpl 接线 + EEPROM 读写往返走真机验证。
|
|
|
+ /// </summary>
|
|
|
+ public class CommanderEepromTests
|
|
|
+ {
|
|
|
+ /// <summary>M-02 读E方→舱室排气阀打开时间。地址 00 03 08,固定 9 字节读命令。</summary>
|
|
|
+ [Fact]
|
|
|
+ public void CreateReadEEPROMVentNum_产出与operate一致的读排气阀时间命令字节()
|
|
|
+ {
|
|
|
+ var custom = new CustomProtocol();
|
|
|
+ custom.CreateReadEEPROMVentNum();
|
|
|
+
|
|
|
+ // 5E 11(READ_EEPROM) 00 09(LTH) 00 03 08(地址) 04 00 → ORC=前8字节和=0x87
|
|
|
+ var expected = new byte[] { 0x5E, 0x11, 0x00, 0x09, 0x00, 0x03, 0x08, 0x04, 0x87 };
|
|
|
+ Assert.Equal(expected, custom.sendBuffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>M-01 写E方→舱室排气阀打开时间。地址 00 03 08 + 小端 4 字节值 + 校验。</summary>
|
|
|
+ [Fact]
|
|
|
+ public void CreateWriteEEPROOpenVentTimeCommand_产出与operate一致的写排气阀时间命令字节()
|
|
|
+ {
|
|
|
+ var custom = new CustomProtocol();
|
|
|
+ custom.CreateWriteEEPROOpenVentTimeCommand(5);
|
|
|
+
|
|
|
+ // 5E 12(WRITE_EEPROM) 00 0C(LTH) 00 03 08(地址) 05 00 00 00(小端5) 00→ORC=前11字节和=0x8C
|
|
|
+ var expected = new byte[] { 0x5E, 0x12, 0x00, 0x0C, 0x00, 0x03, 0x08, 0x05, 0x00, 0x00, 0x00, 0x8C };
|
|
|
+ Assert.Equal(expected, custom.sendBuffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>M-03 写E方→灯光亮度。地址 00 05 34 + 小端 4 字节值 + 校验。</summary>
|
|
|
+ [Fact]
|
|
|
+ public void CreateWriteEEPROMLightNum_产出与operate一致的写灯光亮度命令字节()
|
|
|
+ {
|
|
|
+ var custom = new CustomProtocol();
|
|
|
+ custom.CreateWriteEEPROMLightNum(80);
|
|
|
+
|
|
|
+ // 5E 12(WRITE_EEPROM) 00 0C(LTH) 00 05 34(地址) 50 00 00 00(小端80=0x50) 00→ORC=前11字节和=0x105&0xFF=0x05
|
|
|
+ var expected = new byte[] { 0x5E, 0x12, 0x00, 0x0C, 0x00, 0x05, 0x34, 0x50, 0x00, 0x00, 0x00, 0x05 };
|
|
|
+ Assert.Equal(expected, custom.sendBuffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 交叉校验:写排气阀时间 与 control 已通过的写进气阀时间(地址 00 03 0c)仅"地址低字节"不同(0x08 vs 0x0c)。
|
|
|
+ /// 锚定到既有已验证 builder,防止地址表整体写错。
|
|
|
+ /// </summary>
|
|
|
+ [Fact]
|
|
|
+ public void 写排气阀与写进气阀命令仅地址低字节不同()
|
|
|
+ {
|
|
|
+ var vent = new CustomProtocol();
|
|
|
+ vent.CreateWriteEEPROOpenVentTimeCommand(5);
|
|
|
+ var intake = new CustomProtocol();
|
|
|
+ intake.CreateWriteEEPROOpenIntakeTimeCommand(5);
|
|
|
+
|
|
|
+ Assert.Equal(intake.sendBuffer.Length, vent.sendBuffer.Length);
|
|
|
+ Assert.Equal((byte)0x0c, intake.sendBuffer[6]); // 进气阀地址低字节
|
|
|
+ Assert.Equal((byte)0x08, vent.sendBuffer[6]); // 排气阀地址低字节
|
|
|
+ // 除地址低字节(idx6)与末位校验外,其余字节应完全相同
|
|
|
+ for (int i = 0; i < vent.sendBuffer.Length - 1; i++)
|
|
|
+ {
|
|
|
+ if (i == 6) continue;
|
|
|
+ Assert.Equal(intake.sendBuffer[i], vent.sendBuffer[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|