From fc4a84e0553b71ea2122d8d05828d61ce84656b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 27 May 2021 10:35:19 +0100 Subject: [PATCH 1/2] Improve handling of WP request execution - Idle check is now decreased to 50ms. - Add code to prevent a request from waiting forever for the controller to be idle. - Request time stamp is now added even for failed requests, thus allowing the request to be remove from the queue in any event. --- .../WireProtocol/Controller.cs | 2 +- .../WireProtocol/WireProtocolRequest.cs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Controller.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Controller.cs index 9a0ef98a..1936f006 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Controller.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Controller.cs @@ -59,7 +59,7 @@ internal set public bool IsIdle() { - return (DateTime.UtcNow - _lastActivity).TotalMilliseconds > 100; + return (DateTime.UtcNow - _lastActivity).TotalMilliseconds > 50; } public bool Send(MessageRaw raw) diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/WireProtocolRequest.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/WireProtocolRequest.cs index ac967b1b..8e289f0f 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/WireProtocolRequest.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/WireProtocolRequest.cs @@ -40,10 +40,23 @@ public WireProtocolRequest(OutgoingMessage outgoingMessage, int millisecondsTime internal bool PerformRequest(IController controller) { + const int sleepTimeMs = 10; + int attemptsCount = 10000 / sleepTimeMs; + // wait for controller to be idle - while(!controller.IsIdle()) + while ( + !controller.IsIdle() && + attemptsCount > 0) { Thread.Sleep(10); + + attemptsCount--; + } + + if(attemptsCount == 0) + { + // timeout waiting for idle controller + return false; } Debug.WriteLine($"Performing request"); @@ -67,6 +80,9 @@ internal bool PerformRequest(IController controller) return true; } + // store start time + RequestTimestamp = DateTime.Now; + return false; } From ba47286b304e5dceb87270eb73b2edd89d84cc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Thu, 27 May 2021 10:38:25 +0100 Subject: [PATCH 2/2] Fix setting debug execution conditions - Was returning true even if the set operation failed. --- .../WireProtocol/Engine.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs index 1ec8e913..356700e8 100644 --- a/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs +++ b/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/Engine.cs @@ -453,10 +453,7 @@ public bool UpdateDebugFlags() stateFlagsToSet |= Commands.DebuggingExecutionChangeConditions.State.DebuggerQuiet; } - SetExecutionMode(stateFlagsToSet, 0); - - // done here - return true; + return SetExecutionMode(stateFlagsToSet, 0); } // device isn't connected