From a495133aab53719847afbcf55e595b99a6d4ccec Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Wed, 6 Mar 2024 08:10:10 -0600 Subject: [PATCH] Updated for supporting new HCOM "runtime" text --- .../Connections/SerialConnection.cs | 81 +++---------------- 1 file changed, 9 insertions(+), 72 deletions(-) diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index 29699747..b58556c1 100755 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -372,10 +372,8 @@ private void EncodeAndSendPacket(byte[] messageBytes, int length, CancellationTo try { // Send the data to Meadow - // Debug.Write($"Sending {encodedToSend} bytes..."); - //await _port.BaseStream.WriteAsync(encodedBytes, 0, encodedToSend, cancellationToken ?? CancellationToken.None); + // DO NOT USE _port.BaseStream. It disables port timeouts! _port.Write(encodedBytes, 0, encodedToSend); - // Debug.WriteLine($"sent"); } catch (InvalidOperationException ioe) // Port not opened { @@ -411,7 +409,6 @@ private void EncodeAndSendPacket(byte[] messageBytes, int length, CancellationTo } } - private class SerialMessage { private readonly IList> _segments; @@ -462,20 +459,6 @@ private bool DecodeAndProcessPacket(Memory packetBuffer, CancellationToken var decodedSize = CobsTools.CobsDecoding(packetBuffer.ToArray(), packetLength, ref decodedBuffer); - /* - // If a message is too short it is ignored - if (decodedSize < MeadowDeviceManager.ProtocolHeaderSize) - { - return false; - } - - Debug.Assert(decodedSize <= MeadowDeviceManager.MaxAllowableMsgPacketLength); - - // Process the received packet - ParseAndProcessReceivedPacket(decodedBuffer.AsSpan(0, decodedSize).ToArray(), - cancellationToken); - - */ ArrayPool.Shared.Return(decodedBuffer); return true; } @@ -506,10 +489,10 @@ protected override void Dispose(bool disposing) private List StdErr { get; } = new List(); private List InfoMessages { get; } = new List(); - private const string RuntimeSucessfullyEnabledToken = "Meadow successfully started MONO"; - private const string RuntimeSucessfullyDisabledToken = "Mono is disabled"; - private const string RuntimeStateToken = "Mono is"; - private const string RuntimeIsEnabledToken = "Mono is enabled"; + private const string MonoStateToken = "Mono is"; + private const string RuntimeStateToken = "Runtime is"; + private const string MonoIsEnabledToken = "Mono is enabled"; + private const string RuntimeIsEnabledToken = "Runtime is enabled"; private const string RtcRetrievalToken = "UTC time:"; public int CommandTimeoutSeconds { get; set; } = 30; @@ -641,10 +624,12 @@ public override async Task IsRuntimeEnabled(CancellationToken? cancellatio if (InfoMessages.Count > 0) { - var m = InfoMessages.FirstOrDefault(i => i.Contains(RuntimeStateToken)); + var m = InfoMessages.FirstOrDefault(i => + i.Contains(RuntimeStateToken) || + i.Contains(MonoStateToken)); if (m != null) { - return m == RuntimeIsEnabledToken; + return (m == RuntimeIsEnabledToken) || (m == MonoIsEnabledToken); } } @@ -868,54 +853,6 @@ public override async Task WriteRuntime( cancellationToken); - /* - RaiseConnectionMessage("\nErasing runtime flash blocks..."); - status = await WaitForResult(() => - { - if (_lastRequestConcluded != null) - { - // happens on error - return true; - } - - var m = string.Join('\n', InfoMessages); - return m.Contains("Mono memory erase success"); - }, - cancellationToken); - - InfoMessages.Clear(); - - RaiseConnectionMessage("Moving runtime to flash..."); - - status = await WaitForResult(() => - { - if (_lastRequestConcluded != null) - { - // happens on error - return true; - } - - var m = string.Join('\n', InfoMessages); - return m.Contains("Verifying runtime flash operation."); - }, - cancellationToken); - - InfoMessages.Clear(); - - RaiseConnectionMessage("Verifying..."); - - status = await WaitForResult(() => - { - if (_lastRequestConcluded != null) - { - return true; - } - - return false; - }, - cancellationToken); - */ - if (status) { await WaitForConcluded(null, cancellationToken);