From c2ebe329c537069ae5b16a78ad848523ef6bb388 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 20 Jul 2019 16:53:09 +0100 Subject: [PATCH] Added support for the LX200GPS to use the newer pulse guiding commands. Added support for setting the guide rate on the LX200GPS (untested) --- .../TelescopeUnitTests.cs | 68 +++++++++++++------ Meade.net.Telescope/DoubleExtensions.cs | 14 ++++ .../Meade.net.Telescope.csproj | 1 + Meade.net.Telescope/Telescope.cs | 63 +++++++++++------ Meade.net/ClassFactory.cs | 1 - Meade.net/Meade.net.csproj | 1 + Meade.net/TelescopeList.cs | 30 ++++++++ Meade.net/Wrapper/SharedResourcesWrapper.cs | 14 ---- 8 files changed, 138 insertions(+), 54 deletions(-) create mode 100644 Meade.net.Telescope/DoubleExtensions.cs create mode 100644 Meade.net/TelescopeList.cs diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 230a271..02c3923 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -37,10 +37,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock = new Mock(); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); - _sharedResourcesWrapperMock.Setup(x => x.Autostar497).Returns(() => "AUTOSTAR"); - _sharedResourcesWrapperMock.Setup(x => x.Autostar49731Ee).Returns(() => "31Ee"); - _sharedResourcesWrapperMock.Setup(x => x.Autostar49743Eg) .Returns(() => "43Eg"); - + _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>( (func) => func()); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>((func) => func()); @@ -56,8 +53,8 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _telescope.Connected = true; } @@ -238,8 +235,8 @@ namespace Meade.net.Telescope.UnitTests [TestCase(false)] public void Connected_Get_ReturnsExpectedValue(bool expectedConnected) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _telescope.Connected = expectedConnected; Assert.That(_telescope.Connected, Is.EqualTo(expectedConnected)); @@ -275,8 +272,8 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_WhenFailsToConnect_ThenDisconnects() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny())).Throws(new Exception("TestFailed")); @@ -287,10 +284,11 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.Disconnect(It.IsAny()), Times.Once()); } - [TestCase("AUTOSTAR", "30Ab", false)] - [TestCase("AUTOSTAR","31Ee", true)] - [TestCase("AUTOSTAR", "43Eg", true)] - [TestCase("AUTOSTAR II", "", false)] + [TestCase("Autostar", "30Ab", false)] + [TestCase("Autostar", "31Ee", true)] + [TestCase("Autostar", "43Eg", true)] + [TestCase("Autostar II", "", false)] + [TestCase("LX2001", "", true)] public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string productName, string firmware, bool isSupported) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); @@ -777,12 +775,28 @@ namespace Meade.net.Telescope.UnitTests [Test] public void GuideRateDeclination_Set_ThenThrowsException() { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + var excpetion = Assert.Throws(() => { _telescope.GuideRateDeclination = 0; }); Assert.That(excpetion.Property, Is.EqualTo("GuideRateDeclination")); Assert.That(excpetion.AccessorSet, Is.True); } + [Test] + public void GuideRateDeclination_Set_WhenIsSupported_ThenSetsNewGuideRate() + { + var newGuideRate = 10; + + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); + + _telescope.GuideRateDeclination = newGuideRate; + + _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":Rg10.0#"),Times.Once); + + Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); + } + [Test] public void GuideRateRightAscension_Get_ThenThrowsException() { @@ -794,12 +808,28 @@ namespace Meade.net.Telescope.UnitTests [Test] public void GuideRateRightAscension_Set_ThenThrowsException() { + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + var excpetion = Assert.Throws(() => { _telescope.GuideRateRightAscension = 0; }); Assert.That(excpetion.Property, Is.EqualTo("GuideRateRightAscension")); Assert.That(excpetion.AccessorSet, Is.True); } + [Test] + public void GuideRateRightAscension_Set_WhenIsSupported_ThenSetsNewGuideRate() + { + var newGuideRate = 10; + + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.LX200GPS); + + _telescope.GuideRateRightAscension = newGuideRate; + + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg10.0#"), Times.Once); + + Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); + } + [Test] public void IsPulseGuiding_Get_ReturnsFalse() { @@ -997,8 +1027,8 @@ namespace Meade.net.Telescope.UnitTests public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndWaits(GuideDirections direction) { var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => "31Ed"); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); _telescope.Connected = true; _telescope.PulseGuide(direction, duration); @@ -1033,8 +1063,8 @@ namespace Meade.net.Telescope.UnitTests public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailableButDurationTooLong_ThenSendsOldCommandsAndWaits(GuideDirections direction) { var duration = 10000; - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => "31Ed"); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); _telescope.Connected = true; _telescope.PulseGuide(direction, duration); @@ -1328,8 +1358,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToAltAz_WhenConnected_ThenSendsExpectedMessage() { - string expectedMessage = "test blind Message"; - ConnectTelescope(); var exception = Assert.Throws(() => { _telescope.SyncToAltAz(0,0); }); diff --git a/Meade.net.Telescope/DoubleExtensions.cs b/Meade.net.Telescope/DoubleExtensions.cs new file mode 100644 index 0000000..958400c --- /dev/null +++ b/Meade.net.Telescope/DoubleExtensions.cs @@ -0,0 +1,14 @@ +namespace ASCOM.Meade.net +{ + public static class DoubleExtensions + { + public static bool InRange(this double value, double low, double high) + { + if (value < low) + return false; + if (value > high) + return false; + return true; + } + } +} \ 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 cf50efa..70efc87 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -118,6 +118,7 @@ + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 47389de..166ddeb 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -344,11 +344,25 @@ namespace ASCOM.Meade.net public bool IsNewPulseGuidingSupported() { - if (_sharedResourcesWrapper.ProductName == _sharedResourcesWrapper.Autostar497) + if (_sharedResourcesWrapper.ProductName == TelescopeList.Autostar497) { - return FirmwareIsGreaterThan(_sharedResourcesWrapper.Autostar49731Ee); + return FirmwareIsGreaterThan(TelescopeList.Autostar497_31Ee); } + if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + return true; + } + + return false; + } + + private bool IsGuideRateSettingSupported() + { + if (_sharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + return true; + } return false; } @@ -495,7 +509,7 @@ namespace ASCOM.Meade.net //P If scope in Polar Mode //todo implement GW Command - Supported in Autostar 43Eg and above - //if FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_43EG) + //if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG) //{ //var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); //:GW# Get Scope Alignment Status @@ -531,7 +545,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 (!FirmwareIsGreaterThan(_sharedResourcesWrapper.Autostar49743Eg)) + if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg)) throw new PropertyNotImplementedException("AlignmentMode",true ); //todo make this only try with Autostar 43Eg and above. @@ -904,6 +918,29 @@ namespace ASCOM.Meade.net } } + private void SetNewGuideRate(double value, string propertyName) + { + if (!IsGuideRateSettingSupported()) + { + LogMessage("GuideRateDeclination Set", "Not implemented"); + throw new PropertyNotImplementedException(propertyName, true); + } + + if (!value.InRange(0, 15.0417)) + { + throw new InvalidValueException(propertyName, value.ToString(), "0 to 15.0417”/sec"); + } + + _sharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); + //:RgSS.S# + //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking + //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed + //sidereal speed(approx 15.0417”/sec)[Autostar II only] + //Returns: Nothing + + _guideRate = value; + } + public double GuideRateDeclination { get @@ -913,16 +950,10 @@ namespace ASCOM.Meade.net } set { - LogMessage("GuideRateDeclination Set", "Not implemented"); - throw new PropertyNotImplementedException("GuideRateDeclination", true); - //:RgSS.S# - //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking - //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed - //sidereal speed(approx 15.0417”/ sec)[Autostar II only] - //Returns: Nothing + SetNewGuideRate(value, "GuideRateDeclination"); } } - + public double GuideRateRightAscension { get @@ -932,13 +963,7 @@ namespace ASCOM.Meade.net } set { - LogMessage("GuideRateRightAscension Set", "Not implemented"); - throw new PropertyNotImplementedException("GuideRateRightAscension", true); - //:RgSS.S# - //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking - //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed - //sidereal speed(approx 15.0417”/ sec)[Autostar II only] - //Returns: Nothing + SetNewGuideRate(value, "GuideRateRightAscension"); } } diff --git a/Meade.net/ClassFactory.cs b/Meade.net/ClassFactory.cs index 431e2d0..bbb5771 100644 --- a/Meade.net/ClassFactory.cs +++ b/Meade.net/ClassFactory.cs @@ -112,7 +112,6 @@ namespace ASCOM.Meade.net private readonly Type _mClassType; private Guid _mClassId; private readonly ArrayList _mInterfaceTypes; - private UInt32 _mLocked = 0; private uint _mCookie; private readonly string _mProgid; diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index 5eda70d..eb6cc79 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -133,6 +133,7 @@ + Designer diff --git a/Meade.net/TelescopeList.cs b/Meade.net/TelescopeList.cs new file mode 100644 index 0000000..7569e7a --- /dev/null +++ b/Meade.net/TelescopeList.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; + +namespace ASCOM.Meade.net +{ + public static class TelescopeList + { + #region Autostar 497/Audiostar + + public readonly static string Autostar497 = "Autostar"; + + //Autostar/Audiostar firmware revisions + public readonly static string Autostar497_30Ee = "30Ee"; + public readonly static string Autostar497_31Ee = "31Ee"; + public readonly static string Autostar497_43Eg = "43Eg"; + + #endregion + + #region LX200GPS + + public readonly static string LX200GPS = "LX2001"; + + public readonly static string LX200GPS_42G = "4.2G"; + + #endregion + } +} diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index c49454c..e4df7f5 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -4,11 +4,6 @@ namespace ASCOM.Meade.net.Wrapper { public interface ISharedResourcesWrapper { - string Autostar497 { get; } - string Autostar49731Ee { get; } - - string Autostar49743Eg { get;} - void Connect(string deviceId); void Disconnect(string deviceId); @@ -32,15 +27,6 @@ namespace ASCOM.Meade.net.Wrapper public class SharedResourcesWrapper : ISharedResourcesWrapper { - #region AutostarProducts - - public string Autostar497 => "Autostar"; - - public string Autostar49731Ee => "31Ee"; - public string Autostar49743Eg => "43Eg"; - - #endregion - public void Connect(string deviceId) { SharedResources.Connect( deviceId);