Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
///
|
||||
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TBF.Rig.ControlBoard.Uni
|
||||
{
|
||||
class ValveMoveMsg
|
||||
{
|
||||
public int PayloadLen { get { return 38; } }
|
||||
public byte MessageCode { get { return 0x20; } }
|
||||
|
||||
Command cmd;
|
||||
int regValveNr;
|
||||
|
||||
public ValveMoveMsg(Command cmd, int regValveNr)
|
||||
{
|
||||
this.cmd = cmd;
|
||||
this.regValveNr = regValveNr;
|
||||
}
|
||||
|
||||
public byte[] GetMessage()
|
||||
{
|
||||
byte[] message = new byte[PayloadLen + 5]; /// headed 3 bytes, checksum 2 bytes
|
||||
|
||||
/// Header (3 bytes)
|
||||
message[0] = Const.STX;
|
||||
message[1] = 1; /// Control board addres
|
||||
message[2] = (byte)PayloadLen; /// Payload length
|
||||
|
||||
/// Command
|
||||
message[3] = MessageCode;
|
||||
message[4] = (byte)cmd;
|
||||
|
||||
/// ...
|
||||
|
||||
message[40] = 0;
|
||||
Debug.Assert(40 == PayloadLen + 2);
|
||||
|
||||
/// Checksum (2 bytes)
|
||||
int checksum = 0;
|
||||
for (int i = 1; i < PayloadLen + 3; i++) checksum += message[i];
|
||||
message[PayloadLen + 3] = (byte)(checksum & 0xFF);
|
||||
message[PayloadLen + 4] = (byte)((checksum >> 8) & 0xFF);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("ValveMoveMsg : {0}", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user