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
{
///
/// Represents a machine diagnostics frame package.
///
public class DiagnosticsPackage
{
private static Dictionary _monitorsProperties;
///
/// Gets or sets the diagnostics frame.
///
public DiagnosticsFrame Frame { get; set; }
///
/// Gets or sets the monitors properties.
///
public Dictionary MonitorsProperties { get; private set; }
///
/// Initializes the class.
///
static DiagnosticsPackage()
{
_monitorsProperties = new Dictionary();
foreach (var prop in typeof(DiagnosticsMonitors).GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList())
{
_monitorsProperties.Add(prop.Name, prop);
}
}
///
/// Initializes a new instance of the class.
///
public DiagnosticsPackage(DiagnosticsFrame frame)
{
MonitorsProperties = _monitorsProperties;
Frame = frame;
}
///
/// Gets the monitor value by the specified enumeration.
///
/// The monitor enumeration.
/// The monitor object.
public object GetMonitorObject(TechMonitors monitor)
{
return MonitorsProperties[monitor.ToString()].GetValue(Frame.Data.Monitors);
}
///
/// Gets the last data point of a repeated field monitor by the specified enumeration.
///
/// The monitor enumeration.
/// Last value in the array.
public double GetMonitorLastValue(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
RepeatedField arr = value as RepeatedField;
return arr.LastOrDefault();
}
///
/// Gets the data array from a protobuf repeated monitor by the specified enumeration.
///
/// The monitor enumeration.
/// List of double values representing the monitor data points.
public List GetMonitorArray(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
return (value as RepeatedField).ToList();
}
///
/// Gets the data matrix from a protobuf repeated field of .
///
/// The monitor enumeration.
/// A matrix of double values.
public List> GetMonitorMatrix(TechMonitors monitor)
{
var value = GetMonitorObject(monitor);
DoubleArray[] arrayOfDoubles = Enumerable.ToArray(value as IEnumerable);
return arrayOfDoubles.Select(x => x.Data.ToList()).ToList();
}
///
/// Gets the state of the digital interface.
///
/// The interface.
/// Digital interface state object.
public DigitalInterfaceState GetDigitalInterfaceState(TechIos @interface)
{
return Frame.Data.DigitalInterfaceStates.SingleOrDefault(x => x.InterfaceIO == (InterfaceIOs)@interface);
}
///
/// Gets the state of the specified valve.
///
/// The valve.
/// Valve state object.
public ValveState GetValveState(TechValves valve)
{
return Frame.Data.ValvesStates.SingleOrDefault(x => x.ValveType == (ValveType)valve);
}
///
/// Gets the state of the specified heater.
///
/// The heater.
/// Heater state object.
public HeaterState GetHeaterState(TechHeaters heater)
{
return Frame.Data.HeatersStates.SingleOrDefault(x => x.HeaterType == (HeaterType)heater);
}
}
}