Major upgrade
This commit is contained in:
@@ -15,24 +15,22 @@ GOVERNMENT.
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
using NLog;
|
||||
using Raytheon.Common;
|
||||
using Raytheon.Units;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using Raytheon.Units;
|
||||
|
||||
namespace Raytheon.Instruments
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that provides an interface for controlling simulated power supply systems and their modules.
|
||||
/// </summary>
|
||||
public class PowerSupplySim : IDCPwr
|
||||
{
|
||||
#region PublicClassMembers
|
||||
/// <summary>
|
||||
/// A class that provides an interface for controlling simulated power supply systems and their modules.
|
||||
/// </summary>
|
||||
public class PowerSupplySim : IDCPwr
|
||||
{
|
||||
#region PublicClassMembers
|
||||
#pragma warning disable CS0067
|
||||
public event EventHandler<OverCurrentEventArgs> OverCurrent;
|
||||
public event EventHandler<OverVoltageEventArgs> OverVoltage;
|
||||
public event EventHandler<OverCurrentEventArgs> OverCurrent;
|
||||
public event EventHandler<OverVoltageEventArgs> OverVoltage;
|
||||
#pragma warning restore
|
||||
|
||||
#endregion
|
||||
@@ -131,23 +129,9 @@ namespace Raytheon.Instruments
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
Dispose(true);
|
||||
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>
|
||||
@@ -233,7 +217,7 @@ namespace Raytheon.Instruments
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("PowerSupplySim::Initialize() - expected the supply " + _name + " to be Uninitialized, state was: " + _state.ToString());
|
||||
throw new Exception("Expected the supply " + _name + " to be Uninitialized, state was: " + _state.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,7 +296,7 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
if (volts > _maxVoltageSetpoint || volts < _minVoltageSetpoint)
|
||||
{
|
||||
throw new Exception("PowerSupplySim::OutputVoltage() - Desired voltage setpoint out of range for supply " + _name + ". Commanded setpoint: " + value.ToString() + ", Max: " + _maxVoltageSetpoint.ToString() + ", Min: " + _minVoltageSetpoint.ToString());
|
||||
throw new Exception("Desired voltage setpoint out of range for supply " + _name + ". Commanded setpoint: " + value.ToString() + ", Max: " + _maxVoltageSetpoint.ToString() + ", Min: " + _minVoltageSetpoint.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -452,149 +436,135 @@ namespace Raytheon.Instruments
|
||||
#region PrivateClassMembers
|
||||
|
||||
private string _name;
|
||||
private double _overCurrentProtection;
|
||||
private double _overVoltageProtection;
|
||||
private double _voltageSetpoint;
|
||||
private double _voltageSetpointInitial;
|
||||
private readonly double _maxVoltageSetpoint;
|
||||
private readonly double _minVoltageSetpoint;
|
||||
private readonly int _moduleNumber;
|
||||
private bool _isPowerOn;
|
||||
private double _slewRateVoltsPerSecond;
|
||||
private State _state;
|
||||
private double _overCurrentProtection;
|
||||
private double _overVoltageProtection;
|
||||
private double _voltageSetpoint;
|
||||
private double _voltageSetpointInitial;
|
||||
private readonly double _maxVoltageSetpoint;
|
||||
private readonly double _minVoltageSetpoint;
|
||||
private readonly int _moduleNumber;
|
||||
private bool _isPowerOn;
|
||||
private double _slewRateVoltsPerSecond;
|
||||
private State _state;
|
||||
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
/// <summary>
|
||||
/// NLog logger
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region PrivateFuctions
|
||||
#region PrivateFuctions
|
||||
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~PowerSupplySim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
/// <summary>
|
||||
/// The finalizer.
|
||||
/// </summary>
|
||||
~PowerSupplySim()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Off();
|
||||
/// <summary>
|
||||
/// Dispose of this object.
|
||||
/// </summary>
|
||||
/// <param name="disposing">True = currently disposing, False = not disposing.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (_state == State.Ready)
|
||||
{
|
||||
Off();
|
||||
|
||||
_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
|
||||
}
|
||||
}
|
||||
}
|
||||
_state = State.Uninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns this object module number.
|
||||
/// </summary>
|
||||
/// <returns>The module number.</returns>
|
||||
/*public int GetModuleNumber()
|
||||
/// <summary>
|
||||
/// Returns this object module number.
|
||||
/// </summary>
|
||||
/// <returns>The module number.</returns>
|
||||
/*public int GetModuleNumber()
|
||||
{
|
||||
return _moduleNumber;
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output off (simulated).
|
||||
/// </summary>
|
||||
private void Off()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
/// <summary>
|
||||
/// Turn the output off (simulated).
|
||||
/// </summary>
|
||||
private void Off()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
_isPowerOn = false;
|
||||
}
|
||||
_isPowerOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Turn the output on (simulated).
|
||||
/// </summary>
|
||||
private void On()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
/// <summary>
|
||||
/// Turn the output on (simulated).
|
||||
/// </summary>
|
||||
private void On()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(10);
|
||||
|
||||
_isPowerOn = true;
|
||||
}
|
||||
_isPowerOn = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the current (simulated).
|
||||
/// </summary>
|
||||
/// <returns>The current (simulated).</returns>
|
||||
private double ReadCurrent()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
/// <summary>
|
||||
/// Read the current (simulated).
|
||||
/// </summary>
|
||||
/// <returns>The current (simulated).</returns>
|
||||
private double ReadCurrent()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
|
||||
double currentToReturn = 0.0;
|
||||
double currentToReturn = 0.0;
|
||||
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxCurrent = _overCurrentProtection;
|
||||
double minCurrent = _overCurrentProtection - .5;
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxCurrent = _overCurrentProtection;
|
||||
double minCurrent = _overCurrentProtection - .5;
|
||||
|
||||
Random rnd = new Random();
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
currentToReturn = (seed * (maxCurrent - minCurrent)) + minCurrent;
|
||||
}
|
||||
currentToReturn = (seed * (maxCurrent - minCurrent)) + minCurrent;
|
||||
}
|
||||
|
||||
return currentToReturn;
|
||||
}
|
||||
return currentToReturn;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the voltage.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (simulated).</returns>
|
||||
private double ReadVoltage()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
/// <summary>
|
||||
/// Read the voltage.
|
||||
/// </summary>
|
||||
/// <returns>The voltage (simulated).</returns>
|
||||
private double ReadVoltage()
|
||||
{
|
||||
// a small 10 ms sleep for simulation
|
||||
Thread.Sleep(100);
|
||||
|
||||
double voltageToReturn = 0.0;
|
||||
double voltageToReturn = 0.0;
|
||||
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxVoltage = _voltageSetpoint + 1;
|
||||
double minVoltage = _voltageSetpoint - 1;
|
||||
if (_isPowerOn)
|
||||
{
|
||||
double maxVoltage = _voltageSetpoint + 1;
|
||||
double minVoltage = _voltageSetpoint - 1;
|
||||
|
||||
Random rnd = new Random();
|
||||
Random rnd = new Random();
|
||||
|
||||
double seed = rnd.NextDouble();
|
||||
double seed = rnd.NextDouble();
|
||||
|
||||
voltageToReturn = (seed * (maxVoltage - minVoltage)) + minVoltage;
|
||||
}
|
||||
voltageToReturn = (seed * (maxVoltage - minVoltage)) + minVoltage;
|
||||
}
|
||||
|
||||
return voltageToReturn;
|
||||
}
|
||||
return voltageToReturn;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,72 +30,65 @@
|
||||
// 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 = "PowerSupplySystemSimFactory")]
|
||||
public class PowerSupplySystemSimFactory : 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 = "PowerSupplySystemSimFactory")]
|
||||
public class PowerSupplySystemSimFactory : IInstrumentFactory
|
||||
{
|
||||
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
||||
|
||||
public PowerSupplySystemSimFactory(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 PowerSupplySystemSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
public PowerSupplySystemSimFactory(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>
|
||||
/// PowerSupplySystemSimFactory injection constructor
|
||||
/// </summary>
|
||||
[ImportingConstructor]
|
||||
public PowerSupplySystemSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
||||
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
||||
{
|
||||
DefaultPath = defaultConfigPath;
|
||||
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IPowerSupplySystem));
|
||||
}
|
||||
if (LogManager.Configuration == null)
|
||||
{
|
||||
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new PowerSupplySystemSim(name, _configurationManager, _logger);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
_configurationManager = configManager ?? GetConfigurationManager();
|
||||
_supportedInterfaces.Add(typeof(IPowerSupplySystem));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public IInstrument GetInstrument(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new PowerSupplySystemSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instrument
|
||||
@@ -106,12 +99,11 @@ namespace Raytheon.Instruments
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger = LogManager.GetLogger(name);
|
||||
return new PowerSupplySystemSim(name, _configurationManager, _logger);
|
||||
return new PowerSupplySystemSim(name, _configurationManager);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,17 +112,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user