blob: 5413dd8ec3808345b73a65a371cff576fafdf6cd (
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
using Google.Protobuf.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Enumerations;
using Tango.FSE.Common.Diagnostics;
using Tango.PMR.Diagnostics;
namespace Tango.FSE.Common.Diagnostics
{
/// <summary>
/// Represents a machine diagnostics frame package.
/// </summary>
public class DiagnosticsPackage
{
private static Dictionary<String, PropertyInfo> _monitorsProperties;
/// <summary>
/// Gets or sets the diagnostics frame.
/// </summary>
public DiagnosticsFrame Frame { get; set; }
/// <summary>
/// Gets or sets the monitors properties.
/// </summary>
public Dictionary<String, PropertyInfo> MonitorsProperties { get; private set; }
/// <summary>
/// Initializes the <see cref="DiagnosticsPackage"/> class.
/// </summary>
static DiagnosticsPackage()
{
_monitorsProperties = new Dictionary<string, PropertyInfo>();
foreach (var prop in typeof(DiagnosticsMonitors).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList())
{
_monitorsProperties.Add(prop.Name, prop);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DiagnosticsPackage"/> class.
/// </summary>
public DiagnosticsPackage(DiagnosticsFrame frame)
{
MonitorsProperties = _monitorsProperties;
Frame = frame;
}
/// <summary>
/// Gets the monitor value by the specified <see cref="TechMonitors"/> enumeration.
/// </summary>
/// <param name="monitor">The monitor enumeration.</param>
/// <returns>The monitor object.</returns>
public object GetMonitorObject(TechMonitors monitor)
{
return MonitorsProperties[monitor.ToString()].GetValue(Frame.Data.Monitors);
}
/// <summary>
/// Gets the last data point of a repeated field monitor by the specified <see cref="TechMonitors"/> enumeration.
/// </summary>
/// <param name="monitor">The monitor enumeration.</param>
/// <returns>Last value in the array.</returns>
public double GetMonitorLastValue(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
RepeatedField<double> arr = value as RepeatedField<double>;
return arr.LastOrDefault();
}
/// <summary>
/// Gets the data array from a protobuf repeated monitor by the specified <see cref="TechMonitors"/> enumeration.
/// </summary>
/// <param name="monitor">The monitor enumeration.</param>
/// <returns>List of double values representing the monitor data points.</returns>
public List<double> GetMonitorArray(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
return (value as RepeatedField<double>).ToList();
}
/// <summary>
/// Gets the data matrix from a protobuf repeated field of <see cref="DoubleArray"/>.
/// </summary>
/// <param name="monitor">The monitor enumeration.</param>
/// <returns>A matrix of double values.</returns>
public List<List<double>> GetMonitorMatrix(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
DoubleArray[] arrayOfDoubles = Enumerable.ToArray(value as IEnumerable<DoubleArray>);
return arrayOfDoubles.Select(x => x.Data.ToList()).ToList();
}
/// <summary>
/// Gets the state of the digital interface.
/// </summary>
/// <param name="interface">The interface.</param>
/// <returns>Digital interface state object.</returns>
public DigitalInterfaceState GetDigitalInterfaceState(TechIos @interface)
{
return Frame.Data.DigitalInterfaceStates.SingleOrDefault(x => x.InterfaceIO == (InterfaceIOs)@interface);
}
/// <summary>
/// Gets the state of the specified valve.
/// </summary>
/// <param name="valve">The valve.</param>
/// <returns>Valve state object.</returns>
public ValveState GetValveState(TechValves valve)
{
return Frame.Data.ValvesStates.SingleOrDefault(x => x.ValveType == (ValveType)valve);
}
/// <summary>
/// Gets the state of the specified heater.
/// </summary>
/// <param name="heater">The heater.</param>
/// <returns>Heater state object.</returns>
public HeaterState GetHeaterState(TechHeaters heater)
{
return Frame.Data.HeatersStates.SingleOrDefault(x => x.HeaterType == (HeaterType)heater);
}
}
}
|