diff --git a/.gitignore b/.gitignore index 6553964..a6bb49f 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,7 @@ _TeamCity* _NCrunch_* .*crunch*.local.xml nCrunchTemp_* +*ncrunchsolution.user # MightyMoose *.mm.* diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 0885f04..178e0d4 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -422,6 +422,12 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_SettingFalseWhenTrue_ThenDisconnects() { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + ConnectTelescope(); _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -978,18 +984,22 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Declination_Get_WhenConnected_ThenReturnsExpectedResult() { - var telescopeRaResult = "s12*34’56"; + var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeRaResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeRaResult)).Returns(dmsResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); ConnectTelescope(); var result = _telescope.Declination; _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#"), Times.Exactly(2)); - _utilMock.Verify(x => x.DMSToDegrees(telescopeRaResult), Times.Exactly(2)); + _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); } @@ -1304,6 +1314,12 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailable_ThenSendsNewCommandsAndWaits(GuideDirections direction) { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; ConnectTelescope(); @@ -1370,6 +1386,16 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenIsSlewingRespondsFalse(GuideDirections direction) { + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); @@ -1393,6 +1419,16 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndWaits(GuideDirections direction) { + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 0; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); @@ -1429,6 +1465,12 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenConnectedAndNewerPulseGuidingAvailableButDurationTooLong_ThenSendsOldCommandsAndWaits(GuideDirections direction) { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + var duration = 10000; _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); @@ -1810,6 +1852,12 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); @@ -1888,7 +1936,13 @@ namespace Meade.net.Telescope.UnitTests [TestCase(50, "50*00:00", ":Sd+50*00:00#")] public void TargetDeclination_Get_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString) { + var digitsRA = 2; + var telescopeDecResult = "s12*34’56"; + + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); + _utilMock.Setup(x => x.DMSToDegrees(decstring)).Returns(declination); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); ConnectTelescope(); @@ -1966,7 +2020,11 @@ namespace Meade.net.Telescope.UnitTests [TestCase(15, "15:00:00", ":Sr15:00:00#")] public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); + var digitsRA = 2; + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(hms); + _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); ConnectTelescope(); @@ -2159,18 +2217,54 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToCoordinates_WhenNotConnected_ThenThrowsException() { + double rightAscension = 5.5; + double declination = -30.5; + + var exception = Assert.Throws(() => + { + _telescope.SyncToCoordinates(rightAscension, declination); + }); + + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SyncToCoordinates")); + } + + [Test] + public void SyncToCoordinates_WhenConnected_ThenReturnsExpectedResult() + { + var telescopeDecResult = "s12*34’56"; + var telescopeRaResult = "HH:MM:SS"; + //var hmsResult = 1.2; + double rightAscension = 5.5; string hms = "05:30:00"; double declination = -30.5; string dec = "-30*30:00"; - _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); + var digitsRA = 2; - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(dec); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); + + //_utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _utilMock.Setup(x => x.DMSToDegrees(dec)).Returns(declination); + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(dec); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sd{dec}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#")).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + ConnectTelescope(); _telescope.SyncToCoordinates(rightAscension, declination); @@ -2219,11 +2313,17 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.LX200CLASSIC,"","|", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "", false)] - [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] + //[TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. + [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "", false)] public void Slewing_WhenTelescopeNotSlewing_ThenReturnsFalse(string productName, string firmwareVersion, string response, bool isSlewing) { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2396,11 +2496,25 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinatesAsync_WhenCalled_ThenSetsTargetAndSlews() { + var digitsRA = 2; + var rightAscension = 1; var declination = 2; + var telescopeRaResult = "HH:MM:SS"; + var telescopeDecResult = "s12*34’56"; + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + //var slewCounter = 0; //var iterations = 10; //_sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => @@ -2435,6 +2549,23 @@ namespace Meade.net.Telescope.UnitTests var rightAscension = 1; var declination = 2; + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + var digitsRA = 2; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); var slewCounter = 0; @@ -2451,7 +2582,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToCoordinates(rightAscension, declination); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(rightAscension)); - Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); @@ -2518,6 +2649,17 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + var telescopeRaResult = "HH:MM:SS"; + var telescopeDecResult = "s12*34’56"; + var digitsRA = 2; + + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(rightAscension); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); + ConnectTelescope(); _telescope.SlewToAltAzAsync(azimuth, altitude); @@ -2537,14 +2679,25 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { - var rightAscension = 10; + var rightAscension = 10.0; var declination = 20; var azimuth = 30; var altitude = 40; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 10.0; + + _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeRaResult)).Returns(declination); + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":Sd+HH:MM:SS#")).Returns("1"); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index eb7d34b..39837d0 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -59,7 +59,17 @@ namespace ASCOM.Meade.net private readonly IAstroUtils _astroUtilities; private readonly IAstroMaths _astroMaths; - + + /// + /// Private variable to hold number of decimals for RA + /// + private int _digitsRa = 2; + + /// + /// Private variable to hold number of decimals for DE + /// + private int _digitsDe = 2; + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -117,6 +127,8 @@ namespace ASCOM.Meade.net } private bool _isGuiding; + + private bool _isTargetCoordinateInitRequired = true; // // PUBLIC COM INTERFACE ITelescopeV3 IMPLEMENTATION // @@ -498,6 +510,76 @@ namespace ASCOM.Meade.net 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 + /// + private bool IsTargetCoordinateInitRequired() + { + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + return false; + + if (!_isTargetCoordinateInitRequired) + return _isTargetCoordinateInitRequired; + + if (!IsConnected) + return true; + + if(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + { + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + + const double eps = 0.00001d; + + double rightTargetAscension = RightAscension; + //target RA == 0 + if (Math.Abs(rightTargetAscension) > eps) + { + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + + double targetDeclination = Declination; + //target DE == 0 + if (Math.Abs(targetDeclination) > eps) + { + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + + //target coordinates are equal current coordinates + if((Math.Abs(RightAscension - rightTargetAscension ) <= eps) && + (Math.Abs(Declination - targetDeclination) <= eps)) + { + LogMessage("IsTargetCoordinateInitRequired", $"0 diff -> false"); + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + + LogMessage("IsTargetCoordinateInitRequired", $"{_isTargetCoordinateInitRequired}"); + return _isTargetCoordinateInitRequired; + } + + private void InitTargetCoordinates() + { + try + { + var raAndDec = GetTelescopeRaAndDec(); + //when connection the first time the telescope target coordinates should be the current ones. + //for the classic LX200 at least this is not the case, target ra and dec are 0, when switched on. + LogMessage("InitTargetCoordinates", "sync telescope target"); + SyncToCoordinates(raAndDec.RightAscension, raAndDec.Declination); + + //do it only once + _isTargetCoordinateInitRequired = false; + } + catch (Exception ex) + { + LogMessage("InitTargetCoordinates", $"Error sync telescope position", ex.Message); + } + } + public void SetLongFormat(bool setLongFormat) { IsLongFormat = false; @@ -505,14 +587,17 @@ namespace ASCOM.Meade.net if (!IsLongFormatSupported()) { LogMessage("SetLongFormat", "Long coordinate format not supported for this mount"); + _digitsRa = 1; + _digitsDe = 0; return; } SharedResourcesWrapper.Lock(() => { var result = SharedResourcesWrapper.SendString(":GZ#"); + LogMessage("SetLongFormat", $"Get - Azimuth {result}"); //:GZ# Get telescope azimuth - //Returns: DDD*MM# or DDD*MM’SS# + //Returns: DDD*MM.T or DDD*MM’SS# //The current telescope Azimuth depending on the selected precision. IsLongFormat = result.Length > 6; @@ -525,6 +610,15 @@ namespace ASCOM.Meade.net //Low - RA displays and messages HH:MM.T sDD*MM //High - Dec / Az / El displays and messages HH:MM: SS sDD*MM:SS // Returns Nothing + result = SharedResourcesWrapper.SendString(":GZ#"); + IsLongFormat = result.Length > 6; + LogMessage("SetLongFormat", $"Get - Azimuth {result}"); + if (IsLongFormat == setLongFormat) + LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); + } + else + { + LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); } }); @@ -1091,7 +1185,7 @@ namespace ASCOM.Meade.net double declination = _utilities.DMSToDegrees(result); - LogMessage("Declination", "Get - " + _utilitiesExtra.DegreesToDMS(declination, ":", ":")); + LogMessage("Declination", $"Get - {result} convert to {declination} {_utilitiesExtra.DegreesToDMS(declination, ":", ":")}"); return declination; } } @@ -1456,6 +1550,20 @@ namespace ASCOM.Meade.net } } + /// + /// convert a HH:MM.T (classic LX200 RA Notation) string to a double hours. T is the decimal part of minutes which is converted into seconds + /// + public double HMToHours(string hm) + { + var token = hm.Split('.'); + if (token.Length != 2) + return _utilities.HMSToHours(hm); + + var seconds = short.Parse(token[1]) * 6; + var hms = $"{token[0]}:{seconds}"; + return _utilities.HMSToHours(hms); + } + public double RightAscension { get @@ -1466,9 +1574,9 @@ namespace ASCOM.Meade.net //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope - double rightAscension = _utilities.HMSToHours(result); + double rightAscension = HMToHours(result); - LogMessage("RightAscension", "Get - " + _utilitiesExtra.HoursToHMS(rightAscension)); + LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); return rightAscension; } } @@ -1536,7 +1644,7 @@ namespace ASCOM.Meade.net } } - public double SiteElevation + public new double SiteElevation { get { @@ -1887,26 +1995,43 @@ namespace ASCOM.Meade.net //LX200's – a string of bar characters indicating the distance. //Autostars and Autostar II – a string containing one bar until a slew is complete, then a null string is returned. - if (result == null) + bool isSlewing = !string.IsNullOrEmpty(result); + try { - return false; + //if (string.IsNullOrEmpty(result)) + //{ + // isSlewing = false; + // return isSlewing; + //} + + //if (result.Contains("|")) + //{ + // isSlewing = true; + // return isSlewing; + //} + + ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing + //byte[] ba = Encoding.Default.GetBytes(result); + ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. + //var hexString = BitConverter.ToString(ba).Replace("-", "").Replace("20", ""); + //LogMessage("IsSlewingToTarget", $"Resulthex = {hexString}"); + //isSlewing = (hexString.Length > 0); + + //if (!isSlewing) + // return isSlewing; + + ////classic LX200 got RA 0 DE 0 as Target Coordinates. If the RA DE is not 0 at switch on, the telescope will indicate slewing until + ////the target coordinates are set and the telescope is slewed to that position. + ////a 0 movement will solved that lock if the target coordinates are set to the current coordinates. + //if (IsTargetCoordinateInitRequired()) + // InitTargetCoordinates(); + + return isSlewing; } - - var trimmedResult = result.Trim(); - var isResultEmpty = trimmedResult == string.Empty; - - var isSlewing = !isResultEmpty; - - if (!isResultEmpty) //the LX-200 can return crap from the buffer when it's not slewing so let's try to filter that out. + finally { - if (!trimmedResult.Contains("|")) - { - isSlewing = false; - } + LogMessage("IsSlewingToTarget", $"Result = {isSlewing}"); } - - LogMessage("IsSlewingToTarget", $"Result = {isSlewing} ({trimmedResult})"); - return isSlewing; } public void SyncToAltAz(double azimuth, double altitude) @@ -1918,6 +2043,7 @@ namespace ASCOM.Meade.net public void SyncToCoordinates(double rightAscension, double declination) { LogMessage("SyncToCoordinates", $"RA={rightAscension} Dec={declination}"); + LogMessage("SyncToCoordinates", $"RA={_utilitiesExtra.HoursToHMS(rightAscension)} Dec={_utilitiesExtra.HoursToHMS(declination)}"); CheckConnected("SyncToCoordinates"); SharedResourcesWrapper.Lock(() => @@ -1940,8 +2066,25 @@ namespace ASCOM.Meade.net //LX200's - a "#" terminated string with the name of the object that was synced. // Autostars & Autostar II - A static string: " M31 EX GAL MAG 3.5 SZ178.0'#" - if (result == string.Empty) + if (string.IsNullOrWhiteSpace(result)) throw new InvalidOperationException("Unable to perform sync"); + + // At least the classic LX200 low precision might not slew to the exact target position + // This Requires to retrieve the aimed target ra de from the telescope + double ra = RightAscension; + if (_targetRightAscension != InvalidParameter && + _utilities.HoursToHMS(ra, ":", ":", ":", _digitsRa) != _utilities.HoursToHMS(_targetRightAscension, ":", ":", ":", _digitsRa)) + { + LogMessage("SyncToTarget", $"differ RA real {ra} targeted {_targetRightAscension}"); + _targetRightAscension = ra; + } + double de = Declination; + if (_targetDeclination != InvalidParameter && + _utilities.DegreesToDMS(de, "*", ":", ":", _digitsDe) != _utilities.DegreesToDMS(_targetDeclination, "*", ":", ":", _digitsDe)) + { + LogMessage("SyncToTarget", $"differ DE real {de} targeted {_targetDeclination}"); + _targetDeclination = de; + } } private double _targetDeclination = InvalidParameter; @@ -1970,14 +2113,18 @@ namespace ASCOM.Meade.net CheckConnected("TargetDeclination Set"); - //todo implement low precision version of this. if (value > 90) throw new InvalidValueException("Declination cannot be greater than 90."); if (value < -90) throw new InvalidValueException("Declination cannot be less than -90."); - - var dms = _utilities.DegreesToDMS(value, "*", ":", ":", 2); + + var dms = ""; + if (IsLongFormat) + dms = _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe); + else + dms = _utilities.DegreesToDM(value, "*", "", _digitsDe); + var s = value < 0 ? string.Empty : "+"; var command = $":Sd{s}{dms}#"; @@ -1995,7 +2142,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("Target declination invalid"); } - _targetDeclination = value; + _targetDeclination = _utilities.DMSToDegrees(dms); } } @@ -2028,10 +2175,17 @@ namespace ASCOM.Meade.net if (value >= 24) throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); - //todo implement the low precision version - var hms = _utilities.HoursToHMS(value, ":", ":", ":", 2); - var response = SharedResourcesWrapper.SendChar($":Sr{hms}#"); + var hms = ""; + if(IsLongFormat) + hms = _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa); + else + //meade protocol defines H:MM.T format + hms = _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); + + var command = $":Sr{hms}#"; + LogMessage("TargetRightAscension Set", $"{command}"); + var response = SharedResourcesWrapper.SendChar(command); //:SrHH:MM.T# //:SrHH:MM:SS# //Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting. @@ -2042,7 +2196,7 @@ namespace ASCOM.Meade.net if (response == "0") throw new InvalidOperationException("Failed to set TargetRightAscension."); - _targetRightAscension = value; + _targetRightAscension = _utilities.HMSToHours(hms); } } diff --git a/Meade.net.v3.ncrunchsolution.user b/Meade.net.v3.ncrunchsolution.user deleted file mode 100644 index 9b1f351..0000000 --- a/Meade.net.v3.ncrunchsolution.user +++ /dev/null @@ -1,16 +0,0 @@ - - - True - Run all tests automatically [Global] - False - 80 - - false - false - true - true - false - - 544 - - \ No newline at end of file