Major upgrade
This commit is contained in:
232
Source/Program/Threads/ManualGuiPowerSupplyReadThread.cs
Normal file
232
Source/Program/Threads/ManualGuiPowerSupplyReadThread.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
// 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
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to spawn thread to read power supply data
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public ManualGuiPowerSupplyReadThread()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method that executes on the thread.
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
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...");
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read power supply data and check for faults
|
||||
/// </summary>
|
||||
/// <param name=""></param>
|
||||
/// <returns></returns>
|
||||
private void ReadPowerSupplyData()
|
||||
{
|
||||
int pollRateMs = 1000;
|
||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
||||
|
||||
try
|
||||
{
|
||||
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||
eventDict[Events.GLOBAL_QUIT] = Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT];
|
||||
eventDict[Events.QUIT] = _quitEvent;
|
||||
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||
|
||||
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(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<string> 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<string> 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...");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user