diff --git a/Source/Program/Actions/UutPowerAction.cs b/Source/Program/Actions/UutPowerAction.cs
index c4057cf..bf39aca 100644
--- a/Source/Program/Actions/UutPowerAction.cs
+++ b/Source/Program/Actions/UutPowerAction.cs
@@ -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();
diff --git a/Source/Program/DataDef/PowerSupplyData.cs b/Source/Program/DataDef/PowerSupplyData.cs
new file mode 100644
index 0000000..9b33e1e
--- /dev/null
+++ b/Source/Program/DataDef/PowerSupplyData.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProgramLib
+{
+ ///
+ /// Stores voltage and current reading
+ ///
+ internal class PowerSupplyData
+ {
+ public double _voltage;
+ public double _current;
+ public Raytheon.Instruments.PowerSupplies.PowerSupplyModuleInfo _powerSupplyModuleInfo;
+ public bool _initialized;
+
+ ///
+ /// Set data to unitialized
+ ///
+ public void Reset()
+ {
+ _initialized = false;
+ }
+ }
+}
diff --git a/Source/Program/DataDef/PowerSupplySharedData.cs b/Source/Program/DataDef/PowerSupplySharedData.cs
new file mode 100644
index 0000000..a77cd50
--- /dev/null
+++ b/Source/Program/DataDef/PowerSupplySharedData.cs
@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProgramLib
+{
+ ///
+ /// Stores voltage and current reading for each power module
+ ///
+ internal class PowerSupplySharedData
+ {
+ private object syncObj = new object();
+ private Dictionary syncObjDict = new Dictionary();
+ private Dictionary _powerSupplyDataDict = new Dictionary();
+
+ ///
+ /// Set data for a power supply module
+ ///
+ 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;
+ }
+ }
+
+ ///
+ /// Get data for a power supply module
+ ///
+ 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];
+ }
+ }
+
+ ///
+ /// Set each power supply data to uninialized
+ ///
+ public void ResetAll()
+ {
+ foreach (KeyValuePair 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();
+ }
+ }
+ }
+ }
+}
diff --git a/Source/Program/Program.Actions.cs b/Source/Program/Program.Actions.cs
index 1fcb828..0e1728e 100644
--- a/Source/Program/Program.Actions.cs
+++ b/Source/Program/Program.Actions.cs
@@ -26,8 +26,14 @@ using System.Threading.Tasks;
namespace ProgramLib
{
+ ///
+ /// Methods to call into actions
+ ///
public partial class Program
{
+ ///
+ /// Power on UUT
+ ///
public void UutPowerOn()
{
try
@@ -49,6 +55,9 @@ namespace ProgramLib
}
}
+ ///
+ /// Power off UUT
+ ///
public void UutPowerOff()
{
try
diff --git a/Source/Program/Program.MeasurementManager.cs b/Source/Program/Program.MeasurementManager.cs
index be05777..21d5f17 100644
--- a/Source/Program/Program.MeasurementManager.cs
+++ b/Source/Program/Program.MeasurementManager.cs
@@ -41,6 +41,9 @@ namespace ProgramLib
private PowerSupplyMeasurementManager _psManager = null;
private ProgramGuiManager _guiManager = null;
+ internal bool _isUutPwrOn = false;
+ internal PowerSupplySharedData _powerSupplySharedData = new PowerSupplySharedData();
+
///
/// Initialize power supply measurement manager
///
@@ -112,7 +115,7 @@ namespace ProgramLib
_threadList.Add(new PassthroughDataGuiUpdateThread());
_threadList.Last().Start();
- _threadList.Add(new PowerSupplyGuiUpdateThread());
+ _threadList.Add(new PowerSupplyUpdateThread());
_threadList.Last().Start();
}
}
diff --git a/Source/Program/Program.cs b/Source/Program/Program.cs
index 0888324..a46cfe6 100644
--- a/Source/Program/Program.cs
+++ b/Source/Program/Program.cs
@@ -65,7 +65,6 @@ namespace ProgramLib
internal EventManager _eventManager = new EventManager();
internal FileAndFolderManager _fileAndFolderManager;
internal IConfigurationFile _programConfig { get; private set; }
- internal bool _isUutPwrOn = false;
///
/// Create an instance of this class. Only one instance is allowed
diff --git a/Source/Program/Threads/PassthroughDataGuiUpdateThread.cs b/Source/Program/Threads/PassthroughDataGuiUpdateThread.cs
index aeac74f..fdd7bba 100644
--- a/Source/Program/Threads/PassthroughDataGuiUpdateThread.cs
+++ b/Source/Program/Threads/PassthroughDataGuiUpdateThread.cs
@@ -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);
diff --git a/Source/Program/Threads/PowerSupplyReadThread.cs b/Source/Program/Threads/PowerSupplyReadThread.cs
index 2d686d2..8b149eb 100644
--- a/Source/Program/Threads/PowerSupplyReadThread.cs
+++ b/Source/Program/Threads/PowerSupplyReadThread.cs
@@ -151,6 +151,8 @@ namespace ProgramLib
if (IsVoltageWithinLimits(moduleName, voltage))
break;
+
+ Program.Instance()._powerSupplySharedData.SetData(moduleName, voltage, current, _powerSupplyModuleInfoDict[moduleName]);
}
else
{
diff --git a/Source/Program/Threads/PowerSupplyGuiUpdateThread.cs b/Source/Program/Threads/PowerSupplyUpdateThread.cs
similarity index 73%
rename from Source/Program/Threads/PowerSupplyGuiUpdateThread.cs
rename to Source/Program/Threads/PowerSupplyUpdateThread.cs
index 366e7a9..5b5cc38 100644
--- a/Source/Program/Threads/PowerSupplyGuiUpdateThread.cs
+++ b/Source/Program/Threads/PowerSupplyUpdateThread.cs
@@ -32,7 +32,7 @@ namespace ProgramLib
///
/// Class to spawn thread to update power supply data on GUI
///
- internal class PowerSupplyGuiUpdateThread : BasicThread
+ internal class PowerSupplyUpdateThread : BasicThread
{
private enum Events
{
@@ -53,7 +53,7 @@ namespace ProgramLib
///
/// Constructor
///
- 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
}
///
- /// Update GUI with data
+ /// Log and update GUI with power supply data
///
///
///
- 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);
- }
}
}