From b158d9abe5353f9797ff6615f7261c6361f2e6a4 Mon Sep 17 00:00:00 2001 From: rennmaus-coder <77056626+rennmaus-coder@users.noreply.github.com> Date: Sat, 18 Jan 2025 10:44:56 +0100 Subject: [PATCH 1/3] there is no on => true fix :( --- ninaAPI/api_spec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ninaAPI/api_spec.yaml b/ninaAPI/api_spec.yaml index 8c55416..fb8f69a 100644 --- a/ninaAPI/api_spec.yaml +++ b/ninaAPI/api_spec.yaml @@ -1225,10 +1225,11 @@ paths: description: Set the light on the flatdevice parameters: - in: query - name: "on" + name: on schema: type: boolean required: true + description: The actual parameter name is "on", but for some reason the documentation automatically renames it to true... responses: "200": description: Successful response From 780c959b36b878ca59eab65788c6d5725e3c8281 Mon Sep 17 00:00:00 2001 From: rennmaus-coder <77056626+rennmaus-coder@users.noreply.github.com> Date: Sun, 19 Jan 2025 15:46:16 +0100 Subject: [PATCH 2/3] implement guider calibrate --- ninaAPI/Properties/AssemblyInfo.cs | 4 ++-- ninaAPI/WebService/V2/Equipment/Guider.cs | 4 ++-- ninaAPI/api_spec.yaml | 11 +++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ninaAPI/Properties/AssemblyInfo.cs b/ninaAPI/Properties/AssemblyInfo.cs index 3e2aa05..4e0664b 100644 --- a/ninaAPI/Properties/AssemblyInfo.cs +++ b/ninaAPI/Properties/AssemblyInfo.cs @@ -6,8 +6,8 @@ // [MANDATORY] The assembly versioning //Should be incremented for each new build of a plugin -[assembly: AssemblyVersion("2.1.3.0")] // last one is for beta -[assembly: AssemblyFileVersion("2.1.3.0")] +[assembly: AssemblyVersion("2.1.4.0")] // last one is for beta +[assembly: AssemblyFileVersion("2.1.4.0")] // [MANDATORY] The name of your plugin [assembly: AssemblyTitle("Advanced API")] diff --git a/ninaAPI/WebService/V2/Equipment/Guider.cs b/ninaAPI/WebService/V2/Equipment/Guider.cs index bc6a100..d5059bf 100644 --- a/ninaAPI/WebService/V2/Equipment/Guider.cs +++ b/ninaAPI/WebService/V2/Equipment/Guider.cs @@ -185,7 +185,7 @@ public async Task GuiderDisconnect() } [Route(HttpVerbs.Get, "/equipment/guider/start")] - public async Task GuiderStart() + public async Task GuiderStart([QueryField] bool calibrate) { HttpResponse response = new HttpResponse(); @@ -197,7 +197,7 @@ public async Task GuiderStart() { GuideToken?.Cancel(); GuideToken = new CancellationTokenSource(); - await guider.StartGuiding(false, AdvancedAPI.Controls.StatusMediator.GetStatus(), GuideToken.Token); + await guider.StartGuiding(calibrate, AdvancedAPI.Controls.StatusMediator.GetStatus(), GuideToken.Token); response.Response = "Guiding started"; } else diff --git a/ninaAPI/api_spec.yaml b/ninaAPI/api_spec.yaml index fb8f69a..6e8c252 100644 --- a/ninaAPI/api_spec.yaml +++ b/ninaAPI/api_spec.yaml @@ -1,8 +1,8 @@ openapi: 3.0.0 info: title: Advanced API - description: This is the API documentation for the NINA plugin Advanced API. This documentation applies to plugin version 2.1.3.* - version: 2.1.3 + description: This is the API documentation for the NINA plugin Advanced API. This documentation applies to plugin version 2.1.4.* + version: 2.1.4 servers: - url: http://localhost:1888/v2/api description: V2 api server @@ -1754,6 +1754,13 @@ paths: - Guider summary: Start Guiding description: Start guiding + parameters: + - in: query + name: calibrate + description: Whether to force the guider to calibrate before start guiding + required: false + schema: + type: boolean responses: "200": description: Successful response From 6a0a2511299c8c82aa1b2957d0214b281876a5c8 Mon Sep 17 00:00:00 2001 From: rennmaus-coder <77056626+rennmaus-coder@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:49:25 +0100 Subject: [PATCH 3/3] add `clear-calibration`; use reflection to get `State` in info; guider `graph` --- ninaAPI/WebService/V2/Equipment/Guider.cs | 71 ++++++++- ninaAPI/api_spec.yaml | 170 ++++++++++++++++++++++ 2 files changed, 239 insertions(+), 2 deletions(-) diff --git a/ninaAPI/WebService/V2/Equipment/Guider.cs b/ninaAPI/WebService/V2/Equipment/Guider.cs index d5059bf..b10d0b3 100644 --- a/ninaAPI/WebService/V2/Equipment/Guider.cs +++ b/ninaAPI/WebService/V2/Equipment/Guider.cs @@ -12,10 +12,15 @@ This Source Code Form is subject to the terms of the Mozilla Public using EmbedIO; using EmbedIO.Routing; using EmbedIO.WebApi; +using NINA.Core.Enum; using NINA.Core.Interfaces; using NINA.Core.Utility; +using NINA.Equipment.Equipment; using NINA.Equipment.Equipment.MyGuider; +using NINA.Equipment.Interfaces; using NINA.Equipment.Interfaces.Mediator; +using NINA.Equipment.Interfaces.ViewModel; +using NINA.WPF.Base.Mediator; using ninaAPI.Utility; using System; using System.Collections.Generic; @@ -26,7 +31,7 @@ namespace ninaAPI.WebService.V2 { public class GuideInfo { - public GuideInfo(GuiderInfo inf, GuideStep step) + public GuideInfo(GuiderInfo inf, GuideStep step, string state) { Connected = inf.Connected; Name = inf.Name; @@ -42,6 +47,8 @@ public GuideInfo(GuiderInfo inf, GuideStep step) RMSError = inf.RMSError; PixelScale = inf.PixelScale; LastGuideStep = step; + + State = state; } public bool Connected { get; set; } @@ -63,6 +70,7 @@ public GuideInfo(GuiderInfo inf, GuideStep step) public double PixelScale { get; set; } public GuideStep LastGuideStep { get; set; } + public string State { get; set; } } public class GuideStep @@ -120,7 +128,9 @@ public void GuiderInfo() { IGuiderMediator guider = AdvancedAPI.Controls.Guider; - GuideInfo info = new GuideInfo(guider.GetInfo(), lastGuideStep); + IGuider g = (IGuider)guider.GetDevice(); + + GuideInfo info = new GuideInfo(guider.GetInfo(), lastGuideStep, g?.State); response.Response = info; } catch (Exception ex) @@ -241,5 +251,62 @@ public async Task GuiderStop() HttpContext.WriteToResponse(response); } + + [Route(HttpVerbs.Get, "/equipment/guider/clear-calibration")] + public async Task ClearCalibration() + { + HttpResponse response = new HttpResponse(); + + try + { + IGuiderMediator guider = AdvancedAPI.Controls.Guider; + + if (guider.GetInfo().Connected) + { + response.Success = await guider.ClearCalibration(new CancellationTokenSource().Token); + response.Response = "Calibration cleared"; + } + else + { + response = CoreUtility.CreateErrorTable(new Error("Guider not connected", 409)); + } + } + catch (Exception ex) + { + Logger.Error(ex); + response = CoreUtility.CreateErrorTable(CommonErrors.UNKNOWN_ERROR); + } + + HttpContext.WriteToResponse(response); + } + + [Route(HttpVerbs.Get, "/equipment/guider/graph")] + public void GuiderGraph() + { + HttpResponse response = new HttpResponse(); + + try + { + IGuiderMediator guider = AdvancedAPI.Controls.Guider; + + var handlerField = guider.GetType().GetField("handler", + System.Reflection.BindingFlags.NonPublic | + System.Reflection.BindingFlags.Instance | + System.Reflection.BindingFlags.FlattenHierarchy); + + IGuiderVM gvm = (IGuiderVM)handlerField.GetValue(guider); + var guiderProperty = gvm.GetType().GetProperty("GuideStepsHistory"); + + GuideStepsHistory history = (GuideStepsHistory)guiderProperty.GetValue(gvm); + response.Response = history; + } + catch (Exception ex) + { + Logger.Error(ex); + response = CoreUtility.CreateErrorTable(CommonErrors.UNKNOWN_ERROR); + } + + HttpContext.WriteToResponse(response); + } } } diff --git a/ninaAPI/api_spec.yaml b/ninaAPI/api_spec.yaml index 6e8c252..9a07b99 100644 --- a/ninaAPI/api_spec.yaml +++ b/ninaAPI/api_spec.yaml @@ -1871,6 +1871,84 @@ paths: schema: $ref: "#/components/schemas/UnknownError" + /equipment/guider/clear-calibration: + get: + tags: + - Guider + summary: Clear Calibration + description: Clears the calibration data, forces the guider to recalibrate when it starts guiding + responses: + "200": + description: Successful response + content: + application/json: + schema: + type: object + properties: + Response: + type: string + example: Calibration cleared + Error: + type: string + example: "" + StatusCode: + type: integer + example: 200 + Success: + type: boolean + example: true + Type: + type: string + example: "API" + "409": + description: Guider not connected + content: + application/json: + schema: + type: object + properties: + Response: + type: string + example: "" + Error: + type: string + example: Guider not connected + StatusCode: + type: integer + example: 409 + Success: + type: boolean + example: false + Type: + type: string + example: "API" + "500": + description: Internal server error, Unknown error + content: + application/json: + schema: + $ref: "#/components/schemas/UnknownError" + + /equipment/guider/graph: + get: + tags: + - Guider + summary: Graph + description: Gets the last n guide steps needed to construct a graph, with n being the number of saved steps as configured on the graph in NINA + responses: + "200": + description: Successful response + content: + application/json: + schema: + $ref: "#/components/schemas/GuideStepsHistory" + "500": + description: Internal server error, Unknown error + content: + application/json: + schema: + $ref: "#/components/schemas/UnknownError" + /equipment/mount/info: get: tags: @@ -4894,6 +4972,14 @@ components: - DECDistanceRaw - RADuration - DECDuration + State: + type: string + enum: + - Looping + - LostLock + - Guiding + - Stopped + - Calibrating required: - Connected - CanClearCalibration @@ -6341,6 +6427,7 @@ components: GlobalTriggers: type: array items: {} + Error: type: string example: "" @@ -6354,6 +6441,89 @@ components: type: string example: "API" + GuideStepsHistory: + type: object + properties: + Response: + type: object + properties: + RMS: + type: object + properties: + RA: + type: number + Dec: + type: number + Total: + type: number + RAText: + type: string + DecText: + type: string + TotalText: + type: string + PeakRAText: + type: string + PeakDecText: + type: string + Scale: + type: number + PeakRA: + type: number + PeakDec: + type: number + DataPoints: + type: integer + Interval: + type: integer + MaxY: + type: integer + MinY: + type: integer + MaxDurationY: + type: integer + MinDurationY: + type: integer + GuideSteps: + type: array + items: + type: object + properties: + Id: + type: integer + IdOffsetLeft: + type: number + IdOffsetRight: + type: number + RADistanceRaw: + type: number + RADistanceRawDisplay: + type: number + RADuration: + type: integer + DECDistanceRaw: + type: number + DECDistanceRawDisplay: + type: number + DECDuration: + type: integer + Dither: + type: string + HistorySize: + type: integer + PixelScale: + type: number + Scale: + type: integer + Error: + type: string + StatusCode: + type: integer + Success: + type: boolean + Type: + type: string + UnknownError: type: object properties: