/*------------------------------------------------------------------------- // 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 System; using System.Collections; using System.Collections.Generic; using System.Threading; using NLog; using Raytheon.Instruments.PowerSupply; namespace ProgramLib { /// /// Class to spawn thread to read power supply data /// internal class PowerSupplyReadThread : BasicThread { private enum Events { GLOBAL_QUIT, QUIT, UUT_POWER_ON, UUT_POWER_OFF, // DO NOT change the name // This must be the last member in the enum EVENT_TIMED_OUT } private ILogger _logger; private string _powerSupplySystemName; private List _powerModuleNameList; private int _pollRateMs; Dictionary _powerSupplyModuleInfoDict; /// /// Constructor /// public PowerSupplyReadThread(string powerSupplySystemName, int pollRateMs) { _logger = LogManager.GetCurrentClassLogger(); _powerSupplySystemName = powerSupplySystemName; _pollRateMs = pollRateMs; } /// /// Method that executes on the thread. /// /// /// protected override void DoWork() { _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} is running..."); try { Dictionary eventDict = new Dictionary(); eventDict[Events.GLOBAL_QUIT] = Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT]; eventDict[Events.QUIT] = _quitEvent; eventDict[Events.UUT_POWER_ON] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_ON]; eventDict[Events.EVENT_TIMED_OUT] = null; EventGroup eventGroup = new EventGroup(eventDict); _powerModuleNameList = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.GetPowerSupplyList(_powerSupplySystemName); _powerSupplyModuleInfoDict = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.GetPowerSupplyModuleInfoDict(_powerSupplySystemName); while (true) { Events id = eventGroup.WaitAny(); if (id == Events.UUT_POWER_ON) { ReadPowerSupplyData(); } else break; } } catch (Exception ex) { _logger?.Error(ex.Message + "\n" + ex.StackTrace); } _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} is exiting..."); } /// /// Read power supply data and check for faults /// /// /// private void ReadPowerSupplyData() { _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} is running..."); try { Dictionary eventDict = new Dictionary(); eventDict[Events.GLOBAL_QUIT] = Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT]; eventDict[Events.QUIT] = _quitEvent; eventDict[Events.UUT_POWER_OFF] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_OFF]; eventDict[Events.EVENT_TIMED_OUT] = null; EventGroup eventGroup = new EventGroup(eventDict); while (true) { Events id = eventGroup.WaitAny(_pollRateMs); if (id == Events.EVENT_TIMED_OUT) { foreach (string moduleName in _powerModuleNameList) { PowerData data = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.ReadPowerData(moduleName); BitArray statusReg = new BitArray(new int[] { data.FaultStatus }); bool ovpTriggeredInPowerSupply = statusReg[0]; bool ocpTriggeredInPowerSupply = statusReg[1]; if (!ovpTriggeredInPowerSupply && !ocpTriggeredInPowerSupply) { Program.Instance().PowerSupplySharedData.SetData(moduleName, data.Voltage, data.Current, _powerSupplyModuleInfoDict[moduleName]); CheckVoltageWithinLimits(moduleName, data.Voltage); } else { string errorMsg = String.Empty; if (ovpTriggeredInPowerSupply) { errorMsg = moduleName + "'s OVP circuitry has tripped"; } else if (ocpTriggeredInPowerSupply) { errorMsg = moduleName + "'s OCP circuitry has tripped"; } throw new Exception(errorMsg); } } } else break; } } catch (Exception ex) { if (!Program.Instance().EventManager[EventManager.Events.FATAL_FAILURE].WaitOne(0)) { Program.Instance().SetFatalFailureExceptionFromSupportThread(ex); Program.Instance().EventManager[EventManager.Events.FATAL_FAILURE].Set(); } } _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} is exiting..."); } /// /// Check for voltage's limit exceedence /// /// /// private void CheckVoltageWithinLimits(string moduleName, double voltage) { PowerSupplyModuleInfo powerSupplyModuleInfo = _powerSupplyModuleInfoDict[moduleName]; if ((voltage < powerSupplyModuleInfo.voltageLowerLimit_ || voltage > powerSupplyModuleInfo.voltageUpperLimit_) && powerSupplyModuleInfo.isOn_) { string errorMsg = moduleName + "'s voltage is out of limits (" + powerSupplyModuleInfo.voltageLowerLimit_.ToString("0.00") + "V, " + powerSupplyModuleInfo.voltageUpperLimit_.ToString("0.00") + "V). Voltage reading: " + voltage.ToString("0.00") + "V"; throw new Exception(errorMsg); } } } }