From 21e7bcd530bc46d623e12cb9dea2a6314d188e5e Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 10 Mar 2021 19:25:27 +0000 Subject: [PATCH] Added support for the GW Command. Removed the implementation of Tracking Set as this does not do anything in the code. Set Can Set Tracking to false. Get tracking always returns true is the GW command is not supported. --- .../TelescopeUnitTests.cs | 23 +-- Meade.net.Telescope/Alignment.cs | 10 ++ Meade.net.Telescope/AlignmentStatus.cs | 11 ++ .../Meade.net.Telescope.csproj | 2 + Meade.net.Telescope/Telescope.cs | 131 ++++++++++++------ 5 files changed, 123 insertions(+), 54 deletions(-) create mode 100644 Meade.net.Telescope/Alignment.cs create mode 100644 Meade.net.Telescope/AlignmentStatus.cs diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 16b330d..be47538 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -621,15 +621,18 @@ namespace Meade.net.Telescope.UnitTests } - [TestCase("A", AlignmentModes.algAltAz)] - [TestCase("P", AlignmentModes.algPolar)] - [TestCase("G", AlignmentModes.algGermanPolar)] - public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode) + [TestCase("A", AlignmentModes.algAltAz, TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)] + [TestCase("P", AlignmentModes.algPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_31Ee)] + [TestCase("A", AlignmentModes.algAltAz, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] + [TestCase("P", AlignmentModes.algPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] + [TestCase("G", AlignmentModes.algGermanPolar, TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg)] + public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode, string productName, string firmware) { const char ack = (char)6; _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GW#")).Returns($"{telescopeMode}N0"); - ConnectTelescope(); + ConnectTelescope(productName, firmware); var actualResult = _telescope.AlignmentMode; @@ -897,11 +900,11 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void CanSetTracking_Get_ReturnsTrue() + public void CanSetTracking_Get_ReturnsFalse() { var result = _telescope.CanSetTracking; - Assert.That(result, Is.True); + Assert.That(result, Is.False); } [Test] @@ -2121,11 +2124,9 @@ namespace Meade.net.Telescope.UnitTests [TestCase(true)] [TestCase(false)] - public void Tracking_SetAndGet_WhenValueSet_ThenCanGetNewValue(bool tracking) + public void Tracking_Set_ThenThrowsNotImplementedException(bool tracking) { - _telescope.Tracking = tracking; - - Assert.That(_telescope.Tracking, Is.EqualTo( tracking)); + Assert.Throws( () => { _telescope.Tracking = tracking; } ); } [Test] diff --git a/Meade.net.Telescope/Alignment.cs b/Meade.net.Telescope/Alignment.cs new file mode 100644 index 0000000..7450c67 --- /dev/null +++ b/Meade.net.Telescope/Alignment.cs @@ -0,0 +1,10 @@ +namespace ASCOM.Meade.net +{ + public enum Alignment + { + NeedsAlignment, + OneStarAligned, + TwoStarAligned, + ThreeStarAligned + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/AlignmentStatus.cs b/Meade.net.Telescope/AlignmentStatus.cs new file mode 100644 index 0000000..a602f5a --- /dev/null +++ b/Meade.net.Telescope/AlignmentStatus.cs @@ -0,0 +1,11 @@ +using ASCOM.DeviceInterface; + +namespace ASCOM.Meade.net +{ + public class AlignmentStatus + { + public AlignmentModes AlignmentMode { get; set; } + public bool Tracking { get; set; } + public Alignment Status { get; set; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index cfae8a4..9b8c187 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -118,6 +118,8 @@ + + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index ada8098..1008e89 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -510,7 +510,7 @@ namespace ASCOM.Meade.net private bool FirmwareIsGreaterThan(string minVersion) { var currentVersion = SharedResourcesWrapper.FirmwareVersion; - var comparison = String.Compare(currentVersion, minVersion, StringComparison.Ordinal); + var comparison = string.Compare(currentVersion, minVersion, StringComparison.Ordinal); return comparison >= 0; } @@ -830,47 +830,41 @@ namespace ASCOM.Meade.net CheckConnected("AlignmentMode Get"); - const char ack = (char) 6; - - var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); - //ACK <0x06> Query of alignment mounting mode. - //Returns: - //A If scope in AltAz Mode - //D If scope is currently in the Downloader[Autostar II & Autostar] - //L If scope in Land Mode - //P If scope in Polar Mode - - //todo implement GW Command - Supported in Autostar 43Eg and above - //if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG) - //{ - //var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); - //: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. - //} - - AlignmentModes alignmentMode; - switch (alignmentString) + if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg)) { - case "A": - alignmentMode = AlignmentModes.algAltAz; - break; - case "P": - alignmentMode = AlignmentModes.algPolar; - break; - case "G": - alignmentMode = AlignmentModes.algGermanPolar; - break; - default: - throw new InvalidValueException( - $"unknown alignment returned from telescope: {alignmentString}"); + var alignmentStatus = GetScopeAlignmentStatus(); + return alignmentStatus.AlignmentMode; } + else + { + const char ack = (char)6; + //ACK <0x06> Query of alignment mounting mode. + //Returns: + //A If scope in AltAz Mode + //D If scope is currently in the Downloader[Autostar II & Autostar] + //L If scope in Land Mode + //P If scope in Polar Mode + var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); + AlignmentModes alignmentMode; + switch (alignmentString) + { + case "A": + alignmentMode = AlignmentModes.algAltAz; + break; + case "P": + alignmentMode = AlignmentModes.algPolar; + break; + //case "G": + // alignmentMode = AlignmentModes.algGermanPolar; + // break; + default: + throw new InvalidValueException( + $"unknown alignment returned from telescope: {alignmentString}"); + } - LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}"); - return alignmentMode; + LogMessage("AlignmentMode Get", $"alignmode = {alignmentMode}"); + return alignmentMode; + } } set { @@ -901,6 +895,50 @@ namespace ASCOM.Meade.net //Returns: nothing } } + + private AlignmentStatus GetScopeAlignmentStatus() + { + var alignmentString = SharedResourcesWrapper.SendString(":GW#"); + //: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. + + var alignmentStatus = new AlignmentStatus(); + switch (alignmentString[0]) + { + case 'A': + alignmentStatus.AlignmentMode = AlignmentModes.algAltAz; + break; + case 'P': + alignmentStatus.AlignmentMode = AlignmentModes.algPolar; + break; + case 'G': + alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar; + break; + } + alignmentStatus.Tracking = alignmentString[0] == 'T'; + switch (alignmentString[1]) + { + case '0': + alignmentStatus.Status = Alignment.NeedsAlignment; + break; + case '1': + alignmentStatus.Status = Alignment.OneStarAligned; + break; + case '2': + alignmentStatus.Status = Alignment.TwoStarAligned; + break; + case '3': + alignmentStatus.Status = Alignment.ThreeStarAligned; + break; + } + + + return alignmentStatus; + } public double Altitude { @@ -1111,8 +1149,8 @@ namespace ASCOM.Meade.net { get { - LogMessage("CanSetTracking", "Get - " + true); - return true; + LogMessage("CanSetTracking", "Get - " + false); + return false; } } @@ -2236,12 +2274,19 @@ namespace ASCOM.Meade.net get { LogMessage("Tracking", $"Get - {_tracking}"); + if (FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg)) + { + var alignmentStatus = GetScopeAlignmentStatus(); + _tracking = alignmentStatus.Tracking; + } + return _tracking; } set { - LogMessage("Tracking Set", $"{value}"); - _tracking = value; + throw new ASCOM.NotImplementedException("Tracking Set"); + //LogMessage("Tracking Set", $"{value}"); + //_tracking = value; } }