2026-01-15 16:36:17 +00:00
namespace AiQ_GUI.AiQ_Tests
2025-12-22 14:37:43 +00:00
{
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
2025-12-23 13:01:15 +00:00
// 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 ;
2025-12-22 14:37:43 +00:00
if ( RegexCache . MACRegexNVIDIA ( ) . IsMatch ( DiagsAPI . MAC ) ) // Checks it is in the right format and is a NVIDIA registered MAC address
{
2025-12-23 13:01:15 +00:00
// Valid NVIDIA MAC
2025-12-22 14:37:43 +00:00
}
else if ( RegexCache . MACRegex ( ) . IsMatch ( DiagsAPI . MAC ) ) // Is a valid MAC, but not NVIDIA
{
2025-12-23 13:01:15 +00:00
macIsRed = true ;
2025-12-22 14:37:43 +00:00
MainForm . Instance . AddToActionsList ( $"{DiagsAPI.MAC} not recognised as NVIDIA MAC address" , Level . ERROR ) ;
}
else
{
2025-12-23 13:01:15 +00:00
macIsRed = true ;
2025-12-22 14:37:43 +00:00
MainForm . Instance . AddToActionsList ( $"{DiagsAPI.MAC} not recognised as a MAC address" , Level . ERROR ) ;
}
2025-12-23 13:01:15 +00:00
MainForm . Instance . AddLabelToPanel ( macText , macIsRed ) ;
2025-12-22 14:37:43 +00:00
// 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 ;
2025-12-23 13:01:15 +00:00
string timestampText = "Timestamp = " + dateTime ;
bool timestampIsRed = false ;
2025-12-22 14:37:43 +00:00
if ( timediff > 10 ) // Over 10 seconds ago
{
2025-12-23 13:01:15 +00:00
timestampText + = $" Time behind by {timediff}s" ;
timestampIsRed = true ;
2025-12-22 14:37:43 +00:00
}
else if ( timediff < 0 ) // Time is in the future.
{
2025-12-23 13:01:15 +00:00
timestampText + = $" Time is in the future by {Math.Abs(timediff)}s" ;
timestampIsRed = true ;
2025-12-22 14:37:43 +00:00
}
2025-12-23 13:01:15 +00:00
MainForm . Instance . AddLabelToPanel ( timestampText , timestampIsRed ) ;
2025-12-22 14:37:43 +00:00
2025-12-23 13:01:15 +00:00
// Check Temperature
string tempText = "Temperature = " + DiagsAPI . IntTemperature + "°C" ;
bool tempIsRed = DiagsAPI . IntTemperature < = 20 | | DiagsAPI . IntTemperature > = 70 ;
MainForm . Instance . AddLabelToPanel ( tempText , tempIsRed ) ;
2025-12-22 14:37:43 +00:00
2025-12-23 13:01:15 +00:00
// Check Zoom Lock
string zoomLockText = "Zoom Lock = " + DiagsAPI . zoomLock ;
bool zoomLockIsRed = false ;
2025-12-22 14:37:43 +00:00
if ( DiagsAPI . zoomLock = = true )
{
2025-12-23 13:01:15 +00:00
if ( DiagsAPI . IRmodule . zoom ! = DiagsAPI . OVmodule . zoom ) // Checks if zoomlock is doing what is says it should
2025-12-22 14:37:43 +00:00
{
2025-12-23 13:01:15 +00:00
zoomLockText + = $" Zoomlock on but {DiagsAPI.IRmodule.zoom}≠{DiagsAPI.OVmodule.zoom}" ;
zoomLockIsRed = true ;
2025-12-22 14:37:43 +00:00
}
}
else
2025-12-23 13:01:15 +00:00
zoomLockIsRed = true ;
MainForm . Instance . AddLabelToPanel ( zoomLockText , zoomLockIsRed ) ;
2025-12-22 14:37:43 +00:00
}
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
{
2025-12-23 13:01:15 +00:00
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 ) ;
2025-12-22 14:37:43 +00:00
2026-01-09 15:49:54 +00:00
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 ( ) ;
2025-12-22 14:37:43 +00:00
if ( RegexCache . SerialRegex ( ) . IsMatch ( DiagsAPI . serialNumber ) & & RegexCache . ModelRegex ( ) . IsMatch ( DiagsAPI . modelNumber ) )
{
2026-01-09 15:49:54 +00:00
// If nothing selected yet, do not warn (matches old logic)
if ( ! string . IsNullOrWhiteSpace ( selectedModel )
& & ! string . Equals ( apiModel , selectedModel , StringComparison . OrdinalIgnoreCase ) )
2025-12-22 14:37:43 +00:00
{
2026-01-09 15:49:54 +00:00
MainForm . Instance . AddToActionsList (
"Model number in camera doesn't match what has been selected" ,
Level . WARNING ) ;
2025-12-22 14:37:43 +00:00
}
2026-01-09 15:49:54 +00:00
else if ( ! string . IsNullOrWhiteSpace ( CameraAccessInfo . SpreadsheetID ) & & ! GoogleAPI . CheckWIP ( DiagsAPI . serialNumber , CameraAccessInfo . SpreadsheetID ) ) // Check WIP column in serial number register, if not ticked then RMA
2025-12-22 14:37:43 +00:00
{
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
{
2026-01-09 15:49:54 +00:00
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 ) ;
2025-12-22 14:37:43 +00:00
}
}
2025-12-23 13:01:15 +00:00
catch ( Exception ex )
{
MainForm . Instance . AddToActionsList ( $"Error in CheckDiagsAPIPt2 serial/model: {ex.Message}" , Level . ERROR ) ;
}
2025-12-22 14:37:43 +00:00
// Check licenses
2026-01-09 15:49:54 +00:00
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" ) ;
MainForm . Instance . AddLabelToPanel (
"Licenses = " + ( licensesOnCam . Count = = 0 ? "None" : string . Join ( ", " , licensesOnCam ) ) ,
false ) ;
2025-12-22 14:37:43 +00:00
double CPUround = Math . Round ( DiagsAPI . CPUusage ) ; // Check CPU usage isn't near max
2026-01-09 15:49:54 +00:00
MainForm . Instance . AddLabelToPanel (
"CPU Usage = " + CPUround + "%" ,
CPUround < = 50 | | CPUround > = 98 ) ;
2025-12-22 14:37:43 +00:00
2026-01-09 15:49:54 +00:00
// Check Vaxtor license
2025-12-23 13:01:15 +00:00
bool vaxtorIsRed = false ;
string vaxtorText = "Vaxtor Key ID = " + DiagsAPI . licenses . raptorKeyID ;
2026-01-09 15:49:54 +00:00
if ( DiagsAPI . licenses . raptorKeyID ! = "Not Licensed" ) vaxtorIsRed = false ;
else if ( CameraAccessInfo . VaxtorLic = = false ) vaxtorIsRed = false ;
2025-12-22 14:37:43 +00:00
else if ( await MainForm . Instance . DisplayQuestion ( "Was this camera licensed manually?" ) )
{
string ProdcutKeyID = await MainForm . Instance . DisplayInput ( "What is the Key ID?" , false ) ;
2026-01-09 15:49:54 +00:00
if ( RegexCache . VaxtorRegex ( ) . IsMatch ( ProdcutKeyID ) )
2025-12-22 14:37:43 +00:00
{
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" ) ;
}
2026-01-05 12:35:28 +00:00
DiagsAPI . licenses . raptorKeyID = MainForm . Instance . TxBxProductKey . Text ;
vaxtorText = "Vaxtor Key ID = " + DiagsAPI . licenses . raptorKeyID ;
vaxtorIsRed = false ;
2025-12-22 14:37:43 +00:00
}
2026-01-09 15:49:54 +00:00
else vaxtorIsRed = true ;
2025-12-22 14:37:43 +00:00
2025-12-23 13:01:15 +00:00
MainForm . Instance . AddLabelToPanel ( vaxtorText , vaxtorIsRed ) ;
2026-01-09 15:49:54 +00:00
// Check trim is within 10% both horizontally and vertically
2025-12-22 14:37:43 +00:00
const int HMax = 96 ; // 5% of 1920 each way = ±96
const int VMax = 54 ; // 5% of 1080 each way = ±54
2026-01-09 15:49:54 +00:00
MainForm . Instance . AddLabelToPanel (
"Trim = H: " + DiagsAPI . trim [ 0 ] + " V: " + DiagsAPI . trim [ 1 ] ,
Math . Abs ( DiagsAPI . trim [ 0 ] ) > HMax | | Math . Abs ( DiagsAPI . trim [ 1 ] ) > VMax ) ;
2025-12-22 14:37:43 +00:00
}
}
}