Files
DP44/DataPRO/SLICECommands/.svn/pristine/18/1854890622757d30d8bd77103ea4a36f534ed4c4.svn-base
2026-04-17 14:55:32 -04:00

118 lines
4.0 KiB
Plaintext

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}"
});
}
}
}