Files
DP44/DataPRO/SLICECommands/DownloadCommands/QueryUARTEventInfo.cs
2026-04-17 14:55:32 -04:00

154 lines
5.2 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.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);
}
}
}