Major upgrade

This commit is contained in:
Duc
2025-10-24 15:18:11 -07:00
parent fd85735c93
commit ce583d1664
478 changed files with 237518 additions and 47610 deletions

View File

@@ -15,10 +15,10 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using NLog;
using System;
using System.Collections.Generic;
using System.Threading;
using NLog;
namespace ProgramLib
{
@@ -30,6 +30,7 @@ namespace ProgramLib
private enum Events
{
GLOBAL_QUIT,
QUIT,
FATAL_FAILURE,
// DO NOT change the name
@@ -47,14 +48,6 @@ namespace ProgramLib
_logger = LogManager.GetCurrentClassLogger();
}
/// <summary>
/// Destructor
/// </summary>
~FailureMonitorThread()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
}
/// <summary>
/// Method that executes on the thread.
/// </summary>
@@ -66,6 +59,7 @@ namespace ProgramLib
{
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.FATAL_FAILURE] = Program.Instance().EventManager[EventManager.Events.FATAL_FAILURE];
eventDict[Events.EVENT_TIMED_OUT] = null;
@@ -77,10 +71,10 @@ namespace ProgramLib
{
Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT].Set();
UutPowerAction uutPowerAction = new UutPowerAction();
uutPowerAction.UutPowerOff();
BasicAction action = new UutPowerOffAction();
action.Run();
Program.Instance().TerminateTestOnSupportThreadError();
TestStand.ProgramManager.TerminateTestOnSupportThreadError();
}
}
catch (Exception ex)

View 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...");
}
}
}

View File

@@ -15,13 +15,13 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Threading;
using NLog;
using ProgramLib.GUI.Model;
using ProgramLib.GUI.View;
using ProgramLib.GUI.ViewModel;
using System;
using System.Collections.Generic;
using System.Threading;
namespace ProgramLib
{
@@ -33,6 +33,7 @@ namespace ProgramLib
private enum Events
{
GLOBAL_QUIT,
QUIT,
UUT_POWER_ON,
UUT_POWER_OFF,
@@ -44,27 +45,26 @@ namespace ProgramLib
private ILogger _logger;
private LiveDataWindow _liveDataWindow;
private PassthroughData _passthroughData = null;
int _pollRateMs;
/// <summary>
/// Constructor
/// </summary>
public PassthroughDataUpdateThread()
public PassthroughDataUpdateThread(int pollRateMs)
{
_logger = LogManager.GetCurrentClassLogger();
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA];
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.LIVE_DATA];
_passthroughData = new PassthroughData(_liveDataWindow.datagridPassthroughData.Columns.Count);
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA].Dispatcher.Invoke((Action)delegate
_pollRateMs = pollRateMs;
_liveDataWindow.Dispatcher.Invoke((Action)delegate
{
_liveDataWindow.LiveDataWindowViewModel.AddPassthroughData(_passthroughData.GetPassthroughDataModelDict());
});
}
~PassthroughDataUpdateThread()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
_pollRateMs = pollRateMs;
}
/// <summary>
@@ -80,6 +80,7 @@ namespace ProgramLib
{
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.UUT_POWER_ON] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_ON];
eventDict[Events.EVENT_TIMED_OUT] = null;
@@ -113,74 +114,73 @@ namespace ProgramLib
/// <returns></returns>
private void UpdatePassthroughData()
{
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.UUT_POWER_OFF] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_OFF];
eventDict[Events.EVENT_TIMED_OUT] = null;
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
Random rnd = new Random();
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_ON];
while (true)
{
Events id = eventGroup.WaitAny(pollRateMs);
Events id = eventGroup.WaitAny(_pollRateMs);
if (id == Events.EVENT_TIMED_OUT)
{
rnd = new Random();
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_OFF];
float num = 70.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
Thread.Sleep(100);
num = 30.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR2, num.ToString("0.00"));
Thread.Sleep(200);
num = 40.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR3, num.ToString("0.00"));
Thread.Sleep(100);
num = 50.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
Thread.Sleep(100);
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_ON];
num = 60.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
Thread.Sleep(200);
num = 10.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR6, num.ToString("0.00"));
if (!Program.Instance().IsThereHardware)
SimulatePassThroughData();
}
else
break;
}
}
catch (Exception ex)
catch (Exception)
{
_logger.Error(ex.Message + "\n" + ex.StackTrace);
throw;
}
finally
{
_passthroughData.BlankAllData();
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_OFF];
}
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
}
static float GenerateRandomFraction()
/// <summary>
/// Simulate passthrough data
/// </summary>
private void SimulatePassThroughData()
{
Random rnd = new Random();
int randNum = 0;
const int minimum = 1;
randNum = rnd.Next(20);
float num = 70.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR01, num.ToString("0.00"));
if (randNum <= minimum)
{
randNum += minimum;
}
return (float)(1.0 / (float)randNum);
Thread.Sleep(100);
num = 30.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR02, num.ToString("0.00"));
Thread.Sleep(200);
num = 40.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR03, num.ToString("0.00"));
Thread.Sleep(100);
num = 50.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR04, num.ToString("0.00"));
Thread.Sleep(100);
num = 60.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR05, num.ToString("0.00"));
Thread.Sleep(200);
num = 10.0f + Util.GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR06, num.ToString("0.00"));
}
}
}

View File

@@ -32,6 +32,7 @@ namespace ProgramLib
private enum Events
{
GLOBAL_QUIT,
QUIT,
UUT_POWER_ON,
UUT_POWER_OFF,
@@ -46,22 +47,21 @@ namespace ProgramLib
private List<string> _powerModuleNameList;
private int _pollRateMs;
Dictionary<string, PowerSupplyModuleInfo> _powerSupplyModuleInfoDict;
/// <summary>
/// Constructor
/// </summary>
public PowerSupplyReadThread(string powerSupplySystemName)
public PowerSupplyReadThread(string powerSupplySystemName, int pollRateMs)
{
_logger = LogManager.GetCurrentClassLogger();
_powerSupplySystemName = powerSupplySystemName;
}
_pollRateMs = pollRateMs;
~PowerSupplyReadThread()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
}
/// <summary>
@@ -77,6 +77,7 @@ namespace ProgramLib
{
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.UUT_POWER_ON] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_ON];
eventDict[Events.EVENT_TIMED_OUT] = null;
@@ -113,13 +114,13 @@ namespace ProgramLib
/// <returns></returns>
private void ReadPowerSupplyData()
{
int pollRateMs = 1000;
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {_powerSupplySystemName} 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.UUT_POWER_OFF] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_OFF];
eventDict[Events.EVENT_TIMED_OUT] = null;
@@ -127,7 +128,7 @@ namespace ProgramLib
while (true)
{
Events id = eventGroup.WaitAny(pollRateMs);
Events id = eventGroup.WaitAny(_pollRateMs);
if (id == Events.EVENT_TIMED_OUT)
{
@@ -143,6 +144,8 @@ namespace ProgramLib
if (!ovpTriggeredInPowerSupply && !ocpTriggeredInPowerSupply)
{
Program.Instance().PowerSupplySharedData.SetData(moduleName, data.Voltage, data.Current, _powerSupplyModuleInfoDict[moduleName]);
CheckVoltageWithinLimits(moduleName, data.Voltage);
}
else
{
@@ -157,9 +160,7 @@ namespace ProgramLib
errorMsg = moduleName + "'s OCP circuitry has tripped";
}
HandleOutOfToleranceCondition(errorMsg);
break;
throw new Exception(errorMsg);
}
}
}
@@ -169,68 +170,30 @@ namespace ProgramLib
}
catch (Exception ex)
{
_logger.Error(ex.Message + "\n" + ex.StackTrace);
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...");
}
/// <summary>
/// Check for current's upper limit
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private bool IsCurrentWithinLimits(string moduleName, double current)
{
bool outOfLimits = false;
// Duc - is this function needed?
//Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo powerSupplyModuleInfo = _powerSupplyModuleInfoDict[moduleName];
//if ((current < powerSupplyModuleInfo.currentLowerLimit_ || current > powerSupplyModuleInfo.currentUpperLimit_) && powerSupplyModuleInfo.isOn_)
//{
// outOfLimits = true;
// string errorMsg = moduleName + "'s current is out of limits (" + powerSupplyModuleInfo.currentLowerLimit_.ToString("0.00") + "," + powerSupplyModuleInfo.currentUpperLimit_.ToString("0.00") + "). Current reading: " + current.ToString("0.00");
// HandleOutOfToleranceCondition(errorMsg);
//}
return outOfLimits;
}
/// <summary>
/// Check for voltage's limit exceedence
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private bool IsVoltageWithinLimits(string moduleName, double voltage)
private void CheckVoltageWithinLimits(string moduleName, double voltage)
{
bool outOfLimits = false;
// Duc - is this function needed?
//Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo powerSupplyModuleInfo = _powerSupplyModuleInfoDict[moduleName];
PowerSupplyModuleInfo powerSupplyModuleInfo = _powerSupplyModuleInfoDict[moduleName];
//if ((voltage < powerSupplyModuleInfo.voltageLowerLimit_ || voltage > powerSupplyModuleInfo.voltageUpperLimit_) && powerSupplyModuleInfo.isOn_)
//{
// outOfLimits = true;
// string errorMsg = moduleName + "'s voltage is out of limits (" + powerSupplyModuleInfo.voltageLowerLimit_.ToString("0.00") + "," + powerSupplyModuleInfo.voltageUpperLimit_.ToString("0.00") + "). Voltage reading: " + voltage.ToString("0.00");
// HandleOutOfToleranceCondition(errorMsg);
//}
return outOfLimits;
}
/// <summary>
/// Handle power fault conditions
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private void HandleOutOfToleranceCondition(string errorMsg)
{
if (!Program.Instance().EventManager[EventManager.Events.FATAL_FAILURE].WaitOne(0))
if ((voltage < powerSupplyModuleInfo.voltageLowerLimit_ || voltage > powerSupplyModuleInfo.voltageUpperLimit_) && powerSupplyModuleInfo.isOn_)
{
Program.Instance().SetFatalErrorMsgFromSupportThread(errorMsg);
Program.Instance().EventManager[EventManager.Events.FATAL_FAILURE].Set();
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);
}
}
}
}

View File

@@ -15,12 +15,14 @@ GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using NLog;
using ProgramLib.GUI.Model;
using ProgramLib.GUI.View;
using System;
using System.Collections.Generic;
using System.Threading;
namespace ProgramLib
{
@@ -32,6 +34,7 @@ namespace ProgramLib
private enum Events
{
GLOBAL_QUIT,
QUIT,
UUT_POWER_ON,
UUT_POWER_OFF,
@@ -41,31 +44,51 @@ namespace ProgramLib
}
private ILogger _logger;
private LiveDataWindow _mainWindow;
private LiveDataWindow _liveDataWindow;
private Dictionary<string, PowerModuleDataModel> _powerModuleToPowerDataModelDict = new Dictionary<string, PowerModuleDataModel>();
private Dictionary<string, PowerModuleDataModel> _powerModuleToPowerDataModelDict = new Dictionary<string, PowerModuleDataModel>(StringComparer.OrdinalIgnoreCase);
int _pollRateMs;
private StreamWriter _fileWriter;
private List<string> _powerModulesToBeDisplayed = new List<string>();
private string _logNamePrefix;
private string _logFileExtension;
/// <summary>
/// Constructor
/// </summary>
public PowerSupplyUpdateThread()
public PowerSupplyUpdateThread(int pollRateMs, string logNamePrefix, string logFileExtension)
{
_logger = LogManager.GetCurrentClassLogger();
_mainWindow = (LiveDataWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA];
_powerModuleToPowerDataModelDict["UUT_P20V"] = new PowerModuleDataModel();
_powerModuleToPowerDataModelDict["UUT_N20V"] = new PowerModuleDataModel();
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA].Dispatcher.Invoke((Action)delegate
try
{
_mainWindow.LiveDataWindowViewModel.AddPowerData(_powerModuleToPowerDataModelDict);
});
}
_logger = LogManager.GetCurrentClassLogger();
~PowerSupplyUpdateThread()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
_pollRateMs = pollRateMs;
_logNamePrefix = logNamePrefix;
_logFileExtension = logFileExtension;
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.LIVE_DATA];
ParseConfig();
foreach (string powerModule in _powerModulesToBeDisplayed)
{
if (!_powerModuleToPowerDataModelDict.ContainsKey(powerModule))
{
_powerModuleToPowerDataModelDict[powerModule] = new PowerModuleDataModel();
_powerModuleToPowerDataModelDict[powerModule].Name = powerModule;
_liveDataWindow.Dispatcher.Invoke((Action)delegate
{
_liveDataWindow.LiveDataWindowViewModel.AddPowerData(_powerModuleToPowerDataModelDict[powerModule]);
});
}
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
@@ -81,6 +104,7 @@ namespace ProgramLib
{
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.UUT_POWER_ON] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_ON];
eventDict[Events.EVENT_TIMED_OUT] = null;
@@ -114,47 +138,105 @@ namespace ProgramLib
/// <returns></returns>
private void UpdatePowerSupplyData()
{
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.UUT_POWER_OFF] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_OFF];
eventDict[Events.EVENT_TIMED_OUT] = null;
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
const string LOG_PREFIX = "DateTime,Module,Voltage,VoltageSetpoint,Current,IsOutputOn";
string logFilePath = Path.Combine(Program.Instance().FileAndFolderManager.GetFolder(FileAndFolderManager.Folders.DATA_TEST), Util.GenerateUniqueFilenameUsingDateTime(_logNamePrefix, _logFileExtension));
_fileWriter = new StreamWriter(logFilePath);
_fileWriter.Write(LOG_PREFIX);
_fileWriter.Flush();
while (true)
{
Events id = eventGroup.WaitAny(pollRateMs);
Events id = eventGroup.WaitAny(_pollRateMs);
if (id == Events.EVENT_TIMED_OUT)
{
PowerSupplyData data = Program.Instance().PowerSupplySharedData.GetData("STE_PVM_5V");
if (data != null && data.Initialized)
string logText = String.Empty;
foreach (string powerModule in Program.Instance().PowerSupplySharedData.GetAllPowerModules())
{
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = data.Voltage.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = data.PowerSupplyModuleInfo.voltageSetpoint_.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualCurrent = data.Current.ToString("0.00");
PowerSupplyData data = Program.Instance().PowerSupplySharedData.GetData(powerModule);
if (data != null && data.Initialized)
{
if (_powerModuleToPowerDataModelDict.ContainsKey(powerModule))
{
_powerModuleToPowerDataModelDict[powerModule].ActualVoltage = data.Voltage.ToString("0.00");
_powerModuleToPowerDataModelDict[powerModule].ExpectedVoltage = data.PowerSupplyModuleInfo.voltageSetpoint_.ToString("0.00");
_powerModuleToPowerDataModelDict[powerModule].ActualCurrent = data.Current.ToString("0.00");
}
}
if (!String.IsNullOrEmpty(logText))
logText += "\r\n";
logText += DateTime.Now.ToString("yyyy_MM_dd") + "_" + DateTime.Now.ToString("HH_mm_ss") + "," + powerModule + "," + data.Voltage.ToString("0.00") +
"," + data.PowerSupplyModuleInfo.voltageSetpoint_.ToString("0.00") + "," + data.Current.ToString("0.00") + "," + data.PowerSupplyModuleInfo.isOn_.ToString();
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualVoltage = data.Voltage.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_N20V"].ExpectedVoltage = data.PowerSupplyModuleInfo.voltageSetpoint_.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualCurrent = data.Current.ToString("0.00");
}
// log out the data
_fileWriter.WriteLine(logText);
_fileWriter.Flush();
}
else
break;
}
}
catch (Exception ex)
catch (Exception)
{
_logger.Error(ex.Message + "\n" + ex.StackTrace);
throw;
}
finally
{
if (_fileWriter != null)
{
_fileWriter.Flush();
_fileWriter.Close();
_fileWriter = null;
}
foreach (KeyValuePair<string, PowerModuleDataModel> item in _powerModuleToPowerDataModelDict)
{
item.Value.ExpectedVoltage = "";
item.Value.ActualVoltage = "";
item.Value.ActualCurrent = "";
}
}
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
}
/// <summary>
/// Parse ini file
/// </summary>
public void ParseConfig()
{
try
{
List<string> keys = Program.Instance().ProgramSpecificConfig.ReadAllKeys(ProgramSpecificConfigIni.POWER_MODULES_TO_BE_DISPLAYED.ToString());
foreach (string key in keys)
{
string powerSupplyModule = Program.Instance().ProgramSpecificConfig.ReadValue(ProgramSpecificConfigIni.POWER_MODULES_TO_BE_DISPLAYED.ToString(), key);
if (!_powerModulesToBeDisplayed.Contains(powerSupplyModule, StringComparer.OrdinalIgnoreCase))
_powerModulesToBeDisplayed.Add(powerSupplyModule);
}
}
catch (Exception)
{
throw;
}
}
}
}

View File

@@ -0,0 +1,93 @@
/*-------------------------------------------------------------------------
// 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.Concurrent;
using System.Collections.Generic;
using System.Linq;
using NLog;
using Raytheon.Instruments;
namespace ProgramLib
{
/// <summary>
/// Thread to read tactical UART data
/// </summary>
internal class TacticalUartReadThread : BasicThread
{
private ILogger _logger;
public static ConcurrentQueue<byte[]> _byteQueue = new ConcurrentQueue<byte[]>();
/// <summary>
/// Constructor
/// </summary>
public TacticalUartReadThread()
{
_logger = LogManager.GetCurrentClassLogger();
_byteQueue = new ConcurrentQueue<byte[]>();
}
~TacticalUartReadThread()
{
_logger.Debug($"Waiting for {this.GetType().Name} to exit...");
WaitForExit();
}
/// <summary>
/// Method that executes on the thread.
/// </summary>
protected override void DoWork()
{
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
string serialDeviceInstanceName = Program.Instance().ProgramSpecificConfig.ReadValue("UART_INFO", "SERIAL_DEVICE_INSTANCE_NAME");
ICommDevice _serialDevice = (ICommDevice)Program.Instance().InstrumentManager.GetGenericInstrument(serialDeviceInstanceName);
DateTime startDateTime = DateTime.Now;
const int MAX_PBIT_WAIT_SEC = 17;
try
{
byte[] receiveByteArray = null;
uint numBytesRead = 0;
do
{
try
{
numBytesRead = _serialDevice.Read(ref receiveByteArray);
List<byte> bytelist = receiveByteArray.ToList();
_byteQueue.Enqueue(bytelist.Skip(0).Take((int)numBytesRead).ToArray());
}
catch { }
TimeSpan ts = DateTime.Now - startDateTime;
if (ts.TotalSeconds > MAX_PBIT_WAIT_SEC)
break;
}
while (true);
}
catch (Exception ex)
{
_logger.Error(ex.Message + "\n" + ex.StackTrace);
}
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
}
}
}