tbf/TBF/Rig/ControlBoard/Uni/ExtremaData.cs
2021-03-05 16:12:24 +01:00

54 lines
1.8 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
namespace TBF.Rig.ControlBoard.Uni
{
public class ExtremaData
{
public const int MessageLen = 253;
public const byte MessageCode = (byte)'E';
// TODO: Implement member variables
ExtremaData()
{
}
/// <summary>
/// Returns tru when receive data fit the message frame
/// </summary>
/// <param name="rcvdData">Received data</param>
/// <param name="cumulativeSums">Cumulative sums of received data bytes</param>
/// <param name="rcvdBytesCount">Received bytes count</param>
/// <param name="offset">Offset of the message</param>
/// <returns>true when frame fits data</returns>
public static bool FrameFitsData(byte[] rcvdData, int[] cumulativeSums, int rcvdBytesCount, int offset)
{
if (offset + MessageLen > rcvdBytesCount) return false;
int checksum = cumulativeSums[offset + MessageLen - 3] - cumulativeSums[offset];
return rcvdData[offset] == Const.STX &&
rcvdData[offset + 1] == 0x01 &&
rcvdData[offset + 2] == ((MessageLen - 5) & 0xFF) &&
rcvdData[offset + 3] == MessageCode &&
rcvdData[offset + MessageLen - 2] == (checksum & 0xFF) &&
rcvdData[offset + MessageLen - 1] == ((checksum >> 8) & 0xFF);
}
/// <summary>
/// Proces received data
/// </summary>
/// <param name="rcvdData">Received data</param>
/// <param name="offset">Offset of the message</param>
public static ExtremaData GetData(byte[] rcvdData, int offset)
{
var data = new ExtremaData();
// TODO
return data;
}
}
}