Files
AiQ_GUI/Mobile Tests/MobileTests.cs
Bradley Born 4a2e874b9d - Replaced single TabPage CurrentTab with List<TabPage> CurrentTabs to support multiple tabs.
- Added new tab called Video

- Removed unused tabs on load (Soak, Mobile, Video, Images).

- Refactored InsertCamTab():

- Uses CurrentTabs to manage multiple tabs per camera type.

Mobile → inserts Video + Mobile tabs.
AiQ → inserts Images + Soak tabs.

-Cleans up previous tabs before inserting new ones.

-Updated BtnTest_Click():
Added 5-second delay before snapshot.
Takes snapshot after video starts playing.

- New file created VLC.cs
Streams the given IP into the Video tab and takes a snapshot
2026-01-12 16:30:04 +00:00

96 lines
3.0 KiB
C#

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;
using System.Drawing;
public static class MobilePreTest
{
public static async Task CheckFirmwareAsync()
{
using HttpClient client = new HttpClient
{
BaseAddress = new Uri($"http://{MainForm.Instance.CamOnTest.IP}")
};
try
{
// Login and get JWT token
string token = await LoginAsync(client, "ADMIN", "1234");
// Attach JWT to all requests
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
// Request firmware information
HttpResponseMessage response = await client.GetAsync("/app/v1/system/firmware");
string body = await response.Content.ReadAsStringAsync();
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.AddLabelToPanel($"Firmware = {version}", false);
}
else
{
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);
}
}
private static async Task<string> LoginAsync(HttpClient client, string user, string password)
{
var payload = new
{
userId = user,
userPassword = Sha256(password)
};
HttpResponseMessage response = await client.PostAsJsonAsync("/app/v1/login", payload);
response.EnsureSuccessStatusCode();
JsonElement json = await response.Content.ReadFromJsonAsync<JsonElement>();
return json.GetProperty("token").GetString();
}
private static string Sha256(string input)
{
using SHA256 sha = SHA256.Create();
byte[] bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input));
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
public static async Task RunPreTestAsync()
{
await CheckFirmwareAsync();
}
}