From 7225c2d70f7975346fd63921f4590cb6df6737e4 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 2 May 2019 14:05:23 +0100 Subject: [PATCH] Added support for AlignmentMode --- .../TelescopeControllerUnitTests.cs | 30 +++++++++++++ MeadeAutostar497/AscomClasses/Telescope.cs | 2 +- .../Controller/ITelescopeController.cs | 1 + .../Controller/TelescopeController.cs | 45 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs index dd5ec24..27ccfa4 100644 --- a/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs +++ b/MeadeAutostar497.UnitTests/TelescopeControllerUnitTests.cs @@ -444,5 +444,35 @@ namespace MeadeAutostar497.UnitTests serialMock.Verify(x => x.Command(":Mgs1024#"), Times.Once); } + + [TestCase("AT0", AlignmentModes.algAltAz)] + [TestCase("PT0", AlignmentModes.algPolar)] + [TestCase("GT0", AlignmentModes.algGermanPolar)] + public void AlignmentMode_Get_ReturnsExpectedValue(string commandResponse, AlignmentModes mode) + { + serialMock.Setup(x => x.CommandTerminated(":GW#", "#")).Returns(commandResponse); + + _isConnected = true; + + _telescopeController.Connected = true; + + var result = _telescopeController.AlignmentMode; + + Assert.That(result, Is.EqualTo(mode)); + } + + [TestCase(AlignmentModes.algAltAz, ":AA#")] + [TestCase(AlignmentModes.algPolar, ":AP#")] + [TestCase(AlignmentModes.algGermanPolar, ":AP#")] + public void AligmentMode_Set_WorksAsExpected(AlignmentModes mode, string command) + { + _isConnected = true; + + _telescopeController.Connected = true; + + _telescopeController.AlignmentMode = mode; + + serialMock.Verify( x => x.Command(command), Times.Once); + } } } diff --git a/MeadeAutostar497/AscomClasses/Telescope.cs b/MeadeAutostar497/AscomClasses/Telescope.cs index f15e767..8b4de2e 100644 --- a/MeadeAutostar497/AscomClasses/Telescope.cs +++ b/MeadeAutostar497/AscomClasses/Telescope.cs @@ -298,7 +298,7 @@ namespace ASCOM.MeadeAutostar497 get { tl.LogMessage("AlignmentMode Get", "Not implemented"); - throw new ASCOM.PropertyNotImplementedException("AlignmentMode", false); + return _telescopeController.AlignmentMode; } } diff --git a/MeadeAutostar497/Controller/ITelescopeController.cs b/MeadeAutostar497/Controller/ITelescopeController.cs index a4f26d2..893c470 100644 --- a/MeadeAutostar497/Controller/ITelescopeController.cs +++ b/MeadeAutostar497/Controller/ITelescopeController.cs @@ -12,6 +12,7 @@ namespace ASCOM.MeadeAutostar497.Controller DateTime utcDate { get; set; } double SiteLatitude { get; set; } double SiteLongitude { get; set; } + AlignmentModes AlignmentMode { get; set; } void AbortSlew(); void PulseGuide(GuideDirections direction, int duration); } diff --git a/MeadeAutostar497/Controller/TelescopeController.cs b/MeadeAutostar497/Controller/TelescopeController.cs index 8fd7d7c..44a67d8 100644 --- a/MeadeAutostar497/Controller/TelescopeController.cs +++ b/MeadeAutostar497/Controller/TelescopeController.cs @@ -6,6 +6,7 @@ using ASCOM.DeviceInterface; namespace ASCOM.MeadeAutostar497.Controller { + //todo stop this being a singleton, and instead use a server to make only a single instance. public sealed class TelescopeController : ITelescopeController { private static readonly Lazy lazy = new Lazy(); @@ -248,6 +249,50 @@ namespace ASCOM.MeadeAutostar497.Controller } + public AlignmentModes AlignmentMode + { + get + { + var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); + + switch (alignmentString[0]) + { + case 'A': return AlignmentModes.algAltAz; + case 'P': return AlignmentModes.algPolar; + case 'G': return AlignmentModes.algGermanPolar; + default: + throw new ASCOM.InvalidValueException($"unknown alignment returned from telescope: {alignmentString[0]}"); + } + //:GW# Get Scope Alignment Status + //Returns: # + // where: + //mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial + //tracking: T - tracking, N - not tracking + //alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned. + } + set + { + switch (value) + { + case AlignmentModes.algAltAz: SerialPort.Command(":AA#"); + break; + case AlignmentModes.algPolar: + case AlignmentModes.algGermanPolar: + SerialPort.Command(":AP#"); + break; + default: + throw new ArgumentOutOfRangeException(nameof(value), value, null); + } + + //:AL# Sets telescope to Land alignment mode + //Returns: nothing + //:AP# Sets telescope to Polar alignment mode + //Returns: nothing + //:AA# Sets telescope the AltAz alignment mode + //Returns: nothing + } + } + public void AbortSlew() { SerialPort.Command("#:Q#");