mirror of
https://github.com/pleonex/NitroDebugger.git
synced 2025-06-19 05:35:32 -04:00
Store last command sent for context in reply converter
This commit is contained in:
parent
5951284dfa
commit
4adfb24542
@ -182,7 +182,8 @@ namespace UnitTests
|
|||||||
byte[] expected = new byte[] { 0xCA, 0xFE, 0xBE, 0xBE, 0x00, 0x10, 0x20 };
|
byte[] expected = new byte[] { 0xCA, 0xFE, 0xBE, 0xBE, 0x00, 0x10, 0x20 };
|
||||||
string dataString = BitConverter.ToString(expected).Replace("-", "");
|
string dataString = BitConverter.ToString(expected).Replace("-", "");
|
||||||
|
|
||||||
ReplyPacket reply = ReplyPacketFactory.CreateReplyPacket(dataString);
|
ReadMemoryCommand readMemory = new ReadMemoryCommand(0x00, 0x00);
|
||||||
|
ReplyPacket reply = ReplyPacketFactory.CreateReplyPacket(dataString, readMemory);
|
||||||
|
|
||||||
Assert.IsInstanceOf<DataReply>(reply);
|
Assert.IsInstanceOf<DataReply>(reply);
|
||||||
Assert.AreEqual(expected, ((DataReply)reply).GetData());
|
Assert.AreEqual(expected, ((DataReply)reply).GetData());
|
||||||
|
@ -46,7 +46,7 @@ namespace NitroDebugger.RSP
|
|||||||
return TextEncoding.GetBytes(binPacket.ToString());
|
return TextEncoding.GetBytes(binPacket.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ReplyPacket FromBinary(byte[] data)
|
public static ReplyPacket FromBinary(byte[] data, CommandPacket commandSent = null)
|
||||||
{
|
{
|
||||||
if (!ValidateBinary(data))
|
if (!ValidateBinary(data))
|
||||||
throw new FormatException("[BIN] Invalid packet");
|
throw new FormatException("[BIN] Invalid packet");
|
||||||
@ -61,7 +61,7 @@ namespace NitroDebugger.RSP
|
|||||||
if (receivedChecksum != calculatedChecksum.ToString("x2"))
|
if (receivedChecksum != calculatedChecksum.ToString("x2"))
|
||||||
throw new FormatException("[BIN] Invalid checksum");
|
throw new FormatException("[BIN] Invalid checksum");
|
||||||
|
|
||||||
return ReplyPacketFactory.CreateReplyPacket(packetData);
|
return ReplyPacketFactory.CreateReplyPacket(packetData, commandSent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ValidateBinary(byte[] data)
|
private static bool ValidateBinary(byte[] data)
|
||||||
|
@ -36,6 +36,7 @@ namespace NitroDebugger.RSP
|
|||||||
|
|
||||||
private Session session;
|
private Session session;
|
||||||
private CancellationTokenSource cts;
|
private CancellationTokenSource cts;
|
||||||
|
private CommandPacket lastCommandSent;
|
||||||
|
|
||||||
public Presentation(string hostname, int port)
|
public Presentation(string hostname, int port)
|
||||||
{
|
{
|
||||||
@ -50,6 +51,7 @@ namespace NitroDebugger.RSP
|
|||||||
|
|
||||||
public void SendCommand(CommandPacket command)
|
public void SendCommand(CommandPacket command)
|
||||||
{
|
{
|
||||||
|
this.lastCommandSent = command;
|
||||||
this.SendData(PacketBinConverter.ToBinary(command));
|
this.SendData(PacketBinConverter.ToBinary(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ namespace NitroDebugger.RSP
|
|||||||
try {
|
try {
|
||||||
// Get data
|
// Get data
|
||||||
byte[] packet = this.session.ReadPacket(PacketSeparator);
|
byte[] packet = this.session.ReadPacket(PacketSeparator);
|
||||||
response = PacketBinConverter.FromBinary(packet);
|
response = PacketBinConverter.FromBinary(packet, lastCommandSent);
|
||||||
|
|
||||||
// Send ACK
|
// Send ACK
|
||||||
this.session.Write(RawPacket.Ack);
|
this.session.Write(RawPacket.Ack);
|
||||||
|
@ -26,7 +26,7 @@ namespace NitroDebugger.RSP
|
|||||||
{
|
{
|
||||||
public static class ReplyPacketFactory
|
public static class ReplyPacketFactory
|
||||||
{
|
{
|
||||||
public static ReplyPacket CreateReplyPacket(string data)
|
public static ReplyPacket CreateReplyPacket(string data, CommandPacket commandSent = null)
|
||||||
{
|
{
|
||||||
if (data == "OK")
|
if (data == "OK")
|
||||||
return new OkReply();
|
return new OkReply();
|
||||||
@ -37,7 +37,7 @@ namespace NitroDebugger.RSP
|
|||||||
if (data.Length == 3 && data[0] == 'E')
|
if (data.Length == 3 && data[0] == 'E')
|
||||||
return new ErrorReply(Convert.ToInt32(data.Substring(1), 16));
|
return new ErrorReply(Convert.ToInt32(data.Substring(1), 16));
|
||||||
|
|
||||||
if (data.Length % 2 == 0) {
|
if (commandSent is ReadMemoryCommand) {
|
||||||
try {
|
try {
|
||||||
byte[] dataBytes = Enumerable.Range(0, data.Length / 2)
|
byte[] dataBytes = Enumerable.Range(0, data.Length / 2)
|
||||||
.Select(i => data.Substring(i * 2, 2))
|
.Select(i => data.Substring(i * 2, 2))
|
||||||
|
Loading…
Reference in New Issue
Block a user