145 lines
4.9 KiB
C#
145 lines
4.9 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|