Skip to content

Commit

Permalink
Merge pull request #17 from christian-photo/2.1.4.0
Browse files Browse the repository at this point in the history
2.1.4.0
  • Loading branch information
christian-photo authored Jan 22, 2025
2 parents 5c5dff1 + 6a0a251 commit dbe9009
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ninaAPI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
75 changes: 71 additions & 4 deletions ninaAPI/WebService/V2/Equipment/Guider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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; }
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -185,7 +195,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();

Expand All @@ -197,7 +207,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
Expand Down Expand Up @@ -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);
}
}
}
184 changes: 181 additions & 3 deletions ninaAPI/api_spec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1753,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
Expand Down Expand Up @@ -1863,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:
Expand Down Expand Up @@ -4886,6 +4972,14 @@ components:
- DECDistanceRaw
- RADuration
- DECDuration
State:
type: string
enum:
- Looping
- LostLock
- Guiding
- Stopped
- Calibrating
required:
- Connected
- CanClearCalibration
Expand Down Expand Up @@ -6333,6 +6427,7 @@ components:
GlobalTriggers:
type: array
items: {}

Error:
type: string
example: ""
Expand All @@ -6346,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:
Expand Down

0 comments on commit dbe9009

Please sign in to comment.