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); string apiModel = DiagsAPI.modelNumber?.Trim(); string selectedModel = MainForm.Instance.CamOnTest.Model?.Trim(); if (string.IsNullOrWhiteSpace(selectedModel) && MainForm.Instance.CbBxCameraModel.SelectedItem != null) selectedModel = MainForm.Instance.CbBxCameraModel.SelectedItem.ToString().Split('-')[0].Trim(); if (RegexCache.SerialRegex().IsMatch(DiagsAPI.serialNumber) && RegexCache.ModelRegex().IsMatch(DiagsAPI.modelNumber)) { // If nothing selected yet, do not warn (matches old logic) if (!string.IsNullOrWhiteSpace(selectedModel) && !string.Equals(apiModel, selectedModel, StringComparison.OrdinalIgnoreCase)) { MainForm.Instance.AddToActionsList( "Model number in camera doesn't match what has been selected", Level.WARNING); } else if (!string.IsNullOrWhiteSpace(CameraAccessInfo.SpreadsheetID)&& !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"); } 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 licensesOnCam = new List(); // 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"); MainForm.Instance.AddLabelToPanel( "Licenses = " + (licensesOnCam.Count == 0 ? "None" : string.Join(", ", licensesOnCam)), false); double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max MainForm.Instance.AddLabelToPanel( "CPU Usage = " + CPUround + "%", CPUround <= 50 || CPUround >= 98); // Check Vaxtor license bool vaxtorIsRed = false; string vaxtorText = "Vaxtor Key ID = " + DiagsAPI.licenses.raptorKeyID; if (DiagsAPI.licenses.raptorKeyID != "Not Licensed") vaxtorIsRed = false; else if (CameraAccessInfo.VaxtorLic == false) 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)) { 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 vaxtorIsRed = true; MainForm.Instance.AddLabelToPanel(vaxtorText, vaxtorIsRed); // Check trim is within 10% both horizontally and vertically const int HMax = 96; // 5% of 1920 each way = ±96 const int VMax = 54; // 5% of 1080 each way = ±54 MainForm.Instance.AddLabelToPanel( "Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1], Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax); } } }