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
This commit is contained in:
2026-01-15 16:36:17 +00:00
parent 4c74e237c2
commit 4dace8edef
9 changed files with 67 additions and 79 deletions

View File

@@ -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

2
AiQ_GUI.Designer.cs generated
View File

@@ -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;
//

View File

@@ -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<TabPage>();
List<TabPage> tabsToInsert = new List<TabPage>();
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);
@@ -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);
}
}
}

View File

@@ -123,9 +123,6 @@
<metadata name="ToolTipClipboard.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>159, 17</value>
</metadata>
<metadata name="ToolTipAvailable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="TimerDDC.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>531, 18</value>
</metadata>

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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)