Major upgrade
This commit is contained in:
@@ -15,13 +15,13 @@ GOVERNMENT.
|
||||
|
||||
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
-------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
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
|
||||
{
|
||||
@@ -33,6 +33,7 @@ namespace ProgramLib
|
||||
private enum Events
|
||||
{
|
||||
GLOBAL_QUIT,
|
||||
QUIT,
|
||||
UUT_POWER_ON,
|
||||
UUT_POWER_OFF,
|
||||
|
||||
@@ -44,27 +45,26 @@ namespace ProgramLib
|
||||
private ILogger _logger;
|
||||
private LiveDataWindow _liveDataWindow;
|
||||
private PassthroughData _passthroughData = null;
|
||||
int _pollRateMs;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public PassthroughDataUpdateThread()
|
||||
public PassthroughDataUpdateThread(int pollRateMs)
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA];
|
||||
_liveDataWindow = (LiveDataWindow)ProgramLib.Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.LIVE_DATA];
|
||||
|
||||
_passthroughData = new PassthroughData(_liveDataWindow.datagridPassthroughData.Columns.Count);
|
||||
|
||||
ProgramLib.Program.Instance().GetGuiManager()[ProgramGuiManager.WINDOWS.LIVE_DATA].Dispatcher.Invoke((Action)delegate
|
||||
_pollRateMs = pollRateMs;
|
||||
|
||||
_liveDataWindow.Dispatcher.Invoke((Action)delegate
|
||||
{
|
||||
_liveDataWindow.LiveDataWindowViewModel.AddPassthroughData(_passthroughData.GetPassthroughDataModelDict());
|
||||
});
|
||||
}
|
||||
|
||||
~PassthroughDataUpdateThread()
|
||||
{
|
||||
_logger?.Debug($"Entering {this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() ...");
|
||||
_pollRateMs = pollRateMs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,6 +80,7 @@ namespace ProgramLib
|
||||
{
|
||||
Dictionary<Events, EventWaitHandle> eventDict = new Dictionary<Events, EventWaitHandle>();
|
||||
eventDict[Events.GLOBAL_QUIT] = Program.Instance().EventManager[EventManager.Events.GLOBAL_QUIT];
|
||||
eventDict[Events.QUIT] = _quitEvent;
|
||||
eventDict[Events.UUT_POWER_ON] = Program.Instance().EventManager[EventManager.Events.UUT_POWER_ON];
|
||||
eventDict[Events.EVENT_TIMED_OUT] = null;
|
||||
|
||||
@@ -113,74 +114,73 @@ namespace ProgramLib
|
||||
/// <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.QUIT] = _quitEvent;
|
||||
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();
|
||||
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_ON];
|
||||
|
||||
while (true)
|
||||
{
|
||||
Events id = eventGroup.WaitAny(pollRateMs);
|
||||
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"));
|
||||
if (!Program.Instance().IsThereHardware)
|
||||
SimulatePassThroughData();
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
_logger.Error(ex.Message + "\n" + ex.StackTrace);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_passthroughData.BlankAllData();
|
||||
_liveDataWindow.LiveDataWindowViewModel.UutPowerLedImagePath = _liveDataWindow.LiveDataWindowViewModel.ImageToResourcePathDict[LiveDataWindowViewModel.Images.LED_OFF];
|
||||
}
|
||||
|
||||
_logger?.Debug($"{this.GetType().Name}::{System.Reflection.MethodBase.GetCurrentMethod().Name}() is exiting...");
|
||||
}
|
||||
|
||||
static float GenerateRandomFraction()
|
||||
/// <summary>
|
||||
/// Simulate passthrough data
|
||||
/// </summary>
|
||||
private void SimulatePassThroughData()
|
||||
{
|
||||
Random rnd = new Random();
|
||||
int randNum = 0;
|
||||
const int minimum = 1;
|
||||
|
||||
randNum = rnd.Next(20);
|
||||
float num = 70.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR01, num.ToString("0.00"));
|
||||
|
||||
if (randNum <= minimum)
|
||||
{
|
||||
randNum += minimum;
|
||||
}
|
||||
|
||||
return (float)(1.0 / (float)randNum);
|
||||
Thread.Sleep(100);
|
||||
num = 30.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR02, num.ToString("0.00"));
|
||||
Thread.Sleep(200);
|
||||
num = 40.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR03, num.ToString("0.00"));
|
||||
Thread.Sleep(100);
|
||||
num = 50.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR04, num.ToString("0.00"));
|
||||
Thread.Sleep(100);
|
||||
num = 60.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR05, num.ToString("0.00"));
|
||||
Thread.Sleep(200);
|
||||
num = 10.0f + Util.GenerateRandomFraction();
|
||||
_passthroughData.SetValue(PassthroughData.Variables.VAR06, num.ToString("0.00"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user