Files
AiQ_GUI/AiQ Tests/AiQTests.cs
Bradley Born 36f9639baa Dynamic labels & Changed color to light green
- Filesystem size
- Flexi version
- Flexi Revision
- MAC
- Timestamp
- Temperature
- ZoomLock
- Serial and model Number
- Licenses
- CPU usage
2025-12-23 13:01:15 +00:00

158 lines
10 KiB
C#

using AiQ_GUI;
using AiQ_GUI.AiQ_Tests;
public class AiQTests
{
public static async Task AiQPreTest()
{
if (!await CameraModules.SetZoomLockOn(MainForm.Instance.CamOnTest.IP))
Helper.RestartApp();
string LEDreply = await FlexiAPI.APIHTTPLED(MainForm.Instance.CamOnTest.IP, LEDPOWER.MID); // Set LED's to medium (0x30)
if (!LEDreply.Contains("Power levels set successfully"))
MainForm.Instance.AddToActionsList($"LED level could not be set: {LEDreply}", Level.ERROR);
await CameraModules.FactoryResetModules(MainForm.Instance.CamOnTest.IP); // Reset both modules and double check
MainForm.Instance.sshData = SSH.CollectSSHData(MainForm.Instance.CamOnTest.IP); // SSH into camera to get Vaxtor packages, filesystem size and if tailscale is installed.
await SSH.CheckFSSize(MainForm.Instance.CamOnTest.IP, MainForm.Instance.LblFilesystemSize, MainForm.Instance.sshData); // Check Filesystem size is between 100GB & 150GB
Helper.DCPowerCheck(MainForm.Instance.LblDC); // If the camera is DC powered check it is within limits
// Requests, deserialises and checks the diagnostics API is correct
await TestingFunctions.CheckDiagsAPIPt1();
// Check module has gone to default config
CameraModules.CheckCamModule(TestingFunctions.DiagsAPI.IRmodule, MainForm.Instance.LblIRModule, MainForm.Instance.CamOnTest); // IR
CameraModules.CheckCamModule(TestingFunctions.DiagsAPI.OVmodule, MainForm.Instance.LblOVModule, MainForm.Instance.CamOnTest); // OV
// Check voltage and current are OK.
LED.CheckLEDs(TestingFunctions.DiagsAPI.LedVoltage, MainForm.Instance.LblLEDV, "V", CameraAccessInfo.LED_V); // Voltage
LED.CheckLEDs(TestingFunctions.DiagsAPI.LedCurrent, MainForm.Instance.LblLEDI, "mA", CameraAccessInfo.LED_I); // Current
MainForm.Instance.Refresh(); // Make sure all labels are updated before checking them
// If there are any actions identified then fail the test.
// If any labels are red then fail. Only labels in panel so can foreach on labels not controls
if (MainForm.Instance.RhTxBxActions.Text.Length < 2 && MainForm.Instance.PnlLbls.Controls.OfType<Label>().Any(c => c.ForeColor == Color.Red) == false)
{
// If camera already has a model or serial then ask if it is new
if (RegexCache.SerialRegex().IsMatch(TestingFunctions.DiagsAPI.serialNumber) || RegexCache.ModelRegex().IsMatch(TestingFunctions.DiagsAPI.modelNumber))
{
if (await MainForm.Instance.DisplayQuestion($"Would you like to allocate a serial number to this camera?"))
await MainForm.Instance.AllocateSerial();
else if (GoogleAPI.UpdateSpreadSheetRePreTest(CameraAccessInfo.SpreadsheetID, MainForm.Instance.Vers) != "OK") // If rerun might be different values so update SS
MainForm.Instance.AddToActionsList("Failed to write to spreadsheet, please check manually", Level.WARNING);
// else if (Excel.UpdateSpreadSheetPreTest(CameraAccessInfo.SpreadsheetID, Vers, CamOnTest.GetCamDesc(), CamOnTest.Model) != "OK")
// AddToActionsList("Failed to write to spreadsheet, please check manually");
}
else // No serial or model so allocate one
await MainForm.Instance.AllocateSerial();
if (MainForm.Instance.RhTxBxActions.Text.Length < 2 && MainForm.Instance.PnlLbls.Controls.OfType<Label>().Any(c => c.ForeColor == Color.Red) == false)
await MainForm.Instance.PreTestPassed();
}
else
{
await MainForm.Instance.PreTestFailed("Diagnostic Failure");
}
}
public static async Task AiQFinalTest()
{
if (MainForm.Instance.LblTestTubePing.Text == "❌") // No test tube so test like an IQ
{
string LEDreply = await FlexiAPI.APIHTTPLED(MainForm.Instance.CamOnTest.IP, LEDPOWER.SAFE); // Set LED's to safe (0x0E) to help with eye safety and trim check.
if (!LEDreply.Contains("Power levels set successfully"))
MainForm.Instance.AddToActionsList($"LED level could not be set: {LEDreply}", Level.ERROR);
}
//else if (!await TestTube.CheckInTestTube(MainForm.Instance.CamOnTest.IP)) // Sets LED's to medium power after checking it is in the test tube
// await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Camera not in test tube");
Task VisCheck = Helper.VisualCheck(MainForm.Instance.BtnStartTest);
if (!await CameraModules.ZoomModules("1F40", MainForm.Instance.CamOnTest.IP)) // Zoom to 8000 (1F40h) at the same time.
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Could not zoom modules to 8000");
if (!await CameraModules.SetZoomLockOn(MainForm.Instance.CamOnTest.IP))
Helper.RestartApp();
await Task.Delay(1000); // Without sleep it kept failing the factory reset as camera modules were not ready yet
await CameraModules.FactoryResetModules(MainForm.Instance.CamOnTest.IP); // Reset both modules and double check
string VISCAReply = await FlexiAPI.APIHTTPVISCA(MainForm.Instance.CamOnTest.IP, "8101043903FF", true); // Manual mode to be able to manipulate the SIG settings.
if (VISCAReply != "9041FF9051FF")
MainForm.Instance.AddToActionsList("Couldn't set to manual mode", Level.ERROR);
await CameraModules.SetSIG(MainForm.Instance.CbBxShutter, MainForm.Instance.CbBxIris, MainForm.Instance.CbBxGain, MainForm.Instance.CamOnTest.IP); // Set SIG according to the drop downs in settings for a good picture ready for image check
await ImageProcessing.ImageCheck(MainForm.Instance.PicBxOV, MainForm.Instance.PicBxIRF2, MainForm.Instance.PicBxIRF16, MainForm.Instance.LblIRImageF2, MainForm.Instance.LblIRImageF16, MainForm.Instance.CamOnTest); // Populates the picture boxes and checks iris changes
await VisCheck; // Before changing UI elements wait for user to finish Visual check
MainForm.Instance.TabImagesandSettings.SelectedIndex = 2; // Swaps to the images tab
MainForm.Instance.Refresh(); // Show user things are happening by displaying images taken
// TODO - Force expire sighting.
Task Wait = Task.Delay(5000); // Wait for 5 seconds to allow the camera to zoom in, set settings and capture some plates before auto trim
if (CameraAccessInfo.HardwareExtras.Contains("GPS")) // Check GPS if the hardware has it
await FlexiAPI.GPSFix(MainForm.Instance.CamOnTest.IP);
// While waiting do the SSH tasks.
MainForm.Instance.sshData = SSH.CollectSSHData(MainForm.Instance.CamOnTest.IP); // SSH into camera to get Vaxtor packages, filesystem size and if tailscale is installed.
await SSH.CheckFSSize(MainForm.Instance.CamOnTest.IP, MainForm.Instance.LblFilesystemSize, MainForm.Instance.sshData); // Check Filesystem size is between 100GB & 150GB
Helper.DCPowerCheck(MainForm.Instance.LblDC); // If the camera is DC powered check it is within limits
if (CameraAccessInfo.HardwareExtras.Contains("4G")) // If it is a router camera then test the router.
{
MainForm.Instance.LblRouter.Visible = true;
if (Router.CheckRouter(Router.GetRouterInfo()))
MainForm.Instance.LblRouter.Text += "OK";
else
MainForm.Instance.LblRouter.Text += "Error with router";
}
await Wait; // Finished to 5s wait
await FlexiAPI.SetTrim(MainForm.Instance.CamOnTest.IP, MainForm.Instance.LblTestTubePing.Text); // Auto trims the cameras, some plates should have been captured in the meantime
if (!await CameraModules.ZoomModules("0000", MainForm.Instance.CamOnTest.IP)) // Zoom to full wide
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Could not zoom modules to full wide");
await Task.Delay(1000); // Wait to be sure cameras are zoomed out.
await CameraModules.FactoryResetModules(MainForm.Instance.CamOnTest.IP); // Reset both modules and double check
if (MainForm.Instance.LblTestTubePing.Text == "❌") // Set LED's to MID in prep for diagnostics API
{
string LEDreply = await FlexiAPI.APIHTTPLED(MainForm.Instance.CamOnTest.IP, LEDPOWER.MID); // Set LED's to medium (0x30)
if (!LEDreply.Contains("Power levels set successfully"))
MainForm.Instance.AddToActionsList($"LED level could not be set: {LEDreply}", Level.ERROR);
}
await FlexiAPI.SetVaxtorMinMaxPlate(MainForm.Instance.CamOnTest.IP);
DateTime PCTime = DateTime.Now; // Grab PC time as close to the API as possible to pass onto PDF later
await TestingFunctions.CheckDiagsAPIPt1(); // Requests, deserialises and checks the diagnostics API is correct
await TestingFunctions.CheckDiagsAPIPt2(); // For only final test parts
// Check module has gone to default config
CameraModules.CheckCamModule(TestingFunctions.DiagsAPI.IRmodule, MainForm.Instance.LblIRModule, MainForm.Instance.CamOnTest); // IR
CameraModules.CheckCamModule(TestingFunctions.DiagsAPI.OVmodule, MainForm.Instance.LblOVModule, MainForm.Instance.CamOnTest); // OV
// Check voltage and current are OK.
LED.CheckLEDs(TestingFunctions.DiagsAPI.LedVoltage, MainForm.Instance.LblLEDV, "V", CameraAccessInfo.LED_V); // Voltage
LED.CheckLEDs(TestingFunctions.DiagsAPI.LedCurrent, MainForm.Instance.LblLEDI, "mA", CameraAccessInfo.LED_I); // Current
MainForm.Instance.Refresh(); // Make sure all labels are updated before checking them
// If there are any actions identified then fail the test.
// If any labels are red then fail. Only labels in panel so can foreach on labels not controls
if (MainForm.Instance.RhTxBxActions.Text.Length > 2 || MainForm.Instance.PnlLbls.Controls.OfType<Label>().Any(c => c.ForeColor == Color.Red) == true)
await MainForm.Instance.TestFailed(MainForm.Instance.BtnStartTest, "Diagnostic Failure");// If approved then pass otherwise GUI would have restarted before getting to TestPassed.
await MainForm.Instance.TestPassed(PCTime);
}
}