From 78c440ab7624e2bba3d1c99d63c178e140e25871 Mon Sep 17 00:00:00 2001 From: Bradley Relyea Date: Tue, 4 Nov 2025 13:16:07 +0000 Subject: [PATCH] Updated other uses of Internal Config to GLOBAL--FlexiApplication --- AiQ_GUI.Designer.cs | 1 + AiQ_GUI.cs | 34 +++++++++++++++++++++++++--------- AiQ_GUI_NET_Test.csproj | 2 +- Camera/FlexiAPI.cs | 1 - FakeCamera/FakeCamera.cs | 2 +- GoogleAPI.cs | 2 +- Microsoft/Teams.cs | 6 +++--- Network.cs | 17 +++++++++++++++-- 8 files changed, 47 insertions(+), 18 deletions(-) diff --git a/AiQ_GUI.Designer.cs b/AiQ_GUI.Designer.cs index 1b71868..123b209 100644 --- a/AiQ_GUI.Designer.cs +++ b/AiQ_GUI.Designer.cs @@ -587,6 +587,7 @@ namespace AiQ_GUI BtnTest.TabIndex = 189; BtnTest.Text = "Test"; BtnTest.UseVisualStyleBackColor = false; + BtnTest.Visible = false; BtnTest.Click += BtnTest_Click; // // PicBxIRF2 diff --git a/AiQ_GUI.cs b/AiQ_GUI.cs index ce5b312..3b4836c 100644 --- a/AiQ_GUI.cs +++ b/AiQ_GUI.cs @@ -304,7 +304,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"); @@ -397,15 +397,14 @@ namespace AiQ_GUI List oblistCD = [CamOnTest.Model, FullFailureValues]; GoogleAPI.WriteToSS(oblistCD, "'Approval'!C" + nextRow + ":D" + nextRow, GoogleAPI.spreadsheetId_ModelInfo); - //await Teams.SendMssg(Convert.ToString(nextRow), CbBxUserName.Text); - GoogleAPI.EmailApproval(Convert.ToString(nextRow), CbBxUserName.Text); + await Teams.SendMssg(Convert.ToString(nextRow), CbBxUserName.Text); + //GoogleAPI.EmailApproval(Convert.ToString(nextRow), CbBxUserName.Text); string Approved = ""; while (Approved != "TRUE") { await Task.Delay(1000); - values = GoogleAPI.service.Spreadsheets.Values.Get(GoogleAPI.spreadsheetId_ModelInfo, "'Approval'!B" + nextRow).Execute().Values; if (values?.Count > 0) @@ -925,7 +924,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 +1170,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,9 +1579,24 @@ 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); + } } } } @@ -1702,13 +1716,15 @@ namespace AiQ_GUI } // ***** Test & Debug ***** - private async void BtnTest_Click(object sender, EventArgs e) + private void BtnTest_Click(object sender, EventArgs e) { Stopwatch stopWatchTest = Stopwatch.StartNew(); StatsExcel excelExporter = new(); excelExporter.ExportDatabaseToExcel(); + // /api/config-ids - For getting all available config IDs + stopWatchTest.Stop(); AddToActionsList("RunTime " + stopWatchTest.Elapsed.ToString(@"hh\:mm\:ss\.ff")); } diff --git a/AiQ_GUI_NET_Test.csproj b/AiQ_GUI_NET_Test.csproj index b9e480a..884eb62 100644 --- a/AiQ_GUI_NET_Test.csproj +++ b/AiQ_GUI_NET_Test.csproj @@ -16,7 +16,7 @@ AiQ GUI MAV Systems Ltd AiQ GUI - 4.0.0 + 4.2.0 A GUI to control and test the AiQ MAV Systems Ltd 2025 MAV - Plain - Blue.png diff --git a/Camera/FlexiAPI.cs b/Camera/FlexiAPI.cs index 8bb572e..053dbe4 100644 --- a/Camera/FlexiAPI.cs +++ b/Camera/FlexiAPI.cs @@ -36,7 +36,6 @@ namespace AiQ_GUI { string JSONdata = BuildJsonUpdate(jsonArrayData, ID); JSONdata = JSONdata.Replace("\"14\"", "14").Replace("\"30\"", "30"); // Fixes & encoding issue - MainForm.Instance.AddToActionsList(JSONdata); string url = $"http://{IPAddress}/api/update-config"; return await Network.SendHttpRequest(url, HttpMethod.Post, 2, JSONdata); } diff --git a/FakeCamera/FakeCamera.cs b/FakeCamera/FakeCamera.cs index e14ef55..1a91f16 100644 --- a/FakeCamera/FakeCamera.cs +++ b/FakeCamera/FakeCamera.cs @@ -293,7 +293,7 @@ namespace AiQ_GUI { await HTTPReplySetup(context, "Update successful.", 200, "text/plain"); } - else if (fo.Id == "Internal Config") + else if (fo.Id == "GLOBAL--FlexiApplication") { string SerialNumber = ""; string ModelNumber = ""; diff --git a/GoogleAPI.cs b/GoogleAPI.cs index b2f27e6..df807e9 100644 --- a/GoogleAPI.cs +++ b/GoogleAPI.cs @@ -297,7 +297,7 @@ namespace AiQ_GUI } // Build the MIME message with attachment - using MailMessage mail = new MailMessage(); + using MailMessage mail = new(); mail.From = new MailAddress("me"); mail.To.Add("richard.porter@mav-systems.com"); mail.To.Add("bradley.relyea@mav-systems.com"); diff --git a/Microsoft/Teams.cs b/Microsoft/Teams.cs index 0adf4d7..ea1fc74 100644 --- a/Microsoft/Teams.cs +++ b/Microsoft/Teams.cs @@ -7,9 +7,9 @@ namespace AiQ_GUI { const string webhookUrl = "https://default71bd136a1c65418fb59e927135629c.ac.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/b27c5192e83f4f48b20c1b115985b0b3/triggers/manual/paths/invoke/?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=1-eCbYXms6xInRKHwz3tgAcdQ9x7CSjl3Yzw2V_1MlA"; - public static async Task SendMssg(string ApprovalRow, string User) // Sometimes You will need to reauthenticate the workflow + public static async Task SendMssg(string ApprovalRow, string User) // Sometimes You will need to reauthenticate the workflow { - using HttpClient client = new HttpClient(); + using HttpClient client = new(); string link = $"https://docs.google.com/spreadsheets/d/1bCcCr4OYqfjmydt6UqtmN4FQETezXmZRSStJdCCcqZM/edit#gid=1931079354&range=A{ApprovalRow}"; // Has to be parsed like this as teams doesnt hyperlink otherwise @@ -21,7 +21,7 @@ namespace AiQ_GUI }; string json = JsonConvert.SerializeObject(payload); - StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); + StringContent content = new(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(webhookUrl, content); } diff --git a/Network.cs b/Network.cs index e581920..be8fa55 100644 --- a/Network.cs +++ b/Network.cs @@ -1,7 +1,9 @@ -using System.Net; +using System.Diagnostics; +using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; +using System.Threading; namespace AiQ_GUI { @@ -10,7 +12,7 @@ namespace AiQ_GUI public static HttpClient? SingleHTTPClient; public static HttpClient Client => SingleHTTPClient ?? throw new InvalidOperationException("Client not initialized."); - public static void Initialize(string username, string password) + public async static void Initialize(string username, string password) { HttpClientHandler handler = new() { @@ -23,6 +25,17 @@ namespace AiQ_GUI { Timeout = TimeSpan.FromSeconds(20) }; + + bool UP = false; + int i = 0; + + while (!UP) + { + UP = await PingIP("8.8.8.8"); + await Task.Delay(500); + if (i >= 5) MainForm.Instance.AddToActionsList($"Could not initialise new network with USER: {username} & PSWD: {password}"); // Try 5 times max + i++; + } } // Handles get and post to the camera API