aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-24 11:37:59 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2019-12-24 11:37:59 +0200
commit6230a690fcfae2c51aadf4ce57d555e502fcce93 (patch)
tree6702b4f6929885335564b17b120727367846e30c /Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
parentb6d9b453d2f14f1bbcc3b907d6cc30b513370e5a (diff)
downloadTango-6230a690fcfae2c51aadf4ce57d555e502fcce93.tar.gz
Tango-6230a690fcfae2c51aadf4ce57d555e502fcce93.zip
Implemented offline firmware upgrade support on PPC.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs95
1 files changed, 93 insertions, 2 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
index 8d6e02020..7228c53d3 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs
@@ -517,6 +517,22 @@ namespace Tango.PPC.Common.MachineUpdate
_isUpdating = false;
}
+ private void OnFailed(Exception ex, TaskCompletionSource<object> completionSource)
+ {
+ LogManager.Log(ex, "An error occurred in firmware upgrade.");
+
+ completionSource.SetException(ex);
+ String logs = GetLogsStringAndClear();
+ _isUpdating = false;
+ }
+
+ private void OnCompleted(TaskCompletionSource<object> completionSource)
+ {
+ LogManager.Log("Firmware upgrade completed successfully.");
+ completionSource.SetResult(true);
+ _isUpdating = false;
+ }
+
private String GetLogsStringAndClear()
{
String logsString = String.Join(Environment.NewLine, _logs.ToList().Select(x => x.ToString()));
@@ -585,7 +601,7 @@ namespace Tango.PPC.Common.MachineUpdate
{
throw LogManager.Log(new InvalidOperationException("Could not perform an update while the machine is not connected."));
}
- if (op.Status != MachineStatuses.ReadyToDye)
+ if (!op.CanPrint)
{
throw LogManager.Log(new InvalidOperationException($"Could not perform an update while the machine is in {op.Status} status."));
}
@@ -819,6 +835,81 @@ namespace Tango.PPC.Common.MachineUpdate
return await result.Task;
}
+ public async Task UpdateFromTFP(String fileName)
+ {
+ _updateStartDate = DateTime.UtcNow;
+ _logs.Clear();
+
+ TaskCompletionSource<object> result = new TaskCompletionSource<object>();
+
+ try
+ {
+ _isUpdating = true;
+
+ LogManager.Log("Verifying machine connection and state...");
+
+ UpdateProgress("Verifying machine state", "Initializing...");
+
+ await Task.Delay(1000);
+
+ IMachineOperator op = _machineProvider.MachineOperator;
+
+ if (op.State != Transport.TransportComponentState.Connected)
+ {
+ throw LogManager.Log(new InvalidOperationException("Could not perform a firmware upgrade while the machine is not connected."));
+ }
+ if (!op.CanPrint)
+ {
+ throw LogManager.Log(new InvalidOperationException($"Could not perform a firmware upgrade while the machine is in {op.Status} status."));
+ }
+
+ UpdateProgress("Updating Firmware", "Connecting to firmware device...");
+ LogManager.Log("");
+ LogManager.Log("-------------------------------------------------------------------------");
+ LogManager.Log("Updating Firmware...");
+
+ UpdateProgress("Updating Firmware", "Loading firmware package...");
+ var stream = new FileStream(fileName, FileMode.Open);
+
+ if (!_machineProvider.Machine.IsDemo)
+ {
+ op.FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE;
+ }
+ else
+ {
+ op.FirmwareUpgradeMode = FirmwareUpgradeModes.TFP_PACKAGE;
+ }
+
+ var handler = await op.UpgradeFirmware(stream);
+ handler.Failed += (_, ex) =>
+ {
+ stream.Dispose();
+ OnFailed(ex, result);
+ };
+ handler.Completed += (_, __) =>
+ {
+ UpdateProgress("Updating Firmware", "Firmware update completed successfully.");
+ stream.Dispose();
+ OnCompleted(result);
+ };
+ handler.Canceled += (_, __) =>
+ {
+ stream.Dispose();
+ OnFailed(new Exception("The operation has been canceled."), result);
+ };
+ handler.Progress += (_, e) =>
+ {
+ UpdateProgress("Updating Firmware", e.Message, false, e.Current, e.Total);
+ };
+ }
+ catch (Exception ex)
+ {
+ OnFailed(ex, result);
+ }
+
+ await result.Task;
+ }
+
/// <summary>
/// Checks if any update are available for the specified machine serial number.
/// </summary>
@@ -1166,7 +1257,7 @@ namespace Tango.PPC.Common.MachineUpdate
{
throw LogManager.Log(new InvalidOperationException("Could not perform an update while the machine is not connected."));
}
- if (op.Status != MachineStatuses.ReadyToDye)
+ if (!op.CanPrint)
{
throw LogManager.Log(new InvalidOperationException($"Could not perform an update while the machine is in {op.Status} status."));
}