mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add NOP packet.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
namespace DiscImageChef.Devices.Remote
|
||||
{
|
||||
public enum DicPacketType : byte
|
||||
public enum DicPacketType : sbyte
|
||||
{
|
||||
Nop = -1,
|
||||
Hello = 1,
|
||||
CommandListDevices = 2,
|
||||
ResponseListDevices = 3
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace DiscImageChef.Devices.Remote
|
||||
{
|
||||
public class Remote : IDisposable
|
||||
{
|
||||
private readonly Socket _socket;
|
||||
private readonly string _host;
|
||||
private readonly Socket _socket;
|
||||
|
||||
public Remote(string host)
|
||||
{
|
||||
@@ -54,19 +54,38 @@ namespace DiscImageChef.Devices.Remote
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
byte[] buf;
|
||||
|
||||
if (hdr.packetType != DicPacketType.Hello)
|
||||
{
|
||||
if (hdr.packetType != DicPacketType.Nop)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Expected Hello Packet, got packet type {0}...", hdr.packetType);
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
buf = new byte[hdr.len];
|
||||
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
|
||||
|
||||
if (len < buf.Length)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Could not read from the network...");
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
var nop = Marshal.ByteArrayToStructureLittleEndian<DicPacketNop>(buf);
|
||||
|
||||
DicConsole.ErrorWriteLine($"{nop.reason}");
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
if (hdr.version != Consts.PacketVersion)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Unrecognized packet version...");
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
var buf = new byte[hdr.len];
|
||||
buf = new byte[hdr.len];
|
||||
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
|
||||
|
||||
if (len < buf.Length)
|
||||
@@ -173,12 +192,29 @@ namespace DiscImageChef.Devices.Remote
|
||||
}
|
||||
|
||||
if (hdr.packetType != DicPacketType.ResponseListDevices)
|
||||
{
|
||||
if (hdr.packetType != DicPacketType.Nop)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Expected List Devices Response Packet, got packet type {0}...",
|
||||
hdr.packetType);
|
||||
return new DeviceInfo[0];
|
||||
}
|
||||
|
||||
buf = new byte[hdr.len];
|
||||
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
|
||||
|
||||
if (len < buf.Length)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Could not read from the network...");
|
||||
return new DeviceInfo[0];
|
||||
}
|
||||
|
||||
var nop = Marshal.ByteArrayToStructureLittleEndian<DicPacketNop>(buf);
|
||||
|
||||
DicConsole.ErrorWriteLine($"{nop.reason}");
|
||||
return new DeviceInfo[0];
|
||||
}
|
||||
|
||||
if (hdr.version != Consts.PacketVersion)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Unrecognized packet version...");
|
||||
|
||||
@@ -53,4 +53,17 @@ namespace DiscImageChef.Devices.Remote
|
||||
public readonly DicPacketHeader hdr;
|
||||
public readonly ushort devices;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
||||
public struct DicPacketNop
|
||||
{
|
||||
public DicPacketHeader hdr;
|
||||
public byte reasonCode;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
|
||||
public readonly byte[] spare;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
||||
public string reason;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user