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

@@ -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);
}
}
}
}