/// /// Copyright (c) 2021 Sensus Slovensko a.s. /// namespace TBF.Rig.ControlBoard.Uni { public class DivTransitionData { public const int MessageLen = 255; public const byte MessageCode = (byte)'K'; /// Diverter transition data const int samplesCount = 245; int DiverterTime_ms; byte[] CurveRaw; DivTransitionData() { CurveRaw = new byte[samplesCount]; } /// /// 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 DivTransitionData GetData(byte[] rcvdData, int offset) { var data = new DivTransitionData(); data.DiverterTime_ms = Const.DivTimeResolution * rcvdData[offset + 4]; for (int i = 0; i < samplesCount; i++) { data.CurveRaw[i] = rcvdData[offset + 6 + i]; } return data; } } }