From c6b54e273dcd7704b4bdede75a03effdb2300388 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sun, 25 Apr 2021 18:27:44 +0100 Subject: [PATCH] Added unit testing for bypass feature, and setting the date on first connection --- .../TelescopeUnitTests.cs | 101 ++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 28 +++-- Meade.net/TelescopeList.cs | 1 + 3 files changed, 111 insertions(+), 19 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index f97175f..56b307c 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -52,8 +52,13 @@ namespace Meade.net.Telescope.UnitTests DataBits = 8, GuideRateArcSecondsPerSecond = 1.23, - Precision = "Unchanged", - GuidingStyle = "Auto" + Precision = "Unchanged", + GuidingStyle = "Auto", + + SendDateTime = false, + ParkedBehaviour = ParkedBehaviour.NoCoordinates, + ParkedAlt = 0, + ParkedAz = 180 }; _utilMock = new Mock(); @@ -400,12 +405,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_WhenConnectingLX200GPS_Then_ConnectsToSerialDevice() { - var productName = TelescopeList.LX200GPS; - var firmware = string.Empty; - - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); - _telescope.Connected = true; + ConnectTelescope(TelescopeList.LX200GPS, string.Empty); _sharedResourcesWrapperMock.Verify( x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); @@ -413,6 +413,90 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); } + [Test] + public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_SpecialStartupInstructionSendOnFirstConnect() + { + _profileProperties.SendDateTime = true; + + DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + + _clockMock.Setup(x => x.UtcNow).Returns(() => + { + return endSlewingDatetime; + }); + + string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + + string expectedResult = "Daylight Savings Time:"; + _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand)).Returns("1"); + + ConnectTelescope(TelescopeList.LX200GPS, string.Empty); + + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Once); + } + + [Test] + public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_ByPassDisplaysWhenNotOnDaylightScreen() + { + _profileProperties.SendDateTime = true; + + string telescopeTime = "20:36:25"; + string telescopeDate = "10/03/21"; + DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + + _clockMock.Setup(x => x.UtcNow).Returns(() => + { + return endSlewingDatetime; + }); + + string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + + string expectedResult = "Align"; + _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); + + + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + + ConnectTelescope(TelescopeList.LX200GPS, string.Empty); + + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); + } + + [Test] + public void Connected_WhenConnectingAutostarAndSendDateTimeIsTrue_Then_ByPassDisplaysWhenNotOnDaylightScreen() + { + _profileProperties.SendDateTime = true; + + string telescopeTime = "20:36:25"; + string telescopeDate = "10/03/21"; + DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + + _clockMock.Setup(x => x.UtcNow).Returns(() => + { + return endSlewingDatetime; + }); + + string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + + string expectedResult = "Align"; + _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("0"); + + + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + + ConnectTelescope(); + + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); + } + [Test] public void Connected_Set_WhenConnectingToLX200EMC_Then_ConnectsToSerialDevice() { @@ -473,6 +557,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase("Auto", "Autostar", "30Ab", false)] [TestCase("Auto","Autostar", "31Ee", true)] [TestCase("Auto","Autostar", "43Eg", true)] + [TestCase("Auto","Autostar", "A4S4", true)] [TestCase("Auto","Autostar II", "", false)] [TestCase("Auto","LX2001", "", true)] [TestCase("Auto",":GVP", "", false)] //LX200 Classic diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4daf9fb..8e53e16 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -484,7 +484,7 @@ namespace ASCOM.Meade.net { if (SendDateTime) { - UTCDate = DateTime.UtcNow; + UTCDate = _clock.UtcNow; } } @@ -505,14 +505,19 @@ namespace ASCOM.Meade.net } else if (SharedResourcesWrapper.ProductName == TelescopeList.Autostar497) { - var displayText = Action("Handbox", "readdisplay"); - if (displayText.Contains("Press 0 to Alignor MODE for Menu")) + var i = 10; + while (i > 0) { - for (var i = 0; i < 4; i++) + var displayText = Action("Handbox", "readdisplay"); + if (displayText.Contains("Align:")) { - Action("Handbox", "mode"); - _utilities.WaitForMilliseconds(500); + i = 0; + continue; } + + Action("Handbox", "mode"); + _utilities.WaitForMilliseconds(500); + i--; } } } @@ -1764,7 +1769,7 @@ namespace ASCOM.Meade.net double siderealTime = 0.0; using (var novas = new NOVAS31()) { - var jd = _utilities.DateUTCToJulian(DateTime.UtcNow); + var jd = _utilities.DateUTCToJulian(_clock.UtcNow); novas.SiderealTime(jd, 0, novas.DeltaT(jd), GstType.GreenwichApparentSiderealTime, Method.EquinoxBased, @@ -2573,7 +2578,7 @@ namespace ASCOM.Meade.net } catch (ParkedException e) { - return DateTime.UtcNow; + return _clock.UtcNow; } } set @@ -2639,18 +2644,19 @@ namespace ASCOM.Meade.net AtPark = false; } - private void BypassHandboxEntryForAutostarII() + private bool BypassHandboxEntryForAutostarII() { var utcCorrection = GetUtcCorrection(); - var localDateTime = DateTime.UtcNow - utcCorrection; + var localDateTime = _clock.UtcNow - utcCorrection; //localDateTime: HH: mm: ss - SharedResourcesWrapper.SendBlind($":hI{localDateTime:yyMMddHHmmss}#"); + var result = SharedResourcesWrapper.SendChar($":hI{localDateTime:yyMMddHHmmss}#"); //:hIYYMMDDHHMMSS# //Bypass handbox entry of daylight savings, date and time.Use the values supplied in this command.This feature is //intended to allow use of the Autostar II from permanent installations where GPS reception is not possible, such as within //metal domes. This command must be issued while the telescope is waiting at the initial daylight savings prompt. //Returns: 1 – if command was accepted. + return result == "1"; } #endregion diff --git a/Meade.net/TelescopeList.cs b/Meade.net/TelescopeList.cs index 440c4bd..fd92c1b 100644 --- a/Meade.net/TelescopeList.cs +++ b/Meade.net/TelescopeList.cs @@ -14,6 +14,7 @@ // ReSharper disable once InconsistentNaming public const string Autostar497_43Eg = "43Eg"; + public const string AudioStar_A4S4 = "A4S4"; #endregion #region LX200GPS