From 1208554e06da8aec1b074932df488769572ffcfb Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 19 Dec 2019 18:01:01 +0200 Subject: Implemented auto thread loading. Implemented advanced settings for technician. Implemented thread loading on emulator. Removed PowerUpSelectedRML from settings. Now using LoadedRml settings for ThreadLoading and PowerUp. --- .../ExternalBridge/ExternalBridgeTcpClient.cs | 1 + .../Operation/IMachineOperator.cs | 31 ++++ .../Tango.Integration/Operation/MachineOperator.cs | 170 ++++++++++++++++++++- .../ThreadLoadingConfirmationRequiredEventArgs.cs | 27 ++++ .../Tango.Integration/Tango.Integration.csproj | 3 +- 5 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs (limited to 'Software/Visual_Studio/Tango.Integration') diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs index 3bbef3eb6..d3344aa16 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeTcpClient.cs @@ -133,6 +133,7 @@ namespace Tango.Integration.ExternalBridge OnEnableEventsNotification(EnableEventsNotification); OnEnableApplicationLogsChanged(EnableApplicationLogs); OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates); + OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index b5b7b7393..8156ef8c7 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -23,6 +23,7 @@ using Tango.PMR.FirmwareUpgrade; using Tango.Integration.JobRuns; using Tango.Integration.Emergency; using Tango.PMR.MachineStatus; +using Tango.PMR.ThreadLoading; namespace Tango.Integration.Operation { @@ -63,6 +64,11 @@ namespace Tango.Integration.Operation /// MachineStatus MachineStatus { get; } + /// + /// Gets the current thread loading status. + /// + StartThreadLoadingResponse ThreadLoadingStatus { get; } + /// /// Gets or sets the firmware upgrade mode. /// @@ -198,6 +204,26 @@ namespace Tango.Integration.Operation /// event EventHandler PowerDownStarted; + /// + /// Occurs when the thread loading status has changed. + /// + event EventHandler ThreadLoadingStatusChanged; + + /// + /// Occurs when a thread loading confirmation is required. + /// + event EventHandler ThreadLoadingConfirmationRequired; + + /// + /// Occurs when thread loading has completed. + /// + event EventHandler ThreadLoadingCompleted; + + /// + /// Occurs when thread loading has failed. + /// + event EventHandler ThreadLoadingFailed; + /// /// Gets or sets a value indicating whether direct the embedded device to send diagnostics messages. /// @@ -223,6 +249,11 @@ namespace Tango.Integration.Operation /// bool EnableMachineStatusUpdates { get; set; } + /// + /// Gets or sets a value indicating whether to enable automatic thread loading support. + /// + bool EnableAutomaticThreadLoading { get; set; } + /// /// Gets the last process parameters table sent to the embedded device. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index e142066b6..74c64930b 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -42,6 +42,7 @@ using Newtonsoft.Json; using Tango.PMR.Integration; using System.Globalization; using Tango.PMR.Power; +using Tango.PMR.ThreadLoading; namespace Tango.Integration.Operation { @@ -68,6 +69,7 @@ namespace Tango.Integration.Operation private bool _eventsSent; private bool _debugSent; private bool _machineStatusSent; + private bool _threadLoadingSent; private EmbeddedLogItem _last_embedded_debug_log; private static RunningJobStatus _last_job_status; private bool _isPowerDownRequestInProgress; @@ -224,6 +226,26 @@ namespace Tango.Integration.Operation /// public event EventHandler PowerDownStarted; + /// + /// Occurs when the thread loading status has changed. + /// + public event EventHandler ThreadLoadingStatusChanged; + + /// + /// Occurs when a thread loading confirmation is required. + /// + public event EventHandler ThreadLoadingConfirmationRequired; + + /// + /// Occurs when thread loading has completed. + /// + public event EventHandler ThreadLoadingCompleted; + + /// + /// Occurs when thread loading has failed. + /// + public event EventHandler ThreadLoadingFailed; + #endregion #region Properties @@ -271,7 +293,17 @@ namespace Tango.Integration.Operation public MachineStatus MachineStatus { get { return _machineStatus; } - set { _machineStatus = value; RaisePropertyChangedAuto(); } + private set { _machineStatus = value; RaisePropertyChangedAuto(); } + } + + private StartThreadLoadingResponse _threadLoadingStatus; + /// + /// Gets the current thread loading status. + /// + public StartThreadLoadingResponse ThreadLoadingStatus + { + get { return _threadLoadingStatus; } + private set { _threadLoadingStatus = value; RaisePropertyChangedAuto(); } } /// @@ -409,6 +441,21 @@ namespace Tango.Integration.Operation } } + private bool _enableAutomaticThreadLoading; + /// + /// Gets or sets a value indicating whether to enable automatic thread loading support. + /// + public bool EnableAutomaticThreadLoading + { + get { return _enableAutomaticThreadLoading; } + set + { + _enableAutomaticThreadLoading = value; + RaisePropertyChangedAuto(); + OnEnableAutomaticThreadLoadingChanged(value); + } + } + private bool _enableJobResume; /// /// Gets or sets a value indicating whether to check whether a job is in progress after connection was successful. @@ -745,6 +792,65 @@ namespace Tango.Integration.Operation } } + protected virtual async void OnEnableAutomaticThreadLoadingChanged(bool value) + { + if (value && State == TransportComponentState.Connected && !_threadLoadingSent) + { + var request = new StartThreadLoadingRequest(); + + bool responseLogged = false; + _threadLoadingSent = true; + + SendContinuousRequest(request).ObserveOn(new NewThreadScheduler()).Subscribe( + (response) => + { + OnThreadLoadingStatusChanged(response); + + if (!responseLogged) + { + LogResponseReceived(response.Message); + responseLogged = true; + } + }, + (ex) => + { + _threadLoadingSent = false; + + if (!(ex is ContinuousResponseAbortedException)) + { + LogRequestFailed(request, ex); + } + }, + () => + { + _threadLoadingSent = false; + LogManager.Log("Thread loading response completed!?", LogCategory.Warning); + }); + + LogRequestSent(request); + } + else if (_threadLoadingSent) + { + _threadLoadingSent = false; + + if (State == TransportComponentState.Connected) + { + var req = new StopThreadLoadingRequest(); + + try + { + LogRequestSent(req); + var res = await SendRequest(req); + LogResponseReceived(res.Message); + } + catch (Exception ex) + { + LogRequestFailed(req, ex); + } + } + } + } + /// /// Invokes the event. /// @@ -797,7 +903,7 @@ namespace Tango.Integration.Operation } /// - /// Called when the machine status has been update + /// Called when the machine status has been updated. /// /// The response. protected async virtual void OnMachineStatusChanged(StartMachineStatusUpdateResponse response) @@ -824,9 +930,9 @@ namespace Tango.Integration.Operation case MachineState.Ready: Status = MachineStatuses.ReadyToDye; break; - //case MachineState.Sleep: - // Status = MachineStatuses.Standby; - // break; + case MachineState.Sleep: + Status = MachineStatuses.Standby; + break; case MachineState.PowerOff: Status = MachineStatuses.ShuttingDown; if (!_isPowerDownRequestInProgress) @@ -845,6 +951,59 @@ namespace Tango.Integration.Operation } } + /// + /// Called when the thread loading status has been changed. + /// + /// The response. + protected virtual void OnThreadLoadingStatusChanged(StartThreadLoadingResponse response) + { + bool changed = (ThreadLoadingStatus == null || response.State != ThreadLoadingStatus.State || response.ErrorReason != ThreadLoadingStatus.ErrorReason); + + if (changed) + { + ThreadLoadingStatus = response; + ThreadLoadingStatusChanged?.Invoke(this, response); + + LogManager.Log($"Thread Loading Status Changed: {ThreadLoadingStatus.State}."); + + switch (ThreadLoadingStatus.State) + { + case ThreadLoadingState.ReadyForLoading: + + LogManager.Log("Thread loading is ready for loading. Invoking confirmation event..."); + + ThreadLoadingConfirmationRequired?.Invoke(this, new ThreadLoadingConfirmationRequiredEventArgs((processTable) => + { + //Confirm Action + try + { + var process = processTable.ToProcessParametersPMR(); + LogManager.Log($"Thread loading confirmation received with process parameters:\n{process.ToJsonString()}"); + LogManager.Log("Sending continue thread loading request..."); + var r = SendRequest(new ContinueThreadLoadingRequest() + { + ProcessParameters = process, + }).Result; + } + catch (Exception ex) + { + LogManager.Log(ex, "Error confirming thread loading sequence."); + } + }) + { + Status = ThreadLoadingStatus, + }); + break; + case ThreadLoadingState.Completed: + ThreadLoadingCompleted?.Invoke(this, ThreadLoadingStatus); + break; + case ThreadLoadingState.FinalizationError: + ThreadLoadingFailed?.Invoke(this, ThreadLoadingStatus); + break; + } + } + } + /// /// Called when the request has been sent /// @@ -1065,6 +1224,7 @@ namespace Tango.Integration.Operation OnEnableEmbeddedDebuggingChanged(EnableEmbeddedDebugging); OnEnableEventsNotification(EnableEventsNotification); OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates); + OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading); if (EnableJobResume) { diff --git a/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs new file mode 100644 index 000000000..e5594dd01 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/ThreadLoadingConfirmationRequiredEventArgs.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.PMR.ThreadLoading; + +namespace Tango.Integration.Operation +{ + public class ThreadLoadingConfirmationRequiredEventArgs : EventArgs + { + private Action _confirm; + + public StartThreadLoadingResponse Status { get; set; } + + internal ThreadLoadingConfirmationRequiredEventArgs(Action confirm) + { + _confirm = confirm; + } + + public void Confirm(ProcessParametersTable processTable) + { + _confirm.Invoke(processTable); + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 5a4fcadf1..a3feac546 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -112,6 +112,7 @@ + @@ -198,7 +199,7 @@ - + \ No newline at end of file -- cgit v1.3.1