Files
AiQ_GUI/AiQ Tests/Diagnostics.cs

243 lines
12 KiB
C#
Raw Normal View History

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
MainForm.Instance.lblFlexiVer.Text += DiagsAPI.FlexiVersion; // Check Flexi Version
if (DiagsAPI.FlexiVersion == UniversalData.ExpFlexiVer)
{
MainForm.Instance.lblFlexiVer.ForeColor = Color.LightGreen;
}
else
{
MainForm.Instance.lblFlexiVer.Text += " Expected = " + UniversalData.ExpFlexiVer;
MainForm.Instance.lblFlexiVer.ForeColor = Color.Red;
}
MainForm.Instance.lblFlexiRev.Text += DiagsAPI.FlexiRevision; // Check Flexi Revision
if (DiagsAPI.FlexiRevision == UniversalData.ExpFlexiRev)
{
MainForm.Instance.lblFlexiRev.ForeColor = Color.LightGreen;
}
else
{
MainForm.Instance.lblFlexiRev.Text += " Expected = " + UniversalData.ExpFlexiRev;
MainForm.Instance.lblFlexiRev.ForeColor = Color.Red;
}
MainForm.Instance.lblMac.Text += DiagsAPI.MAC; // Display MAC
if (RegexCache.MACRegexNVIDIA().IsMatch(DiagsAPI.MAC)) // Checks it is in the right format and is a NVIDIA registered MAC address
{
MainForm.Instance.lblMac.ForeColor = Color.LightGreen;
}
else if (RegexCache.MACRegex().IsMatch(DiagsAPI.MAC)) // Is a valid MAC, but not NVIDIA
{
MainForm.Instance.lblMac.ForeColor = Color.Red;
MainForm.Instance.AddToActionsList($"{DiagsAPI.MAC} not recognised as NVIDIA MAC address", Level.ERROR);
}
else
{
MainForm.Instance.lblMac.ForeColor = Color.Red;
MainForm.Instance.AddToActionsList($"{DiagsAPI.MAC} not recognised as a MAC address", Level.ERROR);
}
// Check timestamp
DateTime dateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(DiagsAPI.timeStamp).ToLocalTime();
MainForm.Instance.lbltimestamp.Text += dateTime;
long timediff = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - DiagsAPI.timeStamp;
if (timediff > 10) // Over 10 seconds ago
{
MainForm.Instance.lbltimestamp.Text += $" Time behind by {timediff}s";
MainForm.Instance.lbltimestamp.ForeColor = Color.Red;
}
else if (timediff < 0) // Time is in the future.
{
MainForm.Instance.lbltimestamp.Text += $" Time is in the future by {Math.Abs(timediff)}s";
MainForm.Instance.lbltimestamp.ForeColor = Color.Red;
}
else
MainForm.Instance.lbltimestamp.ForeColor = Color.LightGreen;
MainForm.Instance.lblTemp.Text += DiagsAPI.IntTemperature + "°C"; // Diagnostic API request
if (DiagsAPI.IntTemperature > 20 && DiagsAPI.IntTemperature < 70)
MainForm.Instance.lblTemp.ForeColor = Color.LightGreen;
else
MainForm.Instance.lblTemp.ForeColor = Color.Red;
MainForm.Instance.lblZoomLock.Text += DiagsAPI.zoomLock;
if (DiagsAPI.zoomLock == true)
{
if (DiagsAPI.IRmodule.zoom == DiagsAPI.OVmodule.zoom) // Checks if zoomlock is doing what is says it should
{
MainForm.Instance.lblZoomLock.ForeColor = Color.LightGreen;
}
else
{
MainForm.Instance.lblZoomLock.Text += $" Zoomlock on but {DiagsAPI.IRmodule.zoom}≠{DiagsAPI.OVmodule.zoom}";
MainForm.Instance.lblZoomLock.ForeColor = Color.Red;
}
}
else
MainForm.Instance.lblZoomLock.ForeColor = Color.Red;
}
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
{
MainForm.Instance.lblModel.Text += DiagsAPI.modelNumber; // Update labels with serial and model
MainForm.Instance.lblSerial.Text += DiagsAPI.serialNumber;
if (RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber) && RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber))
{
MainForm.Instance.lblSerial.ForeColor = MainForm.Instance.lblModel.ForeColor = Color.LightGreen; // Set both to green
if (DiagsAPI.modelNumber != MainForm.Instance.CamOnTest.Model)
{
MainForm.Instance.AddToActionsList("Model number in camera doesn't match what has been selected", Level.WARNING);
MainForm.Instance.lblModel.ForeColor = Color.Red;
}
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 { }
// 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.tailscale)
licensesOnCam.Add("Tailscale");
if (licensesOnCam.Count == 0) // No licenses found
MainForm.Instance.lblLic.Text += "None";
else if (licensesOnCam.Count != 0) // Join them comma and space seperated for displaying
MainForm.Instance.lblLic.Text += string.Join(", ", licensesOnCam);
MainForm.Instance.lblLic.ForeColor = Color.LightGreen;
double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max
MainForm.Instance.LblCPUusage.Text += CPUround + "%";
if (CPUround <= 50)
{
MainForm.Instance.LblCPUusage.Text += " Unexpectedly low CPU usage";
MainForm.Instance.LblCPUusage.ForeColor = Color.Red;
}
else if (CPUround >= 98)
{
MainForm.Instance.LblCPUusage.Text += " Unexpectedly high CPU usage";
MainForm.Instance.LblCPUusage.ForeColor = Color.Red;
}
else
{
MainForm.Instance.LblCPUusage.ForeColor = Color.LightGreen;
}
// Check Vaxtor if it doesn't need or have license OR has and wants one then pass
if (CameraAccessInfo.VaxtorLic == false && DiagsAPI.licenses.raptorKeyID == "Not Licensed" || CameraAccessInfo.VaxtorLic == true && DiagsAPI.licenses.raptorKeyID != "Not Licensed")
{
MainForm.Instance.lblVaxtor.Text += DiagsAPI.licenses.raptorKeyID;
MainForm.Instance.lblVaxtor.ForeColor = Color.LightGreen;
}
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)) // Means they chose the 'I don't know' option or isn't 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;
MainForm.Instance.lblVaxtor.Text += DiagsAPI.licenses.raptorKeyID;
MainForm.Instance.lblVaxtor.ForeColor = Color.LightGreen;
}
else // Should have license but doesn't OR shouldn't have but does + any other unforseen circumstance then fail
{
MainForm.Instance.lblVaxtor.Text += DiagsAPI.licenses.raptorKeyID;
MainForm.Instance.lblVaxtor.ForeColor = Color.Red;
}
// Check trim is within 10% both horizontally and vertically, from auto set done earlier in the test
MainForm.Instance.lblTrim.Text += "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
if (Math.Abs(DiagsAPI.trim[0]) <= HMax && Math.Abs(DiagsAPI.trim[1]) <= VMax)
MainForm.Instance.lblTrim.ForeColor = Color.LightGreen;
else
MainForm.Instance.lblTrim.ForeColor = Color.Red;
}
}
}