blob: 68f68d47c1e09fb0b22082fffe225b47cdd6571d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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 diagnostics data available.
/// </summary>
public event EventHandler<StartDiagnosticsResponse> DiagnosticsDataAvailable;
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<StartDiagnosticsRequest, StartDiagnosticsResponse>(new TangoMessage<StartDiagnosticsRequest>(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 ??
});
}
}
/// <summary>
/// Invokes the <see cref="DiagnosticsDataAvailable"/> event.
/// </summary>
/// <param name="data">The sensors data.</param>
protected virtual void OnDiagnosticsDataAvailable(StartDiagnosticsResponse data)
{
DiagnosticsDataAvailable?.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);
}
}
}
|