diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs new file mode 100644 index 000000000..aa039e7ae --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operators/MachineOperator.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.PMR; +using Tango.PMR.Diagnostics; +using Tango.Transport; +using Tango.Transport.Transporters; +using System.Reactive.Linq; +using System.Reactive.Concurrency; +using System.Reactive.Threading; + +namespace Tango.Integration.Operators +{ + public class MachineOperator : BasicTransporter, IMachineOperator + { + /// <summary> + /// Occurs when there is new sensors data available. + /// </summary> + public event EventHandler<PushSensorsResponse> SensorsDataAvailable; + + private bool _enableDiagnostics; + /// <summary> + /// Gets or sets a value indicating whether to enable diagnostics messages by requesting diagnostics messages. + /// </summary> + public bool EnableSensorsUpdate + { + get { return _enableDiagnostics; } + set + { + if (_enableDiagnostics != value) + { + _enableDiagnostics = value; + RaisePropertyChangedAuto(); + OnEnableSensorsUpdateChanged(value); + } + } + } + + /// <summary> + /// Called when the enable sensors update property has been changed + /// </summary> + /// <param name="value">if set to <c>true</c> [value].</param> + protected virtual void OnEnableSensorsUpdateChanged(bool value) + { + if (value && State == TransportComponentState.Connected) + { + SendContinuousRequest<PushSensorsRequest, PushSensorsResponse>(new TangoMessage<PushSensorsRequest>(new PushSensorsRequest(), PMR.Common.MessageType.PushSensorsRequest)).ObserveOn(new NewThreadScheduler()).Subscribe( + (response) => + { + OnSensorsDataAvailable(response); + }, + (ex) => + { + //Do I need separate event for each one ?? + }, + () => + { + //What to do now ?? + }); + } + } + + /// <summary> + /// Invokes the <see cref="SensorsDataAvailable"/> event. + /// </summary> + /// <param name="data">The sensors data.</param> + protected virtual void OnSensorsDataAvailable(PushSensorsResponse data) + { + SensorsDataAvailable?.Invoke(this, data); + } + + /// <summary> + /// Called when the component state has changed. + /// </summary> + /// <param name="state">The state.</param> + protected override void OnStateChanged(TransportComponentState state) + { + base.OnStateChanged(state); + + OnEnableSensorsUpdateChanged(EnableSensorsUpdate); + } + } +} |
