OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
FileTransferStatus.cs
1using System;
2using System.Linq;
3using System.Text;
6
8{
18 public class FileTransferStatus : PayloadData
19 {
23 private const int DataLength = 7;
24
28 [Flags]
29 public enum ControlFlags
30 {
35 None = 0x0,
36
41
46
51 }
52
95
99 private FileTransferStatus()
100 {
101 }
102
118 ushort requestedDelay = 0, ushort updateMessageMaximum = 0)
119 {
120 Detail = detail;
121 Action = action;
122 RequestedDelay = requestedDelay;
123 UpdateMessageMaximum = updateMessageMaximum;
124 }
125
127 public ControlFlags Action { get; private set; }
128
130 public ushort RequestedDelay { get;private set; }
131
133 public StatusDetail Detail { get; private set; }
134
136 public ushort UpdateMessageMaximum { get; private set; }
137
139 public override byte Code => (byte)ReplyType.FileTransferStatus;
140
142 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.ReplyMessageWithDataSecurity;
143
145 public override byte[] BuildData()
146 {
147 var data = new byte[DataLength];
148 data[0] = (byte)Action;
149
150 var delay = Message.ConvertShortToBytes(RequestedDelay);
151 data[1] = delay[0];
152 data[2] = delay[1];
153
154 // StatusDetail travels as a signed little-endian short, so the enum value is reinterpreted
155 // rather than clamped; negative values are the PD's error codes.
156 var detail = Message.ConvertShortToBytes(unchecked((ushort)(short)Detail));
157 data[3] = detail[0];
158 data[4] = detail[1];
159
160 var messageMaximum = Message.ConvertShortToBytes(UpdateMessageMaximum);
161 data[5] = messageMaximum[0];
162 data[6] = messageMaximum[1];
163
164 return data;
165 }
166
170 internal static FileTransferStatus ParseData(ReadOnlySpan<byte> data)
171 {
172 var dataArray = data.ToArray();
173 if (dataArray.Length != DataLength)
174 {
175 throw new Exception("Invalid size for the data");
176 }
177
178 return new FileTransferStatus
179 {
180 Action = (ControlFlags)dataArray[0],
181 RequestedDelay = Message.ConvertBytesToUnsignedShort(dataArray.Skip(1).Take(2).ToArray(), true),
182 Detail = SetStatusDetailDefault(Message.ConvertBytesToShort(dataArray.Skip(3).Take(2).ToArray(), true)),
183 UpdateMessageMaximum = Message.ConvertBytesToUnsignedShort(dataArray.Skip(5).Take(2).ToArray(), true)
184 };
185 }
186
188 public override string ToString()
189 {
190 var build = new StringBuilder();
191 build.AppendLine($" Action: {Action:G}");
192 build.AppendLine($" Requested Delay: {RequestedDelay}");
193 build.AppendLine($" Status Detail: {Detail}");
194 build.AppendLine($" Update Message Max: {UpdateMessageMaximum}");
195
196 return build.ToString();
197 }
198
199 private static StatusDetail SetStatusDetailDefault(short value)
200 {
201 return value switch
202 {
203 < -3 => StatusDetail.UnknownError,
204 > 3 => StatusDetail.UnknownStatus,
205 _ => (StatusDetail)value
206 };
207 }
208 }
209}
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 an OSDP message.
Definition PayloadData.cs:9
The PD file transfer status sent as a reply.
StatusDetail Detail
Gets the file transfer status.
FileTransferStatus(StatusDetail detail, ControlFlags action=ControlFlags.None, ushort requestedDelay=0, ushort updateMessageMaximum=0)
Initializes a new instance of the FileTransferStatus class to be sent by a PD in reply to an osdp_FIL...
@ None
No control flags set; the PD is dedicated to the file transfer, stays in the secure channel,...
@ Interleave
The ACU may interleave other messages with the file transfer.
@ PollResponseAvailable
A separate poll response is available.
@ LeaveSecureChannel
The ACU shall leave the secure channel for the duration of the file transfer.
ushort RequestedDelay
Gets the request ACU time delay in milliseconds before next osdp_FILETRANSFER command.
override ReadOnlySpan< byte > SecurityControlBlock()
@ FileDataUnacceptable
The file data unacceptable (malformed).
@ RebootingNow
Rebooting now, expect full communications reset.
ushort UpdateMessageMaximum
Gets the alternative maximum message size.
ControlFlags Action
Gets the control flags.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
Definition ReplyType.cs:7