OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
FormattedCardData.cs
1using System;
2using System.Linq;
3using System.Text;
4
7
9
14{
22 public FormattedCardData(byte readerNumber, ReadDirection direction, string data)
23 {
24 ReaderNumber = readerNumber;
25 ReadDirection = direction;
26 Data = data;
27 Lenght = (ushort)data.Length;
28 }
29
33 public byte ReaderNumber { get; }
34
39
43 public ushort Lenght { get; }
44
48 public string Data { get; }
49
51 public override byte Code => (byte)ReplyType.FormattedReaderData;
52
54 public override ReadOnlySpan<byte> SecurityControlBlock()
55 {
56 return SecurityBlock.ReplyMessageWithDataSecurity;
57 }
58
64 public static FormattedCardData ParseData(ReadOnlySpan<byte> data)
65 {
66 var dataArray = data.ToArray();
67 var readerNumber = data[0];
68 var reverse = (data[1] & 0x01) == 1;
69 var numberOfBytes = data[2];
70
71 if (reverse)
72 {
73 dataArray = dataArray.Skip(3).Take(numberOfBytes).Reverse().ToArray();
74 }
75 else
76 {
77 dataArray = dataArray.Skip(3).Take(numberOfBytes).ToArray();
78 }
79
80 var cardData = Encoding.ASCII.GetString(dataArray);
81
82 return new FormattedCardData(readerNumber, (ReadDirection)data[1], cardData);
83 }
84
86 public override string ToString()
87 {
88 var build = new StringBuilder();
89 build.AppendLine($" Reader Number: {ReaderNumber}");
90 build.AppendLine($"Read Direction: {ReadDirection}");
91 build.AppendLine($" Data Length: {Lenght}");
92 build.AppendLine($" Data: {Data}");
93 return build.ToString();
94 }
95
97 public override byte[] BuildData()
98 {
99 var lenght = 3 + Data.Length;
100 var buffer = new byte[lenght];
101 buffer[0] = ReaderNumber;
102 buffer[1] = (byte)ReadDirection;
103 buffer[2] = (byte)Data.Length;
104 Encoding.ASCII.GetBytes(Data).CopyTo(buffer, 3);
105
106 return buffer;
107 }
108}
109
113public enum ReadDirection
114{
118 Forward = 0x00,
122 Reverse = 0x01
123}
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
FormattedCardData(byte readerNumber, ReadDirection direction, string data)
Creates a new instance of FormattedCardData.
override ReadOnlySpan< byte > SecurityControlBlock()
static FormattedCardData ParseData(ReadOnlySpan< byte > data)
Parses the data.
ReadDirection ReadDirection
The direction for reading the formatted card data.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
Definition ReplyType.cs:7
ReadDirection
The direction for reading the formatted card data.