OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
CommunicationConfiguration.cs
1using System;
2using System.Linq;
3using System.Text;
6
8
13{
19 public CommunicationConfiguration(byte address, int baudRate)
20 {
21 Address = address;
22 BaudRate = baudRate;
23 }
24
28 public byte Address { get; }
29
33 public int BaudRate { get; }
34
36 public override CommandType CommandType => CommandType.CommunicationSet;
37
39 public override byte Code => (byte)CommandType;
40
42 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.CommandMessageWithDataSecurity;
43
45 public override byte[] BuildData()
46 {
47 var baudRateBytes = Message.ConvertIntToBytes(BaudRate).ToArray();
48
49 return new[]
50 {
51 Address,
52 baudRateBytes[0],
53 baudRateBytes[1],
54 baudRateBytes[2],
55 baudRateBytes[3]
56 };
57 }
58
62 public static CommunicationConfiguration ParseData(ReadOnlySpan<byte> data)
63 {
64 return new CommunicationConfiguration(data[0], Message.ConvertBytesToInt(data.Slice(1, 4).ToArray()));
65 }
66
68 public override string ToString()
69 {
70 var build = new StringBuilder();
71 build.AppendLine($" Address: {Address}");
72 build.AppendLine($"Baud Rate: {BaudRate}");
73
74 return build.ToString();
75 }
76}
A base message class for sending or replying.
Definition Message.cs:12
Contains standard Security Control Block data that can be used when building messages.
Base class representing a payload of a PD command message.
static CommunicationConfiguration ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.
CommunicationConfiguration(byte address, int baudRate)
Initializes a new instance of the CommunicationConfiguration class.
override ReadOnlySpan< byte > SecurityControlBlock()