From f4c26d777b3f0901790a29cac64f2ab79d970e3e Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 3 Aug 2021 21:55:06 +0100 Subject: [PATCH 1/4] Added more logging around the tracking rates. Corrected the Command logged messages to use the correct info. Added a try catch to the setup dialog to see if an error occurs to give a better message. --- .../TelescopeUnitTests.cs | 6 +-- Meade.net.Telescope/Telescope.cs | 50 ++++++++++++------- Meade.net/SharedResources.cs | 33 +++++++----- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 0b9a1d9..6ffcf43 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -822,9 +822,9 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AlignmentMode Set")); } - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algAltAz, "AA")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algPolar, "AP")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algGermanPolar, "AP")] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algAltAz, "AA")] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algPolar, "AP")] + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, AlignmentModes.algGermanPolar, "AP")] public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 2c8928e..339854a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -339,7 +339,7 @@ namespace ASCOM.Meade.net public void CommandBlind(string command, bool raw) { - LogMessage("CommandBlind", "raw: {0} command {0}", raw, command); + LogMessage("CommandBlind", $"raw: {raw} command {command}"); CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); @@ -352,16 +352,16 @@ namespace ASCOM.Meade.net public bool CommandBool(string command, bool raw) { - LogMessage("CommandBool", "raw: {0} command {0}", raw, command); + LogMessage("CommandBool", $"raw: {raw} command {command}"); CheckConnected("CommandBool"); var result = SharedResourcesWrapper.SendBool(command, raw); - LogMessage("CommandBool", "Completed: {0}", result); + LogMessage("CommandBool", $"Completed: {result}"); return result; } public string CommandString(string command, bool raw) { - LogMessage("CommandString", "raw: {0} command {0}", raw, command); + LogMessage("CommandString", $"raw: {raw} command {command}"); CheckConnected("CommandString"); // it's a good idea to put all the low level communication with the device here, // then all communication calls this function @@ -377,7 +377,7 @@ namespace ASCOM.Meade.net { result = SharedResourcesWrapper.SendString(command, raw); } - LogMessage("CommandString", "Completed: {0}", result); + LogMessage("CommandString", $"Completed: {result}"); return result; } @@ -622,13 +622,26 @@ namespace ASCOM.Meade.net return false; } - private bool IsGWCommandSupported() => FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg); + private bool IsGwCommandSupported() + { + switch (SharedResourcesWrapper.ProductName) + { + case TelescopeList.LX200CLASSIC: + return false; + case TelescopeList.Autostar497: + return FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg); + case TelescopeList.LX200GPS: + return FirmwareIsGreaterThan(TelescopeList.LX200GPS_42G); + default: + return false; + } + } // true iff the mount will perform a meridian flip when required // According to "A User's Guide to the Meade LXD55 and LXD75 Telescopes" Autostar supports meridian flip so // we assume that for any telescope that supports the GW command and is not in Alt-Az mode then // meridian flip on slew is supported - private bool IsMeridianFlipOnSlewSupported() => IsGWCommandSupported() && AlignmentMode != AlignmentModes.algAltAz; + private bool IsMeridianFlipOnSlewSupported() => IsGwCommandSupported() && AlignmentMode != AlignmentModes.algAltAz; private bool FirmwareIsGreaterThan(string minVersion) { @@ -955,7 +968,7 @@ namespace ASCOM.Meade.net CheckConnected("AlignmentMode Get"); - if (IsGWCommandSupported()) + if (IsGwCommandSupported()) { var alignmentStatus = GetScopeAlignmentStatus(); return alignmentStatus.AlignmentMode; @@ -996,7 +1009,7 @@ namespace ASCOM.Meade.net CheckConnected("AlignmentMode Set"); //todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly - if (!IsGWCommandSupported()) + if (!IsGwCommandSupported()) throw new PropertyNotImplementedException("AlignmentMode", true); switch (value) @@ -1023,6 +1036,7 @@ namespace ASCOM.Meade.net private AlignmentStatus GetScopeAlignmentStatus() { + LogMessage("GetScopeAlignmentStatus", "Started"); var alignmentString = CommandString("GW", false); //:GW# Get Scope Alignment Status //Returns: # @@ -1045,6 +1059,7 @@ namespace ASCOM.Meade.net alignmentStatus.AlignmentMode = AlignmentModes.algGermanPolar; break; } + alignmentStatus.Tracking = alignmentString[1] == 'T'; switch (alignmentString[2]) { @@ -1068,6 +1083,7 @@ namespace ASCOM.Meade.net break; } + LogMessage("GetScopeAlignmentStatus", $"Result {alignmentStatus}"); return alignmentStatus; } @@ -1309,7 +1325,7 @@ namespace ASCOM.Meade.net { get { - var canSetTracking = IsGWCommandSupported(); + var canSetTracking = IsGwCommandSupported(); LogMessage("CanSetTracking", "Get - " + canSetTracking); return canSetTracking; } @@ -2591,7 +2607,7 @@ namespace ASCOM.Meade.net get { LogMessage("Tracking", "Get"); - if (IsGWCommandSupported()) + if (IsGwCommandSupported()) { var alignmentStatus = GetScopeAlignmentStatus(); return alignmentStatus.Tracking; @@ -2607,7 +2623,7 @@ namespace ASCOM.Meade.net } LogMessage("Tracking Set", $"{value}"); - SharedResourcesWrapper.SendBlind(value ? "AP" : "AL"); + SharedResourcesWrapper.SendBlind(value ? "AP" : "AL"); //todo need to route this to the real commands. } } @@ -2617,11 +2633,11 @@ namespace ASCOM.Meade.net { var rate = CommandString("GT", false); - if (rate == "+60.1") - return DriveRates.driveSidereal; + DriveRates result = rate == "+60.1" ? DriveRates.driveSidereal : DriveRates.driveLunar; - // we only support two rates ATM so return lunar tracking rate - return DriveRates.driveLunar; + LogMessage("TrackingRate Get", $"{rate} {result}"); + + return result; } set { @@ -2737,7 +2753,7 @@ namespace ASCOM.Meade.net return utcDate; } - catch (ParkedException e) + catch (ParkedException) { if (ParkedBehaviour == ParkedBehaviour.NoCoordinates) throw; diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 975b093..2e51fdf 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -292,25 +292,34 @@ namespace ASCOM.Meade.net public static void SetupDialog() { - var profileProperties = ReadProfile(); - - using (SetupDialogForm f = new SetupDialogForm()) + try { - f.SetProfile(profileProperties); + var profileProperties = ReadProfile(); - if (IsConnected()) + using (SetupDialogForm f = new SetupDialogForm()) { - f.SetReadOnlyMode(); - } + f.SetProfile(profileProperties); - var result = f.ShowDialog(); - if (result == DialogResult.OK) - { - profileProperties = f.GetProfile(); + if (IsConnected()) + { + f.SetReadOnlyMode(); + } - WriteProfile(profileProperties); // Persist device configuration values to the ASCOM Profile store + var result = f.ShowDialog(); + if (result == DialogResult.OK) + { + profileProperties = f.GetProfile(); + + WriteProfile( + profileProperties); // Persist device configuration values to the ASCOM Profile store + } } } + catch (Exception e) + { + Console.WriteLine(e); + throw; + } } #endregion From a562b848c0a2ee880afc94de22ad35d7f5b4a5bf Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 4 Aug 2021 09:22:31 +0100 Subject: [PATCH 2/4] Corrected the expected result of the GT command. --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 2 +- Meade.net.Telescope/Telescope.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 6ffcf43..9cd4e95 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -142,7 +142,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(() => _testProperties.telescopeTime); _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(() => _testProperties.telescopeUtcCorrection); - const string siderealTrackingRate = "+60.1"; + const string siderealTrackingRate = "60.1"; _testProperties.TrackingRate = siderealTrackingRate; _sharedResourcesWrapperMock.Setup(x => x.SendString("GT", false)).Returns(() => _testProperties.TrackingRate); _sharedResourcesWrapperMock.Setup(x => x.SendBlind("TL", false)).Callback(() => _testProperties.TrackingRate = "lunar"); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 339854a..2489c6a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2631,9 +2631,13 @@ namespace ASCOM.Meade.net { get { - var rate = CommandString("GT", false); + var rate = CommandString("GT", false); + //:GT# Get tracking rate + //Returns: TT.T# + //Current Track Frequency expressed in hertz assuming a synchonous motor design where a 60.0 Hz motor clock + // would produce 1 revolution of the telescope in 24 hours. - DriveRates result = rate == "+60.1" ? DriveRates.driveSidereal : DriveRates.driveLunar; + DriveRates result = rate == "60.1" ? DriveRates.driveSidereal : DriveRates.driveLunar; LogMessage("TrackingRate Get", $"{rate} {result}"); From 27a0f54b07dccbb8d43c971138d922bae42a22dc Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 4 Aug 2021 17:01:06 +0100 Subject: [PATCH 3/4] Added check to make sure that the tracking rate cannot be set for an LX200. --- .../TelescopeUnitTests.cs | 29 +++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 5 ++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 9cd4e95..713b2b0 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2702,7 +2702,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(DriveRates.driveLunar, "TL")] public void TrackingRate_Set_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate, string commandString) { - ConnectTelescope(); + string productName = TelescopeList.Autostar497; + string firmwareVersion = TelescopeList.Autostar497_43Eg; + + ConnectTelescope(productName, firmwareVersion); _telescope.TrackingRate = rate; @@ -2715,7 +2718,10 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TrackingRate_Set_WhenUnSupportedRateSet_ThenThrowsException() { - ConnectTelescope(); + string productName = TelescopeList.Autostar497; + string firmwareVersion = TelescopeList.Autostar497_43Eg; + + ConnectTelescope(productName, firmwareVersion); var exception = Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveKing); @@ -2736,7 +2742,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(DriveRates.driveLunar)] public void TrackingRate_Get_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate) { - ConnectTelescope(); + string productName = TelescopeList.Autostar497; + string firmwareVersion = TelescopeList.Autostar497_43Eg; + + ConnectTelescope(productName, firmwareVersion); _telescope.TrackingRate = rate; @@ -2745,6 +2754,20 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(rate)); } + [TestCase(DriveRates.driveSidereal)] + [TestCase(DriveRates.driveLunar)] + public void TrackingRate_Set_WhenConnectedToLX200_ThenThrowsException(DriveRates rate) + { + string productName = TelescopeList.LX200CLASSIC; + string firmwareVersion = string.Empty; + + ConnectTelescope(productName, firmwareVersion); + + var result = Assert.Throws( () => _telescope.TrackingRate = rate ); + + Assert.That(result.Message, Is.EqualTo("TrackingRate Set is not implemented in this driver.")); + } + [Test] public void TrackingRates_Get_ReturnsExpectedType() { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 2489c6a..a694f31 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2649,6 +2649,11 @@ namespace ASCOM.Meade.net CheckConnected("TrackingRate Set"); CheckParked(); + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC) + { + throw new ASCOM.NotImplementedException("TrackingRate Set"); + } + switch (value) { case DriveRates.driveSidereal: From 49c43358de3870d74231cdd706ae4df8491305be Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 4 Aug 2021 18:48:24 +0100 Subject: [PATCH 4/4] Added check to ensure that the Lunar Tracking rate cannot be selected on the LX200 Classic. --- .../TelescopeUnitTests.cs | 16 ++++++++++++++-- Meade.net.Telescope/Rates.cs | 10 +++++++--- Meade.net.Telescope/Telescope.cs | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 713b2b0..175c060 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2768,13 +2768,25 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result.Message, Is.EqualTo("TrackingRate Set is not implemented in this driver.")); } - [Test] - public void TrackingRates_Get_ReturnsExpectedType() + [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, true )] + [TestCase(TelescopeList.LX200CLASSIC, "", false)] + public void TrackingRates_Get_ReturnsExpectedType(string productName, string firmwareVersion, bool supportsLunar) { + ConnectTelescope(productName, firmwareVersion); + var result = _telescope.TrackingRates; Assert.That(result, Is.Not.Null); Assert.That(result, Is.AssignableTo()); + + if (supportsLunar) + { + Assert.That(result.Count, Is.EqualTo(2)); + } + else + { + Assert.That(result.Count, Is.EqualTo(1)); + } } [Test] diff --git a/Meade.net.Telescope/Rates.cs b/Meade.net.Telescope/Rates.cs index 6022c64..98f7c49 100644 --- a/Meade.net.Telescope/Rates.cs +++ b/Meade.net.Telescope/Rates.cs @@ -149,15 +149,19 @@ namespace ASCOM.Meade.net // Default constructor - Internal prevents public creation // of instances. Returned by Telescope.AxisRates. // - internal TrackingRates() + internal TrackingRates(bool supportsLunar) { // // This array must hold ONE or more DriveRates values, indicating // the tracking rates supported by your telescope. The one value // (tracking rate) that MUST be supported is driveSidereal! // - _trackingRates = new[] { DriveRates.driveSidereal, DriveRates.driveLunar }; - // TODO Initialize this array with any additional tracking rates that your driver may provide + if (supportsLunar) + { + _trackingRates = new[] {DriveRates.driveSidereal, DriveRates.driveLunar}; + } + else + _trackingRates = new[] { DriveRates.driveSidereal }; } #region ITrackingRates Members diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index a694f31..b39c1e0 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2685,7 +2685,7 @@ namespace ASCOM.Meade.net { get { - ITrackingRates trackingRates = new TrackingRates(); + ITrackingRates trackingRates = new TrackingRates(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC); LogMessage("TrackingRates", "Get - "); foreach (DriveRates driveRate in trackingRates) {