OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
ExtendedRead.cs
1using System;
2using System.Text;
5
7{
17 {
25 public ExtendedRead(byte mode, byte pReply, byte[] pData)
26 {
27 Mode = mode;
28 PReply = pReply;
29 PData = pData ?? throw new ArgumentNullException(nameof(pData));
30 }
31
35 public byte Mode { get; }
36
40 public byte PReply { get; }
41
45 public byte[] PData { get; }
46
48 public override byte Code => (byte)ReplyType.ExtendedRead;
49
51 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.ReplyMessageWithDataSecurity;
52
54 public override byte[] BuildData()
55 {
56 var buffer = new byte[2 + PData.Length];
57 buffer[0] = Mode;
58 buffer[1] = PReply;
59 Array.Copy(PData, 0, buffer, 2, PData.Length);
60 return buffer;
61 }
62
72 public static ExtendedRead ParseData(ReadOnlySpan<byte> data)
73 {
74 byte mode = data.Length > 0 ? data[0] : (byte)0;
75 byte pReply = data.Length > 1 ? data[1] : (byte)0;
76 byte[] pData = data.Length > 2 ? data.Slice(2).ToArray() : [];
77 return new ExtendedRead(mode, pReply, pData);
78 }
79
85 public static ExtendedRead ModeZeroSettingReport(byte currentMode, bool enabled) =>
86 new(0, 1, [currentMode, (byte)(enabled ? 1 : 0)]);
87
92 public static ExtendedRead CardPresent(byte readerNumber) =>
93 new(1, 1, [readerNumber]);
94
101 public static ExtendedRead ApduResponse(byte readerNumber, byte[] response)
102 {
103 if (response == null) throw new ArgumentNullException(nameof(response));
104
105 var data = new byte[response.Length + 1];
106 data[0] = readerNumber;
107 Array.Copy(response, 0, data, 1, response.Length);
108 return new ExtendedRead(1, 1, data);
109 }
110
115 public static ExtendedRead SessionTerminated(byte readerNumber) =>
116 new(1, 2, [readerNumber]);
117
119 public override string ToString()
120 {
121 var sb = new StringBuilder();
122 sb.AppendLine($" Mode: {Mode}");
123 sb.AppendLine($"PReply: {PReply}");
124 sb.AppendLine($" PData: {BitConverter.ToString(PData)}");
125 return sb.ToString();
126 }
127 }
128}
Contains standard Security Control Block data that can be used when building messages.
Base class representing a payload an OSDP message.
Definition PayloadData.cs:9
static ExtendedRead ModeZeroSettingReport(byte currentMode, bool enabled)
Builds a Mode-0 setting report reply (response to CommandData.ExtendedWrite.ReadModeSetting).
byte Mode
Gets the extended READ/WRITE mode.
static ExtendedRead ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
override ReadOnlySpan< byte > SecurityControlBlock()
byte PReply
Gets the mode-specific reply code.
ExtendedRead(byte mode, byte pReply, byte[] pData)
Initializes a new instance of the ExtendedRead class.
byte[] PData
Gets the reply data.
static ExtendedRead CardPresent(byte readerNumber)
Builds an unsolicited card-present notification on the specified reader.
static ExtendedRead SessionTerminated(byte readerNumber)
Builds a Mode-1 smart-card session-terminated reply.
static ExtendedRead ApduResponse(byte readerNumber, byte[] response)
Builds a Mode-1 APDU response reply.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
Definition ReplyType.cs:7