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. --- .../Tango.Integration/Operation/MachineOperator.cs | 170 ++++++++++++++++++++- 1 file changed, 165 insertions(+), 5 deletions(-) (limited to 'Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs') 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) { -- cgit v1.3.1