diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 274f6ea..9a3adf3 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -107,7 +107,9 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock .SetupProperty(x => x.SideOfPier) .SetupProperty(x => x.TargetRightAscension) - .SetupProperty(x => x.TargetDeclination); + .SetupProperty(x => x.TargetDeclination) + .SetupProperty(x => x.SlewSettleTime) + .SetupProperty(x => x.IsLongFormat); _astroMathsMock = new Mock(); @@ -1018,6 +1020,29 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); } + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void SlewSettleTime_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(short slewSettleTime) + { + ConnectTelescope(); + + _telescope.SlewSettleTime = slewSettleTime; + + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(secondTelescopeInstance.SlewSettleTime, Is.EqualTo(slewSettleTime)); + } + [Test] public void CanSetPark_Get_ReturnsFalse() { @@ -2369,6 +2394,46 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(declination)); } + [TestCase(-90d)] + [TestCase(-45d)] + [TestCase(0d)] + [TestCase(45d)] + [TestCase(90d)] + public void TargetDeclination_Set_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(double targetDeclination) + { + var targetDeclinationDMS = targetDeclination + "DMS"; + var sign = targetDeclination >= 0 ? "+" : string.Empty; + var command = $"Sd{sign}{targetDeclinationDMS}"; + + _utilMock.Setup(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2)).Returns(targetDeclinationDMS); + _utilMock.Setup(x => x.DMSToDegrees(targetDeclinationDMS)).Returns(targetDeclination); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(command, false)).Returns("1"); + + ConnectTelescope(); + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + + _telescope.TargetDeclination = targetDeclination; + + Assert.That(_telescope.TargetDeclination, Is.EqualTo(targetDeclination)); + + var secondTelescopeInstance = + new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); + + Assert.That(secondTelescopeInstance.Connected, Is.False); + + _connectionInfo.SameDevice = 2; + secondTelescopeInstance.Connected = true; + + Assert.That(_sharedResourcesWrapperMock.Object.IsLongFormat, Is.True); + Assert.That(secondTelescopeInstance.TargetDeclination, Is.EqualTo(targetDeclination)); + + _utilMock.Verify(x => x.DegreesToDMS(targetDeclination, "*", ":", ":", 2), Times.Once); + _utilMock.Verify(x => x.DMSToDegrees(targetDeclinationDMS), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + } + [Test] public void TargetRightAscension_Set_WhenNotConnected_ThenThrowsException() { diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 80a1cf1..03e9b1b 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -78,8 +78,6 @@ namespace ASCOM.Meade.net /// private int _digitsDe = 2; - private short _settleTime; - /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -487,6 +485,13 @@ namespace ASCOM.Meade.net CheckParked(); } + if (!SharedResourcesWrapper.IsLongFormat) + { + // use low precision digits + _digitsRa = 1; + _digitsDe = 0; + } + var raAndDec = GetTelescopeRaAndDec(); LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); @@ -634,8 +639,6 @@ namespace ASCOM.Meade.net return comparison >= 0; } - private bool IsLongFormat { get; set; } - /// /// classic LX200 needs initial set of target coordinates, if it is slewing and the target RA DE coordinates are 0 and differ from the current coordinates /// @@ -708,13 +711,11 @@ namespace ASCOM.Meade.net public void SetLongFormat(bool setLongFormat) { - IsLongFormat = false; - if (!IsLongFormatSupported()) { LogMessage("SetLongFormat", "Long coordinate format not supported for this mount"); - _digitsRa = 1; - _digitsDe = 0; + + SharedResourcesWrapper.Lock(() => SharedResourcesWrapper.IsLongFormat = false); return; } @@ -726,9 +727,9 @@ namespace ASCOM.Meade.net //Returns: DDD*MM.T or DDD*MM'SS# //The current telescope Azimuth depending on the selected precision. - IsLongFormat = result.Length > 6; + SharedResourcesWrapper.IsLongFormat = result.Length > 6; - if (IsLongFormat != setLongFormat) + if (SharedResourcesWrapper.IsLongFormat != setLongFormat) { _utilities.WaitForMilliseconds(500); SharedResourcesWrapper.SendBlind("U"); @@ -737,9 +738,9 @@ namespace ASCOM.Meade.net //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS // Returns Nothing result = SharedResourcesWrapper.SendString("GZ"); - IsLongFormat = result.Length > 6; + SharedResourcesWrapper.IsLongFormat = result.Length > 6; LogMessage("SetLongFormat", $"Get - Azimuth {result}"); - if (IsLongFormat == setLongFormat) + if (SharedResourcesWrapper.IsLongFormat == setLongFormat) LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); } else @@ -2077,14 +2078,14 @@ namespace ASCOM.Meade.net get { CheckConnected("SlewSettleTime Get"); - LogMessage("SlewSettleTime Get", $"{_settleTime} Seconds"); - return _settleTime; + LogMessage("SlewSettleTime Get", $"{SharedResourcesWrapper.SlewSettleTime} Seconds"); + return SharedResourcesWrapper.SlewSettleTime; } set { CheckConnected("SlewSettleTime Set"); - LogMessage("SlewSettleTime Set", $"Setting from {_settleTime} to {value}"); - _settleTime = value; + LogMessage("SlewSettleTime Set", $"Setting from {SharedResourcesWrapper.SlewSettleTime} to {value}"); + SharedResourcesWrapper.SlewSettleTime = value; } } @@ -2481,7 +2482,7 @@ namespace ASCOM.Meade.net if (value < -90) throw new InvalidValueException("Declination cannot be less than -90."); - var dms = IsLongFormat ? + var dms = SharedResourcesWrapper.IsLongFormat ? _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe) : _utilities.DegreesToDM(value, "*", "", _digitsDe); @@ -2537,7 +2538,7 @@ namespace ASCOM.Meade.net if (value >= 24) throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); - var hms = IsLongFormat ? + var hms = SharedResourcesWrapper.IsLongFormat ? _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 0e36a17..5e4c942 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -33,7 +33,7 @@ namespace ASCOM.Meade.net protected ParkedBehaviour ParkedBehaviour; protected HorizonCoordinates ParkedAltAz; - protected readonly ISharedResourcesWrapper SharedResourcesWrapper; + protected readonly ISharedResourcesWrapper SharedResourcesWrapper; public MeadeTelescopeBase() { @@ -81,7 +81,7 @@ namespace ASCOM.Meade.net Altitude = profileProperties.ParkedAlt, Azimuth = profileProperties.ParkedAz }; - + LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); LogMessage("ReadProfile", $"Backlash Steps: {BacklashCompensation}"); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index bcf1134..8165e7b 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -509,10 +509,14 @@ namespace ASCOM.Meade.net /// Start with . /// As we do not know the physical declination axis position, we have to keep track manually. /// - public static PierSide SideOfPier { get; set; } = PierSide.pierUnknown; + public static PierSide SideOfPier { get; internal set; } = PierSide.pierUnknown; - public static double? TargetRightAscension { get; set; } + public static double? TargetRightAscension { get; internal set; } - public static double? TargetDeclination { get; set; } + public static double? TargetDeclination { get; internal set; } + + public static short SlewSettleTime { get; internal set; } + + public static bool IsLongFormat { get; internal set; } } } \ No newline at end of file diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index 83fe829..d123a71 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -36,6 +36,10 @@ namespace ASCOM.Meade.net.Wrapper PierSide SideOfPier { get; set; } double? TargetRightAscension { get; set; } double? TargetDeclination { get; set; } + + short SlewSettleTime { get; set; } + + bool IsLongFormat { get; set; } } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -135,5 +139,17 @@ namespace ASCOM.Meade.net.Wrapper get => SharedResources.TargetDeclination; set => SharedResources.TargetDeclination = value; } + + public short SlewSettleTime + { + get => SharedResources.SlewSettleTime; + set => SharedResources.SlewSettleTime = value; + } + + public bool IsLongFormat + { + get => SharedResources.IsLongFormat; + set => SharedResources.IsLongFormat = value; + } } }