Update GUI with power supply's voltage and current readings
This commit is contained in:
27
Source/Program/DataDef/PowerSupplyData.cs
Normal file
27
Source/Program/DataDef/PowerSupplyData.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
Source/Program/DataDef/PowerSupplySharedData.cs
Normal file
94
Source/Program/DataDef/PowerSupplySharedData.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user