• Added null-checks so labels are created dynamically when lblVorI is null (uses MainForm.Instance.AddLabelToPanel). • Camera/CameraModules.cs • Added null-label handling to create dynamic module labels with the correct content (OK or the error message). • AiQ_GUI.cs • Increased dynamic label width in MakeNewLabel from 220 → 700 to avoid truncated messages. • Succesfully ran through a pre-test with dynamic labels
87 lines
2.9 KiB
C#
87 lines
2.9 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()?.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);
|
|
}
|
|
else if (version == UniversalData.SRZFirmware)
|
|
{
|
|
MainForm.Instance.AddToActionsList($"Firmware match successful: {version}",Level.Success);
|
|
}
|
|
else
|
|
{
|
|
MainForm.Instance.AddToActionsList($"Firmware mismatch: Camera has {version}, expected {UniversalData.SRZFirmware}",Level.ERROR);
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|