/// /// 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() { } /// /// Returns tru when receive data fit the message frame /// /// Received data /// Cumulative sums of received data bytes /// Received bytes count /// Offset of the message /// true when frame fits data 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); } /// /// Proces received data /// /// Received data /// Offset of the message 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; } } }