187 lines
7.0 KiB
C#
187 lines
7.0 KiB
C#
/*-------------------------------------------------------------------------
|
|
// 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 ProgramLib.GUI.Model;
|
|
using ProgramLib.GUI.View;
|
|
using ProgramLib.GUI.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
|
|
namespace ProgramLib
|
|
{
|
|
/// <summary>
|
|
/// Class to spawn thread to update passthrough data
|
|
/// </summary>
|
|
internal class PassthroughDataUpdateThread : BasicThread
|
|
{
|
|
private enum Events
|
|
{
|
|
GLOBAL_QUIT,
|
|
UUT_POWER_ON,
|
|
UUT_POWER_OFF,
|
|
|
|
// DO NOT change the name
|
|
// This must be the last member in the enum
|
|
EVENT_TIMED_OUT
|
|
}
|
|
|
|
private ILogger _logger;
|
|
private LiveDataWindow _liveDataWindow;
|
|
private PassthroughData _passthroughData = null;
|
|
|
|
/// <summary>
|
|
/// Constructor
|
|
/// </summary>
|
|
public PassthroughDataUpdateThread()
|
|
{
|
|
_logger = LogManager.GetCurrentClassLogger();
|
|
|
|
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA];
|
|
|
|
_passthroughData = new PassthroughData(_liveDataWindow.datagridPassthroughData.Columns.Count);
|
|
|
|
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA].Dispatcher.Invoke((Action)delegate
|
|
{
|
|
_liveDataWindow.LiveDataWindowViewModel.AddPassthroughData(_passthroughData.GetPassthroughDataModelDict());
|
|
});
|
|
}
|
|
|
|
~PassthroughDataUpdateThread()
|
|
{
|
|
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Method that executes on the thread.
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns></returns>
|
|
protected override void DoWork()
|
|
{
|
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
|
|
|
try
|
|
{
|
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
|
eventDict[Events.UUT_POWER_ON] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_ON];
|
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
|
|
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
|
|
|
while (true)
|
|
{
|
|
Events id = eventGroup.WaitAny();
|
|
|
|
if (id == Events.UUT_POWER_ON)
|
|
{
|
|
UpdatePassthroughData();
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger?.Error(ex.Message + "\n" + ex.StackTrace);
|
|
}
|
|
|
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update GUI with data
|
|
/// </summary>
|
|
/// <param name=""></param>
|
|
/// <returns></returns>
|
|
private void UpdatePassthroughData()
|
|
{
|
|
int pollRateMs = 1000;
|
|
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is running...");
|
|
|
|
try
|
|
{
|
|
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
|
eventDict[Events.GLOBAL_QUIT] = Program.Instance()._eventManager[EventManager.Events.GLOBAL_QUIT];
|
|
eventDict[Events.UUT_POWER_OFF] = Program.Instance()._eventManager[EventManager.Events.UUT_POWER_OFF];
|
|
eventDict[Events.EVENT_TIMED_OUT] = null;
|
|
|
|
EventGroup<Events, EventWaitHandle> eventGroup = new EventGroup<Events, EventWaitHandle>(eventDict);
|
|
|
|
Random rnd = new Random();
|
|
while (true)
|
|
{
|
|
Events id = eventGroup.WaitAny(pollRateMs);
|
|
|
|
if (id == Events.EVENT_TIMED_OUT)
|
|
{
|
|
rnd = new Random();
|
|
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_OFF];
|
|
|
|
float num = 70.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR1, num.ToString("0.00"));
|
|
|
|
Thread.Sleep(100);
|
|
num = 30.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR2, num.ToString("0.00"));
|
|
Thread.Sleep(200);
|
|
num = 40.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR3, num.ToString("0.00"));
|
|
Thread.Sleep(100);
|
|
num = 50.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR4, num.ToString("0.00"));
|
|
Thread.Sleep(100);
|
|
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_ON];
|
|
num = 60.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR5, num.ToString("0.00"));
|
|
Thread.Sleep(200);
|
|
num = 10.0f + GenerateRandomFraction();
|
|
_passthroughData.SetValue(PassthroughData.Variables.VAR6, num.ToString("0.00"));
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
|
}
|
|
|
|
_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);
|
|
}
|
|
}
|
|
}
|