V3.14
This commit is contained in:
@@ -71,9 +71,7 @@ namespace AiQ_GUI
|
||||
string OneshotReply = await FlexiAPI.APIHTTPVISCA(IPAddress, "8101041801FF", true); // Oneshot auto focus
|
||||
|
||||
if (!ShutterReply.Contains("41") || !IrisReply.Contains("41") || !GainReply.Contains("41") || !OneshotReply.Contains("41"))
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Could not set Shutter, Iris, Gain correctly" + Environment.NewLine + "Shutter: " + ShutterReply + Environment.NewLine + "Iris: " + IrisReply + Environment.NewLine + "Gain: " + GainReply + Environment.NewLine + "Oneshot: " + OneshotReply);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets back to the latest factory defaults CSV that is in Flexi.
|
||||
|
@@ -49,9 +49,8 @@ namespace AiQ_GUI
|
||||
{
|
||||
try
|
||||
{
|
||||
string JSONdata = "{ \"id\":\"" + ID + "\" }";
|
||||
string url = $"http://{IPAddress}/api/fetch-config";
|
||||
return await Network.SendHttpRequest(url, HttpMethod.Get, Timeout, JSONdata);
|
||||
string url = $"http://{IPAddress}/api/fetch-config?id={ID}";
|
||||
return await Network.SendHttpRequest(url, HttpMethod.Get, Timeout);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -87,14 +86,13 @@ namespace AiQ_GUI
|
||||
try
|
||||
{
|
||||
Network.Client.DefaultRequestHeaders.ExpectContinue = false;
|
||||
MultipartFormDataContent content;
|
||||
|
||||
byte[] fileBytes = await File.ReadAllBytesAsync(filePath).ConfigureAwait(false);
|
||||
MemoryStream ms = new(fileBytes);
|
||||
StreamContent streamContent = new(ms);
|
||||
streamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
|
||||
content = new MultipartFormDataContent { { streamContent, "upload", fileName } };
|
||||
MultipartFormDataContent content = new() { { streamContent, "upload", fileName } };
|
||||
|
||||
using HttpResponseMessage response = await Network.Client.PostAsync(url, content);
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
@@ -189,6 +187,80 @@ namespace AiQ_GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
public static async Task SetTrim(string IPAddress, string LblTxt, int RetryCount = 0) // Sets trim by getting plate postion as metric
|
||||
{
|
||||
Trim trim;
|
||||
string trimData = await APIHTTPRequest("/SightingCreator-plate-positions", IPAddress, 5); // Get plate positions
|
||||
|
||||
try // Deserialise the JSON
|
||||
{
|
||||
Logging.LogMessage("Trim Data: " + trimData);
|
||||
trim = JsonConvert.DeserializeObject<Trim>(trimData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MainForm.Instance.AddToActionsList("Error reading trim JSON - " + trimData);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check no value is -1 (no plate found) or if the positions are identical (one plate found). If it is then try again 3 times
|
||||
if (new[] { trim.infraredX, trim.infraredY, trim.colourX, trim.colourY }.Any(value => value == -1)
|
||||
|| (trim.infraredX == trim.colourX && trim.infraredY == trim.colourY))
|
||||
{
|
||||
if (RetryCount >= 3)
|
||||
{
|
||||
await MainForm.Instance.DisplayOK("Please align trim in webpage then click OK."); // Awaited till OK has been clicked
|
||||
return;
|
||||
}
|
||||
|
||||
await Task.Delay(5000); // Give 5 second delay for it to see a plate
|
||||
await SetTrim(IPAddress, LblTxt, RetryCount++);
|
||||
}
|
||||
|
||||
int offset = 105;
|
||||
|
||||
if (LblTxt == "❌") // Test tube not connected so do the 2.7m check.
|
||||
offset = 98;
|
||||
|
||||
// Horizontal distance offset for 2.7m compared to 30m is 98 pixels. This was empirically found from testing in the car park
|
||||
// Colour camera is to the right of the infrared so it gets the offset.
|
||||
// Using similar triangles going from 2.7m -> 0.65m which is the length of the test tube (Also exactly 1/4 length).
|
||||
// 98 * (29.35/27.3) = 105.35 pixels
|
||||
int OverviewX = trim.colourX + offset;
|
||||
|
||||
if (OverviewX > 1920) // If adding on the offset has pushed it out of limits then remove 0.1
|
||||
{
|
||||
if (OverviewX < 2120 && trim.infraredX > 400) // Within enough of a limit to automatically do it
|
||||
{
|
||||
OverviewX -= 200;
|
||||
trim.infraredX -= 200;
|
||||
}
|
||||
else // Ask user to centre the plate in the field of view
|
||||
{
|
||||
await MainForm.Instance.DisplayOK("Please centralise plate in view THEN press OK"); // Awaited till OK has been clicked
|
||||
|
||||
if (RetryCount >= 3)
|
||||
{
|
||||
await MainForm.Instance.DisplayOK("Please align trim in webpage then click OK."); // Awaited till OK has been clicked
|
||||
return;
|
||||
}
|
||||
await Task.Delay(5000); // Give 5 second delay for it to see a plate
|
||||
await SetTrim(IPAddress, LblTxt, RetryCount++);
|
||||
}
|
||||
}
|
||||
|
||||
// Compensated trim values, therefore should be close to 0,0 with limits of ±5% of 1920 and 1080 respectivly being ±96 and ±54
|
||||
int TrimX = trim.infraredX - OverviewX;
|
||||
int TrimY = trim.infraredY - trim.colourY;
|
||||
|
||||
// Update trim values
|
||||
string[,] Trim_JSON = { { "propInterCameraOffsetX", Convert.ToString(TrimX) }, { "propInterCameraOffsetY", Convert.ToString(TrimY) } };
|
||||
string TrimResp = await HTTP_Update("SightingCreator", IPAddress, Trim_JSON);
|
||||
|
||||
if (!TrimResp.Contains($"\"propInterCameraOffsetX\": {{\"value\": \"{Convert.ToString(TrimX)}\", \"datatype\": \"int\"}}, \"propInterCameraOffsetY\": {{\"value\": \"{Convert.ToString(TrimY)}\", \"datatype\": \"int\"}},"))
|
||||
MainForm.Instance.AddToActionsList("Could not set camera trim");
|
||||
}
|
||||
|
||||
// Processes the network config from the camera and returns a string indicating the status
|
||||
public static async Task<string> ProcessNetworkConfig(string IPAddress)
|
||||
{
|
||||
@@ -210,7 +282,7 @@ namespace AiQ_GUI
|
||||
}
|
||||
|
||||
// Knowing the format this builds the message to send to AiQ
|
||||
private static string BuildJsonUpdate(string[,] jsonData, string id)
|
||||
public static string BuildJsonUpdate(string[,] jsonData, string id)
|
||||
{
|
||||
if (jsonData == null || jsonData.GetLength(1) != 2)
|
||||
throw new ArgumentException("Input data must be a non-null 2D array with two columns.");
|
||||
|
@@ -14,7 +14,7 @@ namespace AiQ_GUI
|
||||
|
||||
try
|
||||
{
|
||||
using SshClient client = new SshClient(IPAddress, SSHUsername, SSHPassword);
|
||||
using SshClient client = new(IPAddress, SSHUsername, SSHPassword);
|
||||
client.Connect();
|
||||
|
||||
try
|
||||
|
Reference in New Issue
Block a user