From b74a9fe3c8efc06d64fac4b88cdc51e1524d5eb2 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 19 Nov 2024 15:46:21 -0800 Subject: [PATCH 1/4] Version bump --- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 2 +- Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 7fad0a2f..b1d62523 100644 --- a/Source/v2/Meadow.Cli/Meadow.CLI.csproj +++ b/Source/v2/Meadow.Cli/Meadow.CLI.csproj @@ -10,7 +10,7 @@ Wilderness Labs, Inc Wilderness Labs, Inc true - 2.0.60.0 + 2.0.61.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.CLI/ https://github.com/WildernessLabs/Meadow.CLI diff --git a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs index 873026bf..e84673a6 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -6,5 +6,5 @@ namespace Meadow.CLI; public static class Constants { - public const string CLI_VERSION = "2.0.60.0"; + public const string CLI_VERSION = "2.0.61.0"; } \ No newline at end of file From 57967865b017582bb657f2e1921283abfdadfbb0 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 19 Nov 2024 15:46:37 -0800 Subject: [PATCH 2/4] Replace queue with concurrent queue --- .../Connections/SerialConnection.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/v2/Meadow.HCom/Connections/SerialConnection.cs b/Source/v2/Meadow.HCom/Connections/SerialConnection.cs index ef37f8b5..ba69186a 100755 --- a/Source/v2/Meadow.HCom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.HCom/Connections/SerialConnection.cs @@ -1,4 +1,5 @@ using System.Buffers; +using System.Collections.Concurrent; using System.IO.Ports; using System.Security.Cryptography; @@ -21,7 +22,7 @@ public partial class SerialConnection : ConnectionBase, IDisposable private bool _isDisposed; private ConnectionState _state; private readonly List _listeners = new List(); - private readonly Queue _pendingCommands = new Queue(); + private readonly ConcurrentQueue _commandQueue = new ConcurrentQueue(); private readonly AutoResetEvent _commandEvent = new AutoResetEvent(false); private bool _maintainConnection; private Thread? _connectionManager = null; @@ -208,8 +209,7 @@ public override void Detach() // local function so we can unsubscribe var count = _messageCount; - _pendingCommands.Enqueue(command); - _commandEvent.Set(); + EnqueueRequest(command); while (timeout-- > 0) { @@ -248,19 +248,17 @@ private void CommandManager() { _commandEvent.WaitOne(1000); - while (_pendingCommands.Count > 0) + while (_commandQueue.Count > 0) { - Debug.WriteLine($"There are {_pendingCommands.Count} pending commands"); + Debug.WriteLine($"There are {_commandQueue.Count} pending commands"); + + _commandQueue.TryDequeue(out var pendingCommand); - var command = _pendingCommands.Dequeue() as Request; - if (command != null) + if (pendingCommand is Request command) { // if this is a file write, we need to packetize for progress - var payload = command.Serialize(); EncodeAndSendPacket(payload); - - // TODO: re-queue on fail? } } } @@ -297,7 +295,7 @@ public void EnqueueRequest(IRequest command) }; } - _pendingCommands.Enqueue(command); + _commandQueue.Enqueue(command); _commandEvent.Set(); } From 26ef8e35498822c4e3b40a602f390d2567bb0adf Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 19 Nov 2024 15:47:11 -0800 Subject: [PATCH 3/4] Increase timeout for Meadow attach --- .../Meadow.HCom/Connections/SerialConnection.ListenerProc.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs b/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs index e7433e33..0f438efe 100644 --- a/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs +++ b/Source/v2/Meadow.HCom/Connections/SerialConnection.ListenerProc.cs @@ -8,7 +8,7 @@ public partial class SerialConnection public override async Task WaitForMeadowAttach(CancellationToken? cancellationToken) { - var timeout = 500; + var timeout = 50; while (timeout-- > 0) { @@ -26,7 +26,7 @@ public override async Task WaitForMeadowAttach(CancellationToken? cancellationTo return; } - await Task.Delay(20); + await Task.Delay(100); if (!_port.IsOpen) { From 071d7da85a213f56c94ef44b4cfd62f6d16bb697 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Tue, 19 Nov 2024 16:04:18 -0800 Subject: [PATCH 4/4] Fix timeout after writing ESP binaries --- .../Commands/Current/Firmware/FirmwareWriteCommand.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index b489e7e5..a298c6dc 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -255,6 +255,8 @@ protected override async ValueTask ExecuteCommand() await WriteEspFiles(connection, deviceInfo, package); + await connection.WaitForMeadowAttach(); + // reset device if (connection != null && connection.Device != null) {