Files
AiQ_GUI/Mobile Tests/MobilePreTest.cs
Bradley Born 872be2e105 Changes:
- Code refactored, DIagsPt1 and 2 moved into there own folder called DIagnostics
- Pre tests and final tests moved into a AiQ tests
- Mobile Pre Tests  added
- Mobile pre test - Added firmware check for the SRZ
2025-12-22 14:37:43 +00:00

86 lines
2.5 KiB
C#

using AiQ_GUI;
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public static class MobilePreTest
{
public static async Task CheckFirmwareAsync()
{
const string cameraIp = "192.168.0.112";
using HttpClient client = new HttpClient
{
BaseAddress = new Uri($"http://{cameraIp}")
};
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();
MainForm.Instance.AddToActionsList(
$"Firmware check response: {(int)response.StatusCode} {response.StatusCode} | {body}",
Level.LOG);
response.EnsureSuccessStatusCode();
JsonElement json =
JsonSerializer.Deserialize<JsonElement>(body);
string version =
json.GetProperty("version").GetString();
MainForm.Instance.AddToActionsList(
$"Current firmware version: {version}",
Level.Success);
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList(
$"Firmware check failed: {ex.Message}",
Level.ERROR);
}
}
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();
}
}