From 9042c76d4864102cebc1f6308a0fe8ebb2a40c03 Mon Sep 17 00:00:00 2001 From: Frank S Date: Sun, 17 Jan 2021 17:01:07 +0100 Subject: [PATCH 01/20] Classic LX 200 low precision and lock on slewing enhancement (issue #8) --- Meade.net.Telescope/Telescope.cs | 199 +++++++++++++++++++++++++++---- 1 file changed, 174 insertions(+), 25 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index d0716fb..b7b7df3 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,81 @@ 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() + { + const double eps = 0.00001d; + if (!_isTargetCoordinateInitRequired) + return _isTargetCoordinateInitRequired; + + if (!IsConnected) + return true; + + if(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + { + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + + var result = SharedResourcesWrapper.SendString(":Gr#"); + + double rightTargetAscension = HMToHours(result); + + //target RA == 0 + if(Math.Abs(rightTargetAscension) > eps) + { + _isTargetCoordinateInitRequired = false; + return _isTargetCoordinateInitRequired; + } + result = SharedResourcesWrapper.SendString(":Gd#"); + + double targetDeclination = _utilities.DMSToDegrees(result); + + //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 telescop 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); + + //doit only once + _isTargetCoordinateInitRequired = false; + + + } + catch (Exception ex) + { + LogMessage("InitTargetCoordinates", $"Error sync telescope position", ex.Message); + } + + } public void SetLongFormat(bool setLongFormat) { IsLongFormat = false; @@ -505,14 +592,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 +615,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 +1190,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 +1555,21 @@ 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) + { + String[] token = hm.Split('.'); + if (token.Length == 2) + { + int seconds = Int16.Parse(token[1]) * 6; + string hms = $"{token[0]}:{seconds}"; + return _utilities.HMSToHours(hms); + } + return _utilities.HMSToHours(hm); + } + public double RightAscension { get @@ -1466,9 +1580,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; } } @@ -1875,25 +1989,29 @@ 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 = result != null && result != string.Empty; + + if (!isSlewing) return false; - } - var trimmedResult = result.Trim(); - var isResultEmpty = trimmedResult == string.Empty; + //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; - var isSlewing = !isResultEmpty; + LogMessage("IsSlewingToTarget", $"Result = {isSlewing}"); - if (!isResultEmpty) //the LX-200 can return crap from the buffer when it's not slewing so let's try to filter that out. - { - if (!trimmedResult.Contains("|")) - { - isSlewing = false; - } - } + //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(); - LogMessage("IsSlewingToTarget", $"Result = {isSlewing} ({trimmedResult})"); return isSlewing; } @@ -1906,6 +2024,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(() => @@ -1930,6 +2049,23 @@ namespace ASCOM.Meade.net if (result == string.Empty) 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; @@ -1964,8 +2100,13 @@ namespace ASCOM.Meade.net 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}#"; @@ -1983,7 +2124,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("Target declination invalid"); } - _targetDeclination = value; + _targetDeclination = _utilities.DMSToDegrees(dms); } } @@ -2018,8 +2159,16 @@ namespace ASCOM.Meade.net 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 protocoll 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. @@ -2030,7 +2179,7 @@ namespace ASCOM.Meade.net if (response == "0") throw new InvalidOperationException("Failed to set TargetRightAscension."); - _targetRightAscension = value; + _targetRightAscension = _utilities.HMSToHours(hms); } } From cd8330196eae0729f75979a5ea76bed043eb9e49 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 17:30:29 +0000 Subject: [PATCH 02/20] Made a few minor tweaks whilst reviewing. --- Meade.net.Telescope/Telescope.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b7b7df3..af77cb1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -515,7 +515,6 @@ namespace ASCOM.Meade.net /// private bool IsTargetCoordinateInitRequired() { - const double eps = 0.00001d; if (!_isTargetCoordinateInitRequired) return _isTargetCoordinateInitRequired; @@ -528,28 +527,24 @@ namespace ASCOM.Meade.net return _isTargetCoordinateInitRequired; } - var result = SharedResourcesWrapper.SendString(":Gr#"); - - double rightTargetAscension = HMToHours(result); + const double eps = 0.00001d; + double rightTargetAscension = RightAscension; //target RA == 0 - if(Math.Abs(rightTargetAscension) > eps) + if (Math.Abs(rightTargetAscension) > eps) { _isTargetCoordinateInitRequired = false; return _isTargetCoordinateInitRequired; } - result = SharedResourcesWrapper.SendString(":Gd#"); - - double targetDeclination = _utilities.DMSToDegrees(result); + double targetDeclination = Declination; //target DE == 0 - if(Math.Abs(targetDeclination) > eps) + 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)) @@ -565,26 +560,23 @@ namespace ASCOM.Meade.net private void InitTargetCoordinates() { - try { var raAndDec = GetTelescopeRaAndDec(); - //when connection the first time the telescop target coordinates should be the current ones. + //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); - //doit only once + //do it only once _isTargetCoordinateInitRequired = false; - - } catch (Exception ex) { LogMessage("InitTargetCoordinates", $"Error sync telescope position", ex.Message); } - } + public void SetLongFormat(bool setLongFormat) { IsLongFormat = false; @@ -1989,7 +1981,7 @@ 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. - bool isSlewing = result != null && result != string.Empty; + bool isSlewing = !string.IsNullOrEmpty(result); if (!isSlewing) return false; From 1297b5eb786a4df062557aa72e4d526d093cfd11 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 17:49:45 +0000 Subject: [PATCH 03/20] Fixed 9 of the broken unit tests by populating the mock information properly. --- Meade.net.Telescope/Telescope.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index af77cb1..7677c15 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -421,7 +421,7 @@ namespace ASCOM.Meade.net var raAndDec = GetTelescopeRaAndDec(); LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); } - catch (Exception) + catch (Exception ex) { SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; From 58992c29478ec9101d4706ade80077aeb8c07280 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:04:24 +0000 Subject: [PATCH 04/20] More unit tests fixed --- .../TelescopeUnitTests.cs | 50 +++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 2 +- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 2a0403c..2310575 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); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 7677c15..b91325c 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1550,7 +1550,7 @@ 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) + public double HMToHours(string hm) { String[] token = hm.Split('.'); if (token.Length == 2) From 65afa07125f98903954de4870e2211c9bdcdc8de Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:13:32 +0000 Subject: [PATCH 05/20] Another unit test fail bites the dust --- Meade.net.v3.ncrunchsolution.user | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net.v3.ncrunchsolution.user b/Meade.net.v3.ncrunchsolution.user index 9b1f351..13e9d26 100644 --- a/Meade.net.v3.ncrunchsolution.user +++ b/Meade.net.v3.ncrunchsolution.user @@ -3,7 +3,7 @@ True Run all tests automatically [Global] False - 80 + 59 false false From 927d6bce47ceb4aa75a5730a2b0f84622c2a2d32 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:19:16 +0000 Subject: [PATCH 06/20] Fixed the log message to be returned from IsSlewing with the final state every time without exception. --- Meade.net.Telescope/Telescope.cs | 44 +++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b91325c..46298c2 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1982,29 +1982,33 @@ namespace ASCOM.Meade.net //Autostars and Autostar II – a string containing one bar until a slew is complete, then a null string is returned. bool isSlewing = !string.IsNullOrEmpty(result); + try + { + if (!isSlewing) + return false; - if (!isSlewing) - return false; + //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(); - //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; - - LogMessage("IsSlewingToTarget", $"Result = {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; + } + finally + { + LogMessage("IsSlewingToTarget", $"Result = {isSlewing}"); + } } public void SyncToAltAz(double azimuth, double altitude) From 902d6bbc6e941eeff13bccd127f6d7bb02356723 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:23:20 +0000 Subject: [PATCH 07/20] Added a check to the telescope to ensure that this is only triggered for the LX200CLASSIC other scopes do not need to the extra work. --- Meade.net.Telescope/Telescope.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 46298c2..daef85a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -515,6 +515,9 @@ namespace ASCOM.Meade.net /// private bool IsTargetCoordinateInitRequired() { + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + return false; + if (!_isTargetCoordinateInitRequired) return _isTargetCoordinateInitRequired; From 579ea164f843ccca15319f78bb7a7e353b1804b7 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:24:15 +0000 Subject: [PATCH 08/20] Fixed another unit test --- .../TelescopeUnitTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 2310575..4078aa8 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1820,6 +1820,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(); @@ -2169,6 +2175,9 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToCoordinates_WhenNotConnected_ThenThrowsException() { + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.2; + double rightAscension = 5.5; string hms = "05:30:00"; @@ -2234,6 +2243,11 @@ namespace Meade.net.Telescope.UnitTests [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); From e8f3b00912c1835669632c769b5b015c7f96580b Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 18:48:53 +0000 Subject: [PATCH 09/20] Fixed test case to send the correct encoded string rather than a english readable non encoded string. --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 4078aa8..c5b77dc 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2238,7 +2238,8 @@ 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", false)] [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) From 199b068e94db400a6e52894cf21cf979a9d0a2ca Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 17 Jan 2021 20:18:07 +0000 Subject: [PATCH 10/20] Fixed another broken unit test --- .../TelescopeUnitTests.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index c5b77dc..408f7a5 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2562,14 +2562,26 @@ 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(), From 779d31474829417e87cb9f57b94034a8299a2b8a Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 15:33:23 +0000 Subject: [PATCH 11/20] Fixed another unit test --- .../TelescopeUnitTests.cs | 43 +++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 19 ++++---- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 408f7a5..dea85a9 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2175,6 +2175,21 @@ 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; @@ -2184,6 +2199,12 @@ namespace Meade.net.Telescope.UnitTests double declination = -30.5; string dec = "-30*30:00"; + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + + _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); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); @@ -2460,6 +2481,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.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _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.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + + _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); var slewCounter = 0; @@ -2476,7 +2514,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)); @@ -2576,8 +2614,7 @@ namespace Meade.net.Telescope.UnitTests _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"); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index daef85a..70a27d5 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1555,14 +1555,13 @@ namespace ASCOM.Meade.net /// public double HMToHours(string hm) { - String[] token = hm.Split('.'); - if (token.Length == 2) - { - int seconds = Int16.Parse(token[1]) * 6; - string hms = $"{token[0]}:{seconds}"; - return _utilities.HMSToHours(hms); - } - return _utilities.HMSToHours(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 @@ -2093,7 +2092,6 @@ 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."); @@ -2156,13 +2154,12 @@ 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 = ""; if(IsLongFormat) hms = _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa); else - //meade protocoll defines H:MM.T format + //meade protocol defines H:MM.T format hms = _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); var command = $":Sr{hms}#"; From 26b94de48c2d5636e502ea3a10b2e67e3a090b41 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 15:42:31 +0000 Subject: [PATCH 12/20] Fixed unit test TargetDeclination_Get_WhenValueOK_ThenSetsNewTargetDeclination --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index dea85a9..9f55e39 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1904,7 +1904,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(); From f827a1ea3a11ba4a7e7806672e82f313571ce6d4 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 15:46:39 +0000 Subject: [PATCH 13/20] Added ncrunchsolution.user files to .gitIgnore --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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.* From d9acad1caad34898a4721ba4179abf6fa026528f Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 15:50:04 +0000 Subject: [PATCH 14/20] removed unneeded ncrunch file --- Meade.net.v3.ncrunchsolution.user | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 Meade.net.v3.ncrunchsolution.user diff --git a/Meade.net.v3.ncrunchsolution.user b/Meade.net.v3.ncrunchsolution.user deleted file mode 100644 index 13e9d26..0000000 --- a/Meade.net.v3.ncrunchsolution.user +++ /dev/null @@ -1,16 +0,0 @@ - - - True - Run all tests automatically [Global] - False - 59 - - false - false - true - true - false - - 544 - - \ No newline at end of file From c848ebd9be5a90cb1e6dbdae263d9a17c5302368 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 15:55:36 +0000 Subject: [PATCH 15/20] Fixed TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 9f55e39..f3280dc 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1988,7 +1988,12 @@ 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; + var telescopeRaResult = "HH:MM:SS"; + + _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(); From 447ff3ace9cb50d0a0bc17caa34d164229b00a29 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 16:00:18 +0000 Subject: [PATCH 16/20] Fixed SlewToAltAzAsync_WhenAltAndAzValid_ThenConvertsToRADec --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f3280dc..e38f700 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1989,7 +1989,6 @@ namespace Meade.net.Telescope.UnitTests public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { var digitsRA = 2; - var telescopeRaResult = "HH:MM:SS"; _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", digitsRA)).Returns(hms); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(rightAscension); @@ -2592,6 +2591,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); From 778b36b7f5edbedb4cf7d1221186add8223e6fbe Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 21:45:47 +0000 Subject: [PATCH 17/20] Fixed SyncToCoordinates_WhenConnected_ThenReturnsExpectedResult --- .../TelescopeUnitTests.cs | 26 ++++++++++++++----- Meade.net.Telescope/Telescope.cs | 2 +- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index e38f700..390d76c 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2201,7 +2201,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeDecResult = "s12*34’56"; var telescopeRaResult = "HH:MM:SS"; - var hmsResult = 1.2; + //var hmsResult = 1.2; double rightAscension = 5.5; string hms = "05:30:00"; @@ -2209,18 +2209,30 @@ namespace Meade.net.Telescope.UnitTests double declination = -30.5; string dec = "-30*30:00"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + var digitsRA = 2; - _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + _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"); - - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(dec); _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); @@ -2501,10 +2513,10 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); - _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); _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); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 70a27d5..8c3e88e 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2045,7 +2045,7 @@ 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 From c7fa7ab095e1b2b5d4b76269a60a044d5c16d1c8 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Jan 2021 21:55:44 +0000 Subject: [PATCH 18/20] Fixed SlewToCoordinatesAsync_WhenCalled_ThenSetsTargetAndSlews --- .../TelescopeUnitTests.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 390d76c..0c9c3f7 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2464,11 +2464,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(() => From a9f57b7ad2edcf3b82178d4add016da06b5cdc73 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 31 Jan 2021 11:33:43 +0000 Subject: [PATCH 19/20] The is Slewing is now actively detecting a | response, or an empty string to return the correct value. There is still an edge case of a string of FF characters which is unresolved --- Meade.net.Telescope/Telescope.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8c3e88e..a8c3104 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1986,8 +1986,17 @@ namespace ASCOM.Meade.net bool isSlewing = !string.IsNullOrEmpty(result); try { - if (!isSlewing) - 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); From 79a404e78a6954163623b032c379a7c852a8a826 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 1 Feb 2021 23:23:00 +0000 Subject: [PATCH 20/20] Fixed the last unit test, seems that the special code for the chr(255)'s isn't needed as it's a non empty string, which should indicate that slewing is happening. --- .../TelescopeUnitTests.cs | 2 +- Meade.net.Telescope/Telescope.cs | 50 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 6da530b..178e0d4 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2314,7 +2314,7 @@ namespace Meade.net.Telescope.UnitTests [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)] //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", false)] + [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) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 874586b..39837d0 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -421,7 +421,7 @@ namespace ASCOM.Meade.net var raAndDec = GetTelescopeRaAndDec(); LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); } - catch (Exception ex) + catch (Exception) { SharedResourcesWrapper.Disconnect("Serial", DriverId); throw; @@ -1644,7 +1644,7 @@ namespace ASCOM.Meade.net } } - public double SiteElevation + public new double SiteElevation { get { @@ -1998,33 +1998,33 @@ namespace ASCOM.Meade.net bool isSlewing = !string.IsNullOrEmpty(result); try { - if (string.IsNullOrEmpty(result)) - { - isSlewing = false; - return isSlewing; - } + //if (string.IsNullOrEmpty(result)) + //{ + // isSlewing = false; + // return isSlewing; + //} - if (result.Contains("|")) - { - isSlewing = true; - 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); + ////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; + //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(); + ////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; }