Initial check-in

This commit is contained in:
Duc
2025-01-03 09:50:39 -07:00
parent 45596e360d
commit 1d8f6e4c96
143 changed files with 9835 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
/*-------------------------------------------------------------------------
// 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 NLog;
using Raytheon.Common;
using Raytheon.Instruments;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
namespace Raytheon
{
/// <summary>
/// Class for controlling all power supplies
/// </summary>
public class PowerModuleMeasurementManager
{
#region PrivateClassMembers
/// <summary>
/// NLog logger
/// </summary>
private static NLog.ILogger _logger;
private PowerSupply _powerSupply;
private IConfigurationFile _powerOffAndSelfTestConfig;
#endregion
public bool FrontPanelEnabled
{
get
{
if (_powerSupply != null)
{
return _powerSupply[null].FrontPanelEnabled;
}
else
return true;
}
set
{
if (_powerSupply != null)
{
_powerSupply[null].FrontPanelEnabled = value;
}
}
}
/// <summary>
/// constructor
/// </summary>
/// <param name="stePowerSupplyInstanceName">the name specified in the Instruments.xml file</param>
public PowerModuleMeasurementManager(PowerSupply powerSupply, IConfigurationFile powerOffAndSelfTestConfig)
{
_logger = LogManager.GetCurrentClassLogger();
_powerSupply = powerSupply;
_powerOffAndSelfTestConfig = powerOffAndSelfTestConfig;
}
/// <summary>
/// The Finalizer
/// </summary>
~PowerModuleMeasurementManager()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
}
/// <summary>
/// Initialize the instrument(s)
/// </summary>
public void Initialize()
{
_logger.Trace($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
}
/// <summary>
/// Shuts down manager, clears resources
/// </summary>
public void Shutdown()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
_powerSupply.Shutdown();
}
/// <summary>
/// Read various power supply data
/// </summary>
public void ReadPowerSupplyData(object module, out double voltage, out double current, out double voltageSetPoint, out bool isOn, out int faultStatus)
{
_powerSupply[module].ReadPowerSupplyData(out voltage, out current, out voltageSetPoint, out isOn, out faultStatus);
}
/// <summary>
/// Enable the output of the power supply.
/// </summary>
/// <param name="moduleName">The name of the module to enable.</param>
public void OutputEnable(object module)
{
_powerSupply[module].On();
}
/// <summary>
/// Disable the output of the power supply.
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public void OutputDisable(object module)
{
_powerSupply[module].ReadPowerSupplyData(out double voltage, out double current, out double voltageSetPoint, out bool isOn, out int faultStatus);
if (isOn)
{
_powerSupply[module].Off();
// save the time of this power off to file
MeasurementManager.PowerSupply.Util.SaveTime(_powerSupply.Name, DateTime.Now.ToString(), null, _powerOffAndSelfTestConfig);
}
}
}
}

View File

@@ -0,0 +1,218 @@
/*-------------------------------------------------------------------------
// 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 NLog;
using Raytheon.Common;
using Raytheon.Instruments;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Raytheon
{
/// <summary>
/// Class for controlling all power supplies
/// </summary>
public class PowerSupplyMeasurementManager
{
#region PrivateClassMembers
/// <summary>
/// NLog logger
/// </summary>
private static NLog.ILogger _logger;
private IConfigurationFile _powerOffAndSelfTestConfig;
private IInstrumentManager _instrumentManager;
private Dictionary<string, PowerModuleMeasurementManager> _powerSystemNameToPowerModuleMeasurementManagerDict = new Dictionary<string, PowerModuleMeasurementManager>();
string _powerSystemWithFailedSelfTest = String.Empty;
#endregion
/// <summary>
/// constructor
/// </summary>
/// <param name="stePowerSupplyInstanceName">the name specified in the Instruments.xml file</param>
public PowerSupplyMeasurementManager(IInstrumentManager instrumentManager, string powerSupplySelfTestLogFile)
{
_logger = LogManager.GetCurrentClassLogger();
_powerOffAndSelfTestConfig = new ConfigurationFile(powerSupplySelfTestLogFile);
_instrumentManager = instrumentManager;
}
/// <summary>
/// The Finalizer
/// </summary>
~PowerSupplyMeasurementManager()
{
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
}
/// <summary>
/// Implement Indexer to obtain a powermodulemeasurementmanager
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public PowerModuleMeasurementManager this[object powerSystemId]
{
get
{
if (!powerSystemId.GetType().IsEnum)
{
throw new ArgumentException($"{nameof(powerSystemId)} must be an enumerated type");
}
if (!_powerSystemNameToPowerModuleMeasurementManagerDict.ContainsKey(powerSystemId.ToString()))
{
throw new Exception($"Invalid power supply system: {powerSystemId.ToString()}");
}
return _powerSystemNameToPowerModuleMeasurementManagerDict[powerSystemId.ToString()];
}
}
/// <summary>
/// Initialize the instrument(s)
/// </summary>
public void Initialize()
{
_logger.Trace($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
PerformSelfTest();
if (_powerSystemWithFailedSelfTest != String.Empty)
{
throw new Exception($"{_powerSystemWithFailedSelfTest}'s self-test failed.");
}
}
/// <summary>
/// Perform self test on power supply system
/// Self test for each power system takes a while, so we don't want to run self test every time we initialize the power system
/// So we only want to run self test under 2 conditions:
/// 1. Certain time has elapsed since last power off
/// 2. Certain time has elapsed since last self test run ( in the absence of power off time)
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private async void PerformSelfTest()
{
_logger.Trace($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() method...");
string errorMsg = String.Empty;
Dictionary<string, Task<SelfTestResult>> powerSystemToSelfTestTaskDict = new Dictionary<string, Task<SelfTestResult>>();
bool allSelfTestsPassed = true;
ICollection<object> psList = _instrumentManager.GetInstruments(typeof(PowerSupply));
foreach (PowerSupply ps in psList)
{
ps.Initialize();
// perform self test on power system
Task<SelfTestResult> task = PerformSelfTestTask(ps);
powerSystemToSelfTestTaskDict[ps.Name] = task;
}
foreach (var item in powerSystemToSelfTestTaskDict)
{
// wait for self test on power system to finish
SelfTestResult result = await item.Value;
if (result == SelfTestResult.Fail && String.IsNullOrEmpty(_powerSystemWithFailedSelfTest))
{
allSelfTestsPassed = false;
_powerSystemWithFailedSelfTest = item.Key;
}
}
if (allSelfTestsPassed)
{
foreach (PowerSupply ps in psList)
{
_powerSystemNameToPowerModuleMeasurementManagerDict[ps.Name] = new PowerModuleMeasurementManager(ps, _powerOffAndSelfTestConfig);
}
}
}
/// <summary>
/// Perform self test on power supply system
/// Self test for each power system takes a while, so we don't want to run self test every time we initialize the power system
/// So we only want to run self test under 2 conditions:
/// 1. Certain time has elapsed since last power off
/// 2. Certain time has elapsed since last self test run ( in the absence of power off time)
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private Task<SelfTestResult> PerformSelfTestTask(PowerSupply ps)
{
SelfTestResult result = SelfTestResult.Pass;
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {ps.Name} is running...");
try
{
bool performSelfTest = false;
const int HOURS_ELAPSED = 2;
string lastSaveTime = MeasurementManager.PowerSupply.Util.GetLastSavedTime(ps.Name, _powerOffAndSelfTestConfig);
if (DateTime.TryParse(lastSaveTime, out DateTime dt))
{
// if this power supply system has been turn off for a certain number of hours, then we want to perform self test on it
if (DateTime.Now.Subtract(dt).TotalHours >= HOURS_ELAPSED)
{
performSelfTest = true;
}
}
else { performSelfTest = true; }
if (performSelfTest)
{
_logger?.Info($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() executing self-test for {ps.Name}...");
result = ps[null].PerformSelfTest();
if (result == SelfTestResult.Pass)
{
// save the time of this self test to file
MeasurementManager.PowerSupply.Util.SaveTime(ps.Name, null, DateTime.Now.ToString(), _powerOffAndSelfTestConfig);
}
}
else
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() skipping self-test for {ps.Name}...");
}
catch (Exception ex)
{
_logger?.Error(ex.Message + "\n" + ex.StackTrace);
}
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() for {ps.Name} is exiting...");
return Task.FromResult(result);
}
}
}

View File

@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(SolutionDir)Program.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>Raytheon.InstrumentManagers.PowerSupplyManager</AssemblyName>
<RootNamespace>Raytheon.InstrumentManagers</RootNamespace>
<Product>Power Supply Manager Implementation</Product>
<Description>Provide access to the actual power supplies</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<Company>Raytheon Technologies</Company>
<Authors>TEEC</Authors>
<Copyright>Copyright © Raytheon Technologies $([System.DateTime]::get_now().ToString("yyyy"))</Copyright>
<!-- Dynamic Versioning (Suitable for Release) -->
<!-- <Version>$(Version)$(Suffix)</Version> -->
<!-- Static Versioning (Suitable for Development) -->
<Version>1.0.0</Version>
<Configurations>Debug;Release;Deploy</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="5.0.0" />
<PackageReference Include="Raytheon.Configuration" Version="2.6.1" />
<PackageReference Include="Raytheon.Configuration.Contracts" Version="2.3.0" />
<PackageReference Include="Raytheon.Instruments.InstrumentManager.GeneralInstrumentManager" Version="1.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Interfaces\PowerSupply\PowerSupply.Contracts.csproj" />
<ProjectReference Include="..\..\Raytheon.Common\Raytheon.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,64 @@
/*-------------------------------------------------------------------------
// 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.IO;
using System.Xml.Serialization;
namespace Raytheon
{
/// <summary>
/// Serialiable class to store self test and power off time to XML
/// and restore info from XML to this class
/// </summary>
[Serializable]
public class PowerSupplySelfTestTime
{
[XmlAttribute("power_system")]
public string _powerSystem { get; set; }
// date and time of last power off of a power module
[XmlAttribute("power_off_time")]
public string _powerOffTime { get; set; }
// date and time of last successful self test
[XmlAttribute("self_test_time")]
public string _selfTestTime { get; set; }
/// <summary>
/// constructor
/// </summary>
public PowerSupplySelfTestTime()
{
_powerOffTime = Raytheon.Common.GeneralConstants.DefaultConfigValue;
_powerSystem = Raytheon.Common.GeneralConstants.DefaultConfigValue;
_selfTestTime = Raytheon.Common.GeneralConstants.DefaultConfigValue;
}
/// <summary>
/// constructor
/// </summary>
public PowerSupplySelfTestTime(string powerSystem, string powerOffTime, string selfTestTime)
{
_powerOffTime = powerOffTime;
_powerSystem = powerSystem;
_selfTestTime = selfTestTime;
}
}
}

View File

@@ -0,0 +1,115 @@
/*-------------------------------------------------------------------------
// 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 Raytheon.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Raytheon.MeasurementManager.PowerSupply
{
/// <summary>
/// Define non-specific constants
/// </summary>
internal static class Util
{
/// <summary>
/// Read from the XML file the time for this power system
/// If time of power off is available, we return this time
/// If time of last self test run is available, we return this time
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static string GetLastSavedTime(string powerSystem, IConfigurationFile powerOffAndSelfTestConfig)
{
string savedTime = "";
string powerOffTime = "";
string selfTestTime = "";
List<PowerSupplySelfTestTime> powerOffEntryListTemp = new List<PowerSupplySelfTestTime>();
List<PowerSupplySelfTestTime> powerOffEntryList = powerOffAndSelfTestConfig.ReadList<PowerSupplySelfTestTime>(nameof(PowerSupplySelfTestTime), nameof(PowerSupplySelfTestTime), powerOffEntryListTemp);
foreach (var powerOffEntry in powerOffEntryList)
{
if (powerOffEntry._powerSystem == powerSystem)
{
if (DateTime.TryParse(powerOffEntry._powerOffTime, out DateTime dt))
powerOffTime = powerOffEntry._powerOffTime;
if (DateTime.TryParse(powerOffEntry._selfTestTime, out dt))
selfTestTime = powerOffEntry._selfTestTime;
}
}
if (String.IsNullOrEmpty(powerOffTime))
savedTime = selfTestTime;
else if (String.IsNullOrEmpty(selfTestTime))
savedTime = powerOffTime;
else if (!String.IsNullOrEmpty(powerOffTime) && !String.IsNullOrEmpty(selfTestTime))
{
if (DateTime.TryParse(powerOffTime, out DateTime powerOffDt) && DateTime.TryParse(selfTestTime, out DateTime selfTestDt))
{
if (DateTime.Compare(powerOffDt, selfTestDt) == 1)
savedTime = powerOffTime;
else
savedTime = selfTestTime;
}
}
return savedTime;
}
/// <summary>
/// Save time of power off or self test event
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public static void SaveTime(string powerSystem, string powerOffTime, string selfTestTime, IConfigurationFile powerOffAndSelfTestConfig)
{
List<PowerSupplySelfTestTime> powerOffEntryListTemp = new List<PowerSupplySelfTestTime>();
List<PowerSupplySelfTestTime> powerOffEntryList = powerOffAndSelfTestConfig.ReadList<PowerSupplySelfTestTime>(nameof(PowerSupplySelfTestTime), nameof(PowerSupplySelfTestTime), powerOffEntryListTemp);
var entry = powerOffEntryList.Find(b => b._powerSystem == powerSystem);
if (entry != null)
{
if (!string.IsNullOrEmpty(powerOffTime))
entry._powerOffTime = powerOffTime;
if (!string.IsNullOrEmpty(selfTestTime))
entry._selfTestTime = selfTestTime;
}
else
{
PowerSupplySelfTestTime data = new PowerSupplySelfTestTime(powerSystem, powerOffTime, selfTestTime);
if (string.IsNullOrEmpty(powerOffTime))
data._powerOffTime = Raytheon.Common.GeneralConstants.DefaultConfigValue;
if (string.IsNullOrEmpty(selfTestTime))
data._selfTestTime = Raytheon.Common.GeneralConstants.DefaultConfigValue;
powerOffEntryList.Add(data);
}
powerOffAndSelfTestConfig.WriteList(nameof(PowerSupplySelfTestTime), nameof(PowerSupplySelfTestTime), powerOffEntryList);
}
}
}