From 4dace8edefbb993527de47719e84e3935f40adcb Mon Sep 17 00:00:00 2001 From: Bradley Born Date: Thu, 15 Jan 2026 16:36:17 +0000 Subject: [PATCH] refactor(gui,api,logging): UI layout tweaks, cleanup, and improved diagnostics - CbBxCamType now spans the full width of CbBxCameraModel - BtnTest_Click moved to the bottom of AiQ_GUI.cs for easier testing/navigation - Unused using directives removed across files - Login credentials factored out and reused in MobileAPI.cs - VLC.cs Capture function reviewed and superseded by TakeSnapshot - InsertCamTab implementation updated to avoid use of `var` - Misleading '// Non-ONVIF cameras' comment corrected - Added Level.Debug logging, accessible only to developers, for detailed diagnostics --- AiQ Tests/AiQTests.cs | 2 +- AiQ Tests/Diagnostics.cs | 8 +- AiQ_GUI.Designer.cs | 2 +- AiQ_GUI.cs | 114 +++++++++--------- AiQ_GUI.resx | 3 - .../Mobile API.cs => MobileTests/MobileAPI.cs | 8 +- .../MobileTests.cs | 0 {Mobile Tests => MobileTests}/VLC.cs | 7 -- Network.cs | 2 +- 9 files changed, 67 insertions(+), 79 deletions(-) rename Mobile Tests/Mobile API.cs => MobileTests/MobileAPI.cs (94%) rename Mobile Tests/Mobile Tests.cs => MobileTests/MobileTests.cs (100%) rename {Mobile Tests => MobileTests}/VLC.cs (80%) diff --git a/AiQ Tests/AiQTests.cs b/AiQ Tests/AiQTests.cs index bd64066..9c1e45d 100644 --- a/AiQ Tests/AiQTests.cs +++ b/AiQ Tests/AiQTests.cs @@ -8,7 +8,7 @@ public class AiQTests 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); diff --git a/AiQ Tests/Diagnostics.cs b/AiQ Tests/Diagnostics.cs index 053e9df..a403d71 100644 --- a/AiQ Tests/Diagnostics.cs +++ b/AiQ Tests/Diagnostics.cs @@ -1,10 +1,4 @@ -using Renci.SshNet.Common; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Text; - -namespace AiQ_GUI.AiQ_Tests +namespace AiQ_GUI.AiQ_Tests { public class TestingFunctions diff --git a/AiQ_GUI.Designer.cs b/AiQ_GUI.Designer.cs index 5bd8d9a..819e7d1 100644 --- a/AiQ_GUI.Designer.cs +++ b/AiQ_GUI.Designer.cs @@ -1932,7 +1932,7 @@ namespace AiQ_GUI CbBxCamType.Margin = new Padding(4, 3, 4, 3); CbBxCamType.MaxDropDownItems = 20; CbBxCamType.Name = "CbBxCamType"; - CbBxCamType.Size = new Size(233, 25); + CbBxCamType.Size = new Size(254, 25); CbBxCamType.TabIndex = 241; CbBxCamType.SelectedIndexChanged += CbBxCamType_SelectedIndexChanged; // diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index 0ad199f..b5ef007 100644 --- a/AiQ_GUI.cs +++ b/AiQ_GUI.cs @@ -1,16 +1,10 @@ using AiQ_GUI.AiQ_Tests; using AiQ_GUI.Mobile_Tests; -using DocumentFormat.OpenXml.Drawing.Diagrams; using LibVLCSharp.Shared; -using LibVLCSharp.WinForms; -using MigraDoc.DocumentObjectModel; using Newtonsoft.Json; using System.ComponentModel; using System.Diagnostics; -using System.Net.Http.Json; using System.Reflection; -using System.Text.Json; -using System.Windows.Forms; using Color = System.Drawing.Color; namespace AiQ_GUI @@ -20,7 +14,8 @@ namespace AiQ_GUI ERROR, WARNING, LOG, - Success + Success, + DEBUG } public partial class MainForm : Form @@ -112,7 +107,6 @@ namespace AiQ_GUI await CheckHWOnline; Flags.Start = false; CbBxCamType.Text = "AiQ"; // Default to AiQ cameras - } @@ -121,11 +115,11 @@ namespace AiQ_GUI // Remove previous tabs if (CurrentTabs != null) { - foreach (var tab in CurrentTabs) + foreach (TabPage tab in CurrentTabs) TabImagesandSettings.TabPages.Remove(tab); } - var tabsToInsert = new List(); + List tabsToInsert = new List(); if (camType == "Mobile") tabsToInsert.AddRange([Video, Mobile]); @@ -134,7 +128,7 @@ namespace AiQ_GUI int idx = Math.Min(3, TabImagesandSettings.TabPages.Count); - foreach (var tab in tabsToInsert) + foreach (TabPage tab in tabsToInsert) { if (!TabImagesandSettings.TabPages.Contains(tab)) TabImagesandSettings.TabPages.Insert(idx++, tab); @@ -169,7 +163,7 @@ namespace AiQ_GUI if (lds.User == "Bradley" || lds.User == "Sophie") BtnTest.Visible = true; - + TxBxCheckValid(TxBxPsuIP); // Set save button color if valid } @@ -563,7 +557,7 @@ namespace AiQ_GUI return; } - // Non-ONVIF cameras + // AiQ cameras if (!await Network.PingIP(ipOnly)) { CbBxFoundCams.BackColor = Color.Red; @@ -660,31 +654,37 @@ namespace AiQ_GUI // ***** Helper functions ***** public void AddToActionsList(string Mssg, Level Lvl = Level.LOG) { - if (Lvl == Level.ERROR) - { - Logging.LogErrorMessage(Mssg); - 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.White; - } - else if (Lvl == Level.Success) - { - Logging.LogMessage(Mssg); - RhTxBxActions.SelectionColor = Color.LightGreen; - } + // DEBUG messages only visible to Bradley + if (Lvl == Level.DEBUG && CbBxUserName.Text != "Bradley") + return; - RhTxBxActions.AppendText(Mssg + Environment.NewLine); - RhTxBxActions.SelectionStart = RhTxBxActions.Text.Length; - RhTxBxActions.SelectionColor = SystemColors.Control; - RhTxBxActions.ScrollToCaret(); + if (Lvl == Level.ERROR) + Logging.LogErrorMessage(Mssg); + + else if (Lvl == Level.WARNING) + Logging.LogWarningMessage(Mssg); + + else if (Lvl == Level.DEBUG) + Logging.LogMessage("[DEBUG]" + Mssg); + + else + Logging.LogMessage(Mssg); + + RhTxBxActions.SelectionColor = Lvl switch + { + Level.ERROR => Color.IndianRed, + Level.WARNING => Color.Orange, + Level.DEBUG => Color.LightBlue, + Level.Success => Color.LightGreen, + _ => Color.White + }; + if (Lvl == Level.DEBUG) + RhTxBxActions.AppendText("[DEBUG] " + Mssg + Environment.NewLine); + else + RhTxBxActions.AppendText(Mssg + Environment.NewLine); + RhTxBxActions.SelectionStart = RhTxBxActions.Text.Length; + RhTxBxActions.SelectionColor = SystemColors.Control; + RhTxBxActions.ScrollToCaret(); } @@ -1444,26 +1444,7 @@ namespace AiQ_GUI } BtnFactoryDefault.BackColor = Color.Green; } - - // ***** Test & Debug ***** - private async void BtnTest_Click(object sender, EventArgs e) - { - Stopwatch stopWatchTest = Stopwatch.StartNew(); - - //StatsExcel excelExporter = new(); - //excelExporter.ExportDatabaseToExcel(); - //await MobileTests.CheckFirmwareAsync(); - //FlexiAPI.GetVersions(CamOnTest.IP).Wait(); - //VLC.Play(VidView); - //await Task.Delay(5000); - //VLC.TakeSnapshot(VidView); - SSH.MobiletxtCheck("100.118.196.113"); - - // await MobileAPI.SetDayModeAsync(); - - AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.LOG); - } - public static Label MakeNewLabel(string text, bool isRed, int yLoc) +public static Label MakeNewLabel(string text, bool isRed, int yLoc) { return new Label { @@ -1504,6 +1485,25 @@ namespace AiQ_GUI VLC.Play(VidView); } } + // ***** Test & Debug ***** + private async void BtnTest_Click(object sender, EventArgs e) + { + Stopwatch stopWatchTest = Stopwatch.StartNew(); + + //StatsExcel excelExporter = new(); + //excelExporter.ExportDatabaseToExcel(); + //await MobileTests.CheckFirmwareAsync(); + //FlexiAPI.GetVersions(CamOnTest.IP).Wait(); + //VLC.Play(VidView); + //await Task.Delay(5000); + //VLC.TakeSnapshot(VidView); + SSH.MobiletxtCheck("100.118.196.113"); + + // await MobileAPI.SetDayModeAsync(); + + AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"), Level.DEBUG); + } + } } diff --git a/AiQ_GUI.resx b/AiQ_GUI.resx index 0bef68b..3ba17b2 100644 --- a/AiQ_GUI.resx +++ b/AiQ_GUI.resx @@ -123,9 +123,6 @@ 159, 17 - - 17, 17 - 531, 18 diff --git a/Mobile Tests/Mobile API.cs b/MobileTests/MobileAPI.cs similarity index 94% rename from Mobile Tests/Mobile API.cs rename to MobileTests/MobileAPI.cs index 6a91de2..13606fe 100644 --- a/Mobile Tests/Mobile API.cs +++ b/MobileTests/MobileAPI.cs @@ -11,6 +11,10 @@ namespace AiQ_GUI.Mobile_Tests { public static class MobileAPI { + // Login credentials + private const string DefaultUsername = "ADMIN"; + private const string DefaultPassword = "1234"; + public static async Task CheckFirmwareAsync() { using HttpClient client = new HttpClient @@ -21,7 +25,7 @@ namespace AiQ_GUI.Mobile_Tests try { // Login and get JWT token - string token = await LoginAsync(client, "ADMIN", "1234"); + string token = await LoginAsync(client, DefaultUsername, DefaultPassword); // Attach JWT to all requests client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); @@ -87,7 +91,7 @@ namespace AiQ_GUI.Mobile_Tests try { // Login - string token = await LoginAsync(client, "ADMIN", "1234"); + string token = await LoginAsync(client, DefaultUsername, DefaultPassword); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token); var payload = new diff --git a/Mobile Tests/Mobile Tests.cs b/MobileTests/MobileTests.cs similarity index 100% rename from Mobile Tests/Mobile Tests.cs rename to MobileTests/MobileTests.cs diff --git a/Mobile Tests/VLC.cs b/MobileTests/VLC.cs similarity index 80% rename from Mobile Tests/VLC.cs rename to MobileTests/VLC.cs index 8ef94fc..a0b417a 100644 --- a/Mobile Tests/VLC.cs +++ b/MobileTests/VLC.cs @@ -40,11 +40,4 @@ internal class VLC { VLCVV.MediaPlayer.Stop(); } - - public static void Capture(VideoView VLCVV) - { - var media = new Media(libVLC, $"rtsp://ADMIN:1234@{MainForm.Instance.CamOnTest.IP}:554/live/main", FromType.FromLocation); - media.AddOption(":rtsp-tcp"); - VLCVV.MediaPlayer.Play(media); - } } diff --git a/Network.cs b/Network.cs index 452bc62..c2f199a 100644 --- a/Network.cs +++ b/Network.cs @@ -97,7 +97,7 @@ namespace AiQ_GUI byte[] discoveryPacket = [ 0x50, 0x4f, 0x4c, 0x4c, 0xaf, 0xb0, 0xb3, 0xb3, - 0xb6, 0x01, 0xa8, 0xc0, 0x0b, 0x1a, 0x00, 0x00 + 0xb6, 0x01, 0xa8, 0xc0, 0x0b, 0x1a, 0x00, 0x00 ]; async Task SendAndListen(IPAddress localIp)