Skip to content

Commit

Permalink
Merge pull request #19 from christian-photo/2.1.6.0
Browse files Browse the repository at this point in the history
2.1.6.0
  • Loading branch information
christian-photo authored Jan 29, 2025
2 parents d91b157 + 6170b02 commit 9475c57
Show file tree
Hide file tree
Showing 26 changed files with 877 additions and 232 deletions.
44 changes: 35 additions & 9 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,59 @@
The changes for each individual beta release can be seen [here](https://github.com/christian-photo/ninaAPI/releases)

## 2.1.6.0

### Changes

- `framing/determine-rotation` added to determine the rotation from the camera
- `camera/set-binning` added to set the binning of the camera, the binning mode has to be supported by the camera
- `camera/capture`:
- URL parameter `omitImage` added to ignore the captured image, use if only the platesolve result is of interest
- URL parameter `stream` added to stream the image, content type will be either image/jpg or image/png
- URL parameter `waitForResult` added to wait for the capture to finish and then return the result. All parameters which you would normally use together with `getResult` will apply here as well
- Added `stream` parameter to `image/{index}` to stream the image, content type will be either image/jpg or image/png
- Added `stream` parameter to `application/screenshot` to stream the image, content type will be either image/jpg or image/png
- New Websocket Events:
- `FOCUSER-USER-FOCUSED`
- `AUTOFOCUS-FINISHED`
- `API-CAPTURE-FINISHED` is sent, when `camera/capture` finishes

## 2.1.5.0
### Changes:
- `mount/flip` added to perfom a meridian flip, the flip will only be executed if it is needed

### Changes

- `mount/flip` added to perform a meridian flip, the flip will only be executed if it is needed
- `mount/slew` slews the mount to the specified ra and dec angles
- `dome/set-follow` to start or stop the dome following the mount
- `dome/sync` to start a sync of mount and scope
- `dome/slew` to slew the dome to the specified azimuth angle (degree)
- `DOME-SLEWED` and `DOME-SYNCED` added as new events in the websocket

## 2.1.4.0
### Changes:

### Changes

- `guider/start` now accepts the parameter calibrate to force a calibration (true / false)
- Guider info now contains a State field indicating what the guider is currently doing
- `guider/clear-calibration` added to clear the current calibration
- `guider/graph` to get the last n guide steps as configured on the guide graph in NINA (in NINA you can set x to be 50, 100, 200 or 400)

## 2.1.3.0
### Changes:

### Changes

- Added query parameter `skipRescan` to all connect endpoints, which can be used to skip the rescanning process resulting in a faster connection
- Some websockets events now include more information:
- Some websocket events now include more information:
- `FILTERWHEEL-CHANGED` includes the previous and new filter
- `FLAT-BRIGHTNESS-CHANGED` includes the previous and new brightness
- `SAFETY-CHANGED` includes the new status
- `image/{index}` now also includes parameters to configure the stretch parameters. These default to the profile default if omitted
- Added `factor`, `blackClipping`, `unlinked` parameters to `image/{index}` to configure the stretch parameters

## 2.1.2.0

**⚠️ THIS UPDATE REMOVES V1 SUPPORT ⚠️**

### Changes:
### Changes

- ⚠️ **Breaking** Removed support for the deprecated v1 api ⚠️
- Added more endpoints to `flatdevice`:
- `flatdevice/set-cover` to open or close the cover
Expand All @@ -43,7 +68,7 @@ The changes for each individual beta release can be seen [here](https://github.c
- The server now automatically picks the next available port to launch the api
- Implemented IMessageBroker for cross Plugin communication. Use Topic `AdvancedAPI.RequestPort` to request the port the api is running on, subscribe to `AdvancedAPI.Port` to recieve the answer. The port is directly written into Content

## 2.1.0.* (betas) and 2.1.1.0
## 2.1.0.\* (betas) and 2.1.1.0

I **heavily** advise everyone still using V1 to start using V2 as V1 is now deprecated and will be removed with the next minor version!
V2 will probably stay for a longer time now, I made some changes behind the scenes that will make it easier to add new features without breaking older versions.
Expand All @@ -53,7 +78,8 @@ The documentation for the [api](https://bump.sh/christian-photo/doc/advanced-api
- It is now possible to add the `Access-Control-Allow-Origin: *` header to make requests via javascript without proxies possible. This does pose a security vulnerability though, so make sure you only enable it when you need to. A proxy may be better suited when in production.
- Eventwatchers are now started independently of the api, therefore Events can still be retrieved using event-history even if the api wasn't running before.

### V2 Changes:
### V2 Changes

- ⚠️ **Breaking** Connection events in the websocket are now seperated into connected and disconnected ⚠️
- ⚠️ **Breaking** Changed the structure of a profile response ⚠️
- ⚠️ **Breaking** Removed the description field from a sequence response, added more specific fields for each item ⚠️
Expand Down
6 changes: 4 additions & 2 deletions ninaAPI/Options.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright © 2024 Christian Palm ([email protected])
Copyright © 2025 Christian Palm ([email protected])
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand Down Expand Up @@ -52,10 +52,12 @@
Margin="0,0,5,0"
VerticalAlignment="Center"
Text="⚠️Use Access-Control-Allow-Origin Header⚠️"
ToolTip="This makes it possible to fetch the api using javascript without having to set up a proxy. However it is advised to setup a proxy for security reasons. Though it is not recommended, it is required for some applications like Touch 'N' Stars" />
ToolTip="This makes it possible to fetch the api using javascript without having to set up a proxy. It is required for some applications like Touch 'N' Stars" />
<CheckBox IsChecked="{Binding UseAccessHeader}" />
</StackPanel>

<TextBlock Margin="0,5,0,0" Text="Access-Control-Allow-Origin is part of the CORS rules and determines which websites are allowed to access a server's data. Without this header, browsers block requests from other domains for security reasons. This is only relevant if the software is accessible via the Internet - in closed networks, such attacks from outside are not possible." />

<Separator
Width="20"
Height="10"
Expand Down
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.5.0")] // last one is for beta
[assembly: AssemblyFileVersion("2.1.5.0")]
[assembly: AssemblyVersion("2.1.6.0")] // last one is for beta
[assembly: AssemblyFileVersion("2.1.6.0")]

// [MANDATORY] The name of your plugin
[assembly: AssemblyTitle("Advanced API")]
Expand Down
23 changes: 18 additions & 5 deletions ninaAPI/Utility/BitmapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
using System.Drawing;
using System.IO;
using System;
using System.Drawing.Drawing2D;

namespace ninaAPI.Utility
{
Expand All @@ -25,31 +26,43 @@ public static string ResizeAndConvertBitmap(BitmapSource source, Size size, int
}

public static string ScaleAndConvertBitmap(BitmapSource source, double scale, int quality)
{
source = ScaleBitmap(source, scale);

string base64 = EncoderToBase64(GetEncoder(source, quality));
return base64;
}

public static BitmapSource ResizeBitmap(BitmapSource source, Size size)
{
return ScaleBitmap(source, size == Size.Empty ? 1 : size.Width / source.Width);
}

public static BitmapSource ScaleBitmap(BitmapSource source, double scale)
{
scale = Math.Clamp(scale, 0.1, 1);

source = new TransformedBitmap(source, new ScaleTransform(scale, scale));

string base64 = EncodeBitmap(source, quality);
return base64;
return source;
}

private static string EncodeBitmap(BitmapSource source, int quality)
public static BitmapEncoder GetEncoder(BitmapSource source, int quality)
{
if (quality < 0)
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(source));

return EncoderToBase64(encoder);
return encoder;
}
else
{
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.QualityLevel = quality;
encoder.Frames.Add(BitmapFrame.Create(source));

return EncoderToBase64(encoder);
return encoder;
}
}

Expand Down
15 changes: 0 additions & 15 deletions ninaAPI/Utility/CoreUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,4 @@ public class HttpResponse
public bool Success { get; set; } = true;
public string Type { get; set; } = TypeAPI;
}

public enum EquipmentType
{
Camera,
Mount,
FilterWheel,
Focuser,
Dome,
Rotator,
Guider,
FlatDevice,
Switch,
SafetyMonitor,
Weather
}
}
54 changes: 27 additions & 27 deletions ninaAPI/WebService/API.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region "copyright"

/*
Copyright © 2024 Christian Palm ([email protected])
Copyright © 2025 Christian Palm ([email protected])
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Expand All @@ -16,7 +16,9 @@ This Source Code Form is subject to the terms of the Mozilla Public
using ninaAPI.Properties;
using ninaAPI.Utility;
using ninaAPI.WebService.V2;
using ninaAPI.WebService.V2.Equipment;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -31,6 +33,8 @@ public class API
private CancellationTokenSource apiToken;
public readonly int Port;

private static List<INinaWatcher> Watchers { get; set; } = new List<INinaWatcher>();

public API(int port)
{
Port = port;
Expand All @@ -49,36 +53,32 @@ public void CreateServer()

public static void StartWatchers()
{
ControllerV2.StartCameraWatchers();
ControllerV2.StartDomeWatchers();
ControllerV2.StartFilterWheelWatchers();
ControllerV2.StartFlatDeviceWatchers();
ControllerV2.StartFocuserWatchers();
ControllerV2.StartGuiderWatchers();
ControllerV2.StartMountWatchers();
ControllerV2.StartRotatorWatchers();
ControllerV2.StartSafetyWatchers();
ControllerV2.StartSwitchWatchers();
ControllerV2.StartWeatherWatchers();
ControllerV2.StartImageWatcher();
ControllerV2.StartLogWatcher();
Watchers.Add(new CameraWatcher());
Watchers.Add(new DomeWatcher());
Watchers.Add(new FilterWheelWatcher());
Watchers.Add(new FlatDeviceWatcher());
Watchers.Add(new FocuserWatcher());
Watchers.Add(new GuiderWatcher());
Watchers.Add(new MountWatcher());
Watchers.Add(new RotatorWatcher());
Watchers.Add(new SafetyWatcher());
Watchers.Add(new SwitchWatcher());
Watchers.Add(new WeatherWatcher());
Watchers.Add(new ImageWatcher());
Watchers.Add(new NinaLogWatcher());

foreach (INinaWatcher watcher in Watchers)
{
watcher.StartWatchers();
}
}

public static void StopWatchers()
{
ControllerV2.StopDomeWatchers();
ControllerV2.StopCameraWatchers();
ControllerV2.StopFilterWheelWatchers();
ControllerV2.StopFlatDeviceWatchers();
ControllerV2.StopFocuserWatchers();
ControllerV2.StopGuiderWatchers();
ControllerV2.StopMountWatchers();
ControllerV2.StopRotatorWatchers();
ControllerV2.StopSafetyWatchers();
ControllerV2.StopSwitchWatchers();
ControllerV2.StopWeatherWatchers();
ControllerV2.StopImageWatcher();
ControllerV2.StopLogWatcher();
foreach (INinaWatcher watcher in Watchers)
{
watcher.StopWatchers();
}
}

public void Start()
Expand Down
46 changes: 39 additions & 7 deletions ninaAPI/WebService/V2/Application/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This Source Code Form is subject to the terms of the Mozilla Public
using System.Windows.Forms;
using System.Windows.Media.Imaging;
using NINA.Image.ImageAnalysis;
using System.IO;
using System.Threading.Tasks;

namespace ninaAPI.WebService.V2
{
Expand Down Expand Up @@ -70,7 +72,7 @@ public void ApplicationSwitchTab([QueryField] string tab)
}

[Route(HttpVerbs.Get, "/application/screenshot")]
public void ApplicationScreenshot([QueryField] bool resize, [QueryField] int quality, [QueryField] string size, [QueryField] double scale)
public async Task ApplicationScreenshot([QueryField] bool resize, [QueryField] int quality, [QueryField] string size, [QueryField] double scale, [QueryField] bool stream)
{
HttpResponse response = new HttpResponse();

Expand Down Expand Up @@ -105,12 +107,42 @@ public void ApplicationScreenshot([QueryField] bool resize, [QueryField] int qua

BitmapSource source = ImageUtility.ConvertBitmap(screenshot);

if (scale == 0 && resize)
response.Response = BitmapHelper.ResizeAndConvertBitmap(source, new_size, quality);
if (scale != 0 && resize)
response.Response = BitmapHelper.ScaleAndConvertBitmap(source, scale, quality);
if (!resize)
response.Response = BitmapHelper.ScaleAndConvertBitmap(source, 1, quality);
if (stream)
{
BitmapEncoder encoder = null;
if (scale == 0 && resize)
{
BitmapSource image = BitmapHelper.ResizeBitmap(source, new_size);
encoder = BitmapHelper.GetEncoder(image, quality);
}
if (scale != 0 && resize)
{
BitmapSource image = BitmapHelper.ScaleBitmap(source, scale);
encoder = BitmapHelper.GetEncoder(image, quality);
}
if (!resize)
{
BitmapSource image = BitmapHelper.ScaleBitmap(source, 1);
encoder = BitmapHelper.GetEncoder(image, quality);
}
HttpContext.Response.ContentType = quality == -1 ? "image/png" : "image/jpg";
using (MemoryStream memory = new MemoryStream())
{
encoder.Save(memory);
await HttpContext.Response.OutputStream.WriteAsync(memory.ToArray());
return;
}
}
else
{

if (scale == 0 && resize)
response.Response = BitmapHelper.ResizeAndConvertBitmap(source, new_size, quality);
if (scale != 0 && resize)
response.Response = BitmapHelper.ScaleAndConvertBitmap(source, scale, quality);
if (!resize)
response.Response = BitmapHelper.ScaleAndConvertBitmap(source, 1, quality);
}
}
catch (Exception ex)
{
Expand Down
Loading

0 comments on commit 9475c57

Please sign in to comment.