/*------------------------------------------------------------------------- // 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 ProgramGui.GUI.ViewModel; using ProgramLib.GUI.Model; using ProgramLib.GUI.View; using Raytheon.Instruments.PowerSupply; namespace ProgramLib { /// /// Class to spawn thread to read power supply data /// internal class ManualGuiPowerSupplyReadThread : BasicThread { private enum Events { GLOBAL_QUIT, QUIT, // DO NOT change the name // This must be the last member in the enum EVENT_TIMED_OUT } private ILogger _logger; /// /// Constructor /// public ManualGuiPowerSupplyReadThread() { _logger = LogManager.GetCurrentClassLogger(); } /// /// Method that executes on the thread. /// /// /// protected override void DoWork() { _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running..."); try { ReadPowerSupplyData(); } catch (Exception ex) { _logger?.Error(ex.Message + "\n" + ex.StackTrace); } _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting..."); } /// /// Read power supply data and check for faults /// /// /// private void ReadPowerSupplyData() { int pollRateMs = 1000; _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running..."); try { Dictionary eventDict = new Dictionary(); eventDict[Events.GLOBAL_QUIT] = Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT]; eventDict[Events.QUIT] = _quitEvent; eventDict[Events.EVENT_TIMED_OUT] = null; EventGroup eventGroup = new EventGroup(eventDict); ManualControlWindow manualGui = (ManualControlWindow)Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.MANUAL_CONTROL]; while (true) { Events id = eventGroup.WaitAny(pollRateMs); if (id == Events.EVENT_TIMED_OUT) { try { manualGui._manualWindowViewModel.GetPoweredModuleDataItemsSem().WaitOne(); List moduleList = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.GetPowerModuleList(); foreach (string module in moduleList) { PowerData data = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.ReadPowerData(module); if (data.IsOutputOn) { PowerModuleDataModel powerData = manualGui.GetPowerModuleDataFromDatagridDataItems(module); if (powerData == null) { powerData = new PowerModuleDataModel(); powerData.Name = module; powerData.PowerLed = manualGui._manualWindowViewModel._imageToResourcePathDict[ManualWindowViewModel.Images.LED_ON]; manualGui.Dispatcher.Invoke((Action)delegate { // update datagrid manualGui._manualWindowViewModel._poweredModuleDataItems.Add(powerData); }); powerData = manualGui.GetPowerModuleDataFromComboBoxDataItems(module); if (powerData != null) { // update combo box powerData.PowerLed = manualGui._manualWindowViewModel._imageToResourcePathDict[ManualWindowViewModel.Images.LED_ON]; } } BitArray statusReg = new BitArray(new int[] { data.FaultStatus }); bool ovpTriggeredInPowerSupply = statusReg[0]; bool ocpTriggeredInPowerSupply = statusReg[1]; if (ovpTriggeredInPowerSupply && ocpTriggeredInPowerSupply) { string errorMsg = String.Empty; if (ovpTriggeredInPowerSupply) { errorMsg = powerData.Name + "'s OVP circuitry has tripped"; } else if (ocpTriggeredInPowerSupply) { errorMsg = powerData.Name + "'s OCP circuitry has tripped"; } throw new Exception(errorMsg); } else { powerData.ExpectedVoltage = data.VoltageSetpoint.ToString("0.00"); powerData.ActualVoltage = data.Voltage.ToString("0.00"); powerData.ActualCurrent = data.Current.ToString("0.00"); } } else { PowerModuleDataModel powerData = manualGui.GetPowerModuleDataFromDatagridDataItems(module); if (powerData != null) { manualGui.Dispatcher.Invoke((Action)delegate { // update datagrid manualGui._manualWindowViewModel._poweredModuleDataItems.Remove(powerData); }); } powerData = manualGui.GetPowerModuleDataFromComboBoxDataItems(module); if (powerData != null) { // update combo box powerData.PowerLed = manualGui._manualWindowViewModel._imageToResourcePathDict[ManualWindowViewModel.Images.LED_OFF]; } } } } catch (Exception) { throw; } finally { manualGui._manualWindowViewModel.GetPoweredModuleDataItemsSem().Release(); } } else { try { manualGui._manualWindowViewModel.GetPoweredModuleDataItemsSem().WaitOne(); List moduleList = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.GetPowerModuleList(); foreach (string module in moduleList) { PowerData data = Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.ReadPowerData(module); if (data.IsOutputOn) { Program.Instance().MalMeasurementLibManager.PowerSupplyMeasurementManager.OutputDisable(module); } } } catch (Exception) { throw; } finally { manualGui._manualWindowViewModel.GetPoweredModuleDataItemsSem().Release(); } break; } } } catch (Exception) { throw; } _logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting..."); } } }