forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommsStream.cs
51 lines (40 loc) · 1.24 KB
/
CommsStream.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.IO;
namespace MissionPlanner.Comms
{
public class CommsStream : Stream
{
private long _len;
public CommsStream(ICommsSerial comm, long len)
{
CommsSerial = comm;
SetLength(len);
}
public ICommsSerial CommsSerial { get; set; }
public override bool CanRead { get; } = true;
public override bool CanSeek { get; } = false;
public override bool CanWrite { get; } = true;
public override long Length => _len;
public override long Position { get; set; }
public override void Flush()
{
}
public override int Read(byte[] buffer, int offset, int count)
{
var read = CommsSerial.Read(buffer, offset, count);
Position += read;
return read;
}
public override long Seek(long offset, SeekOrigin origin)
{
return Position;
}
public override void SetLength(long value)
{
_len = value;
}
public override void Write(byte[] buffer, int offset, int count)
{
CommsSerial.Write(buffer, offset, count);
}
}
}