using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Diagnostics;
using DTS.Common.ICommunication;
namespace DTS.DASLib.Command
{
///
/// this is a base class for slice commands, it contains
/// additional logic that ribeye doesn't have (deviceid, device group)
///
public abstract class SliceCommandBase : AbstractCommandBase
{
protected SliceCommandPacketBase command
{
get => baseCommand as SliceCommandPacketBase;
set => baseCommand = value;
}
protected SliceCommandPacketBase response
{
get => baseResponse as SliceCommandPacketBase;
set => baseResponse = value;
}
public byte DeviceID
{
get => command.DeviceID;
set => command.DeviceID = value;
}
public byte DeviceGroup
{
get => command.DeviceGroup;
set => command.DeviceGroup = value;
}
public SliceCommandBase(DTS.Common.Interface.DASFactory.ICommunication sock) : base(sock) { }
public SliceCommandBase(DTS.Common.Interface.DASFactory.ICommunication sock, int TimeoutMillisec) : base(sock, TimeoutMillisec) { }
///
/// adds the serial number information to the log header
///
///
public override void CommandToString(ref List> list)
{
list[0].Add((null == recorder || null == recorder.DASInfo || DeviceID < 0) ? "" : recorder.DASInfo.StackSerialNumber(DeviceID));
if (null != recorder && null != recorder.Transport) { list[0].Add(recorder.Transport.GetConnectionData()); }
}
///
/// adds serial number information to log header
///
///
public override void ResponseToString(ref List> lines)
{
lines[0].Add((null == recorder || null == recorder.DASInfo || DeviceID < 0) ? "" : recorder.DASInfo.StackSerialNumber(DeviceID));
}
private static SemaphoreSlim _slicePool = new SemaphoreSlim(15, 15);
private static int _slicePoolDelayMs = 10;
///
/// initializes the semaphore for SLICE, note if the semaphore is going to
/// be changed by the application it needs to be done before communication starts.
/// 10852 Add semaphore to SLICE communication to improve SLICE 6 multiple IP performance
///
///
///
public static void Initialize(int spots, int delayMs)
{
_slicePoolDelayMs = delayMs;
_slicePool = new SemaphoreSlim(spots, spots);
}
public override void SyncExecute()
{
//_slicePool.Wait();
//var start = DateTime.Now;
try
{
base.SyncExecute();
}
finally
{
//_slicePool.Release();
//var elapsed = DateTime.Now.Subtract(start);
//if (elapsed.TotalMilliseconds < _slicePoolDelayMs)
//{
// Thread.Sleep(Convert.ToInt32(_slicePoolDelayMs - elapsed.TotalMilliseconds));
//}
}
}
}
}