init
This commit is contained in:
@@ -0,0 +1,326 @@
|
||||
using System.Threading;
|
||||
using DTS.Common.Utilities.Logging;
|
||||
using DTS.Common.ICommunication;
|
||||
using System;
|
||||
using DTS.Common.Interface.Connection;
|
||||
using DTS.Common.Enums.DASFactory;
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
public partial class TDAS<T> : Communication<T>,
|
||||
IDASCommunication,
|
||||
IConfigurationActions,
|
||||
IDiagnosticsActions,
|
||||
ITriggerCheckActions,
|
||||
IRealTimeActions,
|
||||
IArmActions,
|
||||
IDownloadActions where T : IConnection, new()
|
||||
{
|
||||
#region Trigger check
|
||||
void ITriggerCheckActions.PreStartTriggerCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
info.Success();
|
||||
}
|
||||
void ITriggerCheckActions.PostStartTriggerCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
info.Success();
|
||||
}
|
||||
private class TriggerCheckPacket : TDASServiceAsyncInfo
|
||||
{
|
||||
public TriggerCheckPacket(ServiceCallback cb, object ud)
|
||||
: base(cb, ud)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
void ITriggerCheckActions.StartTriggerCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
LaunchAsyncWorker("TDAS.StartTriggerCheck", AsyncStartTriggerCheck, info);
|
||||
}
|
||||
|
||||
private void AsyncStartTriggerCheck(object asyncInfo)
|
||||
{
|
||||
if (!(asyncInfo is TriggerCheckPacket info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (null == DASArmStatus)
|
||||
{
|
||||
SetDASArmStatus(new ArmStatus(), true);
|
||||
}
|
||||
var status = DASArmStatus;
|
||||
try
|
||||
{
|
||||
status.IsArmed = true;
|
||||
status.IsRecording = false;
|
||||
status.IsTriggered = false;
|
||||
foreach (var module in DASInfo.Modules)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (module.TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsG5())
|
||||
{
|
||||
var testTrigger = new Command.TDAS.TestTrigger(this)
|
||||
{
|
||||
ModuleIndex = module.ModuleArrayIndex,
|
||||
SubCommand = Command.TDAS.TestTrigger.SubCommandValues.ARM
|
||||
};
|
||||
testTrigger.SyncExecute();
|
||||
break;
|
||||
}
|
||||
|
||||
var qsn = new Command.TDAS.QuerySerialNumberBroadcast(this, module.ModuleArrayIndex);
|
||||
qsn.SyncExecute();
|
||||
|
||||
var ttb = new Command.TDAS.TestTriggerBroadcast(this, module.ModuleArrayIndex)
|
||||
{
|
||||
SubCommand = Command.TDAS.TestTrigger.SubCommandValues.ARM
|
||||
};
|
||||
ttb.SyncExecute();
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.Error(ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
SetDASArmStatus(status, true);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
//assuming this is for logging purposes...unknown
|
||||
var ta = new Command.TDAS.TestAll(this) { Mode = Command.TDAS.TestAllCommandString.Modes.CURR };
|
||||
ta.SyncExecute();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
info.Error(ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
info.Success();
|
||||
}
|
||||
|
||||
void ITriggerCheckActions.DoTriggerCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
LaunchAsyncWorker("TDAS.DoTriggercheck", AsyncDoTriggerCheck, info);
|
||||
}
|
||||
void ITriggerCheckActions.DoStartCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
LaunchAsyncWorker("TDAS.DoStartcheck", AsyncDoStartCheck, info);
|
||||
}
|
||||
private void AsyncDoStartCheck(object asyncInfo)
|
||||
{
|
||||
if (!(asyncInfo is TriggerCheckPacket info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (null == DASArmStatus)
|
||||
{
|
||||
SetDASArmStatus(new ArmStatus(), false);
|
||||
}
|
||||
var status = DASArmStatus;
|
||||
try
|
||||
{
|
||||
var ta = new Command.TDAS.TestAll(this) { Mode = Command.TDAS.TestAllCommandString.Modes.PREV };
|
||||
try
|
||||
{
|
||||
ta.SyncExecute();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
info.Error(ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ta.StartedRecordingFlag == DFConstantsAndEnums.VoltageStatusColor.Yellow
|
||||
|| ta.StartedRecordingFlag == DFConstantsAndEnums.VoltageStatusColor.Red)
|
||||
{
|
||||
status.IsRecording = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartRecord = false;
|
||||
}
|
||||
|
||||
if (DASArmStatus.IsRecording)
|
||||
{
|
||||
status.IsArmed = false;
|
||||
}
|
||||
status.IsArmed = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SetDASArmStatus(status, true);
|
||||
}
|
||||
|
||||
info.Success();
|
||||
}
|
||||
|
||||
void ITriggerCheckActions.DoTriggerCheckSync()
|
||||
{
|
||||
//this function was created as part of
|
||||
//5211 Add check to ECM event line during ArmChecklist
|
||||
//however to minimize impact since the issue doesn't affect TDAS
|
||||
//I'll not make the changes to TDAS trigger check/armchecklist checks
|
||||
//instead for now I'll leave it as is
|
||||
//since this function shouldn't be used (unless we make the changes above), I'll leave it
|
||||
//with an exception to warn anyone that hooks it up not realizing the issue
|
||||
throw new NotImplementedException("DoTriggerCheckSync is not implemented for TDAS");
|
||||
}
|
||||
private void AsyncDoTriggerCheck(object asyncInfo)
|
||||
{
|
||||
if (!(asyncInfo is TriggerCheckPacket info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var ta = new Command.TDAS.TestAll(this) { Mode = Command.TDAS.TestAllCommandString.Modes.PREV };
|
||||
ta.SyncExecute();
|
||||
|
||||
if (ta.TriggerFlag == DFConstantsAndEnums.VoltageStatusColor.Red
|
||||
|| ta.TriggerFlag == DFConstantsAndEnums.VoltageStatusColor.Yellow)
|
||||
{
|
||||
DASArmStatus.IsTriggered = true;
|
||||
SetDASArmStatus();
|
||||
try
|
||||
{
|
||||
var status = new ArmStatus();
|
||||
|
||||
try
|
||||
{
|
||||
foreach (var module in DASInfo.Modules)
|
||||
{
|
||||
if (IsG5() && 0 < module.ModuleArrayIndex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (module.TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var testTrigger = new Command.TDAS.TestTrigger(this, 5000);
|
||||
testTrigger.ModuleIndex = module.ModuleArrayIndex;
|
||||
testTrigger.SubCommand = Command.TDAS.TestTrigger.SubCommandValues.STATUS;
|
||||
try
|
||||
{
|
||||
testTrigger.SyncExecute();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Module probably timed out because it is still armed and never responded to the rack trigger/event line.
|
||||
status.IsArmed = true;
|
||||
status.IsTriggered = false;
|
||||
info.Error(module.SerialNumber + " did not trigger, but other modules did");
|
||||
return;
|
||||
}
|
||||
|
||||
if (testTrigger.TriggerStatus == Command.TDAS.TestTrigger.StatusValues.OFF)
|
||||
{
|
||||
status.IsTriggered = true;
|
||||
status.IsArmed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (status.IsTriggered)
|
||||
{
|
||||
info.Error(module.SerialNumber + " did not trigger, but other modules did");
|
||||
return;
|
||||
}
|
||||
|
||||
status.IsTriggered = false;
|
||||
status.IsArmed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { SetDASArmStatus(status, true); }
|
||||
|
||||
info.Success();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
info.Error(ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
info.Success();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
APILogger.Log(ex);
|
||||
info.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
void ITriggerCheckActions.CancelTriggerCheck(ServiceCallback callback, object userData)
|
||||
{
|
||||
var info = new TriggerCheckPacket(callback, userData);
|
||||
LaunchAsyncWorker("TDAS.CancelTriggerCheck", AsyncCancelTriggerCheck, info);
|
||||
}
|
||||
|
||||
private void AsyncCancelTriggerCheck(object asyncInfo)
|
||||
{
|
||||
if (!(asyncInfo is TriggerCheckPacket info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
foreach (var m in DASInfo.Modules)
|
||||
{
|
||||
if (m.SerialNumber == "EMPTY" || m.TypeOfModule == DFConstantsAndEnums.ModuleType.EMPTYBANK) continue;
|
||||
if (IsG5())
|
||||
{
|
||||
var testTrigger = new Command.TDAS.TestTrigger(this);
|
||||
testTrigger.ModuleIndex = m.ModuleArrayIndex;
|
||||
testTrigger.SubCommand = Command.TDAS.TestTrigger.SubCommandValues.OFF;
|
||||
testTrigger.SyncExecute();
|
||||
|
||||
var qsn = new Command.TDAS.QuerySerialNumber(this);
|
||||
qsn.ModuleIndex = m.ModuleArrayIndex;
|
||||
qsn.SyncExecute();
|
||||
break;
|
||||
}
|
||||
var qsc = new Command.TDAS.QuerySerialNumberBroadcast(this, m.ModuleArrayIndex);
|
||||
qsc.SyncExecute();
|
||||
|
||||
var tbc = new Command.TDAS.TestTriggerBroadcast(this, m.ModuleArrayIndex);
|
||||
tbc.SubCommand = Command.TDAS.TestTrigger.SubCommandValues.OFF;
|
||||
tbc.SyncExecute();
|
||||
|
||||
var qsnb = new Command.TDAS.QuerySerialNumberBroadcast(this, m.ModuleArrayIndex);
|
||||
qsnb.SyncExecute();
|
||||
break;
|
||||
}
|
||||
info.Success();
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
info.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
using DTS.Common.Interface.DASFactory;
|
||||
using DTS.Common.Interface.DataRecorders;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.DASLib.Service.StateMachine
|
||||
{
|
||||
public class HardwareDiscoveryParameters
|
||||
{
|
||||
public bool ReadIds { get; set; } = false;
|
||||
/// <summary>
|
||||
/// ip addresses that we expliticly want to connect to
|
||||
/// if not specified in known tdas or known slice ip addresses will try connecting as both slice and tdas
|
||||
/// </summary>
|
||||
public string[] Addresses { get; set; } = new string[0];
|
||||
/// <summary>
|
||||
/// range of address to ping
|
||||
/// items must be in the form of aaa.bbb.ccc.ddd
|
||||
/// will ping all addresses iterating from item1 upto the 4th byte on item 2
|
||||
/// any ip that responds will be added to ips to connect to
|
||||
/// if it's not known whether it's a SLICE or TDAS then will be added to both lists to connect to
|
||||
/// </summary>
|
||||
public Tuple<string, string>[] AddressRanges { get; set; } = new Tuple<string, string>[0];
|
||||
/// <summary>
|
||||
/// ip address that are known to be TDAS, so we don't have to try connecting to as a slice
|
||||
/// </summary>
|
||||
public string[] KnownTDASIPAddresses { get; set; } = new string[0];
|
||||
/// <summary>
|
||||
/// ip addresses that are known to be SLICE, so we don't have to try connecting to as a TDAS
|
||||
/// </summary>
|
||||
public string[] KnownSLICEIPAddresses { get; set; } = new string[0];
|
||||
/// <summary>
|
||||
/// controls whether we should remain in state or not
|
||||
/// sometimes the user just wants to see the hardware detected and not go onto resolve channels or any additional
|
||||
/// actions
|
||||
/// </summary>
|
||||
public bool ProceedWhenDone { get; set; } = false;
|
||||
/// <summary>
|
||||
/// whether all das are required to be found
|
||||
/// </summary>
|
||||
public bool RequireAllDASFound { get; set; } = false;
|
||||
/// <summary>
|
||||
/// whether to proceed to download state after completion
|
||||
/// </summary>
|
||||
public bool GoToDownload { get; set; } = false;
|
||||
/// <summary>
|
||||
/// controls whether we are ping and connecting or just pinging ...
|
||||
/// </summary>
|
||||
public bool Connect { get; set; } = false;
|
||||
/// <summary>
|
||||
/// controls whether UDP/Multicast discovery should be performed
|
||||
/// </summary>
|
||||
public bool UseMulticastDiscover { get; set; } = false;
|
||||
public int ConnectTimeoutMS { get; set; } = 30000; //30 seconds
|
||||
/// <summary>
|
||||
/// whether to run auto-sense or not
|
||||
/// note that DisableAutoSense overrules this setting
|
||||
/// </summary>
|
||||
public bool RunAutoSense { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// specific device to query, when present
|
||||
/// this is used to signal that there's a device already attached that
|
||||
/// we want to requery
|
||||
/// this is done when the device configuration is changed
|
||||
/// </summary>
|
||||
public IDASCommunication RequeryDevice { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// serial numbers that are required to connect
|
||||
/// </summary>
|
||||
public string[] RequiredSerials { get; set; } = new string[0];
|
||||
/// <summary>
|
||||
/// controls whether to perform hardware checks (voltage/memory/firmware/etc)
|
||||
/// after connecting to hardware
|
||||
/// </summary>
|
||||
public bool DoHardwareChecks { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// hardware that we expect to be connected once ping and connect completes
|
||||
/// used as part of DoHardwareChecks
|
||||
/// </summary>
|
||||
public IDASHardware[] ExpectedHardware { get; set; } = new IDASHardware[0];
|
||||
|
||||
public delegate bool UnitIsInDbDelegate(IDASCommunication das);
|
||||
public UnitIsInDbDelegate UnitIsInDbQuery { get; set; } = null;
|
||||
|
||||
public delegate string FirmwareExpectedVersionDelegate(IDASCommunication das);
|
||||
public FirmwareExpectedVersionDelegate UnitExpectedFirmwareQuery { get; set; } = null;
|
||||
|
||||
public delegate bool IsCalDateExpiredDelegate(IDASCommunication das);
|
||||
public IsCalDateExpiredDelegate CalDateExpiredQuery { get; set; } = null;
|
||||
|
||||
public delegate long UnitExpectedMaxMemoryDelegate(IDASCommunication das);
|
||||
public UnitExpectedMaxMemoryDelegate UnitExpectedMaxMemoryQuery { get; set; } = null;
|
||||
|
||||
public delegate void UpdateMaxMemoryDelegate(IDASCommunication das);
|
||||
public UpdateMaxMemoryDelegate UpdateMaxMemoryAction { get; set; } = null;
|
||||
/// <summary>
|
||||
/// whether to check the input/battery voltage for units or not
|
||||
/// </summary>
|
||||
public bool DoVoltageChecks { get; set; } = true;
|
||||
public void Reset()
|
||||
{
|
||||
ReadIds = false;
|
||||
Addresses = new string[0];
|
||||
AddressRanges = new Tuple<string, string>[0];
|
||||
ProceedWhenDone = false;
|
||||
RequireAllDASFound = false;
|
||||
KnownSLICEIPAddresses = new string[0];
|
||||
KnownTDASIPAddresses = new string[0];
|
||||
RequeryDevice = null;
|
||||
RequiredSerials = new string[0];
|
||||
DoHardwareChecks = false;
|
||||
ExpectedHardware = new IDASHardware[0];
|
||||
UnitIsInDbQuery = null;
|
||||
UnitExpectedFirmwareQuery = null;
|
||||
CalDateExpiredQuery = null;
|
||||
UnitExpectedMaxMemoryQuery = null;
|
||||
UpdateMaxMemoryAction = null;
|
||||
DoVoltageChecks = true;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.AppendLine($"ReadIds={ReadIds.ToString()}");
|
||||
sb.AppendLine($"Addresses={string.Join(",", Addresses)}");
|
||||
sb.Append("AddressRanges=");
|
||||
for (int i = 0; i < AddressRanges.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append($"({AddressRanges[i].Item1},{AddressRanges[i].Item2})");
|
||||
}
|
||||
sb.AppendLine();
|
||||
sb.AppendLine($"ProceedWhenDone={ProceedWhenDone.ToString()}");
|
||||
sb.AppendLine($"RequireAllDASFound={RequireAllDASFound.ToString()}");
|
||||
sb.AppendLine($"KnownSLICEIPAddresses={string.Join(",", KnownSLICEIPAddresses)}");
|
||||
sb.AppendLine($"KnownTDASIPAddresses={string.Join(",", KnownTDASIPAddresses)}");
|
||||
sb.Append("RequiryDevice=");
|
||||
if (null == RequeryDevice)
|
||||
{
|
||||
sb.AppendLine("null");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendLine(RequeryDevice.SerialNumber);
|
||||
}
|
||||
|
||||
sb.AppendLine($"RequiredSerials={string.Join(",", RequiredSerials)}");
|
||||
sb.AppendLine($"DoHardwareChecks={DoHardwareChecks.ToString()}");
|
||||
sb.Append("ExpectedHardware=");
|
||||
for (var i = 0; i < ExpectedHardware.Length; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append(ExpectedHardware[i].SerialNumber);
|
||||
}
|
||||
sb.AppendLine();
|
||||
|
||||
sb.Append("UnitIsInDbQuery=");
|
||||
sb.AppendLine(null == UnitIsInDbQuery ? "[null]" : "[defined]");
|
||||
|
||||
sb.Append("UnitExpectedFirmwareQuery=");
|
||||
sb.AppendLine(null == UnitExpectedFirmwareQuery ? "[null]" : "[defined]");
|
||||
|
||||
sb.Append("CalDateExpiredQuery=");
|
||||
sb.AppendLine(null == CalDateExpiredQuery ? "[null]" : "[defined]");
|
||||
|
||||
sb.Append("UnitExpectedMaxMemoryQuery=");
|
||||
sb.AppendLine(null == UnitExpectedMaxMemoryQuery ? "[null]" : "[defined]");
|
||||
|
||||
sb.Append("UpdateMaxMemoryAction=");
|
||||
sb.AppendLine(null == UpdateMaxMemoryAction ? "[null]" : "[defined]");
|
||||
|
||||
sb.Append("DoVoltageChecks=");
|
||||
sb.AppendLine(DoVoltageChecks.ToString());
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user