84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using DTS.Common.Enums.DASFactory;
|
|||
|
|
using DTS.Common.ICommunication;
|
|||
|
|
using DTS.Common.Utilities;
|
|||
|
|
|
|||
|
|
namespace DTS.DASLib.Command.SLICE.RealtimeCommands
|
|||
|
|
{
|
|||
|
|
public class RetrieveSampleAverage : RealtimeCommandBase
|
|||
|
|
{
|
|||
|
|
protected override Commands _Command => Commands.RetrieveSampleAverage;
|
|||
|
|
|
|||
|
|
const int SAMPLES_POSITION = 0;
|
|||
|
|
const int DATA_POSITION = 2;
|
|||
|
|
|
|||
|
|
private ushort _samples;
|
|||
|
|
public ushort Samples
|
|||
|
|
{
|
|||
|
|
set { _samples = value; command.SetParameter(SAMPLES_POSITION, _samples); }
|
|||
|
|
get => _samples;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public short[] _data;
|
|||
|
|
public short GetChannelData(int zeroBasedChannel)
|
|||
|
|
{
|
|||
|
|
return _data[zeroBasedChannel];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public ushort Channels
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (null == _data) return 0;
|
|||
|
|
return (ushort)_data.Length;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public RetrieveSampleAverage(DTS.Common.Interface.DASFactory.ICommunication sock)
|
|||
|
|
: base(sock)
|
|||
|
|
{
|
|||
|
|
command.Parameter = new byte[DATA_POSITION];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public RetrieveSampleAverage(DTS.Common.Interface.DASFactory.ICommunication sock, int timeoutMillisec)
|
|||
|
|
: base(sock, timeoutMillisec)
|
|||
|
|
{
|
|||
|
|
command.Parameter = new byte[DATA_POSITION];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override CommandReceiveAction WholePackage()
|
|||
|
|
{
|
|||
|
|
if (response.Status != DFConstantsAndEnums.CommandStatus.StatusNoError)
|
|||
|
|
return CommandReceiveAction.StopReceiving;
|
|||
|
|
// Figure out how many samples were actually used to compute the means --
|
|||
|
|
// we may have requested more than the recorder has RAM to store
|
|||
|
|
response.GetParameter(SAMPLES_POSITION, out _samples);
|
|||
|
|
|
|||
|
|
// Figure out the number of channels returned and grab the means
|
|||
|
|
var numChannels = (response.Parameter.Length - 2) / 2;
|
|||
|
|
_data = new short[numChannels];
|
|||
|
|
for (var i = 0; i < numChannels; i++)
|
|||
|
|
{
|
|||
|
|
response.GetParameter(2 * i + DATA_POSITION, out _data[i]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return CommandReceiveAction.StopReceiving;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void CommandToString(ref List<List<string>> lines)
|
|||
|
|
{
|
|||
|
|
base.CommandToString(ref lines);
|
|||
|
|
lines.Add(new List<string> { $"Samples Requested: {Samples}" });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void ResponseToString(ref List<List<string>> lines)
|
|||
|
|
{
|
|||
|
|
base.ResponseToString(ref lines);
|
|||
|
|
lines.Add(new List<string>
|
|||
|
|
{
|
|||
|
|
$"Channels: {Channels}, Samples Used: {Samples}, Data: {ArrayToString.ArrayObjectToString(_data)}"
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|