init
This commit is contained in:
325
DataPRO/IService/Classes/Download/DownloadReport.cs
Normal file
325
DataPRO/IService/Classes/Download/DownloadReport.cs
Normal file
@@ -0,0 +1,325 @@
|
||||
|
||||
using DASFactoryDb.Download;
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Interface.DASFactory.Config;
|
||||
using DTS.Common.Interface.DASFactory.Download;
|
||||
using DTS.Common.Interface.DownloadEvent;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data.SqlTypes;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This class represent all events stored on the DAS. It is populated during
|
||||
/// <see cref="DownloadService.QueryDownload" />.
|
||||
/// </summary>
|
||||
public class DownloadReport : IDownloadReport
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represent one event/test.
|
||||
/// </summary>
|
||||
public class EventInfo : IEventInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Information about each module that was part of the event. Addressable by
|
||||
/// ModuleArrayIndex of the corresponding module.
|
||||
/// </summary>
|
||||
public IDASModule[] Modules { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The event number this information is regarding.
|
||||
/// </summary>
|
||||
public int EventNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The GUID of the corresponding event.
|
||||
/// </summary>
|
||||
public Guid TestGUID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fault flags (if any)
|
||||
/// </summary>
|
||||
public ushort FaultFlags { get; set; }
|
||||
/// <summary>
|
||||
/// fault flags extended (if any)
|
||||
/// </summary>
|
||||
public ushort FaultFlagsEx { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Arm Attempts (if any)
|
||||
/// </summary>
|
||||
public byte ArmAttempts { get; set; }
|
||||
/// <summary>
|
||||
/// The timestamp of this event.
|
||||
/// </summary>
|
||||
public DateTime TestTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ID of this event.
|
||||
/// </summary>
|
||||
public string TestID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A text description that was stored.
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if this event has already been downloaded.
|
||||
/// </summary>
|
||||
public bool HasBeenDownloaded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if this event received a trigger.
|
||||
/// </summary>
|
||||
public bool WasTriggered { get; set; }
|
||||
/// <summary>
|
||||
/// clears any fault flags
|
||||
/// </summary>
|
||||
public void ClearFaults()
|
||||
{
|
||||
FaultFlags = 0;
|
||||
FaultFlagsEx = 0;
|
||||
}
|
||||
public EventInfo() { }
|
||||
public EventInfo(EventInfo copy)
|
||||
{
|
||||
Modules = copy.Modules;
|
||||
|
||||
EventNumber = copy.EventNumber;
|
||||
|
||||
TestGUID = copy.TestGUID;
|
||||
|
||||
FaultFlags = copy.FaultFlags;
|
||||
FaultFlagsEx = copy.FaultFlagsEx;
|
||||
|
||||
ArmAttempts = copy.ArmAttempts;
|
||||
TestTime = copy.TestTime;
|
||||
|
||||
TestID = copy.TestID;
|
||||
|
||||
Description = copy.Description;
|
||||
|
||||
HasBeenDownloaded = copy.HasBeenDownloaded;
|
||||
|
||||
WasTriggered = copy.WasTriggered;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class represent one event/test.
|
||||
/// </summary>
|
||||
public class UARTEventInfo : IUARTEventInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// From which event do we want to download data?
|
||||
/// </summary>
|
||||
public ushort EventNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is data present?
|
||||
/// </summary>
|
||||
public bool DataPresent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Has data already been downloaded?
|
||||
/// </summary>
|
||||
public bool DataDownloaded { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// How much data is there?
|
||||
/// </summary>
|
||||
public ulong TotalByteCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Where in the data did the trigger occur?
|
||||
/// </summary>
|
||||
public ulong TriggerByteCount { get; set; }
|
||||
/// <summary>
|
||||
/// Where are the faults?
|
||||
/// </summary>
|
||||
public ulong FaultByteCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When did the UART stream start?
|
||||
/// </summary>
|
||||
public ulong StartTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When did the UART stream end?
|
||||
/// </summary>
|
||||
public ulong EndTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// What was the baud rate during UART recording?
|
||||
/// </summary>
|
||||
public uint BaudRate { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An array of all events stored on this DAS.
|
||||
/// </summary>
|
||||
public IEventInfo[] Events { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An array of all UART events stored on this DAS.
|
||||
/// </summary>
|
||||
public IUARTEventInfo[] UARTEvents { get; set; }
|
||||
|
||||
public static void SetEventDownloadStatus(IDASCommunication das, bool[] status, bool bStoreInDb)
|
||||
{
|
||||
if (null == das) { return; }
|
||||
das.EventDownloadedStatus = status;
|
||||
if (!bStoreInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingEventDownloadStatus(das.RecordId);
|
||||
if (null == status) { return; }
|
||||
foreach (var statum in status)
|
||||
{
|
||||
Download.InsertEventDownloadStatus(das.RecordId, statum);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
public static void SetEventArmAttempts(IDASCommunication das, byte[] armAttempts, bool storeInDb)
|
||||
{
|
||||
if (null == das) { return; }
|
||||
das.ArmAttempts = armAttempts;
|
||||
|
||||
if (!storeInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingEventArmAttempts(das.RecordId);
|
||||
if (null == armAttempts) { return; }
|
||||
foreach (byte armAttempt in armAttempts)
|
||||
{
|
||||
Download.InsertEventArmAttempts(das.RecordId, armAttempt);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
public static void SetEventFaultFlags(IDASCommunication das, ushort[] faultFlags, bool storeInDb)
|
||||
{
|
||||
if (null == das) { return; }
|
||||
das.FaultFlags = faultFlags;
|
||||
if (!storeInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingFaultFlags(das.RecordId);
|
||||
if (null == faultFlags) { return; }
|
||||
foreach (var flag in faultFlags)
|
||||
{
|
||||
Download.InsertEventFaultFlags(das.RecordId, flag);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetEventInfo(IDASCommunication das, IDownloadReport eventInfo, bool storeInDB)
|
||||
{
|
||||
if (null == das) { return; }
|
||||
das.EventInfo = eventInfo;
|
||||
if (!storeInDB || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingDownloadReports(das.RecordId);
|
||||
if (null == eventInfo || null == eventInfo.Events) { return; }
|
||||
foreach (var eventData in eventInfo.Events)
|
||||
{
|
||||
InsertEventInfo(das, eventData);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InsertEventInfo(IDASCommunication das, IEventInfo eventInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (null == eventInfo || null == das)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var xml = string.Empty;
|
||||
using (var sw = new StringWriter())
|
||||
{
|
||||
using (var xw = XmlWriter.Create(sw,
|
||||
new XmlWriterSettings() { ConformanceLevel = ConformanceLevel.Document }))
|
||||
{
|
||||
xw.WriteStartDocument();
|
||||
xw.WriteStartElement("Modules");
|
||||
foreach (var mod in eventInfo.Modules)
|
||||
{
|
||||
mod.WriteXml(xw);
|
||||
}
|
||||
|
||||
xw.WriteEndElement();
|
||||
xw.WriteEndDocument();
|
||||
}
|
||||
sw.Flush();
|
||||
xml = sw.ToString();
|
||||
}
|
||||
|
||||
Download.InsertEventInfo(das.RecordId,
|
||||
eventInfo.EventNumber,
|
||||
eventInfo.TestGUID,
|
||||
eventInfo.FaultFlags,
|
||||
eventInfo.ArmAttempts,
|
||||
eventInfo.TestTime,
|
||||
eventInfo.TestID,
|
||||
eventInfo.Description,
|
||||
eventInfo.HasBeenDownloaded,
|
||||
eventInfo.WasTriggered,
|
||||
xml
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
public static void SetEventGuids(IDASCommunication das, Guid[] guids, bool storeInDb)
|
||||
{
|
||||
if (null == das) { return; }
|
||||
das.EventGuids = guids;
|
||||
if (!storeInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingEventGuids(das.RecordId);
|
||||
if (null == guids) { return; }
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
Download.EventGuidInsert(das.RecordId, guid);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
108
DataPRO/IService/Classes/Download/DownloadRequest.cs
Normal file
108
DataPRO/IService/Classes/Download/DownloadRequest.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
|
||||
|
||||
using DASFactoryDb.Download;
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Interface.DASFactory.Download;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using System;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// This class describes what should be downloaded from the DAS to the PC.
|
||||
/// </summary>
|
||||
public class DownloadRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Setting the DASChannelNumber property of this object to this constant value will
|
||||
/// download all channels from the DAS. Currently, this is the only option that is supported
|
||||
/// so DASChannelNumber MUST be equal to this value.
|
||||
/// </summary>
|
||||
public const byte ALL_CHANNELS = 0xFF;
|
||||
|
||||
/// <summary>
|
||||
/// From which event do we want to download data?
|
||||
/// </summary>
|
||||
public ushort EventNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Which channel? (set to ALL_CHANNELS for all)
|
||||
/// </summary>
|
||||
public byte DASChannelNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The first sample you want.
|
||||
/// </summary>
|
||||
public virtual ulong StartSample { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last sample you want.
|
||||
/// </summary>
|
||||
public virtual ulong EndSample { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is used for sub-sampling data, 0 (or 1) means don't sub-sample, 2 means
|
||||
/// give me every other sample and so on. The number of samples requested
|
||||
/// (EndSample-StartSample+1) must be an multiple of SamplesToSkip.
|
||||
/// </summary>
|
||||
public ulong SamplesToSkip { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double StartRecordTimestampSec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double TriggerTimestampSec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double StartRecordTimestampNanoSec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public double TriggerTimestampNanoSec { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool PTPMasterSync { get; set; }
|
||||
|
||||
public static void SetWhatToDownload(IDASCommunication das, IDownloadRequest request, bool bSetInDb)
|
||||
{
|
||||
if (null != request)
|
||||
{
|
||||
APILogger.Log($"WhatToDownload = Event: {request.EventNumber}, StartSample: {request.StartSample}, EndSample: {request.EndSample}");
|
||||
}
|
||||
das.WhatToDownload = request;
|
||||
if (!bSetInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingDownloadRequests(das.RecordId);
|
||||
if (null != request)
|
||||
{
|
||||
Download.DownloadRequestInsert(das.RecordId,
|
||||
request.EventNumber,
|
||||
request.DASChannelNumber,
|
||||
request.StartSample,
|
||||
request.EndSample,
|
||||
request.SamplesToSkip,
|
||||
request.StartRecordTimestampSec,
|
||||
request.TriggerTimestampSec,
|
||||
request.StartRecordTimestampNanoSec,
|
||||
request.TriggerTimestampNanoSec,
|
||||
request.PTPMasterSync);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
68
DataPRO/IService/Classes/Download/UARTDownloadRequest.cs
Normal file
68
DataPRO/IService/Classes/Download/UARTDownloadRequest.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using DASFactoryDb.Download;
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Interface.DASFactory.Download;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public class UARTDownloadRequest : IUARTDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// From which event do we want to download data?
|
||||
/// </summary>
|
||||
public ushort EventNumber { get; set; }
|
||||
/// <summary>
|
||||
/// How much data is there?
|
||||
/// </summary>
|
||||
public ulong TotalByteCount { get; set; }
|
||||
/// <summary>
|
||||
/// Where in the data did the trigger occur?
|
||||
/// </summary>
|
||||
public ulong TriggerByteCount { get; set; }
|
||||
/// <summary>
|
||||
/// Where in the data did the fault occur?
|
||||
/// </summary>
|
||||
public ulong FaultByteCount { get; set; }
|
||||
/// <summary>
|
||||
/// When did the UART stream start?
|
||||
/// </summary>
|
||||
public ulong StartTimestamp { get; set; }
|
||||
/// <summary>
|
||||
/// When did the UART stream end?
|
||||
/// </summary>
|
||||
public ulong EndTimestamp { get; set; }
|
||||
/// <summary>
|
||||
/// What was the baud rate during recording?
|
||||
/// </summary>
|
||||
public int BaudRate { get; set; }
|
||||
|
||||
public static void SetWhatToDownload(IDASCommunication das, IUARTDownloadRequest request, bool bSetInDb)
|
||||
{
|
||||
if (!(das is IUARTDownload udas)) return;
|
||||
udas.WhatUARTToDownload = request;
|
||||
if (!bSetInDb || !DASFactoryDb.DbWrapper.Connected) { return; }
|
||||
|
||||
try
|
||||
{
|
||||
Download.ClearExistingUARTDownloadRequests(das.RecordId);
|
||||
if (null != request)
|
||||
{
|
||||
Download.UARTDownloadRequestInsert(das.RecordId,
|
||||
request.EventNumber,
|
||||
request.TotalByteCount,
|
||||
request.TriggerByteCount,
|
||||
request.FaultByteCount,
|
||||
request.StartTimestamp,
|
||||
request.EndTimestamp,
|
||||
request.BaudRate);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user