Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v2 subdirs #428

Merged
merged 10 commits into from
Jan 17, 2024
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,23 +13,28 @@
/// <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 @@
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 @@ -70,13 +85,13 @@

// if we're deleting the default, we need to det another default
var i = _f7Packages.Count - 1;
while (DefaultPackage.Version == _f7Packages[i].Version)

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

View workflow job for this annotation

GitHub Actions / Build and Optionally Publish Meadow.CLI nuget

Dereference of a possibly null reference.
{
i--;
}
var newDefault = _f7Packages[i].Version;
_f7Packages.Remove(DefaultPackage);
SetDefaultPackage(newDefault);

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

View workflow job for this annotation

GitHub Actions / Build and Optionally Publish Meadow.CLI nuget

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

var path = Path.Combine(PackageFileRoot, version);

Expand All @@ -85,8 +100,10 @@
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 @@

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; }
}
Loading