using System; using System.Collections.Generic; using System.Linq; using static DTS.Common.Enums.DASFactory.DFConstantsAndEnums; namespace DTS.DASLib.Service { /// /// the base class for our internal callbacks (specific service callback to generic service) /// public class ServiceCallbackData { public class DiagnosticNewData { public int DasChannelNumber { get; set; } public enum Actions { MeasureBridgeMv, MeasureShunt, ScaleFactorMv, FactoryExcitation, MeasureExcitation, MeasureOffset, CalSignalCheck, FinalOffset, MeasureNoise, RemoveOffset, ShuntCheck, QueryModules, MeasureVoltages, TestChannelRun, TestChannelRead, MeasureInternalOffset, MeasureFinalInternalOffset }; public Actions Action { get; set; } public object Result { get; set; } } public class TiltNewData { public double[] TiltData { get; set; } public double[] AccelData { get; set; } } public class TemperatureData { public int Channel1 { get; set; } public int Channel2 { get; set; } public DateTime[] Timestamps { get; set; } public double[] Sensor1 { get; set; } public double[] Sensor2 { get; set; } } public class UARTNewData { public ulong DataOffset { get; set; } public byte[] UARTData { get; set; } } /// /// The different types of callbacks /// public enum CallbackStatus { ProgressReport, NewData, Timeout, Success, Failure, Canceled, InvalidParameters // and others } /// /// What kind of message is this /// public CallbackStatus Status { get; set; } /// /// If it was an error (Status==Failure), the message is here /// public string ErrorMessage { get; set; } /// /// If it was an exception (Status==Failure), it's here otherwise null /// public System.Exception ErrorException { get; set; } /// /// If it was ProgressReport, this is the percentage done /// public int ProgressValue { get; set; } /// /// The user supplied data is here /// public object UserData { get; set; } /// /// callback could contain multiple non contiguous samples /// if so, we will need to know a separate sample number and short [][] /// for each break /// this is mostly for nicer realtime handling so data can be obtained from the /// h/w at a different rate then the UI is updated at /// private IList _Data = new List(); /// /// returns a collection of SampleData /// objects which contain sequences of channel data and a number indicating /// which samle number in the h/w each sequence begins at /// public SampleData[] DataSamples { get => _Data.ToArray(); set => _Data = new List(value); } private DiagnosticNewData _newDiagnosticData = null; private TiltNewData _newTiltData = null; private UARTNewData _newUartData = null; private TemperatureData _newTemperatureData = null; public DiagnosticNewData NewDiagnosticData => _newDiagnosticData; public void SetNewDiagnosticData(DiagnosticNewData data) { _newDiagnosticData = data; } public void SetNewTiltData(TiltNewData data) { _newTiltData = data; } public void SetNewTemperatureData(TemperatureData data) { _newTemperatureData = data; } public void SetNewUARTData(UARTNewData data) { _newUartData = data; } private byte[] _byteData = null; public void SetNewByteData(byte[] data) { _byteData = data; } public byte[] ByteData { get => _byteData; } public TiltNewData NewTiltData => _newTiltData; public UARTNewData NewUARTData => _newUartData; public TemperatureData NewTemperatureData => _newTemperatureData; /// /// adds a new sample (composed of multiple channels of short [] data and /// a sample number indicating the start of the data /// /// /// public void AddSampleData(short[][] data, ulong sampleNumber, ulong timeStamp, ulong sequenceNumber) { _Data.Add(new SampleData(data, sampleNumber, timeStamp, sequenceNumber)); } /// /// returns the SampleData struct /// at a given index among a collection of samples /// /// /// public SampleData GetSampleData(int index) { return _Data[index]; } /// /// the total number of different non contiguous samples in the data /// /// public int GetNumberOfSamples() { return _Data.Count; } } }