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 8a14443a..9d13bed8 100644 --- a/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs +++ b/Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs @@ -13,22 +13,27 @@ 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) { } + 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)) @@ -39,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. /// @@ -85,8 +100,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 +113,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..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); @@ -23,6 +24,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; } }