OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
DeviceCapability.cs
2using System;
3using System.Collections.Generic;
4using System.Text;
5
7{
11 public class DeviceCapability
12 {
13 private protected DeviceCapability()
14 {
15 }
16
23 public DeviceCapability(CapabilityFunction function, byte compliance, byte numberOf)
24 {
25 Function = function;
26 Compliance = compliance;
27 NumberOf = numberOf;
28 }
29
33 public CapabilityFunction Function { get; private set; }
34
38 public byte Compliance { get; private set; }
39
43 public byte NumberOf { get; private set; }
44
46 public override string ToString()
47 {
48 var sb = new StringBuilder();
49 sb.AppendLine($" Function: {Helpers.SplitCamelCase(Function.ToString())}");
50 sb.AppendLine($"Compliance: {Compliance}");
51 sb.AppendLine($" Number Of: {NumberOf}");
52 return sb.ToString();
53 }
54
55 internal byte[] BuildData()
56 {
57 return [(byte)Function, Compliance, NumberOf];
58 }
59
60 internal static DeviceCapability ParseData(byte[] data)
61 {
62 var func = typeof(CapabilityFunction).IsEnumDefined((int)data[0])
63 ? (CapabilityFunction)data[0]
65
66 if (!_capFactories.TryGetValue(func, out var creator))
67 {
68 creator = () => new DeviceCapability();
69 }
70
71 var cap = creator();
72 cap.Function = func;
73 cap.Compliance = data[1];
74 cap.NumberOf = data[2];
75 return cap;
76 }
77
78 private static Dictionary<CapabilityFunction, Func<DeviceCapability>> _capFactories = new ()
79 {
80 {CapabilityFunction.CommunicationSecurity, () => new CommSecurityDeviceCap() },
81 {CapabilityFunction.ReceiveBufferSize, () => new RcvBuffSizeDeviceCap() },
82 {CapabilityFunction.LargestCombinedMessageSize, () => new LargestCombMsgSizeDeviceCap() }
83 };
84 }
85
89 public abstract class MsgSizeDeviceCap : DeviceCapability
90 {
92 public override string ToString()
93 {
94 var sb = new StringBuilder();
95 sb.AppendLine($" Function: {Helpers.SplitCamelCase(Function.ToString())}");
96 sb.AppendLine($" Size: {Message.ConvertBytesToUnsignedShort(new[] { Compliance, NumberOf })}");
97 return sb.ToString();
98 }
99 }
100
104 public class RcvBuffSizeDeviceCap : MsgSizeDeviceCap;
105
109 public class LargestCombMsgSizeDeviceCap : MsgSizeDeviceCap;
110
114 public class CommSecurityDeviceCap : DeviceCapability
115 {
119 public bool SupportsAes128 { get => (Compliance & 0x01) != 0; }
120
124 public bool UsesDefaultKey { get => (NumberOf & 0x01) != 0; }
125
127 public override string ToString()
128 {
129 var sb = new StringBuilder();
130 sb.AppendLine($" Function: {Helpers.SplitCamelCase(Function.ToString())}");
131 sb.AppendLine($"Supports AES-128: {SupportsAes128}");
132 sb.AppendLine($"Uses Default Key: {UsesDefaultKey}");
133 return sb.ToString();
134 }
135 }
136}
bool SupportsAes128
Flag indicating whether or not PD support AES-128.
bool UsesDefaultKey
Flag indicating whether or not PD is using a default encryption key.
DeviceCapability(CapabilityFunction function, byte compliance, byte numberOf)
Initializes a new instance of DeviceCapability class.
CapabilityFunction Function
Gets the function code.
byte NumberOf
Gets number of objects of this type.
byte Compliance
Gets level of compliance with defined function.
Common base for the device capabilities that identify byte sizes.
CapabilityFunction
Definitions of the capability function codes.