OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
ReaderLedControls.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
7
9{
14 {
19 public ReaderLedControls(IEnumerable<ReaderLedControl> controls)
20 {
21 if (controls == null) throw new ArgumentNullException(nameof(controls));
22
23 Controls = controls.ToArray();
24
25 if (!Controls.Any())
26 {
27 throw new Exception("Requires at least one output control");
28 }
29 }
30
34 public IEnumerable<ReaderLedControl> Controls { get; }
35
37 public override CommandType CommandType => CommandType.LEDControl;
38
40 public override byte Code => (byte)CommandType;
41
43 public override ReadOnlySpan<byte> SecurityControlBlock()
44 {
45 return SecurityBlock.CommandMessageWithDataSecurity;
46 }
47
49 public override byte[] BuildData()
50 {
51 var data = new List<byte>();
52 foreach (var readerLedControl in Controls)
53 {
54 data.AddRange(readerLedControl.BuildData());
55 }
56
57 return data.ToArray();
58 }
59
63 public static ReaderLedControls ParseData(ReadOnlySpan<byte> payloadData)
64 {
65 return new ReaderLedControls(SplitData(14, data => ReaderLedControl.ParseData(data), payloadData));
66 }
67
69 public override string ToString()
70 {
71 var sb = new StringBuilder();
72 sb.AppendLine($"LED Count: {Controls.Count()}");
73 foreach (var control in Controls)
74 {
75 sb.AppendLine($" Reader #: {control.ReaderNumber}");
76 sb.AppendLine($" LED #: {control.LedNumber}");
77 sb.AppendLine($"Temp Mode: {control.TemporaryMode}");
78 sb.AppendLine($" On Time: {control.TemporaryOnTime} (100ms)");
79 sb.AppendLine($" Off Time: {control.TemporaryOffTime} (100ms)");
80 sb.AppendLine($" On Color: {control.TemporaryOnColor}");
81 sb.AppendLine($"Off Color: {control.TemporaryOffColor}");
82 sb.AppendLine($" Timer: {control.TemporaryTimer} (100ms)");
83 }
84 return sb.ToString();
85 }
86 }
87}
Contains standard Security Control Block data that can be used when building messages.
Base class representing a payload of a PD command message.
Contains data to control the color of a single LED on a PD.
static ReaderLedControl ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
static ReaderLedControls ParseData(ReadOnlySpan< byte > payloadData)
Parses the message payload bytes.
IEnumerable< ReaderLedControl > Controls
One or more commands to control the LEDs of a PD.
ReaderLedControls(IEnumerable< ReaderLedControl > controls)
Initializes a new instance of the ReaderLedControls class.
override ReadOnlySpan< byte > SecurityControlBlock()