OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
EchoResponse.cs
1using System;
5
7{
17 {
18 private static readonly byte[] NoData = new byte[0];
19
25 public EchoResponse(byte sequenceNumber, byte[] data)
26 : this(sequenceNumber, EchoStatus.Success, data ?? throw new ArgumentNullException(nameof(data)))
27 {
28 }
29
35 public EchoResponse(byte sequenceNumber, EchoStatus status)
36 : this(sequenceNumber, status, NoData)
37 {
38 }
39
40 private EchoResponse(byte sequenceNumber, EchoStatus status, byte[] data)
41 {
42 SequenceNumber = sequenceNumber;
43 Status = status;
44 Data = status == EchoStatus.Success ? data : NoData;
45 }
46
48 public byte SequenceNumber { get; }
49
51 public EchoStatus Status { get; }
52
54 public byte[] Data { get; }
55
57 public override byte Code => (byte)ReplyType.ManufactureSpecific;
58
60 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.ReplyMessageWithDataSecurity;
61
63 public override byte[] BuildData()
64 {
65 var data = new byte[LineQualityProtocol.EchoHeaderLength + Data.Length];
66 LineQualityProtocol.VendorCodeBytes.CopyTo(data, 0);
68 data[4] = SequenceNumber;
69 data[5] = (byte)Status;
70 data[6] = (byte)Data.Length;
72 return data;
73 }
74
81 public static bool TryParse(ReadOnlySpan<byte> payload, out EchoResponse response)
82 {
83 response = null;
84
85 if (payload.Length < LineQualityProtocol.EchoHeaderLength) return false;
86 if (!LineQualityProtocol.IsLineQualityVendorCode(payload)) return false;
87 if (payload[3] != LineQualityProtocol.EchoCommandId) return false;
88
89 int available = payload.Length - LineQualityProtocol.EchoHeaderLength;
90 int declared = payload[6];
91 if (declared != available) return false;
92
93 var status = (EchoStatus)payload[5];
94 var data = payload.Slice(LineQualityProtocol.EchoHeaderLength, available).ToArray();
95
96 response = new EchoResponse(payload[4], status, data);
97 return true;
98 }
99 }
100}
override ReadOnlySpan< byte > SecurityControlBlock()
EchoStatus Status
Gets the result status.
EchoResponse(byte sequenceNumber, byte[] data)
Initializes a successful Echo Response carrying echoed test data.
byte[] Data
Gets the echoed test data. Always empty when Status is non-zero.
byte SequenceNumber
Gets the echoed test sequence number.
static bool TryParse(ReadOnlySpan< byte > payload, out EchoResponse response)
Attempts to parse an Echo Response from an osdp_MFGREP payload.
EchoResponse(byte sequenceNumber, EchoStatus status)
Initializes a failed Echo Response.
Constants and helpers for the OSDP Line Quality Test Procedure.
static bool IsLineQualityVendorCode(ReadOnlySpan< byte > candidate)
Determines whether the supplied bytes are the reserved line quality vendor code.
const int EchoHeaderLength
Number of bytes preceding the test data in an echo request or response: three vendor code bytes,...
const byte EchoCommandId
Command and reply identifier for the echo exchange.
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
EchoStatus
Status codes returned in an Echo Response, per section 3.7 of the Line Quality Test Procedure.
@ Success
Pattern received and echoed correctly.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
Definition ReplyType.cs:7