diff options
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs | 7 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs | 95 |
2 files changed, 100 insertions, 2 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs index 421b4ee54..3e3fbcc27 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/IMachineUpdateManager.cs @@ -54,6 +54,13 @@ namespace Tango.PPC.Common.MachineUpdate Task<MachineUpdateResult> UpdateFromTUP(String fileName, bool setupFirmware, bool setupFPGA); /// <summary> + /// Performs a firmware upgrade from the specified TFP file. + /// </summary> + /// <param name="fileName">Name of the file.</param> + /// <returns></returns> + Task UpdateFromTFP(String fileName); + + /// <summary> /// Checks if any update are available for the specified machine serial number. /// </summary> /// <param name="serialNumber">The serial number.</param> 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.")); } |
