Skip to content

Commit

Permalink
Merge pull request #428 from WildernessLabs/feature/v2-subdirs
Browse files Browse the repository at this point in the history
Feature/v2 subdirs
  • Loading branch information
adrianstevens authored Jan 17, 2024
2 parents db2fdd7 + 15c6d15 commit 843ee0a
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Source/v2/Meadow.HCom/Connections/SimulatorConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ public override Task<bool> WriteRuntime(string localFileName, CancellationToken?
{
throw new NotImplementedException();
}

public override void Detach()
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions Source/v2/Meadow.Hcom/Connections/ConnectionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class ConnectionBase : IMeadowConnection, IDisposable

public abstract Task WaitForMeadowAttach(CancellationToken? cancellationToken = null);
public abstract Task<IMeadowDevice?> Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10);
public abstract void Detach();
public abstract Task<DeviceInfo?> GetDeviceInfo(CancellationToken? cancellationToken = null);
public abstract Task<MeadowFileInfo[]?> GetFileList(string folder, bool includeCrcs, CancellationToken? cancellationToken = null);
public abstract Task<bool> WriteFile(string localFileName, string? meadowFileName = null, CancellationToken? cancellationToken = null);
Expand Down
5 changes: 5 additions & 0 deletions Source/v2/Meadow.Hcom/Connections/LocalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,9 @@ public override Task<bool> WriteRuntime(string localFileName, CancellationToken?
{
throw new NotImplementedException();
}

public override void Detach()
{
throw new NotImplementedException();
}
}
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Hcom/Connections/SerialConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void Close()
State = ConnectionState.Disconnected;
}

public void Detach()
public override void Detach()
{
if (MaintainConnection)
{
Expand Down
5 changes: 5 additions & 0 deletions Source/v2/Meadow.Hcom/Connections/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,9 @@ public override Task StartDebugging(int port, ILogger? logger, CancellationToken
{
throw new NotImplementedException();
}

public override void Detach()
{
throw new NotImplementedException();
}
}
1 change: 1 addition & 0 deletions Source/v2/Meadow.Hcom/IMeadowConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IMeadowConnection
string Name { get; }
IMeadowDevice? Device { get; }
Task<IMeadowDevice?> Attach(CancellationToken? cancellationToken = null, int timeoutSeconds = 10);
void Detach();
Task WaitForMeadowAttach(CancellationToken? cancellationToken = null);
ConnectionState State { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 2 additions & 0 deletions Source/v2/Meadow.Hcom/SerialResponses/SerialResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 20 additions & 5 deletions Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ public class F7FirmwarePackageCollection : IFirmwarePackageCollection
/// <inheritdoc/>
public event EventHandler<long> DownloadProgress;

public event EventHandler<FirmwarePackage?> DefaultVersionChanged;

public string PackageFileRoot { get; }

private List<FirmwarePackage> _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)

Check warning on line 37 in Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs

View workflow job for this annotation

GitHub Actions / Build and Optionally Publish Meadow.CLI nuget

Non-nullable event 'DownloadProgress' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.

Check warning on line 37 in Source/v2/Meadow.SoftwareManager/F7FirmwarePackageCollection.cs

View workflow job for this annotation

GitHub Actions / Build and Optionally Publish Meadow.CLI nuget

Non-nullable event 'DefaultVersionChanged' must contain a non-null value when exiting constructor. Consider declaring the event as nullable.
{
if (!Directory.Exists(rootPath))
Expand All @@ -39,6 +44,16 @@ internal F7FirmwarePackageCollection(string rootPath)
PackageFileRoot = rootPath;
}

public FirmwarePackage? DefaultPackage
{
get => _defaultPackage;
private set
{
_defaultPackage = value;
DefaultVersionChanged?.Invoke(this, value);
}
}

/// <summary>
/// Checks the remote (i.e. cloud) store to see if a new firmware package is available.
/// </summary>
Expand Down Expand Up @@ -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)
Expand All @@ -96,8 +113,6 @@ public Task SetDefaultPackage(string version)

var downloadManager = new F7FirmwareDownloadManager();
downloadManager.SetDefaultVersion(PackageFileRoot, version);

return Task.CompletedTask;
}

public async Task<bool> IsVersionAvailableForDownload(string version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IFirmwarePackageCollection : IEnumerable<FirmwarePackage>
/// EventArgs are the total number of bytes retrieved
/// </remarks>
public event EventHandler<long> DownloadProgress;
public event EventHandler<FirmwarePackage?> DefaultVersionChanged;

FirmwarePackage? DefaultPackage { get; }
Task SetDefaultPackage(string version);
Expand All @@ -23,6 +24,7 @@ public interface IFirmwarePackageCollection : IEnumerable<FirmwarePackage>
Task<string?> UpdateAvailable();
Task<bool> IsVersionAvailableForDownload(string version);
Task<bool> RetrievePackage(string version, bool overwrite = false);

FirmwarePackage this[int index] { get; }
FirmwarePackage? this[string version] { get; }
string PackageFileRoot { get; }
}

0 comments on commit 843ee0a

Please sign in to comment.