V4.3 Changes - Bradley B

This commit is contained in:
2025-11-04 12:56:16 +00:00
parent 1c89cf2847
commit dd8e87258f
6 changed files with 215 additions and 18 deletions

View File

@@ -18,6 +18,8 @@ namespace AiQ_GUI
private List<Camera> soakCameraList = [];
private List<CancellationTokenSource> soakCtsList = [];
private List<Task> soakTasks = [];
const string GoogleDrivePath = @"G:\Shared drives\MAV Production GUI's\AiQ\GUI's\";
// Colours
public static readonly Color BtnColour = Color.FromArgb(70, 65, 80);
@@ -304,7 +306,7 @@ namespace AiQ_GUI
{
// Turn off God mode
string[,] GOD_JSON = { { "propGodMode", "false" } };
string IntConf = await FlexiAPI.HTTP_Update("Internal Config", CamOnTest.IP, GOD_JSON);
string IntConf = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", CamOnTest.IP, GOD_JSON);
if (!IntConf.Contains("\"propGodMode\": {\"value\": \"false\", \"datatype\": \"boolean\"},"))
AddToActionsList("Could not turn off God mode");
@@ -925,7 +927,7 @@ namespace AiQ_GUI
try
{
await FlexiAPI.HTTP_Update("Internal Config", CamOnTest.IP, GOD_JSON);
await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", CamOnTest.IP, GOD_JSON);
BtnSetGodMode.Text = newGodModeValue == "true" ? "Set God Mode Off" : "Set God Mode On";
BtnSetGodMode.BackColor = Color.Green;
}
@@ -1171,7 +1173,7 @@ namespace AiQ_GUI
try
{
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera
string RESP = await FlexiAPI.HTTP_Update("Internal Config", SCL.IP, GOD_JSON);
string RESP = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, GOD_JSON);
Instance.AddToActionsList($"Setting God mode for camera {SCL.IP} to {newGodModeValue}", false);
}
catch (Exception ex)
@@ -1580,12 +1582,27 @@ namespace AiQ_GUI
{
if (!SCL.IsChecked)
continue;
try
{
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera, cannot be done in soak test finally becuase of this.
await CameraModules.FactoryResetModules(SCL.IP); // Reset camera modules
Network.Initialize("developer", SCL.DevPass); // Ensure network is initialized to the right camera, cannot be done in soak test finally becuase of this.
await CameraModules.FactoryResetModules(SCL.IP);
string[,] godJson = { { "propGodMode", "false" } }; // Set God mode explicitly off
string GOD = await FlexiAPI.HTTP_Update("GLOBAL--FlexiApplication", SCL.IP, godJson);
if (GOD.Contains("Error"))
throw new Exception("Could not set God mode off");
bool Pass = await FlexiAPI.ChangeNetwork211(SCL.IP); // set camera to 211
if (!Pass)
throw new Exception("Could not set camera to 211");
}
catch (Exception ex)
{
AddToActionsList("Failed to set God mode, reset camera modules or 211 for camera " + SCL.IP + ". Reason: " + ex.Message);
}
}
}
}
}
private void CkBxTickAll_CheckedChanged(object sender, EventArgs e)
{
@@ -1668,7 +1685,7 @@ namespace AiQ_GUI
{
string apiUrl = $"http://{cam.IP}/upload/software-update/2";
Network.Initialize("developer", cam.DevPass);
await Task.Delay(1000); // Gives extra time to allow for Network to initialize
AddToActionsList($"Uploading to {cam.IP}...", false);
string result = await FlexiAPI.SendBlobFileUpload(apiUrl, fileToUpload, fileName);
@@ -1706,11 +1723,122 @@ namespace AiQ_GUI
{
Stopwatch stopWatchTest = Stopwatch.StartNew();
StatsExcel excelExporter = new();
excelExporter.ExportDatabaseToExcel();
//StatsExcel excelExporter = new();
//excelExporter.ExportDatabaseToExcel();
FakeCamera fakeCamera = new FakeCamera(80); // Create an instance of FakeCamera
//CamOnTest.IP = CbBxFoundCams.Text;
_ = fakeCamera.StartAsync(CAMTYPE.GOOD).ContinueWith(task =>
{
//Network.Initialize("developer", "Pass123");
if (task.IsFaulted)
{
AddToActionsList("Error starting FakeCamera: " + task.Exception?.Message);
}
else
{
AddToActionsList($"FakeCamera started successfully. IP: {fakeCamera}", false);
}
});
await Task.Delay(3000); // Wait for server to start
CbBxFoundCams.Text = "localhost"; // Should force update in creds an network reinit
CmBoFoundCams_TextChanged(sender, e);
CbBxCameraType.SelectedIndex = CbBxCameraType.Items.Count - 1; // Selects AB12CD as model number
await Task.Delay(3000); // Wait for server to start
BtnStartTest_Click(sender, e);
stopWatchTest.Stop();
AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff"));
}
private async Task UploadWonwooSet(string ipAddress, bool isIR)
{
string fileToUpload = null;
using OpenFileDialog openFileDialog1 = new()
{
InitialDirectory = GoogleDrivePath,
Filter = "CSV files (*.csv)|*.csv",
FilterIndex = 0
};
if (openFileDialog1.ShowDialog() == DialogResult.OK)
fileToUpload = openFileDialog1.FileName;
else
{
AddToActionsList("File selection cancelled.", false);
return;
}
//Filename validation
string filename = Path.GetFileName(fileToUpload).ToUpper();
if (isIR)
{
if (!filename.Contains("IR") || filename.Contains("OV"))
{
AddToActionsList("Incorrect file selected. Expected IR file.", false);
return;
}
}
else // OV
{
if (!filename.Contains("OV") || filename.Contains("IR"))
{
AddToActionsList("Incorrect file selected. Expected OV file.", false);
return;
}
}
var lines = File.ReadAllLines(fileToUpload);
for (int i = 1; i < lines.Length; i++)
{
var parts = lines[i].Split(',')
.Select(p => p.Trim())
.ToArray();
if (parts.Length < 3)
{
AddToActionsList($"Invalid row format at line {i + 1}", false);
continue;
}
string name = parts[0];
string command = parts[1];
string expectedResponse = parts[2];
// VISCA format check
if (!RegexCache.VISCAAPIRegex().IsMatch(command))
{
AddToActionsList($"{name}: Invalid VISCA command ({command})", false);
continue; // do not send it if bad
}
string result = await FlexiAPI.APIHTTPVISCA(ipAddress, command, isIR);
if (result.Contains(expectedResponse))
AddToActionsList($"{name}: Success ({(isIR ? "IR" : "Colour")})", true);
else
AddToActionsList($"{name}: Unexpected response ({result})", false);
await Task.Delay(150);
}
AddToActionsList($"Upload complete ({(isIR ? "IR" : "Colour")}).", true);
}
private async void UploadWonwooSetOV_Click(object sender, EventArgs e)
{
await UploadWonwooSet(CbBxFoundCams.Text, false); // false = Colour
}
private async void UploadWonwooSetIR_Click(object sender, EventArgs e)
{
await UploadWonwooSet(CbBxFoundCams.Text, true); // true = Infrared
}
}
}