add ACK
This commit is contained in:
parent
931b866ea9
commit
3716ba482f
2 changed files with 24 additions and 2 deletions
|
@ -10,6 +10,7 @@ namespace CollabVMAgent.Protocol
|
|||
}
|
||||
public enum ProtocolOperation : ushort
|
||||
{
|
||||
UploadFile = 0
|
||||
UploadFile = 0,
|
||||
ACK = 1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using CollabVMAgent.Protocol;
|
||||
using MsgPack.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -12,6 +14,7 @@ namespace CollabVMAgent
|
|||
{
|
||||
public class VirtIOSerial : IDisposable
|
||||
{
|
||||
MessagePackSerializer serializer = MessagePackSerializer.Get<ProtocolMessage>();
|
||||
const int READ_INTERVAL = 3000;
|
||||
const int COPY_BUFFER_SIZE = 4096;
|
||||
static Guid GUID_VIOSERIAL_PORT = new Guid(0x6fde7521, 0x1b65, 0x48ae, 0xb6, 0x28, 0x80, 0xbe, 0x62, 0x1, 0x60, 0x26);
|
||||
|
@ -41,6 +44,19 @@ namespace CollabVMAgent
|
|||
uint wrote;
|
||||
return WriteFile(viohnd, data, (uint)data.Length, out wrote, IntPtr.Zero);
|
||||
}
|
||||
|
||||
public bool WriteMsg(ProtocolMessage msg)
|
||||
{
|
||||
byte[] message;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
serializer.Pack(ms, msg);
|
||||
message = ms.ToArray();
|
||||
}
|
||||
byte[] header = BitConverter.GetBytes((UInt32)message.Length);
|
||||
if (!Write(header)) return false;
|
||||
return Write(message);
|
||||
}
|
||||
|
||||
void ReadLoop()
|
||||
{
|
||||
|
@ -93,6 +109,11 @@ namespace CollabVMAgent
|
|||
position += read;
|
||||
}
|
||||
byte[] payload = ms.ToArray();
|
||||
if (this.WriteMsg(new ProtocolMessage
|
||||
{
|
||||
Operation = ProtocolOperation.ACK
|
||||
}))
|
||||
Console.WriteLine("Wrote ACK to serial.");
|
||||
ms.Dispose();
|
||||
Data.Invoke(this, new TypedEventArgs<byte[]>(payload));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue