From 28044d9e74ce1c544dbd76cb35c3fb6055854ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 3 Nov 2017 12:56:29 +0000 Subject: [PATCH] Work on MessageReassembler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add code to set state machine to initialized state in case the class is reused in a subsequent call - add code to ProcessMessage to account for null requests Signed-off-by: José Simões --- .../WireProtocol/MessageReassembler.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/MessageReassembler.cs b/source/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/MessageReassembler.cs index 892a73ca..bbcf7492 100644 --- a/source/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/MessageReassembler.cs +++ b/source/nanoFramework.Tools.DebugLibrary.Shared/WireProtocol/MessageReassembler.cs @@ -189,6 +189,10 @@ internal async Task ProcessAsync(CancellationToken cancellation // FIXME // evaluate the purpose of this reply back to the nanoFramework device, the nanoCLR doesn't seem to have to handle this. In the end it looks like this does have any real purpose and will only be wasting CPU. await IncomingMessage.ReplyBadPacketAsync(_parent, Flags.c_BadHeader, cancellationToken); + + // setup restart + _state = ReceiveState.Initialize; + return GetCompleteMessage(); } @@ -225,12 +229,16 @@ internal async Task ProcessAsync(CancellationToken cancellation { DebuggerEventSource.Log.WireProtocolReceiveState(_state); + // setup restart + _state = ReceiveState.Initialize; + return GetCompleteMessage(); } else { // this is not the message we were waiting // no need to wait for execution just throw it + Debug.WriteLine("-->>>"); _parent.App.ProcessMessageAsync(GetCompleteMessage(), fReply).FireAndForget(); } @@ -252,6 +260,10 @@ internal async Task ProcessAsync(CancellationToken cancellation // FIXME // evaluate the purpose of this reply back to the nanoFramework device, the nanoCLR doesn't seem to have to handle this. In the end it looks like this does have any real purpose and will only be wasting CPU. await IncomingMessage.ReplyBadPacketAsync(_parent, Flags.c_BadPayload, cancellationToken); + + // setup restart + _state = ReceiveState.Initialize; + return GetCompleteMessage(); } @@ -323,7 +335,7 @@ public async Task ProcessMessage(IncomingMessage msg, bool fReply, Cancell Request reply = null; - if (request.MatchesReply(msg)) + if (request != null && request.MatchesReply(msg)) { reply = request;