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 { /// /// Occurs when there is new diagnostics data available. /// public event EventHandler DiagnosticsDataAvailable; private bool _enableDiagnostics; /// /// Gets or sets a value indicating whether to enable diagnostics messages by requesting diagnostics messages. /// public bool EnableSensorsUpdate { get { return _enableDiagnostics; } set { if (_enableDiagnostics != value) { _enableDiagnostics = value; RaisePropertyChangedAuto(); OnEnableSensorsUpdateChanged(value); } } } /// /// Called when the enable sensors update property has been changed /// /// if set to true [value]. protected virtual void OnEnableSensorsUpdateChanged(bool value) { if (value && State == TransportComponentState.Connected) { SendContinuousRequest(new TangoMessage(new StartDiagnosticsRequest() { PushMotors = true, PushSensors = true, }, PMR.Common.MessageType.StartDiagnosticsRequest)).ObserveOn(new NewThreadScheduler()).Subscribe( (response) => { OnDiagnosticsDataAvailable(response); }, (ex) => { //Do I need separate event for each one ?? }, () => { //What to do now ?? }); } } /// /// Invokes the event. /// /// The sensors data. protected virtual void OnDiagnosticsDataAvailable(StartDiagnosticsResponse data) { DiagnosticsDataAvailable?.Invoke(this, data); } /// /// Called when the component state has changed. /// /// The state. protected override void OnStateChanged(TransportComponentState state) { base.OnStateChanged(state); OnEnableSensorsUpdateChanged(EnableSensorsUpdate); } } }