aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2019-12-19 18:01:01 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2019-12-19 18:01:01 +0200
commit1208554e06da8aec1b074932df488769572ffcfb (patch)
tree9858ededeb8badda5fc8b3052ef9745e419f35fd /Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
parent690604e6167bfa4fea0ab02f8b24a68142e8b546 (diff)
downloadTango-1208554e06da8aec1b074932df488769572ffcfb.tar.gz
Tango-1208554e06da8aec1b074932df488769572ffcfb.zip
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.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs')
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs170
1 files changed, 165 insertions, 5 deletions
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
/// </summary>
public event EventHandler<PowerDownStartedEventArgs> PowerDownStarted;
+ /// <summary>
+ /// Occurs when the thread loading status has changed.
+ /// </summary>
+ public event EventHandler<StartThreadLoadingResponse> ThreadLoadingStatusChanged;
+
+ /// <summary>
+ /// Occurs when a thread loading confirmation is required.
+ /// </summary>
+ public event EventHandler<ThreadLoadingConfirmationRequiredEventArgs> ThreadLoadingConfirmationRequired;
+
+ /// <summary>
+ /// Occurs when thread loading has completed.
+ /// </summary>
+ public event EventHandler<StartThreadLoadingResponse> ThreadLoadingCompleted;
+
+ /// <summary>
+ /// Occurs when thread loading has failed.
+ /// </summary>
+ public event EventHandler<StartThreadLoadingResponse> 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;
+ /// <summary>
+ /// Gets the current thread loading status.
+ /// </summary>
+ public StartThreadLoadingResponse ThreadLoadingStatus
+ {
+ get { return _threadLoadingStatus; }
+ private set { _threadLoadingStatus = value; RaisePropertyChangedAuto(); }
}
/// <summary>
@@ -409,6 +441,21 @@ namespace Tango.Integration.Operation
}
}
+ private bool _enableAutomaticThreadLoading;
+ /// <summary>
+ /// Gets or sets a value indicating whether to enable automatic thread loading support.
+ /// </summary>
+ public bool EnableAutomaticThreadLoading
+ {
+ get { return _enableAutomaticThreadLoading; }
+ set
+ {
+ _enableAutomaticThreadLoading = value;
+ RaisePropertyChangedAuto();
+ OnEnableAutomaticThreadLoadingChanged(value);
+ }
+ }
+
private bool _enableJobResume;
/// <summary>
/// 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<StartThreadLoadingRequest, StartThreadLoadingResponse>(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<StopThreadLoadingRequest, StopThreadLoadingResponse>(req);
+ LogResponseReceived(res.Message);
+ }
+ catch (Exception ex)
+ {
+ LogRequestFailed(req, ex);
+ }
+ }
+ }
+ }
+
/// <summary>
/// Invokes the <see cref="DiagnosticsDataAvailable"/> event.
/// </summary>
@@ -797,7 +903,7 @@ namespace Tango.Integration.Operation
}
/// <summary>
- /// Called when the machine status has been update
+ /// Called when the machine status has been updated.
/// </summary>
/// <param name="response">The response.</param>
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)
@@ -846,6 +952,59 @@ namespace Tango.Integration.Operation
}
/// <summary>
+ /// Called when the thread loading status has been changed.
+ /// </summary>
+ /// <param name="response">The response.</param>
+ 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<ContinueThreadLoadingRequest, ContinueThreadLoadingResponse>(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;
+ }
+ }
+ }
+
+ /// <summary>
/// Called when the request has been sent
/// </summary>
/// <param name="response">The request.</param>
@@ -1065,6 +1224,7 @@ namespace Tango.Integration.Operation
OnEnableEmbeddedDebuggingChanged(EnableEmbeddedDebugging);
OnEnableEventsNotification(EnableEventsNotification);
OnEnableMachineStatusUpdatesChanged(EnableMachineStatusUpdates);
+ OnEnableAutomaticThreadLoadingChanged(EnableAutomaticThreadLoading);
if (EnableJobResume)
{