/*------------------------------------------------------------------------- // 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 System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Raytheon.Instruments.PowerSupplies { /// /// Class to simulate any power supply module /// class PowerSupplyModuleSim : PowerSupplyModule { private List _groupedModules; private List _coupledModules; private string _powerSupplySystemName; private bool _frontPanelEnabled = true; private ILogger _logger; /// /// Constructor /// public PowerSupplyModuleSim(string iniFilePath, string powerSupplySystemName) { _logger = LogManager.GetCurrentClassLogger(); _powerSupplySystemName = powerSupplySystemName; IConfigurationFile config = new ConfigurationFile(iniFilePath); string moduleDef = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.MODULE_DEFINITION.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue); string coupledModules = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.COUPLED_MODULES.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue); string groupedModules = config.ReadValue(PowerSupplyConfigIni.GENERAL.ToString(), PowerSupplyConfigIni.GROUPED_MODULES.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue); List powerModules = moduleDef.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList(); _coupledModules = coupledModules.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList(); _groupedModules = groupedModules.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (_groupedModules.Count() > 1) { powerModules.Clear(); // since modules are grouped, we pick the first module as the representative module powerModules.Add(_groupedModules[0]); } // build the power module map string moduleIndex = ""; double ovp = 0.0; double ocp = 0.0; double voltageSetPoint = 0.0; double voltageSlewRate = 0.0; double minVoltage = 0.0; double maxVoltage = 0.0; double minCurrent = 0.0; double maxCurrent = 0.0; for (int i = 0; i < powerModules.Count(); i++) { string moduleName = powerModules[i]; moduleIndex = config.ReadValue(moduleName, PowerSupplyConfigIni.INDEX.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.OCP.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out ocp); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.OVP.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out ovp); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.VOLTAGE_SETPOINT.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out voltageSetPoint); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.VOLTAGE_SLEW_RATE.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out voltageSlewRate); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MIN_VOLTAGE.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out minVoltage); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MAX_VOLTAGE.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out maxVoltage); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MIN_CURRENT.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out minCurrent); Double.TryParse(config.ReadValue(moduleName, PowerSupplyConfigIni.MAX_CURRENT.ToString(), Raytheon.Common.GeneralConstants.DefaultConfigValue), out maxCurrent); PowerModuleInfoDict[moduleName] = new Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo(moduleIndex, ocp, ovp, voltageSetPoint, voltageSlewRate, minVoltage, maxVoltage, minCurrent, maxCurrent); } } /// /// Enable or Disable Front Panel /// /// /// public override bool DisplayEnabled { set { SemObj?.Release(); } } /// /// Enable or disable Front Panel /// /// /// public override bool FrontPanelEnabled { get { SemObj?.Release(); throw new NotImplementedException(); } set { _frontPanelEnabled = value; SemObj?.Release(); } } /// /// Turn on power module's output /// /// /// public override void On() { try { lock (SyncObj) { CheckActivePowerModuleValidity(); if (_coupledModules.Contains(ActivePowerModule)) { foreach (string module in _coupledModules) { PowerModuleInfoDict[module].isOn_ = true; } } else PowerModuleInfoDict[ActivePowerModule].isOn_ = true; } } finally { SemObj?.Release(); } } /// /// Turn off power module's output /// /// /// public override void Off() { try { lock (SyncObj) { CheckActivePowerModuleValidity(); if (_coupledModules.Contains(ActivePowerModule)) { foreach (string module in _coupledModules) { PowerModuleInfoDict[module].isOn_ = false; } } else PowerModuleInfoDict[ActivePowerModule].isOn_ = false; } } finally { SemObj?.Release(); }; } /// /// Perform self test /// /// /// public override SelfTestResult PerformSelfTest() { try { lock (SyncObj) { SelfTestResult = SelfTestResult.Pass; } } finally { SemObj?.Release(); }; return SelfTestResult; } /// /// Read voltage /// /// /// protected override double ReadVoltage() { double val = 0.0; lock (SyncObj) { if (PowerModuleInfoDict[ActivePowerModule].isOn_) val = PowerModuleInfoDict[ActivePowerModule].voltageSetpoint_; } return val; } /// /// Read current /// /// /// protected override double ReadCurrent() { double val = 0.0; lock (SyncObj) { if (PowerModuleInfoDict[ActivePowerModule].isOn_) val = (PowerModuleInfoDict[ActivePowerModule].lowerCurrentLimit_ + PowerModuleInfoDict[ActivePowerModule].upperCurrentLimit_) / 2.0; } return val; } /// /// Read protection status /// /// /// protected override int ReadProtectionStatus() { lock (SyncObj) { return 0; } } /// /// Get error code /// /// /// protected override string GetErrorCode(out int errorCode) { lock (SyncObj) { errorCode = 0; return ""; } } } }