Skip to content

Commit

Permalink
Hook into connection messages, once we start Runtime and ESP writing.
Browse files Browse the repository at this point in the history
  • Loading branch information
CartBlanche committed Jul 2, 2024
1 parent f45c848 commit bbee4ef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 16 additions & 5 deletions Source/v2/Meadow.CLI/Commands/Current/Firmware/FirmwareUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FirmwareUpdater<T> where T : BaseDeviceCommand<T>
private readonly ISettingsManager settings;
private readonly FileManager fileManager;

private int _lastWriteProgress = 0;
private int lastWriteProgress = 0;

private BaseDeviceCommand<T> command;

Expand Down Expand Up @@ -103,7 +103,18 @@ public async Task<bool> UpdateFirmware()
if (!string.IsNullOrWhiteSpace(serialNumber))
{
connection = await GetConnectionAndDisableRuntime(await MeadowConnectionManager.GetRouteFromSerialNumber(serialNumber));
deviceInfo = await connection.GetDeviceInfo(cancellationToken);
if (connection != null)
{
if (provisioninInProgress)
{
connection.ConnectionMessage += (o, e) =>
{
UpdateProgress?.Invoke(this, (e, 0));
};
}

deviceInfo = await connection.GetDeviceInfo(cancellationToken);
}
}

if (firmwareFileTypes.Contains(FirmwareType.Runtime) || Path.GetFileName(individualFile) == F7FirmwarePackageCollection.F7FirmwareFiles.RuntimeFile)
Expand Down Expand Up @@ -303,15 +314,15 @@ private async Task<IMeadowConnection> GetConnectionAndDisableRuntime(string? rou
await connection.Device.RuntimeDisable();
}

_lastWriteProgress = 0;
lastWriteProgress = 0;

connection.FileWriteProgress += (s, e) =>
{
var p = (int)(e.completed / (double)e.total * 100d);
// don't report < 10% increments (decrease spew on large files)
if (p - _lastWriteProgress < 10) { return; }
if (p - lastWriteProgress < 10) { return; }

_lastWriteProgress = p;
lastWriteProgress = p;

logger?.LogInformation($"{Strings.Writing} {e.fileName}: {p:0}% {(p < 100 ? string.Empty : "\r\n")}");
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ await AnsiConsole.Progress()
var firmareUpdater = new FirmwareUpdater<ProvisionCommand>(this, settingsManager, fileManager, this.connectionManager, null, null, true, OsVersion, deviceSerialNumber, null, CancellationToken);
firmareUpdater.UpdateProgress += (o, e) =>
{
task.Value = e.percentage;
if (e.percentage > 0)
{
task.Value = e.percentage;
}
task.Description = $"{formatedDevice}: {e.message}";
};

Expand Down

0 comments on commit bbee4ef

Please sign in to comment.