• Added null-checks so labels are created dynamically when lblVorI is null (uses MainForm.Instance.AddLabelToPanel). • Camera/CameraModules.cs • Added null-label handling to create dynamic module labels with the correct content (OK or the error message). • AiQ_GUI.cs • Increased dynamic label width in MakeNewLabel from 220 → 700 to avoid truncated messages. • Succesfully ran through a pre-test with dynamic labels
218 lines
11 KiB
C#
218 lines
11 KiB
C#
using Renci.SshNet.Common;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Text;
|
|
|
|
namespace AiQ_GUI.AiQ_Tests
|
|
{
|
|
|
|
public class TestingFunctions
|
|
{
|
|
public static Diags DiagsAPI = new();
|
|
|
|
// Colours
|
|
public static readonly Color BtnColour = Color.FromArgb(70, 65, 80);
|
|
public static readonly Color TxBxColour = Color.FromArgb(53, 51, 64);
|
|
|
|
// ***** Testing functions *****
|
|
|
|
|
|
public static async Task CheckDiagsAPIPt1() // Parts done on pre and final test
|
|
{
|
|
DiagsAPI = await FlexiAPI.GetDiagnostics(MainForm.Instance.CamOnTest.IP); // Diagnostic API request
|
|
|
|
// Check Flexi Version
|
|
string flexiVerText = "Flexi Version = " + DiagsAPI.FlexiVersion;
|
|
bool flexiVerGreen = DiagsAPI.FlexiVersion == UniversalData.ExpFlexiVer;
|
|
if (!flexiVerGreen)
|
|
flexiVerText += " Expected = " + UniversalData.ExpFlexiVer;
|
|
MainForm.Instance.AddLabelToPanel(flexiVerText, !flexiVerGreen);
|
|
|
|
// Check Flexi Revision
|
|
string flexiRevText = "Flexi Revision = " + DiagsAPI.FlexiRevision;
|
|
bool flexiRevGreen = DiagsAPI.FlexiRevision == UniversalData.ExpFlexiRev;
|
|
if (!flexiRevGreen)
|
|
flexiRevText += " Expected = " + UniversalData.ExpFlexiRev;
|
|
MainForm.Instance.AddLabelToPanel(flexiRevText, !flexiRevGreen);
|
|
|
|
// Display MAC
|
|
string macText = "MAC = " + DiagsAPI.MAC;
|
|
bool macIsRed = false;
|
|
if (RegexCache.MACRegexNVIDIA().IsMatch(DiagsAPI.MAC)) // Checks it is in the right format and is a NVIDIA registered MAC address
|
|
{
|
|
// Valid NVIDIA MAC
|
|
}
|
|
else if (RegexCache.MACRegex().IsMatch(DiagsAPI.MAC)) // Is a valid MAC, but not NVIDIA
|
|
{
|
|
macIsRed = true;
|
|
MainForm.Instance.AddToActionsList($"{DiagsAPI.MAC} not recognised as NVIDIA MAC address", Level.ERROR);
|
|
}
|
|
else
|
|
{
|
|
macIsRed = true;
|
|
MainForm.Instance.AddToActionsList($"{DiagsAPI.MAC} not recognised as a MAC address", Level.ERROR);
|
|
}
|
|
MainForm.Instance.AddLabelToPanel(macText, macIsRed);
|
|
|
|
// Check timestamp
|
|
DateTime dateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
|
dateTime = dateTime.AddSeconds(DiagsAPI.timeStamp).ToLocalTime();
|
|
long timediff = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - DiagsAPI.timeStamp;
|
|
|
|
string timestampText = "Timestamp = " + dateTime;
|
|
bool timestampIsRed = false;
|
|
if (timediff > 10) // Over 10 seconds ago
|
|
{
|
|
timestampText += $" Time behind by {timediff}s";
|
|
timestampIsRed = true;
|
|
}
|
|
else if (timediff < 0) // Time is in the future.
|
|
{
|
|
timestampText += $" Time is in the future by {Math.Abs(timediff)}s";
|
|
timestampIsRed = true;
|
|
}
|
|
MainForm.Instance.AddLabelToPanel(timestampText, timestampIsRed);
|
|
|
|
// Check Temperature
|
|
string tempText = "Temperature = " + DiagsAPI.IntTemperature + "°C";
|
|
bool tempIsRed = DiagsAPI.IntTemperature <= 20 || DiagsAPI.IntTemperature >= 70;
|
|
MainForm.Instance.AddLabelToPanel(tempText, tempIsRed);
|
|
|
|
// Check Zoom Lock
|
|
string zoomLockText = "Zoom Lock = " + DiagsAPI.zoomLock;
|
|
bool zoomLockIsRed = false;
|
|
if (DiagsAPI.zoomLock == true)
|
|
{
|
|
if (DiagsAPI.IRmodule.zoom != DiagsAPI.OVmodule.zoom) // Checks if zoomlock is doing what is says it should
|
|
{
|
|
zoomLockText += $" Zoomlock on but {DiagsAPI.IRmodule.zoom}≠{DiagsAPI.OVmodule.zoom}";
|
|
zoomLockIsRed = true;
|
|
}
|
|
}
|
|
else
|
|
zoomLockIsRed = true;
|
|
MainForm.Instance.AddLabelToPanel(zoomLockText, zoomLockIsRed);
|
|
}
|
|
|
|
public static async Task CheckDiagsAPIPt2() // Parts only done on final test
|
|
{
|
|
if (MainForm.Instance.RhTxBxActions.Text.Contains("Error reading JSON")) // If failed to deserialise in part 1
|
|
return;
|
|
|
|
try // In case serial or model are blank
|
|
{
|
|
string serialText = "Serial Number = " + DiagsAPI.serialNumber;
|
|
bool serialIsRed = !RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber);
|
|
MainForm.Instance.AddLabelToPanel(serialText, serialIsRed);
|
|
|
|
string modelText = "Model Number = " + DiagsAPI.modelNumber;
|
|
bool modelIsRed = !RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber);
|
|
MainForm.Instance.AddLabelToPanel(modelText, modelIsRed);
|
|
|
|
if (RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber) && RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber))
|
|
{
|
|
if (DiagsAPI.modelNumber != MainForm.Instance.CamOnTest.Model)
|
|
{
|
|
MainForm.Instance.AddToActionsList("Model number in camera doesn't match what has been selected", Level.WARNING);
|
|
}
|
|
else if (!GoogleAPI.CheckWIP(DiagsAPI.serialNumber, CameraAccessInfo.SpreadsheetID)) // Check WIP column in serial number register, if not ticked then RMA
|
|
{
|
|
MainForm.Instance.CamOnTest.RMANum = GoogleAPI.CheckRMANum(DiagsAPI.serialNumber, DiagsAPI.modelNumber); // Corrected by qualifying with the type name
|
|
|
|
if (MainForm.Instance.CamOnTest.RMANum == 0) // Couldn't find RMA num in spreadsheet
|
|
{
|
|
MainForm.Instance.CamOnTest.RMANum = Convert.ToInt32(await MainForm.Instance.DisplayInput("What is the RMA number?"));
|
|
|
|
if (MainForm.Instance.CamOnTest.RMANum == -1) // Means they chose the 'I don't know' option
|
|
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get RMA number from operations team before continuing");
|
|
}
|
|
// Found RMA num and want to verify it with user
|
|
else if (!await MainForm.Instance.DisplayQuestion($"Is {MainForm.Instance.CamOnTest.RMANum} the RMA Number?")) // '!' because if its not the right RMA number let the user to it manually
|
|
{
|
|
MainForm.Instance.CamOnTest.RMANum = Convert.ToInt32(await MainForm.Instance.DisplayInput("What is the RMA number?"));
|
|
|
|
if (MainForm.Instance.CamOnTest.RMANum == -1) // Means they chose the 'I don't know' option
|
|
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get RMA number from operations team before continuing");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MainForm.Instance.AddToActionsList("Camera has not been given a valid serial and model number, suggest you run through pre test again and check serial number register for any issues.", Level.ERROR);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MainForm.Instance.AddToActionsList($"Error in CheckDiagsAPIPt2 serial/model: {ex.Message}", Level.ERROR);
|
|
}
|
|
|
|
// Check licenses
|
|
List<string> licensesOnCam = []; // Temporary list for licenses on camera
|
|
|
|
if (DiagsAPI.licenses.saf1)
|
|
licensesOnCam.Add("SAF1");
|
|
if (DiagsAPI.licenses.saf2)
|
|
licensesOnCam.Add("SAF2");
|
|
if (DiagsAPI.licenses.saf3)
|
|
licensesOnCam.Add("SAF3");
|
|
if (DiagsAPI.licenses.saf4)
|
|
licensesOnCam.Add("SAF4");
|
|
if (DiagsAPI.licenses.audit)
|
|
licensesOnCam.Add("Audit");
|
|
if (DiagsAPI.licenses.stream)
|
|
licensesOnCam.Add("Stream");
|
|
if (MainForm.Instance.sshData != null && MainForm.Instance.sshData.tailscale)
|
|
licensesOnCam.Add("Tailscale");
|
|
|
|
string licText = "Licenses = " + (licensesOnCam.Count == 0 ? "None" : string.Join(", ", licensesOnCam));
|
|
MainForm.Instance.AddLabelToPanel(licText, false);
|
|
|
|
double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max
|
|
string cpuText = "CPU Usage = " + CPUround + "%";
|
|
bool cpuIsRed = CPUround <= 50 || CPUround >= 98;
|
|
MainForm.Instance.AddLabelToPanel(cpuText, cpuIsRed);
|
|
|
|
// Check Vaxtor if it doesn't need or have license OR has and wants one then pass
|
|
bool vaxtorIsRed = false;
|
|
string vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID;
|
|
|
|
if (CameraAccessInfo.VaxtorLic == false && DiagsAPI.licenses.raptorKeyID == "Not Licensed" || CameraAccessInfo.VaxtorLic == true && DiagsAPI.licenses.raptorKeyID != "Not Licensed")
|
|
{
|
|
// OK - passes condition
|
|
vaxtorIsRed = false;
|
|
}
|
|
else if (await MainForm.Instance.DisplayQuestion("Was this camera licensed manually?"))
|
|
{
|
|
string ProdcutKeyID = await MainForm.Instance.DisplayInput("What is the Key ID?", false);
|
|
|
|
if (RegexCache.VaxtorRegex().IsMatch(ProdcutKeyID)) // Valid Key ID
|
|
{
|
|
Access.Stats("Please Get A Valid Vaxtor Product Key Before Continuing", MainForm.Instance.CamOnTest.Model);
|
|
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Please get a valid Vaxtor Product Key before continuing");
|
|
}
|
|
|
|
DiagsAPI.licenses.raptorKeyID = MainForm.Instance.TxBxProductKey.Text;
|
|
vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID;
|
|
vaxtorIsRed = false;
|
|
}
|
|
else // Should have license but doesn't OR shouldn't have but does + any other unforeseen circumstance then fail
|
|
{
|
|
vaxtorIsRed = true;
|
|
}
|
|
|
|
MainForm.Instance.AddLabelToPanel(vaxtorText, vaxtorIsRed);
|
|
|
|
// Check trim is within 10% both horizontally and vertically, from auto set done earlier in the test
|
|
string trimText = "Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1];
|
|
|
|
// Offset accounted for in the SetTrim function, so value should be close to 0,0.
|
|
const int HMax = 96; // 5% of 1920 each way = ±96
|
|
const int VMax = 54; // 5% of 1080 each way = ±54
|
|
|
|
bool trimIsRed = Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax;
|
|
MainForm.Instance.AddLabelToPanel(trimText, trimIsRed);
|
|
}
|
|
}
|
|
}
|