58 lines
2.0 KiB
C#
58 lines
2.0 KiB
C#
///
|
|
/// Copyright (c) 2021 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
namespace TBF.Rig.ControlBoard.Uni
|
|
{
|
|
public class ScopeAnalyzerData
|
|
{
|
|
public const int MessageLen = 1033;
|
|
public const byte MessageCode = (byte)'S';
|
|
|
|
/// Scope analyzer data
|
|
public int KonSc;
|
|
public int ZacSc;
|
|
|
|
ScopeAnalyzerData()
|
|
{
|
|
}
|
|
|
|
/// <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 ScopeAnalyzerData GetData(byte[] rcvdData, int offset)
|
|
{
|
|
var data = new ScopeAnalyzerData();
|
|
|
|
data.KonSc = Convert.ToInt32(rcvdData[4]) + 256 * Convert.ToInt32(rcvdData[5]);
|
|
data.ZacSc = Convert.ToInt32(rcvdData[6]) + 256 * Convert.ToInt32(rcvdData[7]);
|
|
|
|
return data;
|
|
}
|
|
}
|
|
}
|