OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
Control.cs
1namespace OSDP.Net.Messages
2{
3 internal class Control
4 {
5 private readonly bool _hasSecurityControlBlock;
6
7 public Control(byte sequence, bool useCrc, bool hasSecurityControlBlock)
8 {
9 Sequence = sequence;
10 UseCrc = useCrc;
11 _hasSecurityControlBlock = hasSecurityControlBlock;
12 }
13
14 public byte Sequence { get; private set; }
15
16 public bool UseCrc { get; }
17
18 public bool HasSecurityControlBlock => !IsSendingMultiMessageNoSecureChannel && _hasSecurityControlBlock;
19
20 public byte ControlByte =>
21 (byte)(Sequence & 0x03 | (UseCrc ? 0x04 : 0) | (HasSecurityControlBlock ? 0x08 : 0));
22
23 public bool IsSendingMultiMessageNoSecureChannel { get; set; }
24
25 public void IncrementSequence(byte sequence)
26 {
27 sequence++;
28 if (sequence > 3)
29 {
30 sequence = 1;
31 }
32
33 Sequence = sequence;
34 }
35
36 public void ResetSequence()
37 {
38 Sequence = 0;
39 }
40 }
41}