Update GUI with power supply's voltage and current readings

This commit is contained in:
Duc
2025-01-05 12:37:37 -07:00
parent b38765789d
commit 1bb3389ee6
9 changed files with 156 additions and 40 deletions

View File

@@ -119,6 +119,8 @@ namespace ProgramLib
if (_sttoSuccess)
{
Program.Instance()._powerSupplySharedData.ResetAll();
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.IMPEDANCE_CHECK].Dispatcher.Invoke((Action)delegate
{
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.MAIN].Show();

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProgramLib
{
/// <summary>
/// Stores voltage and current reading
/// </summary>
internal class PowerSupplyData
{
public double _voltage;
public double _current;
public Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo _powerSupplyModuleInfo;
public bool _initialized;
/// <summary>
/// Set data to unitialized
/// </summary>
public void Reset()
{
_initialized = false;
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProgramLib
{
/// <summary>
/// Stores voltage and current reading for each power module
/// </summary>
internal class PowerSupplySharedData
{
private object syncObj = new object();
private Dictionary<string,object> syncObjDict = new Dictionary<string, object>();
private Dictionary<string, PowerSupplyData> _powerSupplyDataDict = new Dictionary<string, PowerSupplyData>();
/// <summary>
/// Set data for a power supply module
/// </summary>
public void SetData(string moduleName, double voltage, double current, Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo powerSupplyModuleInfo)
{
lock (syncObj)
{
if (!syncObjDict.ContainsKey(moduleName))
{
// create a mutex for each module
syncObjDict[moduleName] = new object();
}
}
lock (syncObjDict[moduleName])
{
if (!_powerSupplyDataDict.ContainsKey(moduleName))
{
_powerSupplyDataDict[moduleName] = new PowerSupplyData();
}
_powerSupplyDataDict[moduleName]._voltage = voltage;
_powerSupplyDataDict[moduleName]._current = current;
_powerSupplyDataDict[moduleName]._initialized = true;
_powerSupplyDataDict[moduleName]._powerSupplyModuleInfo = powerSupplyModuleInfo;
}
}
/// <summary>
/// Get data for a power supply module
/// </summary>
public PowerSupplyData GetData(string moduleName)
{
lock (syncObj)
{
if (!syncObjDict.ContainsKey(moduleName))
{
// create a mutex for each module
syncObjDict[moduleName] = new object();
}
}
lock (syncObjDict[moduleName])
{
if (!_powerSupplyDataDict.ContainsKey(moduleName))
{
throw new Exception($"{moduleName} is invalid");
}
return _powerSupplyDataDict[moduleName];
}
}
/// <summary>
/// Set each power supply data to uninialized
/// </summary>
public void ResetAll()
{
foreach (KeyValuePair<string, PowerSupplyData> entry in _powerSupplyDataDict)
{
lock (syncObj)
{
if (!syncObjDict.ContainsKey(entry.Key))
{
// create a mutex for each module
syncObjDict[entry.Key] = new object();
}
}
lock (syncObjDict[entry.Key])
{
entry.Value.Reset();
}
}
}
}
}

View File

@@ -26,8 +26,14 @@ using System.Threading.Tasks;
namespace ProgramLib
{
/// <summary>
/// Methods to call into actions
/// </summary>
public partial class Program
{
/// <summary>
/// Power on UUT
/// </summary>
public void UutPowerOn()
{
try
@@ -49,6 +55,9 @@ namespace ProgramLib
}
}
/// <summary>
/// Power off UUT
/// </summary>
public void UutPowerOff()
{
try

View File

@@ -41,6 +41,9 @@ namespace ProgramLib
private PowerSupplyMeasurementManager _psManager = null;
private ProgramGuiManager _guiManager = null;
internal bool _isUutPwrOn = false;
internal PowerSupplySharedData _powerSupplySharedData = new PowerSupplySharedData();
/// <summary>
/// Initialize power supply measurement manager
/// </summary>
@@ -112,7 +115,7 @@ namespace ProgramLib
_threadList.Add(new PassthroughDataGuiUpdateThread());
_threadList.Last().Start();
_threadList.Add(new PowerSupplyGuiUpdateThread());
_threadList.Add(new PowerSupplyUpdateThread());
_threadList.Last().Start();
}
}

View File

@@ -65,7 +65,6 @@ namespace ProgramLib
internal EventManager _eventManager = new EventManager();
internal FileAndFolderManager _fileAndFolderManager;
internal IConfigurationFile _programConfig { get; private set; }
internal bool _isUutPwrOn = false;
/// <summary>
/// Create an instance of this class. Only one instance is allowed

View File

@@ -137,6 +137,7 @@ namespace ProgramLib
if (id == Events.EVENT_TIMED_OUT)
{
rnd = new Random();
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
float num = 70.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
@@ -151,6 +152,7 @@ namespace ProgramLib
num = 50.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
Thread.Sleep(100);
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_ON];
num = 60.0f + GenerateRandomFraction();
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
Thread.Sleep(200);

View File

@@ -151,6 +151,8 @@ namespace ProgramLib
if (IsVoltageWithinLimits(moduleName, voltage))
break;
Program.Instance()._powerSupplySharedData.SetData(moduleName, voltage, current, _powerSupplyModuleInfoDict[moduleName]);
}
else
{

View File

@@ -32,7 +32,7 @@ namespace ProgramLib
/// <summary>
/// Class to spawn thread to update power supply data on GUI
/// </summary>
internal class PowerSupplyGuiUpdateThread : BasicThread
internal class PowerSupplyUpdateThread : BasicThread
{
private enum Events
{
@@ -53,7 +53,7 @@ namespace ProgramLib
/// <summary>
/// Constructor
/// </summary>
public PowerSupplyGuiUpdateThread()
public PowerSupplyUpdateThread()
{
_logger = LogManager.GetCurrentClassLogger();
@@ -68,7 +68,7 @@ namespace ProgramLib
});
}
~PowerSupplyGuiUpdateThread()
~PowerSupplyUpdateThread()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
}
@@ -97,7 +97,7 @@ namespace ProgramLib
if (id == Events.UUT_POWER_ON)
{
UpdatePowerSupplyGui();
UpdatePowerSupplyData();
}
else
break;
@@ -113,11 +113,11 @@ namespace ProgramLib
}
/// <summary>
/// Update GUI with data
/// Log and update GUI with power supply data
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private void UpdatePowerSupplyGui()
private void UpdatePowerSupplyData()
{
int pollRateMs = 1000;
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
@@ -138,24 +138,18 @@ namespace ProgramLib
if (id == Events.EVENT_TIMED_OUT)
{
rnd = new Random();
PowerSupplyData data = Program.Instance()._powerSupplySharedData.GetData(PowerSupplyConstants.POWER_DEVICE.STE_PVM_5V.ToString());
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_OFF];
float num = 20.0f + GenerateRandomFraction();
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualVoltage = num.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_P20V"].ExpectedVoltage = "20.0";
Thread.Sleep(100);
num = 1.0f + GenerateRandomFraction();
_powerModuleToPowerDataModelDict["UUT_P20V"].ActualCurrent = num.ToString("0.00");
Thread.Sleep(100);
num = 20.0f + GenerateRandomFraction();
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualVoltage = num.ToString("0.00");
_powerModuleToPowerDataModelDict["UUT_N20V"].ExpectedVoltage = "20.0";
Thread.Sleep(200);
_mainWindow._mainWindowViewModel.UutPowerLedImagePath = _mainWindow._mainWindowViewModel._imageToResourcePathDict[MainWindowViewModel.Images.LED_ON];
if (data._initialized)
{
_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");
num = 5.0f + GenerateRandomFraction();
_powerModuleToPowerDataModelDict["UUT_N20V"].ActualCurrent = num.ToString("0.00");
_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");
}
}
else
break;
@@ -168,21 +162,5 @@ namespace ProgramLib
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
}
static float GenerateRandomFraction()
{
Random rnd = new Random();
int randNum = 0;
const int minimum = 1;
randNum = rnd.Next(20);
if (randNum <= minimum)
{
randNum += minimum;
}
return (float)(1.0 / (float)randNum);
}
}
}