This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
/// <summary>
/// this is ported from FirmwareTestUtility where it was written by Loc Pham. It is included for
/// 10573 implement SW side of single command/streaming download
/// </summary>
public class DownloadByteConverter
{
public enum DlByteIndex
{
Sync = 0,
Type = 1,
Command = 2,
Status = 3,
Group = 4,
Id = 5,
Datalength = 6,
SequenceNumber = 8,
HeaderCRC = 10,
DataCRC = 12,
DataADCStartOffset = 14,
DataADCEndOffset = 22,
DataStart = 30
}
public ushort SeqNumber { get; }
public ushort SeqNumberPrev { get; }
public ulong DlAdcStartOffset { get; }
public ulong DlAdcEndOffset { get; }
public ulong DlStreamSampleNumber { get; }
public ushort[] DlData { get; }
public uint[] DlChannels { get; }
public DownloadByteConverter(byte[] bytes)
{
SeqNumber = GetUShort(bytes, (int)DlByteIndex.SequenceNumber);
DlAdcStartOffset = GetUInt(bytes, (int)DlByteIndex.DataADCStartOffset);
DlAdcStartOffset = GetULong(bytes, (int)DlByteIndex.DataADCEndOffset);
DlData = new ushort[(bytes.Length - (int)DlByteIndex.DataStart) / 2];
if (SeqNumber == 0)
{
SeqNumberPrev = 0;
}
else
{
if (SeqNumberPrev != 0 &&
SeqNumberPrev != SeqNumber - 1)
{
System.Diagnostics.Debug.WriteLine("sequence out of order: ");
System.Diagnostics.Debug.WriteLine(SeqNumberPrev.ToString());
System.Diagnostics.Debug.WriteLine(SeqNumber.ToString());
}
}
SeqNumberPrev = SeqNumber;
for (var idx = 0; idx < DlData.Length; idx++)
{
DlData[idx] = GetDownloadUShort(bytes, (int)(DlByteIndex.DataStart + idx * 2));
}
}
private static ulong GetULong(byte[] bytes, int offset)
{
return (ulong)bytes[offset + 7] << 0 |
(ulong)bytes[offset + 6] << 8 |
(ulong)bytes[offset + 5] << 16 |
(ulong)bytes[offset + 4] << 24 |
(ulong)bytes[offset + 3] << 32 |
(ulong)bytes[offset + 2] << 40 |
(ulong)bytes[offset + 1] << 48 |
(ulong)bytes[offset + 0] << 56;
}
private static ushort GetUShort(byte[] bytes, int offset)
{
return (ushort)(bytes[offset + 1] |
bytes[offset + 0] << 8);
}
private static uint GetUInt(byte[] bytes, int offset)
{
return (uint)bytes[offset + 3] << 0 |
(uint)bytes[offset + 2] << 8 |
(uint)bytes[offset + 1] << 16 |
(uint)bytes[offset + 0] << 32;
}
/// <summary>
/// data apparently has a different byte order than parameters, so we have to
/// rearrange byte order for parameters but not data.
/// </summary>
/// <param name="bytes"></param>
/// <param name="offset"></param>
/// <returns></returns>
private static ushort GetDownloadUShort(byte[] bytes, int offset)
{
return (ushort)(bytes[offset + 0] | bytes[offset + 1] << 8);
}
}
}

View File

@@ -0,0 +1,42 @@
using DTS.Common.ICommunication;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public abstract class EventDataCommands : CommandBase
{
protected enum Commands
{
Reserved = 0x00,
ResetEventList = 0x01,
QueryTotalEventCount = 0x02,
QueryMatchingEvents = 0x03,
QueryEventData = 0x04,
SetEventData = 0x05,
StartDownloadStreamData = 0x06, // CMDEVD_STREAM_EVENT_DATA_START
GetNextDownloadStreamDataSamples = 0x07, // stream packet of data out to receiver.
QueryUartEventInfo = 0x09, // saved UART info
QueryUartEventData = 0x0A,
SetUartEventData = 0x0B,
GenerateEvent = 0x0C,
QueryEthernetEventInfo = 0x0D,
QueryEthernetEventData = 0x0E,
SetEthernetEventData = 0x0F
};
protected abstract Commands Command { get; }
protected EventDataCommands(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
command.Type = CommandPacket.CommandType.EventData;
command.SetCommand((byte)Command, Command.ToString());
}
protected EventDataCommands(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
: base(sock, timeoutMillisec)
{
command.Type = CommandPacket.CommandType.EventData;
command.SetCommand((byte)Command, Command.ToString());
}
}
}

View File

@@ -0,0 +1,188 @@
using System;
using System.Text;
using DTS.Common.Enums.Communication;
using DTS.Common.Enums.DASFactory;
using DTS.Common.ICommunication;
using DTS.Common.Utilities;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
/// <summary>
/// This was ported from FirmwareTestUtility where it was written by Loc Pham
/// it is being included for
/// 10573 implement SW side of single command/streaming download
/// this command can be used to collect data that has been collecting in a buffer
/// from download streaming
/// </summary>
public class GetNextDownloadStreamDataSamples : EventDataCommands
{
protected override Commands Command => Commands.GetNextDownloadStreamDataSamples;
public GetNextDownloadStreamDataSamples(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
baseCommand = new CommandPacket();
LogCommands = false;
baseCommand.SetCommand((byte)Commands.GetNextDownloadStreamDataSamples, "GetNextDownloadStreamDataSamples");
}
public GetNextDownloadStreamDataSamples(DTS.Common.Interface.DASFactory.ICommunication sock, int msTimeout)
: base(sock, msTimeout)
{
baseCommand = new CommandPacket();
LogCommands = false;
baseCommand.SetCommand((byte)Commands.GetNextDownloadStreamDataSamples, "GetNextDownloadStreamDataSamples");
}
public DownloadByteConverter DlData { get; private set; }
private ushort _lastSequenceProcessed = ushort.MaxValue;
private const int MAX_SEQUENCE_DIFF = 1000;
public void ProcessData()
{
var bytes = baseResponse.ToBytes();
var headerCrc = response.HeaderCRC;
response.ComputeCRCs();
if (headerCrc != response.HeaderCRC)
{
DlData = null;
return;
}
DlData = new DownloadByteConverter(bytes);
if (null == DlData) { return; }
if (_lastSequenceProcessed == DlData.SeqNumber)
{
DlData = null;
return;
}
var delta = Math.Abs(DlData.SeqNumber - _lastSequenceProcessed);
if (delta > MAX_SEQUENCE_DIFF && ushort.MaxValue != _lastSequenceProcessed && 0 != DlData.SeqNumber)
{
//per loc we shouldn't get here, the old code in the FWTU would apparently unintentionally throw an exception
//I've preserved that code in comments below
throw new Exception("sequence number overflow");
//DlData = null;
//_lastSequenceProcessed = DlData.SeqNumber;
//return;
}
_lastSequenceProcessed = DlData.SeqNumber;
}
/// <summary>
/// We need to override SyncExecute because we don't want to send anything (that would tell the G5 to stop sending). Instead we just want to
/// read whatever is out there. Otherwise this is mostly cut and paste of normal SyncExecute with some streamlining for our specific case.
/// </summary>
public override void SyncExecute()
{
// this is a try/finally to handle the ExecuteIsBusy
try
{
DlData = null;
// there can be only one!
recorder.ExecuteIsBusy = true;
if (recorder.IsCanceled())
{
throw new CanceledException();
}
UserCallback = null;
UserCallbackData = null;
IsSynchronous = true;
SyncEvent.Reset();
recorder.PseudoExecute(new byte[0], ExecuteCallback, null, IO_Timeout);
var syncExecTimeout = IO_Timeout;
try
{
if (!WaitWithCondition.Wait(SyncEvent, syncExecTimeout,
recorder.CancelEvent))
{
//timeout
LogString("SyncExecute: timeout");
throw new TimeoutException(MakeLogString("SyncExecute: timeout"));
}
}
catch (WaitWithCondition.ConditionMetException)
{
throw new CanceledException();
}
// we didn't timeout, check the result
switch (ComReport.Result)
{
case CommunicationConstantsAndEnums.CommunicationResult.Canceled:
throw new CanceledException();
case CommunicationConstantsAndEnums.CommunicationResult.ReceiveOK:
if (baseResponse == null)
{
LogString("SyncExecute: ReceiveOK but response==null!");
LogCommand(false);
}
else if (baseResponse.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
// didn't go well
var msg = MakeLogString("SyncExecute: response.Status = " + baseResponse.Status);
LogCommand(false);
switch (baseResponse.Status)
{
case DFConstantsAndEnums.CommandStatus.StatusInvalidModeForCommand:
throw new CommandException(CommandErrorReason.InvalidMode, msg);
case DFConstantsAndEnums.CommandStatus.StatusUnimplemented:
case DFConstantsAndEnums.CommandStatus.StatusInvalidCommand:
case DFConstantsAndEnums.CommandStatus.StatusInvalidCommandType:
throw new NotImplementedException(msg);
}
var ex = new Exception(msg);
ex.Data.Add("Status", baseResponse.Status);
throw ex;
}
// everything is fine, let it exit
if (LogCommands)
{
LogCommand(false);
}
break;
case CommunicationConstantsAndEnums.CommunicationResult.ReceiveFailed:
{
var msg = MakeLogString("SyncExecute: ComReport.Result == " + ComReport.Result);
LogCommand(false);
throw new CommandException(CommandErrorReason.ReceiveFailed, msg);
}
case CommunicationConstantsAndEnums.CommunicationResult.ReceiveTimeout:
{
var msg = MakeLogString("SyncExecute: ComReport.Result == " + ComReport.Result);
LogCommand(false);
throw new CommandException(CommandErrorReason.ReceiveFailed, msg);
}
case CommunicationConstantsAndEnums.CommunicationResult.SendFailed:
case CommunicationConstantsAndEnums.CommunicationResult.SendTimeout:
{
var msg = MakeLogString("SyncExecute: ComReport.Result == " + ComReport.Result);
LogCommand(false);
throw new CommandException(CommandErrorReason.SendFailed, msg);
}
default:
{
var msg = MakeLogString("SyncExecute: Unknown ComReport.Result == " + ComReport.Result);
LogCommand(false);
throw new Exception(msg);
}
}
}
finally
{
recorder.ExecuteIsBusy = false;
}
}
}
}

View File

@@ -0,0 +1,117 @@
using System.Collections.Generic;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
/// <summary>
/// retrieves Ethernet data from an EthernetRecorder
/// </summary>
public class QueryEthernetEventData : EventDataCommands
{
private ushort _eventID = 0;
public ushort EventID
{
get => _eventID;
set { _eventID = value; command.SetParameter(0, _eventID); }
}
protected override Commands Command => Commands.QueryEthernetEventData;
private uint _requestByteCount = 0;
public uint RequestByteCount
{
get => _requestByteCount;
set { _requestByteCount = value; command.SetParameter(2, _requestByteCount); }
}
private ulong _StartDataOffsetBytes = 0UL;
public ulong StartDataOffsetBytes
{
get => _StartDataOffsetBytes;
set { _StartDataOffsetBytes = value; command.SetParameter(6, _StartDataOffsetBytes); }
}
private byte[] _data;
public byte[] Data
{
get => _data;
set
{
if (null == value) { return; }
_data = value;
}
}
private const int PARAMETER_BYTE_COUNT = 14;
public QueryEthernetEventData(ICommunication sock)
: base(sock)
{
command.Parameter = new byte[PARAMETER_BYTE_COUNT];
/*
Byte [1:0] U16 Event ID
Byte [5:2] U32 Request byte count.
Byte [13:6] U64 Start data offset in byte counter.
*/
}
public QueryEthernetEventData(ICommunication sock, int timeoutMS)
: base(sock, timeoutMS)
{
command.Parameter = new byte[PARAMETER_BYTE_COUNT];
/*
Byte [1:0] U16 Event ID
Byte [5:2] U32 Request byte count.
Byte [13:6] U64 Start data offset in byte counter.
*/
}
protected override CommandReceiveAction WholePackage()
{
/*
Byte [1:0]: U16 Event ID
Byte [5:2]: U32 Payload length in byte count.
Byte [13:6]: U64 data offset start.
Byte [payloadLength]: Data byte stream with payload length firmware can fit to a response payload size or that of request whichever less.
*/
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
{
if (response.ParameterLength > 0)
{
response.GetParameter(0, out _eventID);
response.GetParameter(2, out uint payloadLength);
response.GetParameter(6, out _StartDataOffsetBytes);
_data = new byte[payloadLength];
for (var i = 0; i < payloadLength; i++)
{
response.GetParameter(PARAMETER_BYTE_COUNT + i, out _data[i]);
}
}
else { _eventID = 0; }
}
return CommandReceiveAction.StopReceiving;
}
public override void CommandToString(ref List<List<string>> lines)
{
base.CommandToString(ref lines);
lines.Add(new List<string>()
{
$"Event ID: {EventID}",
$"StartDataOffset: {StartDataOffsetBytes}",
$"RequestByteCount: {RequestByteCount}"
});
}
public override void ResponseToString(ref List<List<string>> lines)
{
base.ResponseToString(ref lines);
lines.Add(new List<string>()
{
$"Event ID: {EventID}",
$"Payload(bytes): {_data.Length}",
$"StartDataOffsetBytes: {StartDataOffsetBytes}"
});
}
}
}

View File

@@ -0,0 +1,96 @@
using System.Collections.Generic;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
/// <summary>
/// Retrieves parameters of Ethernet data recorder by EthernetRecorder
/// </summary>
public class QueryEthernetEventInfo : EventDataCommands
{
protected override Commands Command => Commands.QueryEthernetEventInfo;
private ushort _eventID = 0;
public ushort EventID
{
get { return _eventID; }
set { _eventID = value; command.SetParameter(0, _eventID); }
}
private ushort _dataDownloaded = 0;
public ushort DataDownloaded => _dataDownloaded;
private ulong _totalByteCount = 0UL;
public ulong TotalByteCount => _totalByteCount;
private ulong _triggerByteCount = 0UL;
public ulong TriggerByteCount => _triggerByteCount;
private ulong _faultByteCount;
public ulong FaultByteCount => _faultByteCount;
private uint[] _DataStartTimeStamp = new uint[] { 0, 0 };
public uint[] DataStartTimeStamp => _DataStartTimeStamp;
public QueryEthernetEventInfo(ICommunication sock)
: base(sock)
{
//Command Parameters: 4 bytes.
//Byte[1:0] U16 Event ID.
//Byte[3:2]: Reserved.
command.Parameter = new byte[4];
}
public QueryEthernetEventInfo(ICommunication sock, int TimeoutMillisec)
: base(sock, TimeoutMillisec)
{
//Command Parameters: 4 bytes.
//Byte[1:0] U16 Event ID.
//Byte[3:2]: Reserved.
command.Parameter = new byte[4];
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status == DFConstantsAndEnums.CommandStatus.StatusNoError)
{
if (response.ParameterLength > 0)
{
/*
Response: 36 bytes.
Byte [1:0] U16 Event ID.
Byte [3:2] U16 Data Downloaded Flag.
Byte [11:4] U64 Total ByteCount.
Byte [19:12] U64 Trigger ByteCount.
Byte [27:20] U64 Fault ByteCount.
Byte [35:28] U32[2] Data Start Timestamp. U32[0] = Second. U32[1] = Nano-Second
*/
response.GetParameter(0, out _eventID);
response.GetParameter(2, out _dataDownloaded);
response.GetParameter(4, out _totalByteCount);
response.GetParameter(12, out _triggerByteCount);
response.GetParameter(20, out _faultByteCount);
response.GetParameter(28, out uint temp);
_DataStartTimeStamp[0] = temp;
response.GetParameter(32, out temp);
_DataStartTimeStamp[1] = temp;
}
else { _eventID = 0; }
}
return CommandReceiveAction.StopReceiving;
}
public override void ResponseToString(ref List<List<string>> lines)
{
base.ResponseToString(ref lines);
lines.Add(new List<string>()
{
$"EventId: {EventID}",
$"DataDownloaded: {DataDownloaded}",
$"TotalByteCount: {TotalByteCount}",
$"TriggerByteCount: {TriggerByteCount}",
$"FaultByteCount: {FaultByteCount}",
$"DataStartTimeStamp: {DataStartTimeStamp[0]}, {DataStartTimeStamp[1]}"
});
}
}
}

View File

@@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using DTS.Common.DASResource;
using DTS.Common.Enums.DASFactory;
using DTS.Common.ICommunication;
using DTS.Common.Utilities.Logging;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class QueryEventDataBase : EventDataCommands
{
protected override Commands Command => Commands.QueryEventData;
private const ushort ADC_OFFSET = 0x8000;
public const byte ALL_CHANNELS = 0xFF;
protected UInt16 _eventNumber;
protected UInt64 _firstSample;
protected UInt64 _lastSample;
protected UInt64 _samplesDownloaded;
protected byte _channel;
protected int _channelsDownloaded;
protected ushort[] _data;
public UInt16 EventNumber
{
get => _eventNumber;
set { _eventNumber = value; command.SetParameter(0, _eventNumber); }
}
public virtual UInt64 FirstSample
{
get => _firstSample;
set { _firstSample = value; command.SetParameter(2, _firstSample); }
}
public virtual UInt64 LastSample
{
get => _lastSample;
set { _lastSample = value; command.SetParameter(10, _lastSample); }
}
public byte Channel
{
get => _channel;
set
{
_channel = value; command.SetParameter(18, _channel);
ChannelsDownloaded = 0xFF == _channel ? 3 : 1;
}
}
public int ChannelsDownloaded
{
get => _channelsDownloaded;
set => _channelsDownloaded = value;
}
public int Count => (int)_samplesDownloaded;
public QueryEventDataBase(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
command.Parameter = new byte[19];
_data = null;
_eventNumber = 0;
_firstSample = 0;
_lastSample = 0;
_channel = 0;
command.ShouldLog = false;
}
public QueryEventDataBase(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
: base(sock, timeoutMillisec)
{
command.Parameter = new byte[19];
_data = null;
_eventNumber = 0;
_firstSample = 0;
_lastSample = 0;
_channel = 0;
command.ShouldLog = false;
}
public override void Execute(CommandCallback cb, object cbData)
{
// Do a little parameter checking
if (_firstSample > _lastSample)
{
// "QueryEventData.Execute: First Sample cannot be greater than Last Sample"
throw new ApplicationException(Strings.QueryEventData_Execute_Err1);
}
base.Execute(cb, cbData);
}
protected override CommandReceiveAction WholePackagePost()
{
// now send the data to the user
var stat = CommandStatus.Success;
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
var s = (int)response.Status;
APILogger.LogString("QueryEventData.WholePackagePost: reporting failure, status==" + CommandPacketBase.StatusLabels[s] + " (0x" + s.ToString("X") + ")");
stat = CommandStatus.Failure;
}
var cbReport = new QueryEventDataReport(stat, UserCallbackData);
cbReport.Data = new short[_channelsDownloaded][];
for (var i = 0; i < _channelsDownloaded; i++)
GetChannelData(i, out cbReport.Data[i]);
return UserCallback(cbReport);
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
return CommandReceiveAction.StopReceiving;
}
_samplesDownloaded = (ulong)(response.Parameter.Length / 2) / (ulong)_channelsDownloaded;
_data = new ushort[_samplesDownloaded * (ulong)_channelsDownloaded];
for (var i = 0; (ulong)i < _samplesDownloaded * (ulong)_channelsDownloaded; i++)
{
response.GetParameter(2 * i, out _data[i]);
}
return CommandReceiveAction.StopReceiving;
}
public override void SyncExecute()
{
// Do a little parameter checking
if (_firstSample > _lastSample)
{
// "QueryEventData.SyncExecute: First Sample cannot be greater than Last Sample"
throw new ApplicationException(Strings.QueryEventData_SyncExecute_Err1);
}
base.SyncExecute();
}
public virtual void GetChannelData(int channel, out short[] signedADC)
{
if (channel < 0 || channel > _channelsDownloaded)
{
// "QueryEventData.GetChannelData: Data requested on a channel that wasn't downloaded."
throw new ApplicationException(Strings.QueryEventData_GetChannelData_Err1);
}
// Data order for a 9 channel stack
// 7 8 9 4 5 6 1 2 3 7 8 9 4 5 6 1 2 3 etc.
var rv = new short[_samplesDownloaded];
var sliceNumber = channel / 3;
var sliceOffset = (_channelsDownloaded / 3 - sliceNumber - 1) * 3;
if (sliceOffset < 0) sliceOffset = 0;
var channelInSlice = channel % 3;
for (var i = 0; i < rv.Length; i++)
{
rv[i] = (short)(_data[i * _channelsDownloaded + sliceOffset + channelInSlice] - ADC_OFFSET);
}
signedADC = rv;
}
public virtual void GetRawIndexedData(int index, out ushort[] data)
{
data = new ushort[_samplesDownloaded];
for (var i = 0; i < data.Length; i++)
{
data[i] = _data[i * _channelsDownloaded + index];
}
}
public override void CommandToString(ref List<List<string>> lines)
{
lines.Add(new List<string> { $"Event number: {EventNumber}, First sample: {FirstSample}, Last sample: {LastSample}" });
}
public override void ResponseToString(ref List<List<string>> lines)
{
lines.Add(new List<string>
{
$"ChannelsDownloaded: {ChannelsDownloaded}, Count: {Count}"
});
}
public void LogResponse()
{
LogCommand(false);
}
}
}

View File

@@ -0,0 +1,15 @@
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class QueryEventDataReport : ICommandReport
{
public object CallbackObject { get; set; }
public CommandStatus Status { get; set; }
public short[][] Data { get; set; }
public QueryEventDataReport(CommandStatus status, object cbData)
{
Status = status;
CallbackObject = cbData;
}
}
}

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using DTS.Common.Enums.DASFactory;
using DTS.Common.ICommunication;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class QueryTotalEventCount : EventDataCommands
{
protected override Commands Command => Commands.QueryTotalEventCount;
private ushort _count;
public ushort Count => _count;
public QueryTotalEventCount(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
}
public QueryTotalEventCount(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
: base(sock, timeoutMillisec)
{
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
return CommandReceiveAction.StopReceiving;
if (response.ParameterLength > 0)
{
response.GetParameter(0, out _count);
}
else { _count = 0; }
return CommandReceiveAction.StopReceiving;
}
public override void ResponseToString(ref List<List<string>> lines)
{
base.ResponseToString(ref lines);
lines.Add(new List<string>
{
$"Count: {Count}"
});
}
}
}

View File

@@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory;
using DTS.Common.Utilities.Logging;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class QueryUARTEventData : EventDataCommands
{
public const int MAX_DATA_LENGTH = 2000;
public const int PAYLOAD_HEADER_LENGTH = 14;
protected override Commands Command => Commands.QueryUartEventData;
protected ushort _eventNumber;
protected uint _requestByteCount;
protected ulong _requestOffsetByteCount;
protected uint _payloadByteCount;
protected ulong _payloadOffsetByteCount;
protected byte[] _data;
public ushort EventNumber
{
get => _eventNumber;
set { _eventNumber = value; command.SetParameter(0, _eventNumber); }
}
public uint RequestByteCount
{
get => _requestByteCount;
set { _requestByteCount = value; command.SetParameter(2, _requestByteCount); }
}
public ulong RequestOffsetByteCount
{
get => _requestOffsetByteCount;
set { _requestOffsetByteCount = value; command.SetParameter(6, _requestOffsetByteCount); }
}
public uint PayloadByteCount => _payloadByteCount;
public ulong PayloadOffsetByteCount => _payloadOffsetByteCount;
public byte[] PayloadData => _data;
public QueryUARTEventData(ICommunication sock) : base(sock)
{
command.Parameter = new byte[14];
_data = null;
_eventNumber = 0;
_requestByteCount = 0;
_requestOffsetByteCount = 0;
_payloadByteCount = 0;
_payloadOffsetByteCount = 0;
command.ShouldLog = false;
}
public QueryUARTEventData(ICommunication sock, int timeoutMillisec) : base(sock, timeoutMillisec)
{
command.Parameter = new byte[14];
_data = null;
_eventNumber = 0;
_requestByteCount = 0;
_requestOffsetByteCount = 0;
_payloadByteCount = 0;
_payloadOffsetByteCount = 0;
command.ShouldLog = false;
}
public override void Execute(CommandCallback cb, object cbData)
{
// Do a little parameter checking
_data = null;
base.Execute(cb, cbData);
}
protected override CommandReceiveAction WholePackagePost()
{
// now send the data to the user
var stat = CommandStatus.Success;
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
var s = (int)response.Status;
APILogger.LogString("QueryUARTEventData.WholePackagePost: reporting failure, status==" + CommandPacketBase.StatusLabels[s] + " (0x" + s.ToString("X") + ")");
stat = CommandStatus.Failure;
}
var cbReport = new QueryEventDataReport(stat, UserCallbackData);
//cbReport.Data = new short[_channelsDownloaded][];
//for (var i = 0; i < _channelsDownloaded; i++)
// GetChannelData(i, out cbReport.Data[i]);
return UserCallback(cbReport);
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
return CommandReceiveAction.StopReceiving;
}
response.GetParameter(0, out ushort responseEventNum);
response.GetParameter(2, out _payloadByteCount);
response.GetParameter(6, out _payloadOffsetByteCount);
_data = new byte[_payloadByteCount];
for (var i = 0; i < _payloadByteCount; i++)
{
response.GetParameter(PAYLOAD_HEADER_LENGTH + i, out _data[i]);
}
return CommandReceiveAction.StopReceiving;
}
public override void SyncExecute()
{
// Do a little parameter checking
_data = null;
base.SyncExecute();
}
public override void CommandToString(ref List<List<string>> lines)
{
lines.Add(new List<string> { $"Event number: {EventNumber}, RequestByteCount: {RequestByteCount}, OffsetByteCount: {RequestOffsetByteCount}" });
}
public override void ResponseToString(ref List<List<string>> lines)
{
lines.Add(new List<string>
{
$"PayloadByteCount: {PayloadByteCount}, OffsetByteCount: {PayloadOffsetByteCount}"
});
}
public void LogResponse()
{
LogCommand(false);
}
}
}

View File

@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTS.Common.Enums.DASFactory;
using DTS.Common.Interface.DASFactory;
using DTS.Common.Strings;
using DTS.Common.Utilities.Logging;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class QueryUARTEventInfo : EventDataCommands
{
protected override Commands Command => Commands.QueryUartEventInfo;
protected ushort _eventNumber;
protected ushort _dataPresent;
protected ushort _dataDownloaded;
protected ulong _totalByteCount;
protected ulong _triggerByteCount;
protected ulong _faultByteCount;
protected uint _startTimestamp;
protected uint _endTimestamp;
protected uint _baudrate;
public ushort EventNumber
{
get => _eventNumber;
set { _eventNumber = value; command.SetParameter(0, _eventNumber); }
}
public QueryUARTEventInfo(ICommunication sock) : base(sock)
{
command.Parameter = new byte[2];
_eventNumber = 0;
_dataPresent = 0;
_dataDownloaded = 0;
_totalByteCount = 0;
_triggerByteCount = 0;
_faultByteCount = 0;
_startTimestamp = 0;
_endTimestamp = 0;
_baudrate = 0;
command.ShouldLog = false;
}
public QueryUARTEventInfo(ICommunication sock, int timeoutMillisec) : base(sock, timeoutMillisec)
{
command.Parameter = new byte[2];
_eventNumber = 0;
_dataPresent = 0;
_dataDownloaded = 0;
_totalByteCount = 0;
_faultByteCount = 0;
_triggerByteCount = 0;
_startTimestamp = 0;
_endTimestamp = 0;
_baudrate = 0;
command.ShouldLog = false;
}
public bool DataPresent => 1 == _dataPresent;
public bool DataDownloaded => 1 == _dataDownloaded;
public ulong TotalByteCount => _totalByteCount;
public ulong TriggerByteCount => _triggerByteCount;
public ulong FaultByteCount => _faultByteCount;
public uint StartTimestamp => _startTimestamp;
public uint EndTimestamp => _endTimestamp;
public uint BaudRate => _baudrate;
public override void Execute(CommandCallback cb, object cbData)
{
// Do a little parameter checking
base.Execute(cb, cbData);
}
protected override CommandReceiveAction WholePackagePost()
{
// now send the data to the user
var stat = CommandStatus.Success;
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
var s = (int)response.Status;
APILogger.LogString("QueryUARTEventInfo.WholePackagePost: reporting failure, status==" + CommandPacketBase.StatusLabels[s] + " (0x" + s.ToString("X") + ")");
stat = CommandStatus.Failure;
}
var cbReport = new QueryEventDataReport(stat, UserCallbackData);
//cbReport.Data = new short[_channelsDownloaded][];
//for (var i = 0; i < _channelsDownloaded; i++)
// GetChannelData(i, out cbReport.Data[i]);
return UserCallback(cbReport);
}
protected override CommandReceiveAction WholePackage()
{
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
{
return CommandReceiveAction.StopReceiving;
}
response.GetParameter(0, out ushort responseEventNum);
response.GetParameter(2, out _dataPresent);
response.GetParameter(4, out _dataDownloaded);
response.GetParameter(8, out _totalByteCount);
response.GetParameter(16, out _triggerByteCount);
response.GetParameter(24, out _faultByteCount);
response.GetParameter(32, out _startTimestamp);
response.GetParameter(36, out _endTimestamp);
response.GetParameter(40, out _baudrate);
return CommandReceiveAction.StopReceiving;
}
public override void SyncExecute()
{
// Do a little parameter checking
base.SyncExecute();
}
public override void CommandToString(ref List<List<string>> lines)
{
base.CommandToString(ref lines);
lines.Add(new List<string> { $"Event number: {EventNumber}" });
}
public override void ResponseToString(ref List<List<string>> lines)
{
base.ResponseToString(ref lines);
lines.Add(new List<string>
{
$"DataPresent: {DataPresent}, DataDownloaded: {DataDownloaded}, TotalByteCount: {TotalByteCount}, TriggerByteCount: {TriggerByteCount}, StartTimestamp: {StartTimestamp}, EndTimestamp: {EndTimestamp}"
});
}
public void LogResponse()
{
LogCommand(false);
}
}
}

View File

@@ -0,0 +1,19 @@
using DTS.Common.ICommunication;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
public class ResetEventList : EventDataCommands
{
protected override Commands Command => Commands.ResetEventList;
public ResetEventList(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
}
public ResetEventList(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
: base(sock, timeoutMillisec)
{
}
}
}

View File

@@ -0,0 +1,64 @@
using DTS.Common.ICommunication;
namespace DTS.DASLib.Command.SLICE.DownloadCommands
{
/// <summary>
/// this was ported almost directly from FirmwareTestUtility, where it was written by Loc Pham
/// this was done for
/// 10573 implement SW side of single command/streaming download
/// this command should put SLICE2 firmware >= A1N4 into download streaming mode
/// any command should be sufficient to stop this streaming early
/// </summary>
public class StartDownloadStreamData : EventDataCommands
{
protected override Commands Command => Commands.StartDownloadStreamData;
public StartDownloadStreamData(DTS.Common.Interface.DASFactory.ICommunication sock)
: base(sock)
{
command.Parameter = new byte[18];
}
public StartDownloadStreamData(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
: base(sock, timeoutMillisec)
{
command.Parameter = new byte[18];
}
public const byte AllChannels = 0xFF;
private ushort _eventNumber;
private ulong _firstSample;
private ulong _lastSample;
public ushort EventNumber
{
get => _eventNumber;
set
{
_eventNumber = value;
command.SetParameter(0, _eventNumber);
}
}
public virtual ulong FirstSample
{
get => _firstSample;
set
{
_firstSample = value;
command.SetParameter(2, _firstSample);
}
}
public virtual ulong LastSample
{
get => _lastSample;
set
{
_lastSample = value;
command.SetParameter(10, _lastSample);
}
}
}
}