• MobileTests.cs

- Pre test now checks firmware and adds the label dynamically to the panel

• AiQ_GUI.Designer.cs
  - Added CbBxCameraModel.SelectedIndexChanged to properly wire UI element.

• Microsoft/StatsExcel.cs
  - Improved workbook loading error handling to distinguish between corruption and file access issues.
This commit is contained in:
2026-01-09 15:49:54 +00:00
parent 693da58fcb
commit 90b3f7caff
6 changed files with 97 additions and 85 deletions

13
AiQ Tests/AiQLiteTests.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace AiQ_GUI.AiQ_Tests
{
internal class AiQLiteTests
{
// Tests to be written here later
}
}

View File

@@ -110,13 +110,23 @@ namespace AiQ_GUI.AiQ_Tests
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 (DiagsAPI.modelNumber != MainForm.Instance.CamOnTest.Model)
// 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);
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
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
@@ -127,7 +137,6 @@ namespace AiQ_GUI.AiQ_Tests
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?"));
@@ -139,7 +148,9 @@ namespace AiQ_GUI.AiQ_Tests
}
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);
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)
@@ -148,45 +159,36 @@ namespace AiQ_GUI.AiQ_Tests
}
// Check licenses
List<string> licensesOnCam = []; // Temporary list for licenses on camera
List<string> licensesOnCam = new List<string>(); // 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");
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);
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
string cpuText = "CPU Usage = " + CPUround + "%";
bool cpuIsRed = CPUround <= 50 || CPUround >= 98;
MainForm.Instance.AddLabelToPanel(cpuText, cpuIsRed);
MainForm.Instance.AddLabelToPanel(
"CPU Usage = " + CPUround + "%",
CPUround <= 50 || CPUround >= 98);
// Check Vaxtor if it doesn't need or have license OR has and wants one then pass
// Check Vaxtor license
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;
}
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)) // Valid Key ID
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");
@@ -196,22 +198,17 @@ namespace AiQ_GUI.AiQ_Tests
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;
}
else 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.
// 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
bool trimIsRed = Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax;
MainForm.Instance.AddLabelToPanel(trimText, trimIsRed);
MainForm.Instance.AddLabelToPanel(
"Trim = H: " + DiagsAPI.trim[0] + " V: " + DiagsAPI.trim[1],
Math.Abs(DiagsAPI.trim[0]) > HMax || Math.Abs(DiagsAPI.trim[1]) > VMax);
}
}
}

3
AiQ_GUI.Designer.cs generated
View File

@@ -182,7 +182,7 @@ namespace AiQ_GUI
CbBxCameraModel.Name = "CbBxCameraModel";
CbBxCameraModel.Size = new Size(494, 25);
CbBxCameraModel.TabIndex = 188;
CbBxCameraModel.SelectedIndexChanged += CbBxCamTypSelectedIndexChanged;
CbBxCameraModel.SelectedIndexChanged += CbBxCameraModel_SelectedIndexChanged;
//
// BtnStartTest
//
@@ -1815,7 +1815,6 @@ namespace AiQ_GUI
CbBxCamType.Name = "CbBxCamType";
CbBxCamType.Size = new Size(233, 25);
CbBxCamType.TabIndex = 241;
CbBxCamType.Text = "AiQ";
CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged;
//
// MainForm

View File

@@ -99,6 +99,7 @@ namespace AiQ_GUI
await CheckHWOnline;
Flags.Start = false;
CbBxCamType.Text = "AiQ"; // Default to AiQ cameras
}
@@ -139,7 +140,6 @@ namespace AiQ_GUI
CbBxCameraModel.Items.AddRange(models);
}
private void PopulateUIWithLDS(LocalDataStore lds)
{
CbBxUserName.Text = lds.User;
@@ -202,7 +202,7 @@ namespace AiQ_GUI
}
else if (CbBxCamType.Text == "Mobile")
{
await MobilePreTest.RunPreTestAsync();
await PreTestPassed();
}
}
@@ -672,7 +672,7 @@ namespace AiQ_GUI
}
private void CbBxCamTypSelectedIndexChanged(object sender, EventArgs e)
private void CbBxCameraModel_SelectedIndexChanged(object sender, EventArgs e)
{
TestStartConditions();
}
@@ -1434,34 +1434,9 @@ namespace AiQ_GUI
{
Stopwatch stopWatchTest = Stopwatch.StartNew();
await MobilePreTest.CheckFirmwareAsync();
//AddLabelToPanel("Test Complete", false);
//FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
//CamOnTest.IP = CbBxFoundCams.Text;
//_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task =>
//{
// //Network.Initialize("developer", "Pass123");
// if (task.IsFaulted)
// {
// AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message);
// }
// else
// {
// AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}");
// }
//});
//await Task.Delay(3000); // Wait for server to start
//CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
//CmBoFoundCams_TextChanged(sender, e);
//CbBxCameraModel.SelectedIndex = CbBxCameraModel.Items.Count - 1; // Selects AB12CD as model number
//await Task.Delay(3000); // Wait for server to start
//BtnStartTest_Click(sender, e);
//StatsExcel excelExporter = new();
//excelExporter.ExportDatabaseToExcel();
//await MobilePreTest.CheckFirmwareAsync();
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG);
}

View File

@@ -40,7 +40,7 @@ namespace AiQ_GUI
const string selectColumns = @"
ModelNumber,
[Total Tests Run],
[Pre Tests Passed]
[Pre Tests Passed],
[Pre Tests Failed],
[Final Tests Passed],
[Final Tests Failed],
@@ -84,8 +84,28 @@ namespace AiQ_GUI
XLWorkbook workbook;
if (File.Exists(exportPath))
{
workbook = new XLWorkbook(exportPath);
MainForm.Instance.AddToActionsList("Opened existing workbook.");
try
{
workbook = new XLWorkbook(exportPath);
MainForm.Instance.AddToActionsList("Opened existing workbook.");
}
catch (Exception loadEx)
{
// Workbook is corrupted, backup the old file and create a new one
string backupPath = exportPath + ".corrupted_" + DateTime.Now.ToString("yyyyMMdd_HHmmss");
try
{
File.Move(exportPath, backupPath, overwrite: true);
MainForm.Instance.AddToActionsList($"WARNING: Existing workbook was corrupted. Backed up to: {backupPath}");
}
catch (Exception backupEx)
{
MainForm.Instance.AddToActionsList($"WARNING: Could not backup corrupted workbook. Details: {backupEx.Message}");
}
workbook = new XLWorkbook();
MainForm.Instance.AddToActionsList("Created new workbook (previous file was corrupted).");
}
}
else
{

View File

@@ -1,21 +1,23 @@
using AiQ_GUI;
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
public static class MobilePreTest
{
public static async Task CheckFirmwareAsync()
{
const string cameraIp = "192.168.0.112";
using HttpClient client = new HttpClient
{
BaseAddress = new Uri($"http://{cameraIp}")
BaseAddress = new Uri($"http://{MainForm.Instance.CamOnTest.IP}")
};
try
@@ -31,32 +33,32 @@ public static class MobilePreTest
string body = await response.Content.ReadAsStringAsync();
MainForm.Instance.AddToActionsList($"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}",Level.LOG);
response.EnsureSuccessStatusCode();
JsonElement json = JsonSerializer.Deserialize<JsonElement>(body);
string version = json.GetProperty("version").GetString()?.Trim();
// Compare against expected SRZFirmware from UniversalData
if (string.IsNullOrEmpty(UniversalData.SRZFirmware))
{
MainForm.Instance.AddToActionsList($"Firmware check failed: Expected SRZFirmware not loaded in UniversalData",Level.ERROR);
MainForm.Instance.AddLabelToPanel($"Firmware = {version}", true);
}
else if (version == UniversalData.SRZFirmware)
{
MainForm.Instance.AddToActionsList($"Firmware match successful: {version}",Level.Success);
MainForm.Instance.AddLabelToPanel($"Firmware = {version}", false);
}
else
{
MainForm.Instance.AddToActionsList($"Firmware mismatch: Camera has {version}, expected {UniversalData.SRZFirmware}",Level.ERROR);
MainForm.Instance.AddLabelToPanel($"Firmware = {version}", true);
}
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList($"Firmware check failed: {ex.Message}",Level.ERROR);
MainForm.Instance.AddLabelToPanel("Firmware = Unknown", true);
}
}
@@ -83,4 +85,10 @@ public static class MobilePreTest
byte[] bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
public static async Task RunPreTestAsync()
{
await CheckFirmwareAsync();
}
}