Permalink
Browse files

Fixed the issue with CRC timing.

  • Loading branch information...
LegacyNsfw committed Dec 22, 2018
1 parent d9140ca commit a8263079d6fdbf8f4a42f57b08b2cfe0dd833dbc
@@ -11,6 +11,7 @@ public enum TimeoutScenario
{
Undefined = 0,
ReadProperty,
ReadCrc,
SendKernel,
ReadMemoryBlock,
Maximum,
@@ -224,6 +225,11 @@ protected int GetVpwTimeoutMilliseconds(TimeoutScenario scenario)
packetSize = 50;
break;

case TimeoutScenario.ReadCrc:
// These packets are actually only 15 bytes, but the ReadProperty timeout wasn't enough.
packetSize = 200;
break;

case TimeoutScenario.ReadMemoryBlock:
// Adding 20 bytes to account for the 'read request accepted'
// message that comes before the read payload.
@@ -21,6 +21,16 @@ public class Message
/// </summary>
private byte[] message;

/// <summary>
/// When the message was created.
/// </summary>
private ulong timestamp;

/// <summary>
/// Error code, if applicable.
/// </summary>
private ulong error;

/// <summary>
/// Constructor.
/// </summary>
@@ -32,31 +42,29 @@ public Message(byte[] message)
/// <summary>
/// Constructor.
/// </summary>
public Message(byte[] message, ulong Timestamp, ulong Error)
public Message(byte[] message, ulong timestamp, ulong error)
{
this.message = message;
this._Timestamp = Timestamp;
this._Error = Error;
this.timestamp = timestamp;
this.error = error;
}

/// <summary>
/// When the message was created or recevied.
/// </summary>
private ulong _Timestamp;
public ulong TimeStamp
{
get { return this._Timestamp; }
set { this._Timestamp = value; }
get { return this.timestamp; }
set { this.timestamp = value; }
}

/// <summary>
/// The error associated with creating or receiving this message.
/// </summary>
private ulong _Error;
public ulong Error
{
get { return this.Error; }
set { this.Error = value; }
get { return this.error; }
set { this.error = value; }
}

/// <summary>
@@ -480,7 +480,6 @@ internal Response<UInt32> ParseFlashMemoryType(Message responseMessage)
internal Response<UInt32> ParseCrc(Message responseMessage, UInt32 address, UInt32 size)
{
ResponseStatus status;

byte[] expected = new byte[]
{
0x6C,
@@ -94,8 +94,6 @@ public async Task<bool> TestKernel(bool kernelRunning, bool recoveryMode, Cancel

private async Task InvestigateCrc(CancellationToken cancellationToken)
{
await this.device.SetTimeout(TimeoutScenario.Maximum);

IList<MemoryRange> ranges = this.GetMemoryRanges(0x00894471);

logger.AddUserMessage("Requesting CRCs from PCM...");
@@ -104,8 +102,14 @@ private async Task InvestigateCrc(CancellationToken cancellationToken)
this.device.ClearMessageQueue();
bool success = false;
UInt32 crc = 0;
await this.device.SetTimeout(TimeoutScenario.ReadProperty);
int retryDelay = 500;
await this.device.SetTimeout(TimeoutScenario.ReadCrc);

// You might think that a shorter retry delay would speed things up,
// but 1500ms delay gets CRC results in about 3.5 seconds.
// A 1000ms delay resulted in 4+ second CRC responses, and a 750ms
// delay resulted in 5 second CRC responses. The PCM needs to spend
// its time caculating CRCs rather than responding to messages.
int retryDelay = 1500;
Message query = this.messageFactory.CreateCrcQuery(range.Address, range.Size);
for (int attempts = 0; attempts < 100; attempts++)
{
@@ -71,17 +71,21 @@ private static void DecodeFromSerial(string portName)
SendCommand(port, "AT H 1"); // show headers
SendCommand(port, "AT S 0"); // no spaces
SendCommand(port, "AT MA"); // start monitoring

string line = string.Empty;
DateTime lastMessage = DateTime.Now;
while (line != null)
{
line = port.ReadLine();
UInt32 elapsed = (UInt32) DateTime.Now.Subtract(lastMessage).TotalMilliseconds;
lastMessage = DateTime.Now;

if (line == null)
{
break;
}

if (line == "BUFFER FULL")
if ((line == "BUFFER FULL") || (line == "OUT OF MEMORY"))
{
SendCommand(port, "AT MA", false);
}
@@ -93,7 +97,17 @@ private static void DecodeFromSerial(string portName)
}

line = Program.Decode(line);
Console.WriteLine(line);
Console.WriteLine(string.Format("{0:D4} {1}", elapsed, line));

/* while (Console.KeyAvailable)
{
Console.ReadKey();
Console.WriteLine("Key pressed. Re-opening port.");
port.Close();
port.NewLine = "\r";
port.Open();
}
*/
}
}

0 comments on commit a826307

Please sign in to comment.