Big changes

This commit is contained in:
Duc
2025-03-13 12:04:22 -07:00
parent c689fcb7f9
commit ffa9905494
748 changed files with 199255 additions and 3743 deletions

View File

@@ -0,0 +1,600 @@
// UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using NLog;
using Raytheon.Common;
using Raytheon.Units;
using System;
using System.Net.Sockets;
using System.Threading;
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
#pragma warning disable CS0067
public event EventHandler<OverCurrentEventArgs> OverCurrent;
public event EventHandler<OverVoltageEventArgs> OverVoltage;
#pragma warning restore
#endregion
#region PublicFuctions
/// <summary>
/// The constructor for a sim power supply (simulated).
/// </summary>
/// <param name="overCurrentProtection">The overcurrent protection setting (Amps).</param>
/// <param name="overVoltageProtection">The overvoltage protection setting (Volts).</param>
/// <param name="voltageSetpoint">The voltage setpoint (Volts).</param>
/// <param name="maxVoltageSetpoint">The max voltage setpoint (Volts).</param>
/// <param name="minVoltageSetpoint">The min voltage setpoint (Volts).</param>
/// <param name="moduleNumber">The module number (multiple modules in a system).</param>
public PowerSupplySim(string name, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double maxVoltageSetpoint, double minVoltageSetpoint, double slewRateVoltsPerSecond, int moduleNumber = -1)
{
_name = name;
_logger = LogManager.GetCurrentClassLogger();
_overCurrentProtection = overCurrentProtection;
_overVoltageProtection = overVoltageProtection;
_voltageSetpoint = voltageSetpoint;
_voltageSetpointInitial = voltageSetpoint;
_maxVoltageSetpoint = maxVoltageSetpoint;
_minVoltageSetpoint = minVoltageSetpoint;
_moduleNumber = moduleNumber;
_isPowerOn = false;
_slewRateVoltsPerSecond = slewRateVoltsPerSecond;
// make sure it is off
Enabled = false;
// set up power supply
OutputVoltage = Voltage.FromVolts(_voltageSetpoint);
_state = State.Uninitialized;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public Current CurrentLimit
{
get
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
return Current.FromAmps(_overCurrentProtection);
}
set
{
_overCurrentProtection = value.Amps;
}
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Sim Power Supply called " + _name;
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Dispose of this object's resources.
/// </summary>
public void Dispose()
{
try
{
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
}
}
}
/// <summary>
///
/// </summary>
public bool Enabled
{
get
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
return _isPowerOn;
}
set
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
if (value == false)
{
_isPowerOn = false;
}
else
{
_isPowerOn = true;
}
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double GetSlewRate()
{
return _slewRateVoltsPerSecond;
}
/// <summary>
///
/// </summary>
public bool InhibitEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
// if we have not yet been initialized, go ahead and create the socket
if (_state == State.Uninitialized)
{
_state = State.Ready;
}
else
{
throw new Exception("PowerSupplySim::Initialize() - expected the supply " + _name + " to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
/// Control the power supply internal mechanical relay state
/// </summary>
/// <param name="shallWeConnect">True to connect, false to disconnect</param>
public void MechanicalRelayOutputControl(bool shallWeConnect)
{
// nothing to do here
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Current MeasureCurrent()
{
return Current.FromAmps(ReadCurrent());
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public Voltage MeasureVoltage()
{
return Voltage.FromVolts(ReadVoltage());
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
///
/// </summary>
public Voltage OutputVoltage
{
get
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
return Voltage.FromVolts(_voltageSetpoint);
}
set
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
double volts = value.Volts;
// do not let host set the voltage out of range, unless it is being set to 0
if (volts != 0.0)
{
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());
}
}
_voltageSetpoint = volts;
}
}
/// <summary>
///
/// </summary>
public Voltage OverVoltageProtection
{
get
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
return Voltage.FromVolts(_overVoltageProtection);
}
set
{
_overVoltageProtection = value.Volts;
}
}
/// <summary>
///
/// </summary>
public bool OverVoltageProtectionEnabled
{
get
{
return true;
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
throw new NotImplementedException();
}
/// <summary>
/// Reads the overcurrent and overvoltage protection (simulation).
/// </summary>
/// <returns>No Errors (simulated).</returns>
public int ReadProtectionStatus()
{
const int PROTECTION_STATUS = 0;
// a small 10 ms sleep for simulation
Thread.Sleep(10);
return PROTECTION_STATUS;
}
/// <summary>
///
/// </summary>
public void Reset()
{
// nothing to do
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
/// <param name="slew"></param>
/*public void SetSlewRate(double slew)
{
_slew = slew;
}*/
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
Off();
Reset();
_state = State.Uninitialized;
}
}
/// <summary>
///
/// </summary>
public Voltage VoltageSoftLimit
{
get
{
return Voltage.FromVolts(_maxVoltageSetpoint);
}
set
{
throw new NotImplementedException();
}
}
#endregion
#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;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
#endregion
#region PrivateFuctions
/// <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();
_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
}
}
}
/// <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);
_isPowerOn = false;
}
/// <summary>
/// Turn the output on (simulated).
/// </summary>
private void On()
{
// a small 10 ms sleep for simulation
Thread.Sleep(10);
_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);
double currentToReturn = 0.0;
if (_isPowerOn)
{
double maxCurrent = _overCurrentProtection;
double minCurrent = _overCurrentProtection - .5;
Random rnd = new Random();
double seed = rnd.NextDouble();
currentToReturn = (seed * (maxCurrent - minCurrent)) + minCurrent;
}
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);
double voltageToReturn = 0.0;
if (_isPowerOn)
{
double maxVoltage = _voltageSetpoint + 1;
double minVoltage = _voltageSetpoint - 1;
Random rnd = new Random();
double seed = rnd.NextDouble();
voltageToReturn = (seed * (maxVoltage - minVoltage)) + minVoltage;
}
return voltageToReturn;
}
#endregion
}
}

View File

@@ -0,0 +1,934 @@
// UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
// Ignore Spelling: ocp
using System;
using System.Collections.Generic;
using Raytheon.Units;
using System.Threading;
using NLog;
using Raytheon.Common;
using System.Net.Sockets;
using System.Linq;
using System.IO;
using System.Reflection;
using Raytheon.Instruments.PowerSupply;
namespace Raytheon.Instruments
{
/// <summary>
/// A class to control a power supply system.
/// </summary>
public class PowerSupplySystemSim : IPowerSupplySystem
{
#region PrivateClassMembers
private SortedDictionary<string, IDCPwr> _powerModuleMap;
private Dictionary<string, PowerSupplyModuleInfo> _powerModuleInfoDict = new Dictionary<string, PowerSupplyModuleInfo>();
private SortedDictionary<string, double> _powerModuleInitialVoltageSetpoint;
private string _name;
private object _syncObj = new Object();
private List<int> _moduleNumbersThatHaveBeenAdded;
private State _state;
private SelfTestResult _selfTestResult;
/// <summary>
/// NLog logger
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Raytheon configuration
/// </summary>
private readonly IConfigurationManager _configurationManager;
private readonly IConfiguration _configuration;
#endregion
#region PrivateFuctions
/// <summary>
/// The Finalizer.
/// </summary>
~PowerSupplySystemSim()
{
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
{
lock (_syncObj)
{
if (disposing)
{
if (_state == State.Ready)
{
try
{
//Reset System
Reset();
}
catch (Exception)
{
}
try
{
foreach (KeyValuePair<string, IDCPwr> entry in _powerModuleMap)
{
entry.Value.Shutdown();
}
}
catch (Exception)
{
}
_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
#region PublicFuctions
/// <summary>
/// PowerSupplySystemSim factory constructor
/// </summary>
/// <param name="deviceName"></param>
/// <param name="configurationManager"></param>
/// <param name="logger"></param>
public PowerSupplySystemSim(string deviceName, IConfigurationManager configurationManager, ILogger logger)
{
try
{
Name = deviceName;
_logger = logger;
_configurationManager = configurationManager;
_configuration = _configurationManager.GetConfiguration(Name);
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string powerSupplySystemDefPath = _configuration.GetConfigurationValue(deviceName, PowerSupply.ConfigXml.POWER_SUPPLY_SYSTEM_DEF_FILEPATH.ToString());
if (!Path.IsPathRooted(powerSupplySystemDefPath))
powerSupplySystemDefPath = Path.GetFullPath(Path.Combine(assemblyFolder, powerSupplySystemDefPath));
IConfigurationFile config = new ConfigurationFile(powerSupplySystemDefPath);
_powerModuleInitialVoltageSetpoint = new SortedDictionary<string, double>(StringComparer.InvariantCultureIgnoreCase);
_moduleNumbersThatHaveBeenAdded = new List<int>();
_powerModuleMap = new SortedDictionary<string, IDCPwr>(StringComparer.InvariantCultureIgnoreCase);
string moduleDef = config.ReadValue(deviceName, PowerSupply.ConfigIni.MODULE_DEFINITION.ToString());
List<string> powerModules = moduleDef.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
double overCurrentProtection;
double overVoltageProtection;
double voltageSetpoint;
double maxVoltageSetpoint;
double minVoltageSetpoint;
double slewRateVoltsPerSecond;
double inRushDelaySecs;
int moduleNumber = -1;
for (int i = 0; i < powerModules.Count(); i++)
{
string moduleName = powerModules[i];
int.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.INDEX.ToString()), out moduleNumber);
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.OCP.ToString()), out overCurrentProtection);
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.OVP.ToString()), out overVoltageProtection);
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.VOLTAGE_SETPOINT.ToString()), out voltageSetpoint);
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.MIN_VOLTAGE.ToString()), out minVoltageSetpoint);
Double.TryParse(config.ReadValue($"{deviceName}.{moduleName}", PowerSupply.ConfigIni.MAX_VOLTAGE.ToString()), out maxVoltageSetpoint);
try
{
if (!Double.TryParse(config.ReadValue($"{Name}.{moduleName}", PowerSupply.ConfigIni.VOLTAGE_SLEW_RATE.ToString()), out slewRateVoltsPerSecond))
slewRateVoltsPerSecond = -1.0;
}
catch
{
slewRateVoltsPerSecond = -1.0;
}
try
{
if (!Double.TryParse(config.ReadValue($"{Name}.{moduleName}", PowerSupply.ConfigIni.IN_RUSH_DELAY_SECS.ToString()), out inRushDelaySecs))
inRushDelaySecs = -1.0;
}
catch
{
inRushDelaySecs = -1.0;
}
_powerModuleInfoDict[moduleName] = new PowerSupplyModuleInfo(moduleNumber, overCurrentProtection, overVoltageProtection, voltageSetpoint, slewRateVoltsPerSecond, minVoltageSetpoint, maxVoltageSetpoint);
// create and initialize the power module
IDCPwr powerSupply = new PowerSupplySim(moduleName, overCurrentProtection, overVoltageProtection, voltageSetpoint, maxVoltageSetpoint, minVoltageSetpoint, inRushDelaySecs, moduleNumber);
// remember that we have added this module
_moduleNumbersThatHaveBeenAdded.Add(moduleNumber);
// remember the module name
_powerModuleMap.Add(moduleName.ToUpper(), powerSupply);
// remember the initial voltage setpoint
_powerModuleInitialVoltageSetpoint.Add(moduleName.ToUpper(), voltageSetpoint);
}
_selfTestResult = SelfTestResult.Unknown;
_state = State.Uninitialized;
}
catch (Exception)
{
throw;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool ClearErrors()
{
throw new NotImplementedException();
}
/// <summary>
/// Couple modules together
/// </summary>
/// <param name="moduleNameList"></param>
public void CoupleChannels(List<string> moduleNameList)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
public string DetailedStatus
{
get
{
return "This is a Power Supply System Sim called " + _name;
}
}
/// <summary>
///
/// </summary>
public bool DisplayEnabled
{
get
{
throw new NotImplementedException();
}
set { ; }
}
/// <summary>
/// Dispose of this object.
/// </summary>
public void Dispose()
{
try
{
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
}
}
}
/// <summary>
///
/// </summary>
public bool FrontPanelEnabled
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// Get the error code.
/// </summary>
/// <param name="errorCode">The error code.</param>
/// <returns>The error description.</returns>
public string GetErrorCode(out int errorCode)
{
lock (_syncObj)
{
errorCode = 0;
return "";
}
}
/// <summary>
/// Get the names of the modules in this system
/// </summary>
/// <returns></returns>
public List<string> GetModuleNames()
{
lock (_syncObj)
{
List<string> moduleNames = new List<string>();
foreach (KeyValuePair<string, IDCPwr> modules in _powerModuleMap)
{
moduleNames.Add(modules.Key);
}
return moduleNames;
}
}
/// <summary>
/// Get the dictionary that contains configuration information for each module
/// </summary>
/// <returns></returns>
public Dictionary<string, PowerSupplyModuleInfo> GetPowerSupplyModuleInfoDict(string powerSystem)
{
lock (_syncObj)
{
return _powerModuleInfoDict;
}
}
/// <summary>
/// Get the overcurrent protection setting.
/// </summary>
/// <param name="name">The module to get the overcurrent protection setting.</param>
/// <returns>The current (Amps).</returns>
public double GetOverCurrentSetting(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::GetOverCurrentSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].CurrentLimit.Amps;
}
}
/// <summary>
/// Get the overvoltage protection setting.
/// </summary>
/// <param name="name">The module to get the overvoltage protection setting.</param>
/// <returns>The voltage (Volts).</returns>
public double GetOverVoltageSetting(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::GetOverVoltageSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].OverVoltageProtection.Volts;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public double GetSlewRate(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::GetSlewRate() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
throw new NotImplementedException();
//return _powerModuleMap[name.ToUpper()].GetSlewRate();
}
}
/// <summary>
/// Get the voltage setpoint.
/// </summary>
/// <param name="name">The module to get the voltage setpoint setting.</param>
/// <returns>the voltage setpoint (Volts).</returns>
public double GetVoltageSetting(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::GetVoltageSetting() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].OutputVoltage.Volts;
}
}
/// <summary>
/// Group Modules Together
/// </summary>
/// <param name="modules"></param>
public void GroupModules(List<string> moduleNameList)
{
lock (_syncObj)
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public InstrumentMetadata Info
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
///
/// </summary>
public void Initialize()
{
// if we have not yet been initialized, go ahead and create the socket
if (_state == State.Uninitialized)
{
Reset();
PerformSelfTest();
// initialize each module
foreach (KeyValuePair<string, IDCPwr> powerModPair in _powerModuleMap)
{
powerModPair.Value.Initialize();
}
_state = State.Ready;
}
else
{
throw new Exception("PowerSupplySystemSim::Initialize() - expected the System " + _name + " to be Uninitialized, state was: " + _state.ToString());
}
}
/// <summary>
/// Send a command and return the response
/// </summary>
/// <param name="commandString"></param>
/// <returns></returns>
public string IOQuery(string commandString)
{
Thread.Sleep(500);
// return something
return "1.11";
}
/// <summary>
/// Send a command
/// </summary>
/// <param name="commandString"></param>
public void IOWrite(string commandString)
{
Thread.Sleep(50);
}
/// <summary>
/// Query the output state.
/// </summary>
/// <param name="name">The module to query.</param>
/// <returns>The output state. True = On, False = Off.</returns>
public bool IsOutputOn(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::IsOutputOn() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].Enabled;
}
}
/// <summary>
/// Control the power supply internal mechanical relay state
/// </summary>
/// <param name="name">The module to act on</param>
/// <param name="shallWeConnect">True to connect, false to disconnect</param>
public void MechanicalRelayOutputControl(string name, bool shallWeConnect)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::MechanicalRelayOutputControl() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
}
}
/// <summary>
/// Read the current.
/// </summary>
/// <param name="name">The name of the module.</param>
/// <returns>The current (Amps).</returns>
public double MeasureCurrent(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::MeasureCurrent() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].MeasureCurrent().Amps;
}
}
/// <summary>
/// Read the voltage.
/// </summary>
/// <param name="name">The name of the module.</param>
/// <returns>The voltage (Volts).</returns>
public double MeasureVoltage(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::MeasureVoltage() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].MeasureVoltage().Volts;
}
}
/// <summary>
///
/// </summary>
public string Name
{
get
{
return _name;
}
set { _name = value; }
}
/// <summary>
/// Turn the output off.
/// </summary>
/// <param name="name">The name of the module.</param>
public void Off(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::Off() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
_powerModuleMap[name.ToUpper()].Enabled = false;
}
}
/// <summary>
/// Turn the output on.
/// </summary>
/// <param name="name">The name of the module.</param>
public void On(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::On() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
_powerModuleMap[name.ToUpper()].Enabled = true;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public SelfTestResult PerformSelfTest()
{
_selfTestResult = SelfTestResult.Pass;
return _selfTestResult;
}
/// <summary>
/// Read the overvoltage and overcurrent protection status.
/// </summary>
/// <param name="name">The name of the module.</param>
/// <returns>The binary sum of all bits (decimal value) set in the Questionable Status Enable register.</returns>
public int ReadProtectionStatus(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::ReadProtectionStatus() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
return _powerModuleMap[name.ToUpper()].ReadProtectionStatus();
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public PowerData ReadPowerData(string name)
{
lock (_syncObj)
{
// voltage, voltage setpoint, current, output status
double voltage = MeasureVoltage(name);
double voltageSetpoint = GetVoltageSetting(name);
double current = MeasureCurrent(name);
bool outputStatus = IsOutputOn(name);
int faultStatus = ReadProtectionStatus(name);
double overVoltageProtection = GetOverVoltageSetting(name);
double overCurrentProtection = GetOverCurrentSetting(name);
return new PowerData(voltage, voltageSetpoint, overVoltageProtection, current, overCurrentProtection, outputStatus, faultStatus);
}
}
/// <summary>
///
/// </summary>
public void Reset()
{
lock (_syncObj)
{
}
}
/// <summary>
///
/// </summary>
public SelfTestResult SelfTestResult
{
get
{
return _selfTestResult;
}
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
public void SetInitialVoltage(string name)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::SetInitialVoltage() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
double initializeVoltage = _powerModuleInitialVoltageSetpoint[name.ToUpper()];
SetVoltageSetpoint(name.ToUpper(), initializeVoltage);
}
}
/// <summary>
/// Set the slew rate
/// </summary>
/// <param name="commandedSlew">slew in volts per second</param>
public void SetSlewRate(string name, double commandedSlew)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::SetSlewRate() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
throw new NotImplementedException();
//_powerModuleMap[name.ToUpper()].SetSlewRate(commandedSlew);
}
}
/// <summary>
///
/// </summary>
/// <param name="moduleName"></param>
/// <param name="ocpValue"></param>
public void SetOverCurrentProtection(string moduleName, double ocpValue)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(moduleName.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::SetOverCurrentProtection() - could not find supply: " + moduleName.ToUpper() + " In System " + _name);
}
_powerModuleMap[moduleName.ToUpper()].CurrentLimit = Current.FromAmps(ocpValue);
}
}
/// <summary>
///
/// </summary>
/// <param name="moduleName"></param>
/// <param name="ovpValue"></param>
public void SetOverVoltageProtection(string moduleName, double ovpValue)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(moduleName.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::SetOverVoltageProtection() - could not find supply: " + moduleName.ToUpper() + " In System " + _name);
}
_powerModuleMap[moduleName.ToUpper()].OverVoltageProtection = Voltage.FromVolts(ovpValue);
}
}
/// <summary>
/// Set the voltage setpoint.
/// </summary>
/// <param name="name">The name of the module.</param>
/// <param name="voltage">The desired voltage.</param>
public void SetVoltageSetpoint(string name, double volts)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == false)
{
throw new Exception("PowerSupplySystemSim::SetVoltageSetpoint() - could not find supply: " + name.ToUpper() + " In System " + _name);
}
_powerModuleMap[name.ToUpper()].OutputVoltage = Voltage.FromVolts(volts);
}
}
/// <summary>
///
/// </summary>
public void Shutdown()
{
if (_state == State.Ready)
{
string errorMsg = "";
try
{
//Reset System
Reset();
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
try
{
foreach (KeyValuePair<string, IDCPwr> entry in _powerModuleMap)
{
entry.Value.Shutdown();
}
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
try
{
}
catch (Exception err)
{
errorMsg += err.Message + " ";
}
_state = State.Uninitialized;
if (errorMsg != "")
{
throw new Exception("PowerSupplySystemSim::ShutdDown() - System " + _name + " had an error: " + errorMsg);
}
}
}
/// <summary>
///
/// </summary>
public State Status
{
get
{
return _state;
}
}
/// <summary>
/// Turn off the watchdog capability.
/// </summary>
public void WatchdogDisable()
{
lock (_syncObj)
{
}
}
/// <summary>
/// Turn on the watchdog capability.
/// </summary>
/// <param name="time">The watchdog time in seconds.</param>
public void WatchdogEnable(uint time)
{
lock (_syncObj)
{
}
}
/// <summary>
/// Adds another power supply to the Power Supply System
/// </summary>
/// <param name="name"></param>
/// <param name="overCurrentProtection"></param>
/// <param name="overVoltageProtection"></param>
/// <param name="voltageSetpoint"></param>
/// <param name="maxVoltageSetpoint"></param>
/// <param name="minVoltageSetpoint"></param>
/// <param name="moduleNumber"></param>
/// <exception cref="Exception"></exception>
public void AddPowerSupply(string name, double overCurrentProtection, double overVoltageProtection, double voltageSetpoint, double maxVoltageSetpoint, double minVoltageSetpoint, int moduleNumber = -1)
{
lock (_syncObj)
{
if (_powerModuleMap.ContainsKey(name.ToUpper()) == true)
{
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - system already contains a supply named: " + name.ToUpper() + " In System " + _name);
}
// check to see if this index has already been added
// would like to ask the IDCPwr object, but that functionality is not exposed in the interface
if (_moduleNumbersThatHaveBeenAdded.Contains(moduleNumber) == true)
{
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - module number has already been added: " + moduleNumber + " In System " + _name);
}
// confirm we are already initialized
if (_state != State.Uninitialized)
{
throw new Exception("PowerSupplySystemSim::AddPowerSupply() - System " + _name + " must be Uninitialized when adding power supplies. Current state is: " + _state.ToString());
}
// create and initialize the power module
IDCPwr powerSupply = new PowerSupplySim(name, overCurrentProtection, overVoltageProtection, voltageSetpoint, maxVoltageSetpoint, minVoltageSetpoint, moduleNumber);
_moduleNumbersThatHaveBeenAdded.Add(moduleNumber);
_powerModuleMap.Add(name.ToUpper(), powerSupply);
_powerModuleInitialVoltageSetpoint.Add(name.ToUpper(), voltageSetpoint);
}
}
/// <summary>
/// returns system name
/// </summary>
/// <returns></returns>
public string GetSystemName() => Name;
/// <summary>
/// reads power data
/// </summary>
/// <param name="moduleName"></param>
/// <param name="voltage"></param>
/// <param name="voltageSetpoint"></param>
/// <param name="current"></param>
/// <param name="outputStatus"></param>
/// <param name="faultStatus"></param>
public void ReadPowerData(string moduleName, out double voltage, out double voltageSetpoint, out double current, out bool outputStatus, out int faultStatus)
{
lock (_syncObj)
{
// voltage, voltage setpoint, current, output status
voltage = MeasureVoltage(moduleName);
voltageSetpoint = GetVoltageSetting(moduleName);
current = MeasureCurrent(moduleName);
outputStatus = IsOutputOn(moduleName);
faultStatus = ReadProtectionStatus(moduleName);
}
}
#endregion
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Solution.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>Raytheon.Instruments.PowerSupplySystemSim</AssemblyName>
<Product>Power Supply System Sim implementation</Product>
<Description>Power Supply System Sim implementation</Description>
<OutputType>Library</OutputType>
<!-- Static versioning (Suitable for Development) -->
<!-- Disable the line below for dynamic versioning -->
<Version>1.1.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.0.0" />
<PackageReference Include="Raytheon.Instruments.PowerSupplySystem.Contracts" Version="1.3.0" />
<PackageReference Include="Raytheon.Instruments.DCPwr.Contracts" Version="2.7.0" />
<PackageReference Include="Raytheon.Common" Version="1.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,136 @@
// **********************************************************************************************************
// PowerSupplySystemSimFactory.cs
// 2/20/2023
// NGI - Next Generation Interceptor
//
// Contract No. HQ0856-21-C-0003/1022000209
//
// THIS DOCUMENT DOES NOT CONTAIN TECHNOLOGY OR TECHNICAL DATA CONTROLLED UNDER EITHER THE U.S.
// INTERNATIONAL TRAFFIC IN ARMS REGULATIONS OR THE U.S. EXPORT ADMINISTRATION REGULATIONS.
//
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION PROPRIETARY TO RAYTHEON
// COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.
// DISCLOSURE TO UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO RAYTHEON
// COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS CONTENTS SHALL BE FURNISHED OR DISCLOSED
// TO OR COPIED OR USED BY PERSONS OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF
// RAYTHEON COMPANY.
//
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
//
// DESTRUCTION NOTICE: FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN DOD 5220.22-M,
// NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006,
// INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR DODM 5200.01-VOLUME 3,
// DOD INFORMATION SECURITY PROGRAM: PROTECTION OF CLASSIFIED INFORMATION, ENCLOSURE 3,
// SECTION 17. FOR CONTROLLED UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4,
// INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION.
//
// CONTROLLED BY: MISSILE DEFENSE AGENCY
// CONTROLLED BY: GROUND-BASED MIDCOURSE DEFENSE PROGRAM OFFICE
// CUI CATEGORY: CTI
// 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;
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;
public PowerSupplySystemSimFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
/// <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;
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(IPowerSupplySystem));
}
/// <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;
}
}
/// <summary>
/// Gets the instrument
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object GetInstrument(string name, bool simulateHw)
{
try
{
_logger = LogManager.GetLogger(name);
return new PowerSupplySystemSim(name, _configurationManager, _logger);
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// Gets supported interfaces
/// </summary>
/// <returns></returns>
public ICollection<Type> GetSupportedInterfaces()
{
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);
}
}
}