From dd4c1f5f7800d0341c4c2781c8091695f4d1ea9e Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 8 Jan 2024 16:59:02 -0600 Subject: [PATCH 1/7] v2 subdir work --- Source/v2/Meadow.Cli/AppManager.cs | 2 +- .../Current/File/FileDeleteCommand.cs | 2 +- .../Commands/Current/File/FileListCommand.cs | 5 +++- .../Meadow.Cli/Properties/launchSettings.json | 2 +- .../ConnectionManagerTests.cs | 4 +-- .../SerialCommandTests.cs | 4 +-- .../Connections/SimulatorConnection.cs | 2 +- .../Meadow.Hcom/Connections/ConnectionBase.cs | 2 +- .../Connections/LocalConnection.cs | 4 +-- .../Connections/SerialConnection.cs | 9 +++++- .../Meadow.Hcom/Connections/TcpConnection.cs | 2 +- Source/v2/Meadow.Hcom/IMeadowConnection.cs | 2 +- Source/v2/Meadow.Hcom/IMeadowDevice.cs | 2 +- Source/v2/Meadow.Hcom/MeadowDevice.cs | 4 +-- Source/v2/Meadow.Hcom/MeadowFileInfo.cs | 29 +++++++++++++++++-- .../SerialRequests/GetFileListRequest.cs | 27 +++++++++++++++-- .../Meadow.Hcom/SerialRequests/RequestType.cs | 2 ++ 17 files changed, 81 insertions(+), 23 deletions(-) diff --git a/Source/v2/Meadow.Cli/AppManager.cs b/Source/v2/Meadow.Cli/AppManager.cs index e587e6bf..41e135fa 100644 --- a/Source/v2/Meadow.Cli/AppManager.cs +++ b/Source/v2/Meadow.Cli/AppManager.cs @@ -69,7 +69,7 @@ public static async Task DeployApplication( } // get a list of files on-device, with CRCs - var deviceFiles = await connection.GetFileList(true, cancellationToken) ?? Array.Empty(); + var deviceFiles = await connection.GetFileList("/meadow0/", true, cancellationToken) ?? Array.Empty(); // get a list of files of the device files that are not in the list we intend to deploy var removeFiles = deviceFiles diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs index 221db0af..ce6e6001 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs @@ -25,7 +25,7 @@ protected override async ValueTask ExecuteCommand() if (connection != null) { - var fileList = await connection.GetFileList(false); + var fileList = await connection.GetFileList("/meadow0/", false); if (MeadowFile == "all") { diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs index ce4c9e69..bfa86eaf 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs @@ -11,6 +11,9 @@ public class FileListCommand : BaseDeviceCommand [CommandOption("verbose", 'v', IsRequired = false)] public bool Verbose { get; set; } + [CommandParameter(0, Name = "Folder", IsRequired = false)] + public string? Folder { get; set; } = default!; + public FileListCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) : base(connectionManager, loggerFactory) { @@ -28,7 +31,7 @@ protected override async ValueTask ExecuteCommand() if (connection != null) { - var files = await connection.Device.GetFileList(Verbose, CancellationToken); + var files = await connection.Device.GetFileList(Folder ?? "/meadow0/", Verbose, CancellationToken); if (files == null || files.Length == 0) { diff --git a/Source/v2/Meadow.Cli/Properties/launchSettings.json b/Source/v2/Meadow.Cli/Properties/launchSettings.json index 8e3cb20e..ad9092c6 100644 --- a/Source/v2/Meadow.Cli/Properties/launchSettings.json +++ b/Source/v2/Meadow.Cli/Properties/launchSettings.json @@ -45,7 +45,7 @@ }, "Config: Set Route Serial": { "commandName": "Project", - "commandLineArgs": "config route COM7" + "commandLineArgs": "config route COM10" }, "Config: Set Route TCP": { "commandName": "Project", diff --git a/Source/v2/Meadow.HCom.Integration.Tests/ConnectionManagerTests.cs b/Source/v2/Meadow.HCom.Integration.Tests/ConnectionManagerTests.cs index f5f025d4..d016e798 100644 --- a/Source/v2/Meadow.HCom.Integration.Tests/ConnectionManagerTests.cs +++ b/Source/v2/Meadow.HCom.Integration.Tests/ConnectionManagerTests.cs @@ -124,7 +124,7 @@ public async Task TestGetFileListWithoutCrcs() Assert.Fail("no device"); return; } - var files = await device.GetFileList(false); + var files = await device.GetFileList("/meadow0/", false); Assert.NotNull(files); Assert.True(files.Any()); Assert.True(files.All(f => f.Name != null)); @@ -143,7 +143,7 @@ public async Task TestGetFileListWithCrcs() Assert.Fail("no device"); return; } - var files = await device.GetFileList(true); + var files = await device.GetFileList("/meadow0/", true); Assert.NotNull(files); Assert.True(files.Any()); Assert.True(files.All(f => f.Name != null)); diff --git a/Source/v2/Meadow.HCom.Integration.Tests/SerialCommandTests.cs b/Source/v2/Meadow.HCom.Integration.Tests/SerialCommandTests.cs index d60dc865..74aed9b7 100644 --- a/Source/v2/Meadow.HCom.Integration.Tests/SerialCommandTests.cs +++ b/Source/v2/Meadow.HCom.Integration.Tests/SerialCommandTests.cs @@ -39,7 +39,7 @@ public async void TestGetFileListNoCrc() { Assert.Equal(ConnectionState.Disconnected, connection.State); - var files = await connection.GetFileList(false); + var files = await connection.GetFileList("/meadow0/", false); Assert.NotNull(files); Assert.True(files.Length > 0); @@ -53,7 +53,7 @@ public async void TestGetFileListWithCrc() { Assert.Equal(ConnectionState.Disconnected, connection.State); - var files = await connection.GetFileList(true); + var files = await connection.GetFileList("/meadow0/", true); Assert.NotNull(files); Assert.True(files.Length > 0); diff --git a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs index 90e2d140..c1e04328 100644 --- a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs +++ b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs @@ -42,7 +42,7 @@ public override Task EraseFlash(CancellationToken? cancellationToken = null) throw new NotImplementedException(); } - public override Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null) + public override Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs index 5055f0d3..dac98459 100644 --- a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs +++ b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs @@ -20,7 +20,7 @@ public abstract class ConnectionBase : IMeadowConnection, IDisposable public abstract Task WaitForMeadowAttach(CancellationToken? cancellationToken = null); public abstract Task Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10); public abstract Task GetDeviceInfo(CancellationToken? cancellationToken = null); - public abstract Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null); + public abstract Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null); public abstract Task WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null); public abstract Task ReadFile(string meadowFileName, string? localFileName = null, CancellationToken? cancellationToken = null); public abstract Task ReadFileString(string fileName, CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs index f42afbb7..ed767e34 100644 --- a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs @@ -58,7 +58,7 @@ public LocalConnection() _deviceInfo = new DeviceInfo(info); } - return Task.FromResult< DeviceInfo?>(_deviceInfo); + return Task.FromResult(_deviceInfo); } private string ExecuteBashCommandLine(string command) @@ -143,7 +143,7 @@ public override Task EraseFlash(CancellationToken? cancellationToken = null) throw new NotImplementedException(); } - public override Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null) + public override Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index 53b7fe73..98186f68 100644 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -173,6 +173,11 @@ private void Close() State = ConnectionState.Disconnected; } + public void Detach() + { + Close(); + } + public override async Task Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10) { try @@ -759,11 +764,13 @@ public override async Task ResetDevice(CancellationToken? cancellationToken = nu return _deviceInfo; } - public override async Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null) + public override async Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null) { var command = RequestBuilder.Build(); command.IncludeCrcs = includeCrcs; + command.Path = folder; + EnqueueRequest(command); if (!await WaitForResult( diff --git a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs index 36b76549..7346c761 100644 --- a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs @@ -68,7 +68,7 @@ public override Task WaitForMeadowAttach(CancellationToken? cancellationToken = throw new NotImplementedException(); } - public override Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null) + public override Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/IMeadowConnection.cs b/Source/v2/Meadow.Hcom/IMeadowConnection.cs index 75dbce9c..aa8b8f80 100644 --- a/Source/v2/Meadow.Hcom/IMeadowConnection.cs +++ b/Source/v2/Meadow.Hcom/IMeadowConnection.cs @@ -21,7 +21,7 @@ public interface IMeadowConnection Task ReadFileString(string fileName, CancellationToken? cancellationToken = null); Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); Task GetDeviceInfo(CancellationToken? cancellationToken = null); - Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null); + Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null); Task ResetDevice(CancellationToken? cancellationToken = null); Task IsRuntimeEnabled(CancellationToken? cancellationToken = null); Task RuntimeDisable(CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Hcom/IMeadowDevice.cs b/Source/v2/Meadow.Hcom/IMeadowDevice.cs index b599cb0a..3d20142b 100644 --- a/Source/v2/Meadow.Hcom/IMeadowDevice.cs +++ b/Source/v2/Meadow.Hcom/IMeadowDevice.cs @@ -9,7 +9,7 @@ public interface IMeadowDevice Task RuntimeEnable(CancellationToken? cancellationToken = null); Task IsRuntimeEnabled(CancellationToken? cancellationToken = null); Task GetDeviceInfo(CancellationToken? cancellationToken = null); - Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null); + Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null); Task ReadFile(string meadowFileName, string? localFileName = null, CancellationToken? cancellationToken = null); Task WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null); Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Hcom/MeadowDevice.cs b/Source/v2/Meadow.Hcom/MeadowDevice.cs index f9b55b41..9b9b3b7c 100644 --- a/Source/v2/Meadow.Hcom/MeadowDevice.cs +++ b/Source/v2/Meadow.Hcom/MeadowDevice.cs @@ -36,9 +36,9 @@ public async Task RuntimeEnable(CancellationToken? cancellationToken = null) return await _connection.GetDeviceInfo(cancellationToken); } - public async Task GetFileList(bool includeCrcs, CancellationToken? cancellationToken = null) + public async Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null) { - return await _connection.GetFileList(includeCrcs, cancellationToken); + return await _connection.GetFileList(folder, includeCrcs, cancellationToken); } public async Task ReadFile(string meadowFileName, string? localFileName = null, CancellationToken? cancellationToken = null) diff --git a/Source/v2/Meadow.Hcom/MeadowFileInfo.cs b/Source/v2/Meadow.Hcom/MeadowFileInfo.cs index 46590ad9..a4a06981 100644 --- a/Source/v2/Meadow.Hcom/MeadowFileInfo.cs +++ b/Source/v2/Meadow.Hcom/MeadowFileInfo.cs @@ -3,6 +3,12 @@ public string Name { get; private set; } = default!; public long? Size { get; private set; } public string? Crc { get; private set; } + public bool IsDirectory { get; private set; } + + public override string ToString() + { + return $"{(IsDirectory ? "/" : "")}{Name}"; + } public static MeadowFileInfo? Parse(string info) { @@ -13,11 +19,29 @@ { mfi = new MeadowFileInfo(); - // "/meadow0/App.deps.json [0xa0f6d6a2] 28 KB (26575 bytes)" + mfi.Name = info.Substring(1); + mfi.IsDirectory = true; + } + else + { + // v2 file lists have changed + + if (info.StartsWith("Directory:")) + { + // this is the first line and contains the directory name being parsed + return mfi; + } + else if (info.StartsWith("A total of")) + { + return mfi; + } + + mfi = new MeadowFileInfo(); + var indexOfSquareBracket = info.IndexOf('['); if (indexOfSquareBracket <= 0) { - mfi.Name = info; + mfi.Name = info.Trim(); } else { @@ -28,6 +52,7 @@ mfi.Size = int.Parse(info.Substring(indexOfParen + 1, end - indexOfParen)); } } + return mfi; } } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/SerialRequests/GetFileListRequest.cs b/Source/v2/Meadow.Hcom/SerialRequests/GetFileListRequest.cs index 117f0468..7d8b4ee9 100644 --- a/Source/v2/Meadow.Hcom/SerialRequests/GetFileListRequest.cs +++ b/Source/v2/Meadow.Hcom/SerialRequests/GetFileListRequest.cs @@ -1,13 +1,34 @@ -namespace Meadow.Hcom +using System.Text; + +namespace Meadow.Hcom { internal class GetFileListRequest : Request { public override RequestType RequestType => IncludeCrcs - ? RequestType.HCOM_MDOW_REQUEST_LIST_PART_FILES_AND_CRC - : RequestType.HCOM_MDOW_REQUEST_LIST_PARTITION_FILES; + ? RequestType.HCOM_MDOW_REQUEST_LIST_FILES_SUBDIR_CRC + : RequestType.HCOM_MDOW_REQUEST_LIST_FILES_SUBDIR; public bool IncludeCrcs { get; set; } + public string? Path + { + get + { + if (Payload == null) return null; + + if (Payload.Length == 0) { return null; } + + return Encoding.ASCII.GetString(Payload).Trim(); + } + set + { + if (value != null) + { + base.Payload = Encoding.ASCII.GetBytes(value); + } + } + } + public GetFileListRequest() { } diff --git a/Source/v2/Meadow.Hcom/SerialRequests/RequestType.cs b/Source/v2/Meadow.Hcom/SerialRequests/RequestType.cs index eacee4ca..b00a012d 100644 --- a/Source/v2/Meadow.Hcom/SerialRequests/RequestType.cs +++ b/Source/v2/Meadow.Hcom/SerialRequests/RequestType.cs @@ -64,6 +64,8 @@ public enum RequestType : ushort // ToDo HCOM_MDOW_REQUEST_RTC_READ_TIME_CMD doesn't send text, it's a header only message type HCOM_MDOW_REQUEST_RTC_READ_TIME_CMD = 0x04 | ProtocolType.HCOM_PROTOCOL_HEADER_SIMPLE_TEXT_TYPE, HCOM_MDOW_REQUEST_RTC_WAKEUP_TIME_CMD = 0x05 | ProtocolType.HCOM_PROTOCOL_HEADER_SIMPLE_TEXT_TYPE, + HCOM_MDOW_REQUEST_LIST_FILES_SUBDIR = 0x06 | ProtocolType.HCOM_PROTOCOL_HEADER_SIMPLE_TEXT_TYPE, + HCOM_MDOW_REQUEST_LIST_FILES_SUBDIR_CRC = 0x07 | ProtocolType.HCOM_PROTOCOL_HEADER_SIMPLE_TEXT_TYPE, // This is a simple type with binary data From 15d4821101e264ad30a889626ffa6148f7993051 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 11 Jan 2024 10:25:27 -0600 Subject: [PATCH 2/7] updated Delete api to return a value --- .../v2/Meadow.HCom/Connections/SimulatorConnection.cs | 2 +- Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs | 2 +- Source/v2/Meadow.Hcom/Connections/LocalConnection.cs | 2 +- .../Connections/SerialConnection.ListenerProc.cs | 1 + Source/v2/Meadow.Hcom/Connections/SerialConnection.cs | 10 ++++++++-- Source/v2/Meadow.Hcom/Connections/TcpConnection.cs | 2 +- Source/v2/Meadow.Hcom/IMeadowConnection.cs | 2 +- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs index c1e04328..296f422d 100644 --- a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs +++ b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs @@ -32,7 +32,7 @@ public override Task RuntimeEnable(CancellationToken? cancellationToken = null) throw new NotImplementedException(); } - public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) + public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs index dac98459..650510eb 100644 --- a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs +++ b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs @@ -24,7 +24,7 @@ public abstract class ConnectionBase : IMeadowConnection, IDisposable public abstract Task WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null); public abstract Task ReadFile(string meadowFileName, string? localFileName = null, CancellationToken? cancellationToken = null); public abstract Task ReadFileString(string fileName, CancellationToken? cancellationToken = null); - public abstract Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); + public abstract Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); public abstract Task ResetDevice(CancellationToken? cancellationToken = null); public abstract Task IsRuntimeEnabled(CancellationToken? cancellationToken = null); public abstract Task RuntimeDisable(CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs index ed767e34..0861889e 100644 --- a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs @@ -133,7 +133,7 @@ public override Task GetPublicKey(CancellationToken? cancellationToken = - public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) + public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.ListenerProc.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.ListenerProc.cs index 69e6af6e..6bce3d63 100644 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.ListenerProc.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.ListenerProc.cs @@ -262,6 +262,7 @@ private async Task ListenerProc() } else if (response is RequestErrorTextResponse ret) { + Debug.WriteLine(ret.Text); RaiseDeviceMessageReceived(ret.Text, "hcom"); _lastError = ret.Text; } diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index 98186f68..cf236bbf 100644 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -175,6 +175,11 @@ private void Close() public void Detach() { + if (MaintainConnection) + { + // TODO: close this up + } + Close(); } @@ -1137,7 +1142,7 @@ void OnFileDataReceived(object? sender, string data) return contents; } - public override async Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) + public override async Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) { var command = RequestBuilder.Build(); command.MeadowFileName = meadowFileName; @@ -1146,7 +1151,8 @@ public override async Task DeleteFile(string meadowFileName, CancellationToken? EnqueueRequest(command); - await WaitForConcluded(null, cancellationToken); + var result = await WaitForConcluded(null, cancellationToken); + return result; } public override async Task EraseFlash(CancellationToken? cancellationToken = null) diff --git a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs index 7346c761..8e3dd4b6 100644 --- a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs @@ -113,7 +113,7 @@ public override Task ReadFile(string meadowFileName, string? localFileName throw new NotImplementedException(); } - public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) + public override Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null) { throw new NotImplementedException(); } diff --git a/Source/v2/Meadow.Hcom/IMeadowConnection.cs b/Source/v2/Meadow.Hcom/IMeadowConnection.cs index aa8b8f80..d7479502 100644 --- a/Source/v2/Meadow.Hcom/IMeadowConnection.cs +++ b/Source/v2/Meadow.Hcom/IMeadowConnection.cs @@ -19,7 +19,7 @@ public interface IMeadowConnection Task WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null); Task ReadFile(string meadowFileName, string? localFileName = null, CancellationToken? cancellationToken = null); Task ReadFileString(string fileName, CancellationToken? cancellationToken = null); - Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); + Task DeleteFile(string meadowFileName, CancellationToken? cancellationToken = null); Task GetDeviceInfo(CancellationToken? cancellationToken = null); Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null); Task ResetDevice(CancellationToken? cancellationToken = null); From d94f37df493e0c8150904f378c72fbd8e62f62f7 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 11 Jan 2024 10:32:32 -0600 Subject: [PATCH 3/7] Updated file list CLI command output --- .../Commands/Current/File/FileListCommand.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs index bfa86eaf..77b5ddc2 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileListCommand.cs @@ -17,7 +17,19 @@ public class FileListCommand : BaseDeviceCommand public FileListCommand(MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory) : base(connectionManager, loggerFactory) { - Logger?.LogInformation($"Getting file list..."); + if (Folder != null) + { + if (!Folder.EndsWith('/')) + { + Folder += "/"; + } + + Logger?.LogInformation($"Getting file list from '{Folder}'..."); + } + else + { + Logger?.LogInformation($"Getting file list..."); + } } protected override async ValueTask ExecuteCommand() From 8e9a558c63454ec0649e2b685bc375136beba6ff Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 11 Jan 2024 11:16:27 -0600 Subject: [PATCH 4/7] file delete CLI check updates --- .../Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs index ce6e6001..30b60f09 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs @@ -25,7 +25,9 @@ protected override async ValueTask ExecuteCommand() if (connection != null) { - var fileList = await connection.GetFileList("/meadow0/", false); + // get a list of files in the target folder + var folder = Path.GetDirectoryName(MeadowFile)!.Replace(Path.DirectorySeparatorChar, '/'); + var fileList = await connection.GetFileList($"{folder}/", false); if (MeadowFile == "all") { @@ -38,7 +40,9 @@ protected override async ValueTask ExecuteCommand() } else { - var exists = fileList?.Any(f => Path.GetFileName(f.Name) == MeadowFile) ?? false; + var requested = Path.GetFileName(MeadowFile); + + var exists = fileList?.Any(f => Path.GetFileName(f.Name) == requested) ?? false; if (!exists) { From 984ebb4ff66593e81e397f5bf504bb402b156628 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Thu, 11 Jan 2024 11:51:34 -0600 Subject: [PATCH 5/7] added a null check --- .../v2/Meadow.Hcom/Connections/SerialConnection.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index cf236bbf..2f4e5f81 100644 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -246,13 +246,15 @@ private async void CommandManager() Debug.WriteLine($"There are {_pendingCommands.Count} pending commands"); var command = _pendingCommands.Dequeue() as Request; + if (command != null) + { + // if this is a file write, we need to packetize for progress - // if this is a file write, we need to packetize for progress - - var payload = command.Serialize(); - EncodeAndSendPacket(payload); + var payload = command.Serialize(); + EncodeAndSendPacket(payload); - // TODO: re-queue on fail? + // TODO: re-queue on fail? + } } Thread.Sleep(1000); From 9f24f3e8d3045d685ff47a9ee709ef879eb730d6 Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Mon, 15 Jan 2024 09:58:47 -0600 Subject: [PATCH 6/7] added indexers to FirmwarePackageCollection --- .../F7FirmwarePackageCollection.cs | 10 +++++++--- .../IFirmwarePackageCollection.cs | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs index 8a14443a..5e5fdb0e 100644 --- a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs @@ -29,6 +29,10 @@ internal F7FirmwarePackageCollection() { } + public FirmwarePackage? this[string version] => _f7Packages.FirstOrDefault(p => p.Version == version); + + public FirmwarePackage this[int index] => _f7Packages[index]; + internal F7FirmwarePackageCollection(string rootPath) { if (!Directory.Exists(rootPath)) @@ -85,8 +89,10 @@ public Task DeletePackage(string version) return Task.CompletedTask; } - public Task SetDefaultPackage(string version) + public async Task SetDefaultPackage(string version) { + await Refresh(); + var existing = _f7Packages.FirstOrDefault(p => p.Version == version); if (existing == null) @@ -96,8 +102,6 @@ public Task SetDefaultPackage(string version) var downloadManager = new F7FirmwareDownloadManager(); downloadManager.SetDefaultVersion(PackageFileRoot, version); - - return Task.CompletedTask; } public async Task IsVersionAvailableForDownload(string version) diff --git a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs index 5d0cf341..e33cb196 100644 --- a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs @@ -23,6 +23,7 @@ public interface IFirmwarePackageCollection : IEnumerable Task UpdateAvailable(); Task IsVersionAvailableForDownload(string version); Task RetrievePackage(string version, bool overwrite = false); - + FirmwarePackage this[int index] { get; } + FirmwarePackage? this[string version] { get; } string PackageFileRoot { get; } } From 15c6d1583ec11a752c3ffe43fd21843eea86312e Mon Sep 17 00:00:00 2001 From: Chris Tacke Date: Wed, 17 Jan 2024 12:06:51 -0600 Subject: [PATCH 7/7] more housekeeping/hardening/etc --- .../Connections/SimulatorConnection.cs | 5 +++++ .../TextRequestRejectedResponse.cs | 15 +++++++++++++++ .../v2/Meadow.Hcom/Connections/ConnectionBase.cs | 1 + .../v2/Meadow.Hcom/Connections/LocalConnection.cs | 5 +++++ .../Meadow.Hcom/Connections/SerialConnection.cs | 2 +- .../v2/Meadow.Hcom/Connections/TcpConnection.cs | 5 +++++ Source/v2/Meadow.Hcom/IMeadowConnection.cs | 1 + .../FileWriteInitFailedSerialResponse.cs | 8 +++++++- .../Meadow.Hcom/SerialResponses/SerialResponse.cs | 2 ++ .../F7FirmwarePackageCollection.cs | 15 +++++++++++++-- .../IFirmwarePackageCollection.cs | 1 + 11 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 Source/v2/Meadow.HCom/SerialResponses/TextRequestRejectedResponse.cs diff --git a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs index 296f422d..78c1b92c 100644 --- a/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs +++ b/Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs @@ -141,4 +141,9 @@ public override Task WriteRuntime(string localFileName, CancellationToken? { throw new NotImplementedException(); } + + public override void Detach() + { + throw new NotImplementedException(); + } } diff --git a/Source/v2/Meadow.HCom/SerialResponses/TextRequestRejectedResponse.cs b/Source/v2/Meadow.HCom/SerialResponses/TextRequestRejectedResponse.cs new file mode 100644 index 00000000..2f6e0023 --- /dev/null +++ b/Source/v2/Meadow.HCom/SerialResponses/TextRequestRejectedResponse.cs @@ -0,0 +1,15 @@ +using System.Diagnostics; +using System.Text; + +namespace Meadow.Hcom; + +internal class TextRequestRejectedResponse : SerialResponse +{ + public string Text => Encoding.UTF8.GetString(_data, RESPONSE_PAYLOAD_OFFSET, PayloadLength); + + internal TextRequestRejectedResponse(byte[] data, int length) + : base(data, length) + { + Debug.WriteLine(Text); + } +} diff --git a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs index 650510eb..f1119097 100644 --- a/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs +++ b/Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs @@ -19,6 +19,7 @@ public abstract class ConnectionBase : IMeadowConnection, IDisposable public abstract Task WaitForMeadowAttach(CancellationToken? cancellationToken = null); public abstract Task Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10); + public abstract void Detach(); public abstract Task GetDeviceInfo(CancellationToken? cancellationToken = null); public abstract Task GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null); public abstract Task WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null); diff --git a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs index 0861889e..f0cdeae5 100644 --- a/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/LocalConnection.cs @@ -247,4 +247,9 @@ public override Task WriteRuntime(string localFileName, CancellationToken? { throw new NotImplementedException(); } + + public override void Detach() + { + throw new NotImplementedException(); + } } diff --git a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs index 26663cbb..698af035 100644 --- a/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/SerialConnection.cs @@ -173,7 +173,7 @@ private void Close() State = ConnectionState.Disconnected; } - public void Detach() + public override void Detach() { if (MaintainConnection) { diff --git a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs index 8e3dd4b6..a7b3157f 100644 --- a/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs +++ b/Source/v2/Meadow.Hcom/Connections/TcpConnection.cs @@ -181,4 +181,9 @@ public override Task StartDebugging(int port, ILogger? logger, CancellationToken { throw new NotImplementedException(); } + + public override void Detach() + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/Source/v2/Meadow.Hcom/IMeadowConnection.cs b/Source/v2/Meadow.Hcom/IMeadowConnection.cs index d7479502..16e3dc67 100644 --- a/Source/v2/Meadow.Hcom/IMeadowConnection.cs +++ b/Source/v2/Meadow.Hcom/IMeadowConnection.cs @@ -13,6 +13,7 @@ public interface IMeadowConnection string Name { get; } IMeadowDevice? Device { get; } Task Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10); + void Detach(); Task WaitForMeadowAttach(CancellationToken? cancellationToken = null); ConnectionState State { get; } diff --git a/Source/v2/Meadow.Hcom/SerialResponses/FileWriteInitFailedSerialResponse.cs b/Source/v2/Meadow.Hcom/SerialResponses/FileWriteInitFailedSerialResponse.cs index 653d532b..2135f2ea 100644 --- a/Source/v2/Meadow.Hcom/SerialResponses/FileWriteInitFailedSerialResponse.cs +++ b/Source/v2/Meadow.Hcom/SerialResponses/FileWriteInitFailedSerialResponse.cs @@ -1,9 +1,15 @@ -namespace Meadow.Hcom; +using System.Diagnostics; +using System.Text; + +namespace Meadow.Hcom; internal class FileWriteInitFailedSerialResponse : SerialResponse { + public string Text => Encoding.UTF8.GetString(_data, RESPONSE_PAYLOAD_OFFSET, PayloadLength); + internal FileWriteInitFailedSerialResponse(byte[] data, int length) : base(data, length) { + Debug.Write(Text); } } diff --git a/Source/v2/Meadow.Hcom/SerialResponses/SerialResponse.cs b/Source/v2/Meadow.Hcom/SerialResponses/SerialResponse.cs index 22836753..bdb66bab 100644 --- a/Source/v2/Meadow.Hcom/SerialResponses/SerialResponse.cs +++ b/Source/v2/Meadow.Hcom/SerialResponses/SerialResponse.cs @@ -32,6 +32,8 @@ public static SerialResponse Parse(byte[] data, int length) return new TextInformationResponse(data, length); case ResponseType.HCOM_HOST_REQUEST_TEXT_ACCEPTED: return new TextRequestResponse(data, length); + case ResponseType.HCOM_HOST_REQUEST_TEXT_REJECTED: + return new TextRequestRejectedResponse(data, length); case ResponseType.HCOM_HOST_REQUEST_TEXT_DEVICE_INFO: return new DeviceInfoSerialResponse(data, length); case ResponseType.HCOM_HOST_REQUEST_TEXT_CONCLUDED: diff --git a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs index 5e5fdb0e..9d13bed8 100644 --- a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs @@ -13,16 +13,17 @@ public class F7FirmwarePackageCollection : IFirmwarePackageCollection /// public event EventHandler DownloadProgress; + public event EventHandler DefaultVersionChanged; + public string PackageFileRoot { get; } private List _f7Packages = new(); - public FirmwarePackage? DefaultPackage { get; private set; } - public static string DefaultF7FirmwareStoreRoot = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WildernessLabs", "Firmware"); + private FirmwarePackage? _defaultPackage; internal F7FirmwarePackageCollection() : this(DefaultF7FirmwareStoreRoot) @@ -43,6 +44,16 @@ internal F7FirmwarePackageCollection(string rootPath) PackageFileRoot = rootPath; } + public FirmwarePackage? DefaultPackage + { + get => _defaultPackage; + private set + { + _defaultPackage = value; + DefaultVersionChanged?.Invoke(this, value); + } + } + /// /// Checks the remote (i.e. cloud) store to see if a new firmware package is available. /// diff --git a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs index e33cb196..822cea0c 100644 --- a/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/IFirmwarePackageCollection.cs @@ -14,6 +14,7 @@ public interface IFirmwarePackageCollection : IEnumerable /// EventArgs are the total number of bytes retrieved /// public event EventHandler DownloadProgress; + public event EventHandler DefaultVersionChanged; FirmwarePackage? DefaultPackage { get; } Task SetDefaultPackage(string version);