Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -15,93 +15,86 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using System;
using FpgaMeasurementInstrumentsLib;
using NLog;
using Raytheon.Common;
using System;
namespace Raytheon.Instruments
{
/// <summary>
/// A class that implements the Teradyne HSS Sub System Card with the HSI Library
/// </summary>
public unsafe class CommFpgaHssubCardSsHsi : IFpgaComm
{
#region PrivateClassMembers
private enum Mode
{
PRIMARY_CONTROL,
SECONDARY_CONTROL
};
/// <summary>
/// A class that implements the Teradyne HSS Sub System Card with the HSI Library
/// </summary>
public unsafe class CommFpgaHssubCardSsHsi : IFpgaComm
{
#region PrivateClassMembers
private enum Mode
{
PRIMARY_CONTROL,
SECONDARY_CONTROL
};
private readonly string _cardAddress;
private readonly uint _startingOffset;
private readonly string _cardFirmwareFile;
private uint _cardHandle;
private static object _syncObj = new Object();
private readonly Mode __mode;
private SelfTestResult _selfTestResult;
private State _state;
private string _name;
private readonly string _cardAddress;
private readonly uint _startingOffset;
private readonly string _cardFirmwareFile;
private uint _cardHandle;
private static object _syncObj = new Object();
private readonly Mode __mode;
private SelfTestResult _selfTestResult;
private State _state;
private string _name;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
private readonly ILogger _logger;
#endregion
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#region PrivateFuctions
#endregion
/// <summary>
/// The finalizer.
/// </summary>
~CommFpgaHssubCardSsHsi()
{
Dispose(false);
}
#region PrivateFuctions
/// <summary>
///
/// </summary>
private void LoadFirmware()
{
// lock up the FPGA resource
lock (_syncObj)
{
//ErrorLogger.Instance().Write("begin for " + _cardAddress.ToString(), ErrorLogger.LogLevel.INFO);
/// <summary>
/// The finalizer.
/// </summary>
~CommFpgaHssubCardSsHsi()
{
Dispose(false);
}
ushort customerId = 0;
ushort appId = 0;
uint revId = 0;
/// <summary>
///
/// </summary>
private void LoadFirmware()
{
// lock up the FPGA resource
lock (_syncObj)
{
ushort customerId = 0;
ushort appId = 0;
uint revId = 0;
int ret = HssubNativeMethods.terHsi_Firmware_Load(_cardHandle, HssubNativeMethods.TERHSI_FPGA_TEST_DEFINED, _cardFirmwareFile, ref customerId, ref appId, ref revId);
if ((uint)ret == 0xbffa4442)
{
// expected, load still seems to work
}
else if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
int ret = HssubNativeMethods.terHsi_Firmware_Load(_cardHandle, HssubNativeMethods.TERHSI_FPGA_TEST_DEFINED, _cardFirmwareFile, ref customerId, ref appId, ref revId);
if ((uint)ret == 0xbffa4442)
{
// expected, load still seems to work
}
else if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
throw new Exception("terHsi_Firmware_Load() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
throw new Exception("terHsi_Firmware_Load() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
/// <summary>
///
/// </summary>
private void SelfTest()
{
// loop through each card and command self test
/// <summary>
///
/// </summary>
private void SelfTest()
{
// loop through each card and command self test
/*short testResults = -1;
/*short testResults = -1;
StringBuilder errorStrTemp = new StringBuilder(512);
@@ -117,445 +110,418 @@ namespace Raytheon.Instruments
{
throw new Exception("HSSub Self Test returned an error: " + testResults.ToString() + ": " + errorStrTemp.ToString());
}*/
}
}
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
try
{
if (disposing)
{
lock (_syncObj)
{
if (_state == State.Ready)
{
int ret = HssubNativeMethods.terHsi_close(_cardHandle);
/// <summary>
/// Dispose of this object's resources.
/// </summary>
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
lock (_syncObj)
{
if (_state == State.Ready)
{
int ret = HssubNativeMethods.terHsi_close(_cardHandle);
_state = State.Uninitialized;
}
}
}
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
#endregion
_state = State.Uninitialized;
}
}
}
}
#endregion
#region PublicFuctions
#region PublicFuctions
/// <summary>
/// CommFpgaHssubCardSsHsi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public CommFpgaHssubCardSsHsi(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
Name = deviceName;
/// <summary>
/// CommFpgaHssubCardSsHsi factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
public CommFpgaHssubCardSsHsi(string deviceName, IConfigurationManager configurationManager)
{
Name = deviceName;
_logger = logger;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
_cardAddress = _configuration.GetConfigurationValue("CommFpgaHssubCardSsHsi", "CardAddress", "127.0.0.1");
_startingOffset = _configuration.GetConfigurationValue<uint>("CommFpgaHssubCardSsHsi", "StartingOffset", 0);
_cardFirmwareFile = _configuration.GetConfigurationValue("CommFpgaHssubCardSsHsi", "CardFirmwareFile", "");
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.PRIMARY_CONTROL;
}
_cardAddress = _configuration.GetConfigurationValue("CommFpgaHssubCardSsHsi", "CardAddress", "127.0.0.1");
_startingOffset = _configuration.GetConfigurationValue<uint>("CommFpgaHssubCardSsHsi", "StartingOffset", 0);
_cardFirmwareFile = _configuration.GetConfigurationValue("CommFpgaHssubCardSsHsi", "CardFirmwareFile", "");
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.PRIMARY_CONTROL;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="cardName"></param>
/// <param name="cardAddress"></param>
/// <param name="startingOffset"></param>
/// <param name="cardFirmwareFile"></param>
public CommFpgaHssubCardSsHsi(string name, string cardAddress, uint startingOffset, string cardFirmwareFile)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_cardAddress = cardAddress;
_startingOffset = startingOffset;
_cardFirmwareFile = cardFirmwareFile;
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.PRIMARY_CONTROL;
}
/// <summary>
///
/// </summary>
/// <param name="deviceName"></param>
/// <param name="cardName"></param>
/// <param name="cardAddress"></param>
/// <param name="startingOffset"></param>
/// <param name="cardFirmwareFile"></param>
public CommFpgaHssubCardSsHsi(string deviceName, string cardAddress, uint startingOffset, string cardFirmwareFile)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_cardAddress = cardAddress;
_startingOffset = startingOffset;
_cardFirmwareFile = cardFirmwareFile;
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.PRIMARY_CONTROL;
}
/// <summary>
/// Overloaded constructor for a secondary hsi control. (Firmware load done elsewhere, device reset done elsewhere)
/// Using this constructor will allow the hsot access to the HSS, but it will not load firmware or reset the device
/// </summary>
/// <param name="name"></param>
/// <param name="cardAddress"></param>
/// <param name="startingOffset"></param>
public CommFpgaHssubCardSsHsi(string name, string cardAddress, uint startingOffset)
{
_name = name;
_cardAddress = cardAddress;
_startingOffset = startingOffset;
_cardFirmwareFile = null;
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.SECONDARY_CONTROL;
}
/// <summary>
/// Overloaded constructor for a secondary hsi control. (Firmware load done elsewhere, device reset done elsewhere)
/// Using this constructor will allow the hsot access to the HSS, but it will not load firmware or reset the device
/// </summary>
/// <param name="deviceName"></param>
/// <param name="cardAddress"></param>
/// <param name="startingOffset"></param>
public CommFpgaHssubCardSsHsi(string deviceName, string cardAddress, uint startingOffset)
{
_name = deviceName;
_logger = LogManager.GetLogger($"{this.GetType().Name} - {deviceName}");
_cardAddress = cardAddress;
_startingOffset = startingOffset;
_cardFirmwareFile = null;
_cardHandle = 0;
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
__mode = Mode.SECONDARY_CONTROL;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
return false;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
return false;
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a FPGA HSS HSI called " + _name;
}
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a FPGA HSS HSI called " + _name;
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this object's resources.
/// </summary>
public void Dispose()
{
// lock up the FPGA resource
lock (_syncObj)
{
try
{
Dispose(true);
/// <summary>
/// Dispose of this object's resources.
/// </summary>
public void Dispose()
{
// lock up the FPGA resource
lock (_syncObj)
{
Dispose(true);
GC.SuppressFinalize(this);
}
catch (Exception)
{
try
{
//ErrorLogger.Instance().Write(err.Message + "\r\n" + err.StackTrace);
}
catch (Exception)
{
//Do not rethrow. Exception from error logger that has already been garbage collected
}
}
}
}
GC.SuppressFinalize(this);
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
Initialize(string.Empty);
}
/// <summary>
///
/// </summary>
public void Initialize()
{
Initialize(string.Empty);
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
public void Initialize(string fpgaName)
{
lock (_syncObj)
{
if (_state == State.Uninitialized)
{
int ret = HssubNativeMethods.terHsi_init(_cardAddress, 0, 0, ref _cardHandle);
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
public void Initialize(string fpgaName)
{
lock (_syncObj)
{
if (_state == State.Uninitialized)
{
int ret = HssubNativeMethods.terHsi_init(_cardAddress, 0, 0, ref _cardHandle);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(0, ret, _name);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(0, ret, _name);
throw new Exception("terHsi_init returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name + " on card " + _name);
}
throw new Exception("terHsi_init returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name + " on card " + _name);
}
// reset it and load firmware if this is the primary controller of the HSS
if (__mode == Mode.PRIMARY_CONTROL)
{
Reset();
// reset it and load firmware if this is the primary controller of the HSS
if (__mode == Mode.PRIMARY_CONTROL)
{
Reset();
LoadFirmware();
}
LoadFirmware();
}
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString() + " on card " + _name);
}
}
}
_state = State.Ready;
}
else
{
throw new Exception("expected the state to be Uninitialized, state was: " + _state.ToString() + " on card " + _name);
}
}
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Unknown;
return _selfTestResult;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Unknown;
return _selfTestResult;
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <returns></returns>
public uint Read(string fpgaName, uint address)
{
// lock up the FPGA resource
lock (_syncObj)
{
uint dataRead = 0;
int ret = HssubNativeMethods.terHsi_LB_Read32(_cardHandle, _startingOffset + address, ref dataRead);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <returns></returns>
public uint Read(string fpgaName, uint address)
{
// lock up the FPGA resource
lock (_syncObj)
{
uint dataRead = 0;
int ret = HssubNativeMethods.terHsi_LB_Read32(_cardHandle, _startingOffset + address, ref dataRead);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
throw new Exception("terHsi_LB_Read32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
throw new Exception("terHsi_LB_Read32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
return dataRead;
}
}
return dataRead;
}
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="numberOfWordsToRead"></param>
/// <param name="dataRead"></param>
public void ReadBlock(string fpgaName, uint address, uint numberOfWordsToRead, bool shallWeIncrementAddress, ref uint[] dataRead)
{
// lock up the FPGA resource
lock (_syncObj)
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="numberOfWordsToRead"></param>
/// <param name="dataRead"></param>
public void ReadBlock(string fpgaName, uint address, uint numberOfWordsToRead, bool shallWeIncrementAddress, ref uint[] dataRead)
{
// lock up the FPGA resource
lock (_syncObj)
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
lock (_syncObj)
{
int ret = HssubNativeMethods.terHsi_reset(_cardHandle);
/// <summary>
///
/// </summary>
public void Reset()
{
lock (_syncObj)
{
int ret = HssubNativeMethods.terHsi_reset(_cardHandle);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
throw new Exception("terHsi_reset() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
throw new Exception("terHsi_reset() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
// lock up the FPGA resource
lock (_syncObj)
{
string errorMsg = "";
bool wasThereAnError = false;
/// <summary>
///
/// </summary>
public void Shutdown()
{
// lock up the FPGA resource
lock (_syncObj)
{
string errorMsg = "";
bool wasThereAnError = false;
if (_state == State.Ready)
{
int ret = 0;
if (_state == State.Ready)
{
int ret = 0;
// reset it if this is the primary controller of the HSS
if (__mode == Mode.PRIMARY_CONTROL)
{
ret = HssubNativeMethods.terHsi_reset(_cardHandle);
if (ret != 0)
{
wasThereAnError = true;
errorMsg += "terHsi_reset returned error code: " + ret.ToString() + ". ";
}
}
// reset it if this is the primary controller of the HSS
if (__mode == Mode.PRIMARY_CONTROL)
{
ret = HssubNativeMethods.terHsi_reset(_cardHandle);
if (ret != 0)
{
wasThereAnError = true;
errorMsg += "terHsi_reset returned error code: " + ret.ToString() + ". ";
}
}
ret = HssubNativeMethods.terHsi_close(_cardHandle);
if (ret != 0)
{
wasThereAnError = true;
errorMsg += "terHsi_close returned error code: " + ret.ToString();
}
_state = State.Uninitialized;
ret = HssubNativeMethods.terHsi_close(_cardHandle);
if (ret != 0)
{
wasThereAnError = true;
errorMsg += "terHsi_close returned error code: " + ret.ToString();
}
_state = State.Uninitialized;
if (wasThereAnError == true)
{
throw new Exception(errorMsg);
}
}
}
}
if (wasThereAnError == true)
{
throw new Exception(errorMsg);
}
}
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="value"></param>
public void Write(string fpgaName, uint address, uint value)
{
// lock up the FPGA resource
lock (_syncObj)
{
int ret = HssubNativeMethods.terHsi_LB_Write32(_cardHandle, _startingOffset + address, value);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="value"></param>
public void Write(string fpgaName, uint address, uint value)
{
// lock up the FPGA resource
lock (_syncObj)
{
int ret = HssubNativeMethods.terHsi_LB_Write32(_cardHandle, _startingOffset + address, value);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
throw new Exception("terHsi_LB_Write32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
throw new Exception("terHsi_LB_Write32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="numberOfWordsToWrite"></param>
/// <param name="data"></param>
/// <param name="shallWeIncrementAddress"></param>
public void WriteBlock(string fpgaName, uint address, uint numberOfWordsToWrite, uint[] data, bool shallWeIncrementAddress)
{
// lock up the FPGA resource
lock (_syncObj)
{
if (shallWeIncrementAddress == false)
{
throw new Exception("terHsi_LB_WriteBlock32() does not support shallWeIncrementAddress = false command on card " + _name);
}
else
{
int ret = HssubNativeMethods.terHsi_LB_WriteBlock32(_cardHandle, _startingOffset + address, numberOfWordsToWrite, data);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
/// <summary>
///
/// </summary>
/// <param name="fpgaName"></param>
/// <param name="address"></param>
/// <param name="numberOfWordsToWrite"></param>
/// <param name="data"></param>
/// <param name="shallWeIncrementAddress"></param>
public void WriteBlock(string fpgaName, uint address, uint numberOfWordsToWrite, uint[] data, bool shallWeIncrementAddress)
{
// lock up the FPGA resource
lock (_syncObj)
{
if (shallWeIncrementAddress == false)
{
throw new Exception("terHsi_LB_WriteBlock32() does not support shallWeIncrementAddress = false command on card " + _name);
}
else
{
int ret = HssubNativeMethods.terHsi_LB_WriteBlock32(_cardHandle, _startingOffset + address, numberOfWordsToWrite, data);
if (ret != 0)
{
string errorStr = HssUtilSs.BuildErrorString(_cardHandle, ret, _name);
throw new Exception("terHsi_LB_WriteBlock32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
}
throw new Exception("terHsi_LB_WriteBlock32() returned an error(" + ret + ")" + ": " + errorStr + " on card " + _name);
}
}
}
}
/// <summary>
/// Loads firmware
/// </summary>
/// <param name="fpgaName"></param>
public void LoadFirmware(string fpgaName)
{
LoadFirmware();
}
/// <summary>
/// Loads firmware
/// </summary>
/// <param name="fpgaName"></param>
public void LoadFirmware(string fpgaName)
{
LoadFirmware();
}
#endregion
}
#endregion
}
}

View File

@@ -30,71 +30,64 @@
// DISTRIBUTION/DISSEMINATION CONTROL: F
// POC: Alex Kravchenko (1118268)
// **********************************************************************************************************
using NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
using NLog;
using Raytheon.Common;
namespace Raytheon.Instruments
{
[ExportInstrumentFactory(ModelNumber = "CommFpgaHssubCardSsHsiFactory")]
public class CommFpgaHssubCardSsHsiFactory : IInstrumentFactory
{
/// <summary>
/// The supported interfaces
/// </summary>
private readonly List<Type> _supportedInterfaces = new List<Type>();
private ILogger _logger;
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
[ExportInstrumentFactory(ModelNumber = "CommFpgaHssubCardSsHsiFactory")]
public class CommFpgaHssubCardSsHsiFactory : IInstrumentFactory
{
private readonly List<Type> _supportedInterfaces = new List<Type>();
public CommFpgaHssubCardSsHsiFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
/// <summary>
/// COECommDeviceInstrumentFactory injection constructor
/// </summary>
/// <param name="configManager"></param>
/// <param name="simEngine"></param>
/// <param name="logger"></param>
[ImportingConstructor]
public CommFpgaHssubCardSsHsiFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
public CommFpgaHssubCardSsHsiFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
/// <summary>
/// CommFpgaHssubCardSsHsiFactory injection constructor
/// </summary>
[ImportingConstructor]
public CommFpgaHssubCardSsHsiFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(IFpgaComm));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
_logger = LogManager.GetLogger(name);
return new CommFpgaHssubCardSsHsi(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
if (LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(IFpgaComm));
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IInstrument GetInstrument(string name)
{
try
{
return new CommFpgaHssubCardSsHsi(name, _configurationManager);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets the instrument
@@ -105,12 +98,10 @@ namespace Raytheon.Instruments
{
try
{
_logger = LogManager.GetLogger(name);
if (simulateHw)
return new CommFpgaSim(name, _configurationManager, _logger);
return new CommFpgaSim(name, _configurationManager);
else
return new CommFpgaHssubCardSsHsi(name, _configurationManager, _logger);
return new CommFpgaHssubCardSsHsi(name, _configurationManager);
}
catch (Exception)
{
@@ -123,17 +114,17 @@ namespace Raytheon.Instruments
/// </summary>
/// <returns></returns>
public ICollection<Type> GetSupportedInterfaces()
{
return _supportedInterfaces.ToArray();
}
{
return _supportedInterfaces.ToArray();
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
/// <summary>
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
/// </summary>
/// <returns></returns>
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
}