Files
tbf/TBF/Rig/ControlBoard/Uni/SwitchCountersData.cs
T

70 lines
3.6 KiB
C#

///
/// Copyright (c) 2021 Sensus Slovensko a.s.
///
namespace TBF.Rig.ControlBoard.Uni
{
public class SwitchCountersData
{
public const int MessageLen = 303;
public const byte MessageCode = (byte)'C';
// TODO: Implement member variables
SwitchCountersData()
{
}
/// <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 SwitchCountersData GetData(byte[] rcvdData, int offset)
{
var data = new SwitchCountersData();
// TODO
return data;
}
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
return " [---- Switch counters data --------------------------------------------------------------------------------------------------------------------------" +
// 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 100 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 150 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 200 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 250 51 52 53 54
"---------- Sum]";
}
}
}