Files
GenericTeProgramLibrary/Source/Program/TestStand/TestStand.ActionManager.cs
2025-10-24 15:18:11 -07:00

370 lines
14 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 System;
using NationalInstruments.TestStand.Interop.API;
using ProgramLib;
using ProgramLib.GUI.View;
namespace TestStand
{
/// <summary>
/// Provide wrapper function to call into Action classes
/// All methods defined in this class must be called from TestStand.
/// No other code should be calling these methods outside of TestStand.
/// </summary>
public static class ActionManager
{
/// <summary>
/// Reset display for steps in a loop. Call this function right after While, Do or For step
/// </summary>
public static void ResetDisplayForStepsInLoop()
{
try
{
if (ProgramLib.Program.TestStandSeqContext != null)
{
int numSteps = ProgramLib.Program.TestStandSeqContext.Sequence.GetNumSteps(ProgramLib.Program.TestStandSeqContext.Step.StepGroup);
int currentStepIndex = ProgramLib.Program.TestStandSeqContext.Step.StepIndex;
while (++currentStepIndex < numSteps)
{
Step step = ProgramLib.Program.TestStandSeqContext.Sequence.GetStep(currentStepIndex, ProgramLib.Program.TestStandSeqContext.Step.StepGroup);
if (!string.IsNullOrEmpty(step.ResultStatus))
step.ResultStatus = "";
}
ProgramLib.Program.TestStandSeqContext.Engine.PostUIMessage(ProgramLib.Program.TestStandSeqContext.Execution, ProgramLib.Program.TestStandSeqContext.Thread, UIMessageCodes.UIMsg_RefreshWindows, 0, "", null, true);
}
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Power on
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void UutPowerOn()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.UutPowerOnAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Power off
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void UutPowerOff()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.UutPowerOffAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Perform Safe-to-turn-on (STTO)
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void PerformStto()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.PerformSttoAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Connect to UUT test port
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void UutTestPortConnect()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.UutTestPortConnectAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Disconnect from UUT test port
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void UutTestPortDisconnect()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.UutTestPortDisconnectAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Select a MSFR test case
/// </summary>
/// <param name="endStepComment">Unique comment to identify the end step associated with the loop we trying to break out of</param>
/// <returns></returns>
public static void SelectMsfrTestCase(string endStepComment = default)
{
ProgramLib.GUI.Util.StandardButtons button = ProgramLib.GUI.Util.StandardButtons.NOT_SET;
try
{
ProgramLib.Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.DEFAULT].Dispatcher.Invoke((Action)delegate
{
ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.LIVE_DATA].Hide();
ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.MSFR_TEST_CASES].ShowDialog();
ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.LIVE_DATA].Show();
button = ((MsfrTestCasesWindow)ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.MSFR_TEST_CASES]).ClickedButton;
});
if (button == ProgramLib.GUI.Util.StandardButtons.CANCEL_NO && !string.IsNullOrEmpty(endStepComment))
{
Util.BreakOutOfLoop(endStepComment);
}
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Display a confirmation message. Can use the cancel button as a mechanism to break out of loop if we're in a loop
/// </summary>
/// <param name="endStepComment">Unique comment to identify the end step associated with the loop we trying to break out of</param>
/// <returns></returns>
public static void DisplayConfirmationMessage(string message, string leftButtonText = "OK", string rightButtonText = "Cancel", string endStepComment = default)
{
ProgramLib.GUI.Util.StandardButtons button = ProgramLib.GUI.Util.StandardButtons.NOT_SET;
try
{
ConfirmationWindow window = (ConfirmationWindow)ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.CONFIRMATION];
ProgramLib.Program.Instance().GuiManager[ProgramGuiManager.WINDOWS.DEFAULT].Dispatcher.Invoke((Action)delegate
{
ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.LIVE_DATA].Hide();
window.ConfirmationMessage = message;
window.OkButtonText = leftButtonText;
window.CancelButtonText = rightButtonText;
window.ShowDialog();
ProgramLib.Program.Instance().GuiManager[ProgramLib.ProgramGuiManager.WINDOWS.LIVE_DATA].Show();
button = window.ClickedButton;
});
if (button == ProgramLib.GUI.Util.StandardButtons.CANCEL_NO && !string.IsNullOrEmpty(endStepComment))
{
Util.BreakOutOfLoop(endStepComment);
}
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Display wait message with countdown timer
/// </summary>
/// <param name="message">message to display</param>
/// <param name="delaySec">number of seconds to wait</param>
/// <returns></returns>
public static void DisplayWaitMessage(string message, double delaySec)
{
try
{
ProgramLib.Program.Instance().GuiManager.DisplayWaitMessage(message, delaySec);
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Send test message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void SendTestMessageToUut(string messageName, string configSectionName = null)
{
try
{
ProgramLib.BasicAction action = new ProgramLib.SendTestMessageToUutAction(messageName, configSectionName);
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Send Uart Handshake message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void StartTacticalUartReadThreadAction()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.StartTacticalUartReadThreadAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Send Uart Handshake message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void PerformTacticalUartCommAction()
{
try
{
ProgramLib.BasicAction action = new ProgramLib.PerformTacticalUartCommAction();
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex);
}
}
/// <summary>
/// Send Uart Handshake message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void SendCoeAdnucMsgToUut(string coeDeviceName, bool continueOnError = false)
{
try
{
ProgramLib.BasicAction action = new ProgramLib.SendCoeAdnucMsgToUutAction(coeDeviceName);
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex, continueOnError);
}
}
/// <summary>
/// Send Uart Handshake message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void SendCoeUncageMsgToUut(string coeDeviceName, bool continueOnError = false)
{
try
{
ProgramLib.BasicAction action = new ProgramLib.SendCoeUncageMsgToUutAction(coeDeviceName);
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex, continueOnError);
}
}
/// <summary>
/// Send Uart Handshake message to UUT
/// </summary>
/// <param name=""></param>
/// <returns></returns>
public static void SendCoeBatteryGoodMsgToUut(string coeDeviceName, bool continueOnError = false)
{
try
{
ProgramLib.BasicAction action = new ProgramLib.SendCoeBatteryGoodMsgToUutAction(coeDeviceName);
action.Run();
}
catch (Exception ex)
{
// DO NOT THROW in this block
// this function will handle the error accordingly since we could be calling this from third-party test executive like TestStand
ProgramManager.TerminateTestOnMainThreadError(ex, continueOnError);
}
}
}
}