V4.5
This commit is contained in:
200
AiQ_GUI.cs
200
AiQ_GUI.cs
@@ -5,6 +5,13 @@ using System.Reflection;
|
||||
|
||||
namespace AiQ_GUI
|
||||
{
|
||||
public enum Level
|
||||
{
|
||||
ERROR,
|
||||
WARNING,
|
||||
LOG
|
||||
}
|
||||
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
// Classes
|
||||
@@ -19,8 +26,6 @@ namespace AiQ_GUI
|
||||
private List<CancellationTokenSource> soakCtsList = [];
|
||||
private List<Task> soakTasks = [];
|
||||
|
||||
public const string GoogleDrivePath = @"G:\Shared drives\MAV Production GUI's\AiQ\GUI's\";
|
||||
|
||||
// Colours
|
||||
public static readonly Color BtnColour = Color.FromArgb(70, 65, 80);
|
||||
public static readonly Color TxBxColour = Color.FromArgb(53, 51, 64);
|
||||
@@ -36,20 +41,18 @@ namespace AiQ_GUI
|
||||
|
||||
private async void AiQGUI_Load(object sender, EventArgs e)
|
||||
{
|
||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||
|
||||
Task? closeProcessesTask = Windows.CloseProcesses(); // Fire and forget closing other apps
|
||||
Windows.UpdateFirewall();
|
||||
Task UniDataTask = Task.Run(() => Access.ReadUniData()); // Get universal data
|
||||
Task<LocalDataStore> LDSWAIT = Task.Run(() => LDS.GetLDS()); // Get and deserialise LDS.json
|
||||
Task<string> guiVerTask = Task.Run(() => GUIUpdate.FindGUIVersion()); // Get GUI Version
|
||||
Task<LocalDataStore> LDSWAIT = Task.Run(() => LDS.GetLDS()); // Get and deserialise LDS.json
|
||||
Task<string> guiVerTask = Task.Run(() => GUIUpdate.FindGUIVersion()); // Get GUI Version
|
||||
|
||||
Network.Initialize("admin", "admin"); // Initialise HTTP client
|
||||
|
||||
if (await Network.PingIP("8.8.8.8")) // Ping to check if we're online
|
||||
{
|
||||
if (!GoogleAPI.Setup())
|
||||
AddToActionsList("Cannot setup Google API");
|
||||
AddToActionsList("Cannot setup Google API", Level.WARNING);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -71,6 +74,7 @@ namespace AiQ_GUI
|
||||
// Load local data store
|
||||
localDataStore = await LDSWAIT;
|
||||
Logging.LogMessage("Opening GUI"); // Done after LDS to make sure directory exists.
|
||||
|
||||
if (localDataStore == null)
|
||||
{
|
||||
AddToActionsList("Could not deserialise LDS.json please help!");
|
||||
@@ -89,9 +93,6 @@ namespace AiQ_GUI
|
||||
|
||||
await CheckHWOnline;
|
||||
Flags.Start = false;
|
||||
|
||||
stopwatch.Stop();
|
||||
Debug.WriteLine("RunTime " + stopwatch.Elapsed.ToString(@"hh\:mm\:ss\.ff"));
|
||||
}
|
||||
|
||||
private void PopulateUIWithLDS(LocalDataStore lds)
|
||||
@@ -209,8 +210,8 @@ namespace AiQ_GUI
|
||||
await CheckDiagsAPIPt2(); // For only final test parts
|
||||
|
||||
// Check module has gone to default config
|
||||
CameraModules.CheckCamModule(DiagsAPI.IRmodule, LblIRModule); // IR
|
||||
CameraModules.CheckCamModule(DiagsAPI.OVmodule, LblOVModule); // OV
|
||||
CameraModules.CheckCamModule(DiagsAPI.IRmodule, LblIRModule, CamOnTest); // IR
|
||||
CameraModules.CheckCamModule(DiagsAPI.OVmodule, LblOVModule, CamOnTest); // OV
|
||||
|
||||
// Check voltage and current are OK.
|
||||
LED.CheckLEDs(DiagsAPI.LedVoltage, LblLEDV, "V", CameraAccessInfo.LED_V); // Voltage
|
||||
@@ -253,8 +254,8 @@ namespace AiQ_GUI
|
||||
await CheckDiagsAPIPt1();
|
||||
|
||||
// Check module has gone to default config
|
||||
CameraModules.CheckCamModule(DiagsAPI.IRmodule, LblIRModule); // IR
|
||||
CameraModules.CheckCamModule(DiagsAPI.OVmodule, LblOVModule); // OV
|
||||
CameraModules.CheckCamModule(DiagsAPI.IRmodule, LblIRModule, CamOnTest); // IR
|
||||
CameraModules.CheckCamModule(DiagsAPI.OVmodule, LblOVModule, CamOnTest); // OV
|
||||
|
||||
// Check voltage and current are OK.
|
||||
LED.CheckLEDs(DiagsAPI.LedVoltage, LblLEDV, "V", CameraAccessInfo.LED_V); // Voltage
|
||||
@@ -286,8 +287,6 @@ namespace AiQ_GUI
|
||||
{
|
||||
await PreTestFailed("Diagnostic Failure");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ***** Pass/Fails *****
|
||||
@@ -336,15 +335,11 @@ namespace AiQ_GUI
|
||||
BtnStartTest.Text = "Test Passed";
|
||||
PnlQuestion.Visible = false; // just in case this came from an override
|
||||
Logging.LogMessage("Final Test Passed");
|
||||
if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA
|
||||
{
|
||||
Access.Stats("Final Tests Passed", CamOnTest.Model);
|
||||
}
|
||||
else
|
||||
{
|
||||
Access.Stats("RMA Final Tests Passed", CamOnTest.Model);
|
||||
}
|
||||
|
||||
if (CamOnTest.RMANum == 0) // Yap to check if it is not a RMA
|
||||
Access.Stats("Final Tests Passed", CamOnTest.Model);
|
||||
else
|
||||
Access.Stats("RMA Final Tests Passed", CamOnTest.Model);
|
||||
}
|
||||
|
||||
public async Task TestFailed(Button Btn, string ErrMssg)
|
||||
@@ -354,13 +349,10 @@ namespace AiQ_GUI
|
||||
Btn.Text = "Test Failed";
|
||||
|
||||
if (!(CamOnTest.RMANum != 0)) // Yap to check if it is not a RMA
|
||||
{
|
||||
Access.Stats(["Final Tests Failed", ErrMssg], CamOnTest.Model);
|
||||
}
|
||||
else
|
||||
{
|
||||
Access.Stats("RMA Final Tests Failed", CamOnTest.Model);
|
||||
}
|
||||
|
||||
AddToActionsList(ErrMssg);
|
||||
|
||||
string RedLbls = string.Join(Environment.NewLine, PnlLbls.Controls
|
||||
@@ -400,7 +392,6 @@ namespace AiQ_GUI
|
||||
GoogleAPI.WriteToSS(oblistCD, "'Approval'!C" + nextRow + ":D" + nextRow, GoogleAPI.spreadsheetId_ModelInfo);
|
||||
|
||||
await Teams.SendMssg(Convert.ToString(nextRow), CbBxUserName.Text);
|
||||
//GoogleAPI.EmailApproval(Convert.ToString(nextRow), CbBxUserName.Text);
|
||||
|
||||
string Approved = "";
|
||||
|
||||
@@ -514,7 +505,10 @@ namespace AiQ_GUI
|
||||
AddToActionsList($"{DiagsAPI.MAC} not recognised as NVIDIA MAC address");
|
||||
}
|
||||
else
|
||||
{
|
||||
lblMac.ForeColor = Color.Red;
|
||||
AddToActionsList($"{DiagsAPI.MAC} not recognised as a MAC address");
|
||||
}
|
||||
|
||||
// Check timestamp
|
||||
DateTime dateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
@@ -597,9 +591,7 @@ namespace AiQ_GUI
|
||||
CamOnTest.RMANum = Convert.ToInt32(await DisplayInput("What is the RMA number?"));
|
||||
|
||||
if (CamOnTest.RMANum == -1) // Means they chose the 'I don't know' option
|
||||
{
|
||||
await TestFailed(BtnStartTest, "Please get RMA number from operations team before continuing");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -638,11 +630,7 @@ namespace AiQ_GUI
|
||||
double CPUround = Math.Round(DiagsAPI.CPUusage); // Check CPU usage isn't near max
|
||||
LblCPUusage.Text += CPUround + "%";
|
||||
|
||||
if (CPUround < 98 && CPUround > 50)
|
||||
{
|
||||
LblCPUusage.ForeColor = Color.LightGreen;
|
||||
}
|
||||
else if (CPUround <= 50)
|
||||
if (CPUround <= 50)
|
||||
{
|
||||
LblCPUusage.Text += " Unexpectedly low CPU usage";
|
||||
LblCPUusage.ForeColor = Color.Red;
|
||||
@@ -652,6 +640,10 @@ namespace AiQ_GUI
|
||||
LblCPUusage.Text += " Unexpectedly high CPU usage";
|
||||
LblCPUusage.ForeColor = Color.Red;
|
||||
}
|
||||
else
|
||||
{
|
||||
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")
|
||||
@@ -727,7 +719,6 @@ namespace AiQ_GUI
|
||||
lblSerial.Text += DiagsAPI.serialNumber;
|
||||
|
||||
Printer.ZebraIP = localDataStore.ZebraIP;
|
||||
|
||||
Printer.PrintGBLbl(); // Print GB label
|
||||
Printer.PrintSerialLbl(CamOnTest.Model, NewSerial, CameraAccessInfo.Processor); // Print model/serial label
|
||||
}
|
||||
@@ -804,7 +795,9 @@ namespace AiQ_GUI
|
||||
|
||||
foreach (Camera soakInfo in soakCameraList)
|
||||
{
|
||||
TabSoak.Controls.Add(SoakTest.MakeNewCheckbox(soakInfo, YLoc));
|
||||
CheckBox chkBox = SoakTest.MakeNewCheckbox(soakInfo, YLoc);
|
||||
TabSoak.Controls.Add(chkBox);
|
||||
soakInfo.CheckBox = chkBox;
|
||||
YLoc += 24;
|
||||
}
|
||||
|
||||
@@ -937,15 +930,27 @@ namespace AiQ_GUI
|
||||
}
|
||||
|
||||
// ***** Helper functions *****
|
||||
public void AddToActionsList(string Mssg, bool IsErr = true)
|
||||
public void AddToActionsList(string Mssg, Level Lvl = Level.LOG)
|
||||
{
|
||||
if (IsErr)
|
||||
if (Lvl == Level.ERROR)
|
||||
{
|
||||
Logging.LogErrorMessage(Mssg);
|
||||
else
|
||||
RhTxBxActions.SelectionColor = Color.IndianRed;
|
||||
}
|
||||
else if (Lvl == Level.WARNING)
|
||||
{
|
||||
Logging.LogWarningMessage(Mssg);
|
||||
RhTxBxActions.SelectionColor = Color.Orange;
|
||||
}
|
||||
else if (Lvl == Level.LOG)
|
||||
{
|
||||
Logging.LogMessage(Mssg);
|
||||
RhTxBxActions.SelectionColor = Color.LightGreen;
|
||||
}
|
||||
|
||||
RhTxBxActions.AppendText(Mssg + Environment.NewLine);
|
||||
RhTxBxActions.SelectionStart = RhTxBxActions.Text.Length;
|
||||
RhTxBxActions.SelectionColor = SystemColors.Control;
|
||||
RhTxBxActions.ScrollToCaret();
|
||||
}
|
||||
|
||||
@@ -1146,7 +1151,7 @@ namespace AiQ_GUI
|
||||
{
|
||||
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera
|
||||
await FlexiAPI.HTTP_Update("GLOBAL--NetworkConfig", SCL.IP, Network_JSON);
|
||||
Instance.AddToActionsList($"Setting 211 for camera {SCL.IP}", false);
|
||||
Instance.AddToActionsList($"Setting 211 for camera {SCL.IP}", Level.LOG);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1173,7 +1178,7 @@ namespace AiQ_GUI
|
||||
{
|
||||
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera
|
||||
string RESP = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, GOD_JSON);
|
||||
Instance.AddToActionsList($"Setting God mode for camera {SCL.IP} to {newGodModeValue}", false);
|
||||
Instance.AddToActionsList($"Setting God mode for camera {SCL.IP} to {newGodModeValue}", Level.LOG);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1313,7 +1318,11 @@ namespace AiQ_GUI
|
||||
{
|
||||
VaxtorLicResp = JsonConvert.DeserializeObject<VaxtorLic>(ALresponse);
|
||||
|
||||
if (VaxtorLicResp.protectionKeyId != string.Empty)
|
||||
if (VaxtorLicResp.error != string.Empty)
|
||||
{
|
||||
AddToActionsList(VaxtorLicResp.error, Level.ERROR);
|
||||
}
|
||||
else if (VaxtorLicResp.protectionKeyId != string.Empty)
|
||||
{
|
||||
string err = GoogleAPI.UpdateSpreadSheetVaxtor(VaxtorLicResp, Vers.Serial, CamOnTest.Model);
|
||||
|
||||
@@ -1327,18 +1336,14 @@ namespace AiQ_GUI
|
||||
|
||||
await DisplayOK("Please wait at least a minute before turning off the unit.");
|
||||
}
|
||||
else if (VaxtorLicResp.error != string.Empty)
|
||||
{
|
||||
RhTxBxCode.AppendText(VaxtorLicResp.error);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddToActionsList($"Error reading JSON - {ALresponse}");
|
||||
AddToActionsList($"Error reading JSON - {ALresponse}", Level.ERROR);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
AddToActionsList($"Error reading JSON - {ALresponse}");
|
||||
AddToActionsList($"Error reading JSON - {ALresponse}", Level.ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1574,7 +1579,7 @@ namespace AiQ_GUI
|
||||
|
||||
CancellationTokenSource cts = new();
|
||||
soakCtsList.Add(cts);
|
||||
soakTasks.Add(SoakTest.StartSoak(SCL, cts.Token));
|
||||
soakTasks.Add(SoakTest.StartSoak(SCL, SCL.CheckBox, cts.Token));
|
||||
await Task.Delay(10000);
|
||||
}
|
||||
}
|
||||
@@ -1596,7 +1601,7 @@ namespace AiQ_GUI
|
||||
continue;
|
||||
try
|
||||
{
|
||||
AddToActionsList($"Setting 211 & God Mode off for camera {SCL.IP}", false);
|
||||
AddToActionsList($"Setting 211 & God Mode off for camera {SCL.IP}", Level.LOG);
|
||||
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera
|
||||
await CameraModules.FactoryResetModules(SCL.IP); // Reset camera modules
|
||||
|
||||
@@ -1612,6 +1617,13 @@ namespace AiQ_GUI
|
||||
{
|
||||
AddToActionsList("Failed to set all cameras to 211 and god mode off. Reason: " + ex.Message); // In case non AiQ's get caught up
|
||||
}
|
||||
|
||||
if (SCL.CheckBox.ForeColor == Color.Red)
|
||||
{
|
||||
DialogResult DR = MessageBox.Show($"CAMERA {SCL.Serial} {SCL.Model} DID NOT PASS SOAK TEST. Check soak test report to see error. Do you want to open the test report", "SOAK TEST FAILED", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
|
||||
if (DR == DialogResult.Yes)
|
||||
File.Open(SCL.TestReportLoc, FileMode.Open);
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(5000); // Wait for 5 seconds to allow the camera to restart
|
||||
@@ -1619,11 +1631,11 @@ namespace AiQ_GUI
|
||||
|
||||
if ((FoundCams.Count == i && FoundCams.Contains("192.168.1.211")) || FoundCams.Count == 1)
|
||||
{
|
||||
AddToActionsList("All cameras successfully changed to 211.", false);
|
||||
AddToActionsList("All cameras successfully changed to 211.", Level.LOG);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddToActionsList($"Some cameras failed: Found {FoundCams.Count}, expected {i}.", true);
|
||||
AddToActionsList($"Some cameras failed: Found {FoundCams.Count}, expected {i}.", Level.ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1671,59 +1683,7 @@ namespace AiQ_GUI
|
||||
private async void BtnUploadBlob_Click(object sender, EventArgs e)
|
||||
{
|
||||
BtnUploadBlob.BackColor = BtnColour;
|
||||
const string networkFolderPath = @"G:\Shared drives\MAV Production\MAV_146_AiQ_Mk2\Flexi";
|
||||
string fileToUpload = null;
|
||||
|
||||
if (await DisplayQuestion("Do you want the latest Flexi version from the MAV Production folder?"))
|
||||
{
|
||||
fileToUpload = Directory.GetFiles(networkFolderPath, "*.blob").OrderByDescending(File.GetLastWriteTime).FirstOrDefault();
|
||||
|
||||
if (fileToUpload == null)
|
||||
{
|
||||
AddToActionsList("No .blob file found in the directory.", false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using OpenFileDialog openFileDialog1 = new()
|
||||
{
|
||||
InitialDirectory = networkFolderPath,
|
||||
Filter = "Blob files (*.blob)|*.blob",
|
||||
FilterIndex = 0
|
||||
};
|
||||
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
fileToUpload = openFileDialog1.FileName;
|
||||
else
|
||||
{
|
||||
AddToActionsList("File selection cancelled.", false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string fileName = Path.GetFileName(fileToUpload);
|
||||
AddToActionsList($"Selected file to upload: {fileToUpload}", false);
|
||||
|
||||
foreach (Camera? cam in soakCameraList.Where(c => c.IsChecked))
|
||||
{
|
||||
string apiUrl = $"http://{cam.IP}/upload/software-update/2";
|
||||
Network.Initialize("developer", cam.DevPass);
|
||||
await Task.Delay(1000); // Gives extra time to allow for Network to initialize
|
||||
AddToActionsList($"Uploading to {cam.IP}...", false);
|
||||
string result = await FlexiAPI.SendBlobFileUpload(apiUrl, fileToUpload, fileName);
|
||||
|
||||
// Retry once on transient errors
|
||||
if (result.Contains("Error while copying content to a stream") || result.Contains("Timeout"))
|
||||
{
|
||||
AddToActionsList($"Retrying upload to {cam.IP}...", false);
|
||||
await Task.Delay(1000);
|
||||
result = await FlexiAPI.SendBlobFileUpload(apiUrl, fileToUpload, fileName);
|
||||
}
|
||||
|
||||
AddToActionsList($"Upload result for {cam.IP}: {result}", false);
|
||||
await Task.Delay(500);
|
||||
}
|
||||
FlexiAPI.UploadBlob(soakCameraList);
|
||||
BtnUploadBlob.BackColor = Color.Green;
|
||||
}
|
||||
|
||||
@@ -1743,19 +1703,37 @@ namespace AiQ_GUI
|
||||
}
|
||||
|
||||
// ***** Test & Debug *****
|
||||
private async void BtnTest_Click(object sender, EventArgs e)
|
||||
private void BtnTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
Stopwatch stopWatchTest = Stopwatch.StartNew();
|
||||
|
||||
//StatsExcel excelExporter = new();
|
||||
//excelExporter.ExportDatabaseToExcel();
|
||||
|
||||
string ans = await FlexiAPI.HTTP_Fetch("GLOBAL--Device", "192.168.0.71");
|
||||
AddToActionsList(ans);
|
||||
// /api/config-ids - For getting all available config IDs
|
||||
|
||||
// Make every log file in the soak log directory into a soak test report PDF
|
||||
var files = from file in Directory.EnumerateFiles("C:\\ProgramData\\MAV\\AiQ_GUI") select file;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (file.Contains("SoakLog"))
|
||||
{
|
||||
// File name: SoakLog_{Serial}_{Model}.log
|
||||
string[] parts = file.Split('_', '.').Select(p => p.Trim()).ToArray();
|
||||
|
||||
Camera NewCam = new()
|
||||
{
|
||||
Model = parts[3],
|
||||
Serial = parts[2],
|
||||
};
|
||||
|
||||
PDF.CreateSoakTestReport(NewCam, "SoakTestRig", DateTime.Now, file);
|
||||
}
|
||||
}
|
||||
|
||||
stopWatchTest.Stop();
|
||||
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"));
|
||||
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user