From 70e615bb4e78baa53ebf1eb43556997d280b29ae Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Mon, 26 Apr 2021 20:51:41 +0100 Subject: [PATCH 01/21] Made sure that CommandString, CommandBool and CommandBlind work as expected, complete with Raw and non raw support. (Implementation is the same as one of the LX200 drivers.) --- .../FocuserUnitTests.cs | 50 +- .../TelescopeUnitTests.cs | 625 +++++++++--------- Meade.net.Telescope/Telescope.cs | 162 +++-- .../SharedResourcesUnitTests.cs | 25 +- Meade.net.focuser/Focuser.cs | 13 +- Meade.net/SharedResources.cs | 32 +- Meade.net/Wrapper/SharedResourcesWrapper.cs | 24 +- 7 files changed, 480 insertions(+), 451 deletions(-) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index 9f945d2..e96a219 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -109,16 +109,17 @@ namespace Meade.net.Focuser.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBlind")); } - [Test] - public void CommandBlind_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBlind_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; ConnectFocuser(); - _focuser.CommandBlind(expectedMessage, true); + _focuser.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); } [Test] @@ -130,16 +131,19 @@ namespace Meade.net.Focuser.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to focuser when trying to execute: CommandBool")); } - [Test] - public void CommandBool_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; + _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); ConnectFocuser(); - var exception = Assert.Throws(() => { _focuser.CommandBool(expectedMessage, true); }); + var result = _focuser.CommandBool(expectedMessage, raw); - Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver.")); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + Assert.That(result, Is.True); } [Test] @@ -319,7 +323,7 @@ namespace Meade.net.Focuser.UnitTests _focuser.Halt(); - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":FQ#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("FQ", false), Times.AtLeastOnce); } [Test] @@ -334,13 +338,13 @@ namespace Meade.net.Focuser.UnitTests [TestCase(false)] [TestCase(true)] - public void Link_Get_ReturnsSameValueAsConnected( bool connected) + public void Link_Get_ReturnsSameValueAsConnected(bool connected) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); _focuser.Connected = connected; - Assert.That( _focuser.Link, Is.EqualTo(connected)); + Assert.That(_focuser.Link, Is.EqualTo(connected)); } [TestCase(false)] @@ -394,12 +398,12 @@ namespace Meade.net.Focuser.UnitTests _focuser.Move(0); - _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Never); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Never); } [TestCase(200)] [TestCase(-200)] - public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser( int position) + public void Move_WhenIncrementIsNot0_ThenMovesFocuserAndStopsFocuser(int position) { _profileProperties.BacklashCompensation = 0; @@ -409,16 +413,16 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); } - _sharedResourcesWrapperMock.Verify( x => x.Lock(It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Lock(It.IsAny()), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); @@ -437,16 +441,16 @@ namespace Meade.net.Focuser.UnitTests if (position < 0) { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position)), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(_profileProperties.BacklashCompensation)), Times.Never); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(1)); } else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F-#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":F+#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F-", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("F+", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(Math.Abs(position) + _profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(_profileProperties.BacklashCompensation), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(100), Times.Exactly(2)); @@ -503,7 +507,7 @@ namespace Meade.net.Focuser.UnitTests { var exception = Assert.Throws(() => { - var result = _focuser.Temperature; + var result = _focuser.Temperature; Assert.Fail($"{result} should not have a value"); }); Assert.That(exception.Message, Is.EqualTo("Property read Temperature is not implemented in this driver.")); diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index d3f3f03..82d2909 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -70,7 +70,7 @@ namespace Meade.net.Telescope.UnitTests _astroUtilsMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); @@ -98,10 +98,10 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(_testProperties.SiteLatitudeString); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns(_testProperties.SiteLatitudeString); _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns(_testProperties.SiteLatitudeValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#", true)).Returns(_testProperties.telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); @@ -157,43 +157,43 @@ namespace Meade.net.Telescope.UnitTests public void Action_Handbox_ReadDisplay() { string expectedResult = "test result string"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); _telescope.Connected = true; var actualResult = _telescope.Action("handbox", "readdisplay"); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("ED", false), Times.Once); Assert.That(actualResult, Is.EqualTo(expectedResult)); } - [TestCase("enter", ":EK13#")] - [TestCase("mode", ":EK9#")] - [TestCase("longMode", ":EK11#")] - [TestCase("goto", ":EK24#")] - [TestCase("0", ":EK48#")] - [TestCase("1", ":EK49#")] - [TestCase("2", ":EK50#")] - [TestCase("3", ":EK51#")] - [TestCase("4", ":EK52#")] - [TestCase("5", ":EK53#")] - [TestCase("6", ":EK54#")] - [TestCase("7", ":EK55#")] - [TestCase("8", ":EK56#")] - [TestCase("9", ":EK57#")] - [TestCase("up", ":EK94#")] - [TestCase("down", ":EK118#")] - [TestCase("back", ":EK87#")] - [TestCase("forward", ":EK69#")] - [TestCase("?", ":EK63#")] + [TestCase("enter", "EK13")] + [TestCase("mode", "EK9")] + [TestCase("longMode", "EK11")] + [TestCase("goto", "EK24")] + [TestCase("0", "EK48")] + [TestCase("1", "EK49")] + [TestCase("2", "EK50")] + [TestCase("3", "EK51")] + [TestCase("4", "EK52")] + [TestCase("5", "EK53")] + [TestCase("6", "EK54")] + [TestCase("7", "EK55")] + [TestCase("8", "EK56")] + [TestCase("9", "EK57")] + [TestCase("up", "EK94")] + [TestCase("down", "EK118")] + [TestCase("back", "EK87")] + [TestCase("forward", "EK69")] + [TestCase("?", "EK63")] public void Action_Handbox_WhenCalling_ThenSendsAppropriateBlindCommands(string action, string expectedString) { ConnectTelescope(); _telescope.Action("handbox", action); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedString, false), Times.Once); } [TestCase("1")] @@ -207,7 +207,7 @@ namespace Meade.net.Telescope.UnitTests string parameters = $"select {site}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); } [TestCase("0")] @@ -222,20 +222,20 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } - [TestCase("1", ":GM#", "Home")] - [TestCase("2", ":GN#", "Club")] - [TestCase("3", ":GO#", "GPS")] - [TestCase("4", ":GP#", "Parents")] + [TestCase("1", "GM", "Home")] + [TestCase("2", "GN", "Club")] + [TestCase("3", "GO", "GPS")] + [TestCase("4", "GP", "Parents")] public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, true)).Returns(siteName); + _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, false)).Returns(siteName); ConnectTelescope(); string parameters = $"GetName {site}"; var result = _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, false), Times.Once); Assert.That(result, Is.EqualTo(siteName)); } @@ -262,21 +262,21 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo("4")); } - [TestCase("1", ":SMHome#", "Home")] - [TestCase("2", ":SNClub#", "Club")] - [TestCase("3", ":SOGPS Site#", "GPS Site")] - [TestCase("4", ":SPParents#", "Parents")] + [TestCase("1", "SMHome", "Home")] + [TestCase("2", "SNClub", "Club")] + [TestCase("3", "SOGPS Site", "GPS Site")] + [TestCase("4", "SPParents", "Parents")] public void Action_Site_SetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(telescopeCommand, false)).Returns("1"); ConnectTelescope(); string parameters = $"SetName {site} {siteName}"; _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(telescopeCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(telescopeCommand, false), Times.Once); } [TestCase("0")] @@ -334,16 +334,17 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBlind")); } - [Test] - public void CommandBlind_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandBlind_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; ConnectTelescope(); - _telescope.CommandBlind(expectedMessage, true); + _telescope.CommandBlind(expectedMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedMessage, raw), Times.Once); } [Test] @@ -355,18 +356,22 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBool")); } - [Test] - public void CommandBool_WhenConnected_ThenSendsExpectedMessage() + + [TestCase(false)] + [TestCase(true)] + public void CommandBool_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "test blind Message"; + _sharedResourcesWrapperMock.Setup(x => x.SendBool(expectedMessage, raw)).Returns(true); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.CommandBool(expectedMessage, true); }); + var result = _telescope.CommandBool(expectedMessage, raw); - Assert.That(exception.Message, Is.EqualTo("Method CommandBool is not implemented in this driver.")); + _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); + Assert.That(result, Is.True); } - + [Test] public void CommandString_WhenNotConnected_ThenThrowsNotConnectedException() { @@ -376,19 +381,20 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandString")); } - [Test] - public void CommandString_WhenConnected_ThenSendsExpectedMessage() + [TestCase(false)] + [TestCase(true)] + public void CommandString_WhenConnected_ThenSendsExpectedMessage(bool raw) { string expectedMessage = "expected result message"; string sendMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, raw)).Returns(() => expectedMessage); ConnectTelescope(); - var actualMessage = _telescope.CommandString(sendMessage, true); + var actualMessage = _telescope.CommandString(sendMessage, raw); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, raw), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -401,25 +407,25 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) ConnectTelescope(); - + Assert.That(_telescope.Connected, Is.EqualTo(expectedConnected)); if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } } - + [Test] public void Connected_Set_WhenConnectingLX200GPS_Then_ConnectsToSerialDevice() { 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); + _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Once); } [Test] @@ -431,16 +437,16 @@ namespace Meade.net.Telescope.UnitTests _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); - string setDateCommand = $":hI{testNow:yyMMddHHmmss}#"; + string setDateCommand = $"hI{testNow: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"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand, false)).Returns("1"); ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Once); } [Test] @@ -457,19 +463,19 @@ namespace Meade.net.Telescope.UnitTests return endSlewingDatetime; }); - string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + 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.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); - + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); + ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -487,19 +493,19 @@ namespace Meade.net.Telescope.UnitTests return endSlewingDatetime; }); - string setDateCommand = $":hI{endSlewingDatetime:yyMMddHHmmss}#"; + 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.SendString("ED", false)).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -514,8 +520,8 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; _sharedResourcesWrapperMock.Verify(x => x.Connect("Serial", It.IsAny(), It.IsAny()), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GZ", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}", false), Times.Never); } @@ -523,7 +529,7 @@ namespace Meade.net.Telescope.UnitTests public void Connected_Set_SettingTrueWhenTrue_ThenDoesNothing() { ConnectTelescope(); - _sharedResourcesWrapperMock.Verify( x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.Connect(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); //act _telescope.Connected = true; @@ -561,15 +567,15 @@ 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 + [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 [TestCase("Guide Rate Slew", "LX2001", "", false)] //force old style [TestCase("Pulse Guiding", ":GVP", "", true)] //force new style - + public void IsNewPulseGuidingSupported_ThenIsSupported_ThenReturnsTrue(string guidingStyle, string productName, string firmware, bool isSupported) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); @@ -587,37 +593,37 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsShortFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"),Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); } [Test] public void SetLongFormatFalse_WhenTelescopeReturnsLongFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(false); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsLongFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Never); } [Test] public void SetLongFormatTrue_WhenTelescopeReturnsShortFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GZ", false)).Returns("DDD*MM"); _telescope.SetLongFormat(true); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("U", false), Times.Once); } [Test] @@ -659,7 +665,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SelectSite(site); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":W{site}#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"W{site}", false), Times.Once); } [Test] @@ -731,12 +737,12 @@ namespace Meade.net.Telescope.UnitTests public void AlignmentMode_Get_WhenScopeInAltAz_ReturnsAltAz(string telescopeMode, AlignmentModes alignmentMode) { const char ack = (char)6; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString())).Returns(telescopeMode); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(ack.ToString(), true)).Returns(telescopeMode); ConnectTelescope(); - + var actualResult = _telescope.AlignmentMode; - + Assert.That(actualResult, Is.EqualTo(alignmentMode)); } @@ -755,13 +761,13 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AlignmentMode_Set_WhenNotConnected_ThrowsException() { - var exception = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); + var exception = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AlignmentMode Set")); } - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algAltAz, ":AA#")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algPolar, ":AP#")] - [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algGermanPolar, ":AP#")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algAltAz, "AA")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algPolar, "AP")] + [TestCase("AUTOSTAR", "43Eg", AlignmentModes.algGermanPolar, "AP")] public void AlignmentMode_Set_WhenConnected_ThenSendsExpectedCommand(string productName, string firmware, AlignmentModes alignmentMode, string expectedCommand) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); @@ -770,11 +776,11 @@ namespace Meade.net.Telescope.UnitTests _telescope.AlignmentMode = alignmentMode; - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(expectedCommand, false), Times.Once); } [TestCase("AUTOSTAR", "43Ef")] - public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware ) + public void AlignmentMode_Set_WhenAutostarFirmwareToLow_ThenThrowsException(string productName, string firmware) { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); @@ -901,7 +907,7 @@ namespace Meade.net.Telescope.UnitTests }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CanSetGuideRates Get")); } - + [Test] public void CanSetGuideRates_Get_WhenConnectedToAutostar_ThenReturnsFalse() { @@ -929,7 +935,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#", true), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("P", false), Times.Never); } [TestCase("High", false, true)] @@ -941,7 +947,7 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.Precision = desiredPresision; var currentPrecision = telescopePrecision; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":P#")).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendChar("P", false)).Returns(() => { currentPrecision = !currentPrecision; @@ -957,7 +963,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); Assert.That(currentPrecision, Is.EqualTo(finalPrecision)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.AtLeastOnce); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.AtLeastOnce); } [TestCase("High", false, true)] @@ -973,7 +979,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":P#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); } [Test] @@ -1121,7 +1127,7 @@ namespace Meade.net.Telescope.UnitTests public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) { var expectedResult = 12.34; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(declincationString); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(declincationString); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); ConnectTelescope(); @@ -1135,15 +1141,15 @@ namespace Meade.net.Telescope.UnitTests { var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(); var result = _telescope.Declination; - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#", true), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("GD", false), Times.Exactly(2)); _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); @@ -1153,7 +1159,7 @@ namespace Meade.net.Telescope.UnitTests public void DeclinationRate_Get_ThenReturns0() { var actualResult = _telescope.DeclinationRate; - + Assert.That(actualResult, Is.EqualTo(0)); } @@ -1171,7 +1177,7 @@ namespace Meade.net.Telescope.UnitTests { var excpetion = Assert.Throws(() => { - var result = _telescope.DestinationSideOfPier(0,0); + var result = _telescope.DestinationSideOfPier(0, 0); Assert.Fail($"{result} should not have returned"); }); @@ -1211,7 +1217,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void FindHome_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.FindHome();}); + var excpetion = Assert.Throws(() => { _telescope.FindHome(); }); Assert.That(excpetion.Method, Is.EqualTo("FindHome")); } @@ -1257,7 +1263,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateDeclination = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1290,7 +1296,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.GuideRateRightAscension = newGuideRate; - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Rg01.2#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Rg01.2", false), Times.Once); Assert.That(_telescope.GuideRateDeclination, Is.EqualTo(newGuideRate)); } @@ -1311,24 +1317,24 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: MoveAxis")); } - [TestCase( 0, "", TelescopeAxes.axisPrimary)] - [TestCase( 1, ":RG#", TelescopeAxes.axisPrimary)] - [TestCase(-1, ":RG#", TelescopeAxes.axisPrimary)] - [TestCase( 2, ":RC#", TelescopeAxes.axisPrimary)] - [TestCase(-2, ":RC#", TelescopeAxes.axisPrimary)] - [TestCase( 3, ":RM#", TelescopeAxes.axisPrimary)] - [TestCase(-3, ":RM#", TelescopeAxes.axisPrimary)] - [TestCase( 4, ":RS#", TelescopeAxes.axisPrimary)] - [TestCase(-4, ":RS#", TelescopeAxes.axisPrimary)] + [TestCase(0, "", TelescopeAxes.axisPrimary)] + [TestCase(1, "RG", TelescopeAxes.axisPrimary)] + [TestCase(-1, "RG", TelescopeAxes.axisPrimary)] + [TestCase(2, "RC", TelescopeAxes.axisPrimary)] + [TestCase(-2, "RC", TelescopeAxes.axisPrimary)] + [TestCase(3, "RM", TelescopeAxes.axisPrimary)] + [TestCase(-3, "RM", TelescopeAxes.axisPrimary)] + [TestCase(4, "RS", TelescopeAxes.axisPrimary)] + [TestCase(-4, "RS", TelescopeAxes.axisPrimary)] [TestCase(0, "", TelescopeAxes.axisSecondary)] - [TestCase(1, ":RG#", TelescopeAxes.axisSecondary)] - [TestCase(-1, ":RG#", TelescopeAxes.axisSecondary)] - [TestCase(2, ":RC#", TelescopeAxes.axisSecondary)] - [TestCase(-2, ":RC#", TelescopeAxes.axisSecondary)] - [TestCase(3, ":RM#", TelescopeAxes.axisSecondary)] - [TestCase(-3, ":RM#", TelescopeAxes.axisSecondary)] - [TestCase(4, ":RS#", TelescopeAxes.axisSecondary)] - [TestCase(-4, ":RS#", TelescopeAxes.axisSecondary)] + [TestCase(1, "RG", TelescopeAxes.axisSecondary)] + [TestCase(-1, "RG", TelescopeAxes.axisSecondary)] + [TestCase(2, "RC", TelescopeAxes.axisSecondary)] + [TestCase(-2, "RC", TelescopeAxes.axisSecondary)] + [TestCase(3, "RM", TelescopeAxes.axisSecondary)] + [TestCase(-3, "RM", TelescopeAxes.axisSecondary)] + [TestCase(4, "RS", TelescopeAxes.axisSecondary)] + [TestCase(-4, "RS", TelescopeAxes.axisSecondary)] public void MoveAxis_WhenConnected_ThenExecutesCorrectCommandSequence(double rate, string slewRateCommand, TelescopeAxes axis) { ConnectTelescope(); @@ -1336,13 +1342,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axis, rate); if (slewRateCommand != string.Empty) - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(slewRateCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(slewRateCommand, false), Times.Once); else { - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RC#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RM#"), Times.Never); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RS#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RC", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RM", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RS", false), Times.Never); } switch (axis) @@ -1351,14 +1357,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qe#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qw#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qe", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qw", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Me#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Me", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Mw#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mw", false), Times.Once); break; } break; @@ -1366,14 +1372,14 @@ namespace Meade.net.Telescope.UnitTests switch (rate.Compare(0)) { case ComparisonResult.Equals: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qn#"), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Qs#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qn", false), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Qs", false), Times.Once); break; case ComparisonResult.Greater: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Mn#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Mn", false), Times.Once); break; case ComparisonResult.Lower: - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":Ms#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Ms", false), Times.Once); break; } break; @@ -1390,7 +1396,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws( () => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); + var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); Assert.That(exception.Message, Is.EqualTo($"Rate {testRate} not supported")); } @@ -1419,11 +1425,11 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); Assert.That(_telescope.AtPark, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Never); _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } @@ -1434,7 +1440,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.Park(); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); @@ -1442,14 +1448,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.Park(); //no change from previous state. - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":hP#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("hP", false), Times.Once); Assert.That(_telescope.AtPark, Is.True); } [Test] public void PulseGuide_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast,0); }); + var exception = Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: PulseGuide")); } @@ -1481,8 +1487,8 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Mg{d}{duration:0000}#")); - _utilMock.Verify( x => x.WaitForMilliseconds(duration), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Mg{d}{duration:0000}", false)); + _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); } [TestCase(GuideDirections.guideEast)] @@ -1491,7 +1497,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); var duration = 0; ConnectTelescope(); @@ -1507,7 +1513,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(""); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); var duration = 0; ConnectTelescope(); @@ -1530,7 +1536,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.rightAscension = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); var duration = 0; @@ -1546,7 +1552,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.PulseGuide(direction, duration); - + Assert.That(isSlewing, Is.False); } @@ -1560,7 +1566,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1584,10 +1590,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#")); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":M{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); } [TestCase(GuideDirections.guideEast)] @@ -1603,9 +1609,9 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); - + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); _telescope.PulseGuide(direction, duration); @@ -1658,10 +1664,10 @@ namespace Meade.net.Telescope.UnitTests break; } - _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":RG#")); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":M{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("RG", false)); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"M{d}", false)); _utilMock.Verify(x => x.WaitForMilliseconds(duration), Times.Once); - _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind($"Q{d}", false)); } [Test] @@ -1679,10 +1685,10 @@ namespace Meade.net.Telescope.UnitTests public void RightAscension_Get_WhenConnected_ThenReturnsExpectedResult() { ConnectTelescope(); - + var result = _telescope.RightAscension; - Assert.That(result,Is.EqualTo(_testProperties.rightAscension)); + Assert.That(result, Is.EqualTo(_testProperties.rightAscension)); } [Test] @@ -1782,7 +1788,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SiteElevation = newElevation; Assert.That(_telescope.SiteElevation, Is.EqualTo(newElevation)); - _sharedResourcesWrapperMock.Verify( x => x.WriteProfile(It.IsAny()), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.WriteProfile(It.IsAny()), Times.Once); Assert.That(writtenSiteElevation, Is.EqualTo(newElevation)); } @@ -1851,10 +1857,10 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var result = _telescope.SiteLatitude; - - _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.AtLeastOnce); - Assert.That(result,Is.EqualTo(_testProperties.SiteLatitudeValue)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("Gt", false), Times.AtLeastOnce); + + Assert.That(result, Is.EqualTo(_testProperties.SiteLatitudeValue)); } [Test] @@ -1886,7 +1892,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(20.75)] public void SiteLatitude_Set_WhenValueSetAndTelescopRejects_ThenExceptionThrown(double siteLatitude) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -1895,17 +1901,17 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude.")); } - [TestCase(-10.5, ":St-10*30#")] - [TestCase(20.75, ":St+20*45#")] + [TestCase(-10.5, "St-10*30")] + [TestCase(20.75, "St+20*45")] public void SiteLatitude_Set_WhenValidValues_ThenValueSentToTelescope(double siteLatitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLatitude = siteLatitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); } [Test] @@ -1928,7 +1934,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeLongitude = "testLongitude"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); ConnectTelescope(); @@ -1966,7 +1972,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -1975,16 +1981,16 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude.")); } - [TestCase(10, ":Sg350*00#")] + [TestCase(10, "Sg350*00")] public void SiteLongitude_Set_WhenConnectedAndTelescopeFails_ThenThrowsException(double longitude, string expectedCommand) { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(expectedCommand, false)).Returns("1"); ConnectTelescope(); _telescope.SiteLongitude = longitude; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(expectedCommand, false), Times.Once); } [Test] @@ -1992,7 +1998,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToAltAz(0,0); }); + var exception = Assert.Throws(() => { _telescope.SyncToAltAz(0, 0); }); Assert.That(exception.Message, Is.EqualTo("Method SyncToAltAz is not implemented in this driver.")); } @@ -2007,26 +2013,26 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(string.Empty); + _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(string.Empty); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToTarget(); } ); + var exception = Assert.Throws(() => { _telescope.SyncToTarget(); }); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("CM", false)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); - + Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } [Test] @@ -2057,7 +2063,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetDeclination_Set_WhenTelescopeReportsInvalidDec_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2065,21 +2071,21 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Target declination invalid")); } - [TestCase(-30.5, "-30*30:00", ":Sd-30*30:00#")] - [TestCase(30.5, "30*30:00", ":Sd+30*30:00#")] - [TestCase(-75.25, "-75*15:00", ":Sd-75*15:00#")] - [TestCase(50, "50*00:00", ":Sd+50*00:00#")] - public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination( double declination,string decstring, string commandString) + [TestCase(-30.5, "-30*30:00", "Sd-30*30:00")] + [TestCase(30.5, "30*30:00", "Sd+30*30:00")] + [TestCase(-75.25, "-75*15:00", "Sd-75*15:00")] + [TestCase(50, "50*00:00", "Sd+50*00:00")] + public void TargetDeclination_Set_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString) { _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(decstring); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetDeclination = declination; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); } [Test] @@ -2095,7 +2101,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Target not set")); } - [TestCase(50, "50*00:00", ":Sd+50*00:00#")] + [TestCase(50, "50*00:00", "Sd+50*00:00")] public void TargetDeclination_Get_WhenValueOK_ThenSetsNewTargetDeclination(double declination, string decstring, string commandString) { var digitsRA = 2; @@ -2105,7 +2111,7 @@ namespace Meade.net.Telescope.UnitTests _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"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); @@ -2144,7 +2150,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetRightAscension_Set_WhenTelescopeReportsInvalidRA_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny())).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(It.IsAny(), false)).Returns("0"); ConnectTelescope(); @@ -2152,18 +2158,18 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension.")); } - [TestCase(5.5, "05:30:00", ":Sr05:30:00#")] - [TestCase(10, "10:00:00", ":Sr10:00:00#")] + [TestCase(5.5, "05:30:00", "Sr05:30:00")] + [TestCase(10, "10:00:00", "Sr10:00:00")] public void TargetRightAscension_Set_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { _utilMock.Setup(x => x.HoursToHMS(rightAscension, ":", ":", ":", 2)).Returns(hms); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); _telescope.TargetRightAscension = rightAscension; - _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(commandString, false), Times.Once); } [Test] @@ -2179,7 +2185,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Target not set")); } - [TestCase(15, "15:00:00", ":Sr15:00:00#")] + [TestCase(15, "15:00:00", "Sr15:00:00")] public void TargetRightAscension_Get_WhenValueOK_ThenSetsNewTargetDeclination(double rightAscension, string hms, string commandString) { var digitsRA = 2; @@ -2187,7 +2193,7 @@ namespace Meade.net.Telescope.UnitTests _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"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar(commandString, false)).Returns("1"); ConnectTelescope(); @@ -2210,7 +2216,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Tracking = tracking; - Assert.That(_telescope.Tracking, Is.EqualTo( tracking)); + Assert.That(_telescope.Tracking, Is.EqualTo(tracking)); } [Test] @@ -2220,15 +2226,15 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TrackingRate Set")); } - [TestCase(DriveRates.driveSidereal, ":TQ#")] - [TestCase(DriveRates.driveLunar, ":TL#")] + [TestCase(DriveRates.driveSidereal, "TQ")] + [TestCase(DriveRates.driveLunar, "TL")] public void TrackingRate_Set_WhenConnected_ThenSendsCommandToTelescope(DriveRates rate, string commandString) { ConnectTelescope(); _telescope.TrackingRate = rate; - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(commandString), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind(commandString, false), Times.Once); } [Test] @@ -2236,7 +2242,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws( () => { _telescope.TrackingRate = DriveRates.driveKing; }); + var exception = Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveKing; }); Assert.That(exception.Message, Is.EqualTo("Exception of type 'System.ArgumentOutOfRangeException' was thrown.\r\nParameter name: value\r\nActual value was driveKing.")); } @@ -2289,9 +2295,9 @@ namespace Meade.net.Telescope.UnitTests public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns(telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns(telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns(telescopeDate); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(telescopeTime); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); ConnectTelescope(); @@ -2311,7 +2317,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void UTCDate_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.UTCDate = new DateTime(2010,10,15,16,42,32, DateTimeKind.Utc); }); + var exception = Assert.Throws(() => { _telescope.UTCDate = new DateTime(2010, 10, 15, 16, 42, 32, DateTimeKind.Utc); }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: UTCDate Set")); } @@ -2324,12 +2330,12 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; } ); + var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; }); Assert.That(exception.Message, Is.EqualTo("Failed to set local time")); } @@ -2343,12 +2349,12 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{newDate:MM/dd/yy}#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{newDate:MM/dd/yy}", false)).Returns("0"); ConnectTelescope(); - + var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; }); Assert.That(exception.Message, Is.EqualTo("Failed to set local date")); @@ -2365,9 +2371,9 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); @@ -2381,12 +2387,12 @@ namespace Meade.net.Telescope.UnitTests { 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")); } @@ -2403,7 +2409,7 @@ namespace Meade.net.Telescope.UnitTests var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(hms)).Returns(_testProperties.rightAscension); @@ -2414,18 +2420,18 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(_testProperties.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.SendChar($"Sr{hms}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sd{dec}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#", true)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString($"CM", false)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); ConnectTelescope(); _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2437,7 +2443,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); } [Test] @@ -2449,13 +2455,13 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [Test] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns("|"); ConnectTelescope(); @@ -2463,9 +2469,9 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } - + [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)] [TestCase(5, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", false)] @@ -2479,7 +2485,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", true)] [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:24", true)] [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:25", false)] - public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime( short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) + public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime(short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) { _profileProperties.SettleTime = profileSettleTime; @@ -2494,22 +2500,22 @@ namespace Meade.net.Telescope.UnitTests timescalled++; return startSlewingDateTime; } - + return endSlewingDatetime; }); var slewingText = "|"; var notSlewingText = String.Empty; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns( () => - { - if (timescalled == 0) - { - return slewingText; - } + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => + { + if (timescalled == 0) + { + return slewingText; + } - return notSlewingText; - }); + return notSlewingText; + }); ConnectTelescope(); @@ -2524,7 +2530,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); } - [TestCase(TelescopeList.LX200CLASSIC,"","|", true)] + [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)] //The test case below is this same string encoded to return exactly what the telescope will return. @@ -2534,7 +2540,7 @@ 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) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(response); + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2542,7 +2548,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [TestCase(1, TelescopeAxes.axisPrimary)] @@ -2558,7 +2564,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Slewing; Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); } [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] @@ -2581,7 +2587,7 @@ namespace Meade.net.Telescope.UnitTests DateTime currentTime = MakeTime("2021-01-23T22:02:10"); - _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime ); + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime); ConnectTelescope(); @@ -2610,7 +2616,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); } - private DateTime MakeTime( string dateTimeString ) + private DateTime MakeTime(string dateTimeString) { return DateTime.ParseExact(dateTimeString, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); } @@ -2660,7 +2666,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTargetSetAndSlewIsPossible_ThenAttemptsSlew() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); ConnectTelescope(); @@ -2670,13 +2676,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTargetAsync(); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] public void SlewToTargetAsync_WhenTargetBelowHorizon_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Below horizon"); ConnectTelescope(); @@ -2691,7 +2697,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTargetBelowElevation_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("2"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("2"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("Above below elevation"); ConnectTelescope(); @@ -2706,7 +2712,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenTelescopeCanHitTripod_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("3"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("3"); _sharedResourcesWrapperMock.Setup(x => x.ReadTerminated()).Returns("the telescope can hit the tripod"); ConnectTelescope(); @@ -2728,11 +2734,11 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() { - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2747,13 +2753,13 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTarget(); - _utilMock.Verify( x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); } [Test] public void SlewToCoordinatesAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0,0); }); + var exception = Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToCoordinatesAsync")); } @@ -2768,10 +2774,10 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -2779,7 +2785,7 @@ namespace Meade.net.Telescope.UnitTests //var slewCounter = 0; //var iterations = 10; - //_sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(() => + //_sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => //{ // slewCounter++; // if (slewCounter <= iterations) @@ -2795,7 +2801,7 @@ namespace Meade.net.Telescope.UnitTests //_utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify( x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] @@ -2815,18 +2821,18 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GD", false)).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{_testProperties.telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _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"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2839,7 +2845,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToCoordinates(_testProperties.rightAscension, declination); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(dmsResult)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); } @@ -2896,21 +2902,21 @@ namespace Meade.net.Telescope.UnitTests var azimuth = 45; var declination = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var telescopeRaResult = "HH:MM:SS"; var telescopeDecResult = "s12*34’56"; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{telescopeRaResult}#")).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"Sr{telescopeRaResult}", false)).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(_testProperties.rightAscension); @@ -2920,10 +2926,10 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.SlewToAltAzAsync(azimuth, altitude); - + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] @@ -2944,21 +2950,21 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(declination); - - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":Sd+HH:MM:SS#")).Returns("1"); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("Sd+HH:MM:SS", false)).Returns("1"); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); - _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; var iterations = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(() => + _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2967,12 +2973,12 @@ namespace Meade.net.Telescope.UnitTests }); ConnectTelescope(); - - _telescope.SlewToAltAz( azimuth, altitude); + + _telescope.SlewToAltAz(azimuth, altitude); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); } @@ -2994,16 +3000,16 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - + var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); @@ -3012,7 +3018,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Azimuth; - Assert.That(result,Is.EqualTo(expectedAzimuth)); + Assert.That(result, Is.EqualTo(expectedAzimuth)); } [Test] @@ -3036,11 +3042,10 @@ namespace Meade.net.Telescope.UnitTests var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#", true)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#", true)).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); @@ -3068,12 +3073,12 @@ namespace Meade.net.Telescope.UnitTests _telescope.AbortSlew(); - _sharedResourcesWrapperMock.Verify( x => x.SendBlind(":Q#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendBlind("Q", false), Times.Once); var isSloSlewing = _telescope.Slewing; Assert.That(isSloSlewing, Is.False); - _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#", true), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Once); } [Test] @@ -3163,7 +3168,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToCoordinates(0,0); }); + Assert.Throws(() => { _telescope.SyncToCoordinates(0, 0); }); } [Test] @@ -3264,7 +3269,7 @@ namespace Meade.net.Telescope.UnitTests var l = _telescope.SiteLongitude; Assert.That(l, Is.EqualTo(siteLongitude)); } - + } [TestCase(ParkedBehaviour.NoCoordinates)] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 81605b3..2c0cc16 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -189,68 +189,68 @@ namespace ASCOM.Meade.net { //Read the screen case "readdisplay": - var output = SharedResourcesWrapper.SendString(":ED#"); + var output = SharedResourcesWrapper.SendString("ED"); return output; //top row of buttons case "enter": - SharedResourcesWrapper.SendBlind(":EK13#"); + SharedResourcesWrapper.SendBlind("EK13"); break; case "mode": - SharedResourcesWrapper.SendBlind(":EK9#"); + SharedResourcesWrapper.SendBlind("EK9"); break; case "longmode": - SharedResourcesWrapper.SendBlind(":EK11#"); + SharedResourcesWrapper.SendBlind("EK11"); break; case "goto": - SharedResourcesWrapper.SendBlind(":EK24#"); + SharedResourcesWrapper.SendBlind("EK24"); break; case "0": //light and 0 - SharedResourcesWrapper.SendBlind(":EK48#"); + SharedResourcesWrapper.SendBlind("EK48"); break; case "1": - SharedResourcesWrapper.SendBlind(":EK49#"); + SharedResourcesWrapper.SendBlind("EK49"); break; case "2": - SharedResourcesWrapper.SendBlind(":EK50#"); + SharedResourcesWrapper.SendBlind("EK50"); break; case "3": - SharedResourcesWrapper.SendBlind(":EK51#"); + SharedResourcesWrapper.SendBlind("EK51"); break; case "4": - SharedResourcesWrapper.SendBlind(":EK52#"); + SharedResourcesWrapper.SendBlind("EK52"); break; case "5": - SharedResourcesWrapper.SendBlind(":EK53#"); + SharedResourcesWrapper.SendBlind("EK53"); break; case "6": - SharedResourcesWrapper.SendBlind(":EK54#"); + SharedResourcesWrapper.SendBlind("EK54"); break; case "7": - SharedResourcesWrapper.SendBlind(":EK55#"); + SharedResourcesWrapper.SendBlind("EK55"); break; case "8": - SharedResourcesWrapper.SendBlind(":EK56#"); + SharedResourcesWrapper.SendBlind("EK56"); break; case "9": - SharedResourcesWrapper.SendBlind(":EK57#"); + SharedResourcesWrapper.SendBlind("EK57"); break; case "up": - SharedResourcesWrapper.SendBlind(":EK94#"); + SharedResourcesWrapper.SendBlind("EK94"); break; case "down": - SharedResourcesWrapper.SendBlind(":EK118#"); + SharedResourcesWrapper.SendBlind("EK118"); break; case "back": - SharedResourcesWrapper.SendBlind(":EK87#"); + SharedResourcesWrapper.SendBlind("EK87"); break; case "forward": - SharedResourcesWrapper.SendBlind(":EK69#"); + SharedResourcesWrapper.SendBlind("EK69"); break; case "?": - SharedResourcesWrapper.SendBlind(":EK63#"); + SharedResourcesWrapper.SendBlind("EK63"); break; default: LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters); @@ -335,7 +335,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - SharedResourcesWrapper.SendBlind(command); + SharedResourcesWrapper.SendBlind(command, raw); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -345,9 +345,10 @@ namespace ASCOM.Meade.net { CheckConnected("CommandBool"); //string ret = CommandString(command, raw); + return SharedResourcesWrapper.SendBool(command, raw); // TODO decode the return string and return true or false // or - throw new MethodNotImplementedException("CommandBool"); + //throw new MethodNotImplementedException("CommandBool"); // DO NOT have both these sections! One or the other } @@ -675,7 +676,7 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.Lock(() => { - var result = SharedResourcesWrapper.SendString(":GZ#"); + var result = SharedResourcesWrapper.SendString("GZ"); LogMessage("SetLongFormat", $"Get - Azimuth {result}"); //:GZ# Get telescope azimuth //Returns: DDD*MM.T or DDD*MM’SS# @@ -686,12 +687,12 @@ namespace ASCOM.Meade.net if (IsLongFormat != setLongFormat) { _utilities.WaitForMilliseconds(500); - SharedResourcesWrapper.SendBlind(":U#"); + SharedResourcesWrapper.SendBlind("U"); //:U# Toggle between low/hi precision positions //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#"); + result = SharedResourcesWrapper.SendString("GZ"); IsLongFormat = result.Length > 6; LogMessage("SetLongFormat", $"Get - Azimuth {result}"); if (IsLongFormat == setLongFormat) @@ -709,7 +710,7 @@ namespace ASCOM.Meade.net private bool TogglePrecision() { LogMessage("TogglePrecision", "Toggling slewing precision"); - var result = SharedResourcesWrapper.SendChar(":P#"); + var result = SharedResourcesWrapper.SendChar("P"); //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //Returns: //“HIGH PRECISION” Current setting after this command. @@ -729,9 +730,6 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.ReadCharacters(throwAwayCharacters); - //Make sure that the buffers are cleared out. - SharedResourcesWrapper.SendBlind("#"); - return highPrecision; } @@ -749,7 +747,7 @@ namespace ASCOM.Meade.net { CheckConnectedAndValidateSite(site, "SelectSite"); - SharedResourcesWrapper.SendBlind($":W{site}#"); + SharedResourcesWrapper.SendBlind($"W{site}"); //:W# //Set current site to, an ASCII digit in the range 1..4 //Returns: Nothing @@ -775,7 +773,7 @@ namespace ASCOM.Meade.net switch (site) { case 1: - command = $":SM{sitename}#"; + command = $"SM{sitename}"; //:SM# //Set site 1’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: @@ -783,7 +781,7 @@ namespace ASCOM.Meade.net //1 - Valid break; case 2: - command = $":SN{sitename}#"; + command = $"SN{sitename}"; //:SN# //Set site 2’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: @@ -791,7 +789,7 @@ namespace ASCOM.Meade.net //1 - Valid break; case 3: - command = $":SO{sitename}#"; + command = $"SO{sitename}"; //:SO# //Set site 3’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: @@ -799,7 +797,7 @@ namespace ASCOM.Meade.net //1 - Valid break; case 4: - command = $":SP{sitename}#"; + command = $"SP{sitename}"; //:SP# //Set site 4’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: @@ -824,22 +822,22 @@ namespace ASCOM.Meade.net switch (site) { case 1: - return SharedResourcesWrapper.SendString(":GM#"); + return SharedResourcesWrapper.SendString("GM"); //:GM# Get Site 1 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 2: - return SharedResourcesWrapper.SendString(":GN#"); + return SharedResourcesWrapper.SendString("GN"); //:GN# Get Site 2 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 3: - return SharedResourcesWrapper.SendString(":GO#"); + return SharedResourcesWrapper.SendString("GO"); //:GO# Get Site 3 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. case 4: - return SharedResourcesWrapper.SendString(":GP#"); + return SharedResourcesWrapper.SendString("GP"); //:GP# Get Site 4 Name //Returns: # //A ‘#’ terminated string with the name of the requested site. @@ -864,11 +862,11 @@ namespace ASCOM.Meade.net { //string name = "Short driver name - please customise"; - //var telescopeProduceName = _sharedResourcesWrapper.SendString(":GVP#"); + //var telescopeProduceName = _sharedResourcesWrapper.SendString("GVP"); ////:GVP# Get Telescope Product Name ////Returns: # - //var firmwareVersion = _sharedResourcesWrapper.SendString(":GVN#"); + //var firmwareVersion = _sharedResourcesWrapper.SendString("GVN"); ////:GVN# Get Telescope Firmware Number ////Returns: dd.d# @@ -889,7 +887,7 @@ namespace ASCOM.Meade.net CheckParked(); LogMessage("AbortSlew", "Aborting slew"); - SharedResourcesWrapper.SendBlind(":Q#"); + SharedResourcesWrapper.SendBlind("Q"); //:Q# Halt all current slewing //Returns:Nothing @@ -914,7 +912,7 @@ namespace ASCOM.Meade.net const char ack = (char) 6; - var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString()); + var alignmentString = SharedResourcesWrapper.SendChar(ack.ToString(), true); //ACK <0x06> Query of alignment mounting mode. //Returns: //A If scope in AltAz Mode @@ -965,13 +963,13 @@ namespace ASCOM.Meade.net switch (value) { case AlignmentModes.algAltAz: - SharedResourcesWrapper.SendBlind(":AA#"); + SharedResourcesWrapper.SendBlind("AA"); //:AA# Sets telescope the AltAz alignment mode //Returns: nothing break; case AlignmentModes.algPolar: case AlignmentModes.algGermanPolar: - SharedResourcesWrapper.SendBlind(":AP#"); + SharedResourcesWrapper.SendBlind("AP"); //:AP# Sets telescope to Polar alignment mode //Returns: nothing break; @@ -995,7 +993,7 @@ namespace ASCOM.Meade.net return altAz.Altitude; //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - //var result = _sharedResourcesWrapper.SendString(":GA#"); + //var result = _sharedResourcesWrapper.SendString("GA"); ////:GA# Get Telescope Altitude ////Returns: sDD* MM# or sDD*MM’SS# ////The current scope altitude. The returned format depending on the current precision setting. @@ -1085,7 +1083,7 @@ namespace ASCOM.Meade.net { CheckConnected("Azimuth Get"); - //var result = _sharedResourcesWrapper.SendString(":GZ#"); + //var result = _sharedResourcesWrapper.SendString("GZ"); //:GZ# Get telescope azimuth //Returns: DDD*MM#T or DDD*MM’SS# //The current telescope Azimuth depending on the selected precision. @@ -1275,7 +1273,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var result = SharedResourcesWrapper.SendString(":GD#"); + var result = SharedResourcesWrapper.SendString("GD"); //:GD# Get Telescope Declination. //Returns: sDD*MM# or sDD*MM’SS# //Depending upon the current precision setting for the telescope. @@ -1378,7 +1376,7 @@ namespace ASCOM.Meade.net } LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)"); - SharedResourcesWrapper.SendBlind($":Rg{value:00.0}#"); + SharedResourcesWrapper.SendBlind($"Rg{value:00.0}"); //:RgSS.S# //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed @@ -1460,22 +1458,22 @@ namespace ASCOM.Meade.net //do nothing, it's ok this time as we're halting the slew. break; case 1: - SharedResourcesWrapper.SendBlind(":RG#"); + SharedResourcesWrapper.SendBlind("RG"); //:RG# Set Slew rate to Guiding Rate (slowest) //Returns: Nothing break; case 2: - SharedResourcesWrapper.SendBlind(":RC#"); + SharedResourcesWrapper.SendBlind("RC"); //:RC# Set Slew rate to Centering rate (2nd slowest) //Returns: Nothing break; case 3: - SharedResourcesWrapper.SendBlind(":RM#"); + SharedResourcesWrapper.SendBlind("RM"); //:RM# Set Slew rate to Find Rate (2nd Fastest) //Returns: Nothing break; case 4: - SharedResourcesWrapper.SendBlind(":RS#"); + SharedResourcesWrapper.SendBlind("RS"); //:RS# Set Slew rate to max (fastest) //Returns: Nothing break; @@ -1495,21 +1493,21 @@ namespace ASCOM.Meade.net } _movingPrimary = false; - SharedResourcesWrapper.SendBlind(":Qe#"); + SharedResourcesWrapper.SendBlind("Qe"); //:Qe# Halt eastward Slews //Returns: Nothing - SharedResourcesWrapper.SendBlind(":Qw#"); + SharedResourcesWrapper.SendBlind("Qw"); //:Qw# Halt westward Slews //Returns: Nothing break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind(":Me#"); + SharedResourcesWrapper.SendBlind("Me"); //:Me# Move Telescope East at current slew rate //Returns: Nothing _movingPrimary = true; break; case ComparisonResult.Lower: - SharedResourcesWrapper.SendBlind(":Mw#"); + SharedResourcesWrapper.SendBlind("Mw"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing _movingPrimary = true; @@ -1525,21 +1523,21 @@ namespace ASCOM.Meade.net SetSlewingMinEndTime(); } _movingSecondary = false; - SharedResourcesWrapper.SendBlind(":Qn#"); + SharedResourcesWrapper.SendBlind("Qn"); //:Qn# Halt northward Slews //Returns: Nothing - SharedResourcesWrapper.SendBlind(":Qs#"); + SharedResourcesWrapper.SendBlind("Qs"); //:Qs# Halt southward Slews //Returns: Nothing break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind(":Mn#"); + SharedResourcesWrapper.SendBlind("Mn"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing _movingSecondary = true; break; case ComparisonResult.Lower: - SharedResourcesWrapper.SendBlind(":Ms#"); + SharedResourcesWrapper.SendBlind("Ms"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing _movingSecondary = true; @@ -1561,7 +1559,7 @@ namespace ASCOM.Meade.net //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. AtPark = true; - SharedResourcesWrapper.SendBlind(":hP#"); + SharedResourcesWrapper.SendBlind("hP"); //:hP# Autostar, Autostar II and LX 16”Slew to Park Position //Returns: Nothing } @@ -1611,7 +1609,7 @@ namespace ASCOM.Meade.net } LogMessage("PulseGuide", "Using new pulse guiding technique"); - SharedResourcesWrapper.SendBlind($":Mg{d}{duration:0000}#"); + SharedResourcesWrapper.SendBlind($"Mg{d}{duration:0000}"); //:MgnDDDD# //:MgsDDDD# //:MgeDDDD# @@ -1696,7 +1694,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var result = SharedResourcesWrapper.SendString(":GR#"); + var result = SharedResourcesWrapper.SendString("GR"); //:GR# Get Telescope RA //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope @@ -1824,7 +1822,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var latitude = SharedResourcesWrapper.SendString(":Gt#"); + var latitude = SharedResourcesWrapper.SendString("Gt"); //:Gt# Get Current Site Latitude //Returns: sDD* MM# //The latitude of the current site. Positive inplies North latitude. @@ -1865,7 +1863,7 @@ namespace ASCOM.Meade.net var absValue = Math.Abs(value); int d = Convert.ToInt32(Math.Floor(absValue)); int m = Convert.ToInt32(60 * (absValue - d)); - var commandString = $":St{sign}{d:00}*{m:00}#"; + var commandString = $"St{sign}{d:00}*{m:00}"; var result = SharedResourcesWrapper.SendChar(commandString); //:StsDD*MM# @@ -1891,7 +1889,7 @@ namespace ASCOM.Meade.net { CheckParked(); - var longitude = SharedResourcesWrapper.SendString(":Gg#"); + var longitude = SharedResourcesWrapper.SendString("Gg"); //:Gg# Get Current Site Longitude //Returns: sDDD*MM# //The current site Longitude. East Longitudes are expressed as negative @@ -1934,7 +1932,7 @@ namespace ASCOM.Meade.net int d = Convert.ToInt32(Math.Floor(newLongitude)); int m = Convert.ToInt32(60 * (newLongitude - d)); - var commandstring = $":Sg{d:000}*{m:00}#"; + var commandstring = $"Sg{d:000}*{m:00}"; var result = SharedResourcesWrapper.SendChar(commandstring); //:SgDDD*MM# @@ -2030,7 +2028,7 @@ namespace ASCOM.Meade.net switch (polar) { case true: - var response = SharedResourcesWrapper.SendChar(":MS#"); + var response = SharedResourcesWrapper.SendChar("MS"); //:MS# Slew to Target Object //Returns: //0 Slew is Possible @@ -2067,7 +2065,7 @@ namespace ASCOM.Meade.net break; case false: - var maResponse = SharedResourcesWrapper.SendChar(":MA#"); + var maResponse = SharedResourcesWrapper.SendChar("MA"); //:MA# Autostar, LX 16”, Autostar II – Slew to target Alt and Az //Returns: //0 - No fault @@ -2204,7 +2202,7 @@ namespace ASCOM.Meade.net string result; try { - result = SharedResourcesWrapper.SendString(":D#"); + result = SharedResourcesWrapper.SendString("D"); } catch (TimeoutException) { @@ -2289,7 +2287,7 @@ namespace ASCOM.Meade.net CheckConnected("SyncToTarget"); CheckParked(); - var result = SharedResourcesWrapper.SendString(":CM#"); + var result = SharedResourcesWrapper.SendString("CM"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: //LX200's - a "#" terminated string with the name of the object that was synced. @@ -2355,7 +2353,7 @@ namespace ASCOM.Meade.net var s = value < 0 ? string.Empty : "+"; - var command = $":Sd{s}{dms}#"; + var command = $"Sd{s}{dms}"; LogMessage("TargetDeclination Set", $"{command}"); var result = SharedResourcesWrapper.SendChar(command); @@ -2409,7 +2407,7 @@ namespace ASCOM.Meade.net _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); - var command = $":Sr{hms}#"; + var command = $"Sr{hms}"; LogMessage("TargetRightAscension Set", $"{command}"); var response = SharedResourcesWrapper.SendChar(command); //:SrHH:MM.T# @@ -2471,12 +2469,12 @@ namespace ASCOM.Meade.net switch (value) { case DriveRates.driveSidereal: - SharedResourcesWrapper.SendBlind(":TQ#"); + SharedResourcesWrapper.SendBlind("TQ"); //:TQ# Selects sidereal tracking rate //Returns: Nothing break; case DriveRates.driveLunar: - SharedResourcesWrapper.SendBlind(":TL#"); + SharedResourcesWrapper.SendBlind("TL"); //:TL# Set Lunar Tracking Rage //Returns: Nothing break; @@ -2513,7 +2511,7 @@ namespace ASCOM.Meade.net private TimeSpan GetUtcCorrection() { - string utcOffSet = SharedResourcesWrapper.SendString(":GG#"); + string utcOffSet = SharedResourcesWrapper.SendString("GG"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the @@ -2544,11 +2542,11 @@ namespace ASCOM.Meade.net { var tdd = new TelescopeDateDetails { - TelescopeDate = SharedResourcesWrapper.SendString(":GC#"), + TelescopeDate = SharedResourcesWrapper.SendString("GC"), //:GC# Get current date. //Returns: MM/DD/YY# //The current local calendar date for the telescope. - TelescopeTime = SharedResourcesWrapper.SendString(":GL#"), + TelescopeTime = SharedResourcesWrapper.SendString("GL"), //:GL# Get Local Time in 24 hour format //Returns: HH:MM:SS# //The Local Time in 24 - hour Format @@ -2597,7 +2595,7 @@ namespace ASCOM.Meade.net var utcCorrection = GetUtcCorrection(); var localDateTime = value - utcCorrection; - string localStingCommand = $":SL{localDateTime:HH:mm:ss}#"; + string localStingCommand = $"SL{localDateTime:HH:mm:ss}"; var timeResult = SharedResourcesWrapper.SendChar(localStingCommand); //:SLHH:MM:SS# //Set the local Time @@ -2609,7 +2607,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("Failed to set local time"); } - string localDateCommand = $":SC{localDateTime:MM/dd/yy}#"; + string localDateCommand = $"SC{localDateTime:MM/dd/yy}"; var dateResult = SharedResourcesWrapper.SendChar(localDateCommand); //:SCMM/DD/YY# //Change Handbox Date to MM/DD/YY @@ -2640,7 +2638,7 @@ namespace ASCOM.Meade.net if (!AtPark) return; - SharedResourcesWrapper.SendChar(":I#"); + SharedResourcesWrapper.SendChar("I"); //:I# LX200 GPS Only - Causes the telescope to cease current operations and restart at its power on initialization. //Returns: X once the handset restart has completed @@ -2655,7 +2653,7 @@ namespace ASCOM.Meade.net var localDateTime = _clock.UtcNow - utcCorrection; //localDateTime: HH: mm: ss - var result = SharedResourcesWrapper.SendChar($":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 diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 634c33e..0465c34 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -32,35 +32,36 @@ namespace Meade.net.UnitTests Assert.That(SharedResources.SharedSerial,Is.EqualTo(_serialMock.Object)); } - [Test] - public void SendBlind_WhenCalled_Then_ClearsBuffersAndSendsMessage() + [TestCase(true, "Test")] + [TestCase(false, "#:Test#")] + public void SendBlind_WhenCalled_Then_ClearsBuffersAndSendsMessage(bool raw, string expectedMessage) { - var expectedMessage = "Test"; - - SharedResources.SendBlind(expectedMessage); + var sendMessage = "Test"; + SharedResources.SendBlind(sendMessage, raw); _serialMock.Verify(x=> x.ClearBuffers(), Times.Once); _serialMock.Verify(x=>x.Transmit(expectedMessage), Times.Once); } - [Test] - public void SendChar_WhenCalled_ThenSendsMessageAndReadsExpectedNumberOfCharacters() + [TestCase(false, "#:Test#")] + [TestCase(true, "Test")] + public void SendChar_WhenCalled_ThenSendsMessageAndReadsExpectedNumberOfCharacters(bool raw, string expectedCommand) { - var expectedMessage = "Test"; + var command = "Test"; var expectedResult = "A"; _serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult); - var result = SharedResources.SendChar(expectedMessage); + var result = SharedResources.SendChar(command, raw); _serialMock.Verify(x => x.ClearBuffers(), Times.Once); - _serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); + _serialMock.Verify(x => x.Transmit(expectedCommand), Times.Once); _serialMock.Verify(x => x.ReceiveCounted(1), Times.Once); Assert.That(result, Is.EqualTo(expectedResult)); } - [TestCase(false, "Test")] - [TestCase(true, "#Test")] + [TestCase(true, "Test")] + [TestCase(false, "#:Test#")] public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound(bool includePrefix, string expectedMessage) { var transmitMessage = "Test"; diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index ab8220a..caa25fc 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -104,7 +104,7 @@ namespace ASCOM.Meade.net CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); - SharedResourcesWrapper.SendBlind(command); + SharedResourcesWrapper.SendBlind(command, raw); // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other @@ -114,9 +114,10 @@ namespace ASCOM.Meade.net { CheckConnected("CommandBool"); //string ret = CommandString(command, raw); + return SharedResourcesWrapper.SendBool(command, raw); // decode the return string and return true or false // or - throw new MethodNotImplementedException("CommandBool"); + //throw new MethodNotImplementedException("CommandBool"); // DO NOT have both these sections! One or the other } @@ -126,7 +127,7 @@ namespace ASCOM.Meade.net // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return SharedResourcesWrapper.SendString(command); + return SharedResourcesWrapper.SendString(command, raw); //throw new ASCOM.MethodNotImplementedException("CommandString"); } @@ -225,7 +226,7 @@ namespace ASCOM.Meade.net //todo fix this issue: A single halt command is sometimes missed by the #909 apm, so let's do it a few times to be safe. - SharedResourcesWrapper.SendBlind(":FQ#"); + SharedResourcesWrapper.SendBlind("FQ"); //:FQ# Halt Focuser Motion //Returns: Nothing } @@ -329,7 +330,7 @@ namespace ASCOM.Meade.net private void MoveFocuser(bool directionOut, int steps) { - //_sharedResourcesWrapper.SendBlind(":FF#"); + //_sharedResourcesWrapper.SendBlind("FF"); //:FF# Set Focus speed to fastest setting //Returns: Nothing @@ -350,7 +351,7 @@ namespace ASCOM.Meade.net private void PerformFocuserMove(bool directionOut) { - SharedResourcesWrapper.SendBlind(directionOut ? ":F+#" : ":F-#"); + SharedResourcesWrapper.SendBlind(directionOut ? "F+" : "F-"); //:F+# Start Focuser moving inward (toward objective) //Returns: None diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 61a6249..ff69268 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Runtime.InteropServices; +using System.Security.AccessControl; using System.Windows.Forms; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities; @@ -77,12 +78,13 @@ namespace ASCOM.Meade.net } //todo add code to ensure that there is a minimum gap between commands. 5ms as default. - public static void SendBlind(string message) + public static void SendBlind(string message, bool raw = false) { lock (LockObject) { SharedSerial.ClearBuffers(); - SharedSerial.Transmit(message); + var encodedMessage = raw ? message : $"#:{message}#"; + SharedSerial.Transmit(encodedMessage); } } @@ -93,14 +95,16 @@ namespace ASCOM.Meade.net /// and that the reply will always be terminated by a "#" character. /// /// + /// /// - public static string SendString(string message, bool includePrefix = true) + public static string SendString(string message, bool raw = false) { lock (LockObject) { SharedSerial.ClearBuffers(); - SharedSerial.Transmit(includePrefix ? $"#{message}" : message); + var encodedMessage = raw ? message : $"#:{message}#"; + SharedSerial.Transmit(encodedMessage); try { @@ -116,12 +120,22 @@ namespace ASCOM.Meade.net } } - public static string SendChar(string message) + public static bool SendBool(string command, bool raw = false) + { + + var result = SendChar(command, raw); + + return result == "1"; + } + + public static string SendChar(string command, bool raw = false) { lock (LockObject) { SharedSerial.ClearBuffers(); - SharedSerial.Transmit(message); + + var encodedMessage = raw ? command : $"#:{command}#"; + SharedSerial.Transmit(encodedMessage); try { @@ -357,8 +371,8 @@ namespace ASCOM.Meade.net try { - ProductName = SendString(":GVP#"); - FirmwareVersion = SendString(":GVN#"); + ProductName = SendString("GVP"); + FirmwareVersion = SendString("GVN"); } catch (Exception ex) { @@ -378,7 +392,7 @@ namespace ASCOM.Meade.net try { - string utcOffSet = SendString(":GG#"); + string utcOffSet = SendString("GG"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index 82e24e0..c855b6b 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -15,9 +15,10 @@ namespace ASCOM.Meade.net.Wrapper void Lock(Action action); T Lock(Func func); - string SendString(string message, bool includePrefix = true); - void SendBlind(string message); - string SendChar(string message); + string SendString(string message, bool raw = false); + void SendBlind(string message, bool raw = false); + bool SendBool(string command, bool raw = false); + string SendChar(string message, bool raw = false); string ReadTerminated(); @@ -54,19 +55,24 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.Lock(func); } - public string SendString(string message, bool includePrefix = true) + public string SendString(string message, bool raw = false) { - return SharedResources.SendString(message, includePrefix); + return SharedResources.SendString(message, raw); } - public void SendBlind(string message) + public void SendBlind(string message, bool raw = false) { - SharedResources.SendBlind(message); + SharedResources.SendBlind(message, raw); } - public string SendChar(string message) + public bool SendBool(string command, bool raw = false) { - return SharedResources.SendChar(message); + return SharedResources.SendBool(command, raw); + } + + public string SendChar(string message,bool raw = false) + { + return SharedResources.SendChar(message, raw); } public string ReadTerminated() From 2c2c59290e4f4e88599d5cb7c57c1eacb98bb4ba Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 27 Apr 2021 20:14:57 +0100 Subject: [PATCH 02/21] Reinstated the Real Alt Az methods for the LX200GPS. Changes how the parked behaviour is implemented, so that it doesn't need to make as many calls. --- .../TelescopeUnitTests.cs | 306 +++++++++--------- .../Meade.net.Telescope.csproj | 1 + Meade.net.Telescope/ParkedPosition.cs | 10 + Meade.net.Telescope/Telescope.cs | 122 +++++-- 4 files changed, 246 insertions(+), 193 deletions(-) create mode 100644 Meade.net.Telescope/ParkedPosition.cs diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 82d2909..893c9b9 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -17,11 +17,19 @@ namespace Meade.net.Telescope.UnitTests public class TestProperties { internal string telescopeRaResult = "HH:MM:SS"; - internal double rightAscension = 1.2; //todo rename to RightAscension; + internal double rightAscension = 1.2; //todo rename to declination; + internal double declination = 45; internal string SiteLatitudeString = "testLatString"; internal double SiteLatitudeValue = 123.45; + internal string telescopeDate = "10/15/20"; + internal string telescopeTime = "20:15:10"; + internal string telescopeUtcCorrection = "-1.0"; + + internal double hourAngle; + internal int telescopeAltitude = 45; + internal int telescopeAzimuth = 200; } [TestFixture] @@ -84,8 +92,7 @@ namespace Meade.net.Telescope.UnitTests }; _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo ); - - + _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); _astroMathsMock = new Mock(); @@ -98,14 +105,27 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { - _sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns(_testProperties.SiteLatitudeString); - _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns(_testProperties.SiteLatitudeValue); + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gt", false)).Returns( () => _testProperties.SiteLatitudeString); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.SiteLatitudeString)).Returns( () => _testProperties.SiteLatitudeValue); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns( () =>_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns( () => _testProperties.rightAscension); + + _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns(() => _testProperties.telescopeDate); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(() => _testProperties.telescopeTime); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(() => _testProperties.telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); + + _astroMathsMock + .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension }); + + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(() =>_testProperties.hourAngle); + + _astroMathsMock.Setup(x => x.ConvertEqToHoz(_testProperties.hourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = _testProperties.telescopeAltitude, Azimuth = _testProperties.telescopeAzimuth }); + _telescope.Connected = true; } @@ -146,10 +166,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Action_WhenNotConnected_ThrowsNotConnectedException() { - var exception = Assert.Throws(() => - { - _telescope.Action(string.Empty, string.Empty); - }); + var exception = Assert.Throws(() => _telescope.Action(string.Empty, string.Empty) ); Assert.That(exception.Message,Is.EqualTo("Not connected to telescope when trying to execute: Action")); } @@ -217,7 +234,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"select {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters) ); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } @@ -246,7 +263,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"GetName {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters) ); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } @@ -286,7 +303,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = $"SetName {site}"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters)); Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } @@ -297,7 +314,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string parameters = "unknown"; - var exception = Assert.Throws(() => { _telescope.Action("site", parameters); }); + var exception = Assert.Throws(() => _telescope.Action("site", parameters)); Assert.That(exception.Message, Is.EqualTo($"Site parameters {parameters} not known")); } @@ -309,7 +326,7 @@ namespace Meade.net.Telescope.UnitTests string actionName = "handbox"; string actionParameters = "doesnotexist"; - var exception = Assert.Throws(() => { _telescope.Action(actionName, actionParameters); }); + var exception = Assert.Throws(() => _telescope.Action(actionName, actionParameters)); Assert.That(exception.Message, Is.EqualTo($"Action {actionName}({actionParameters}) is not implemented in this driver is not implemented in this driver.")); } @@ -320,7 +337,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); string actionName = "doesnotexist"; - var exception = Assert.Throws(() => { _telescope.Action(actionName, string.Empty); }); + var exception = Assert.Throws(() => _telescope.Action(actionName, string.Empty)); Assert.That(exception.Message, Is.EqualTo($"Action {actionName} is not implemented in this driver is not implemented in this driver.")); } @@ -329,7 +346,7 @@ namespace Meade.net.Telescope.UnitTests public void CommandBlind_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandBlind(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandBlind(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBlind")); } @@ -351,7 +368,7 @@ namespace Meade.net.Telescope.UnitTests public void CommandBool_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandBool(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandBool(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandBool")); } @@ -376,7 +393,7 @@ namespace Meade.net.Telescope.UnitTests public void CommandString_WhenNotConnected_ThenThrowsNotConnectedException() { string expectedMessage = "test blind Message"; - var exception = Assert.Throws(() => { _telescope.CommandString(expectedMessage, true); }); + var exception = Assert.Throws(() => _telescope.CommandString(expectedMessage, true)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: CommandString")); } @@ -432,16 +449,15 @@ namespace Meade.net.Telescope.UnitTests public void Connected_WhenConnectingLX200GPSAndSendDateTimeIsTrue_Then_SpecialStartupInstructionSendOnFirstConnect() { _profileProperties.SendDateTime = true; - + _testProperties.telescopeUtcCorrection = "0"; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); string setDateCommand = $"hI{testNow:yyMMddHHmmss}"; string expectedResult = "Daylight Savings Time:"; _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar(setDateCommand, false)).Returns("1"); ConnectTelescope(TelescopeList.LX200GPS, string.Empty); @@ -456,19 +472,15 @@ namespace Meade.net.Telescope.UnitTests string telescopeTime = "20:36:25"; string telescopeDate = "10/03/21"; + _testProperties.telescopeUtcCorrection = "0"; 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; - }); + _clockMock.Setup(x => x.UtcNow).Returns(() => endSlewingDatetime); string setDateCommand = $"hI{endSlewingDatetime:yyMMddHHmmss}"; string expectedResult = "Align"; _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); @@ -486,6 +498,7 @@ namespace Meade.net.Telescope.UnitTests string telescopeTime = "20:36:25"; string telescopeDate = "10/03/21"; + _testProperties.telescopeUtcCorrection = "0"; DateTime endSlewingDatetime = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); _clockMock.Setup(x => x.UtcNow).Returns(() => @@ -497,7 +510,6 @@ namespace Meade.net.Telescope.UnitTests string expectedResult = "Align"; _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); @@ -629,7 +641,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SelectSite_Get_WhenNotConnected_ThrowsException() { - var exception = Assert.Throws(() => { _telescope.SelectSite(1); }); + var exception = Assert.Throws(() => _telescope.SelectSite(1)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SelectSite")); } @@ -639,7 +651,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var site = 0; - var result = Assert.Throws(() => { _telescope.SelectSite(site); }); + var result = Assert.Throws(() => _telescope.SelectSite(site)); Assert.That(result.Message, Is.EqualTo($"Site cannot be lower than 1\r\nParameter name: site\r\nActual value was {site}.")); } @@ -650,7 +662,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); var site = 5; - var result = Assert.Throws(() => { _telescope.SelectSite(site); }); + var result = Assert.Throws(() => _telescope.SelectSite(site)); Assert.That(result.Message, Is.EqualTo($"Site cannot be higher than 4\r\nParameter name: site\r\nActual value was {site}.")); } @@ -761,7 +773,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AlignmentMode_Set_WhenNotConnected_ThrowsException() { - var exception = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); + var exception = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AlignmentMode Set")); } @@ -786,7 +798,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(firmware); _telescope.Connected = true; - var excpetion = Assert.Throws(() => { _telescope.AlignmentMode = AlignmentModes.algAltAz; }); + var excpetion = Assert.Throws(() => _telescope.AlignmentMode = AlignmentModes.algAltAz); Assert.That(excpetion.Property, Is.EqualTo("AlignmentMode")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1102,10 +1114,10 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(productVersion, firmware); if (canUnPark) - Assert.DoesNotThrow(() => { _telescope.Unpark(); }); + Assert.DoesNotThrow(() => _telescope.Unpark()); else { - var exception = Assert.Throws(() => { _telescope.Unpark(); }); + var exception = Assert.Throws(() => _telescope.Unpark()); Assert.That(exception.Message, Is.EqualTo("Unable to unpark this telescope type")); } @@ -1166,7 +1178,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void DeclinationRate_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.DeclinationRate = 0; }); + var excpetion = Assert.Throws(() => _telescope.DeclinationRate = 0); Assert.That(excpetion.Property, Is.EqualTo("DeclinationRate")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1200,7 +1212,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void DoesRefraction_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.DoesRefraction = true; }); + var excpetion = Assert.Throws(() => _telescope.DoesRefraction = true); Assert.That(excpetion.Property, Is.EqualTo("DoesRefraction")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1217,7 +1229,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void FindHome_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.FindHome(); }); + var excpetion = Assert.Throws(() => _telescope.FindHome()); Assert.That(excpetion.Method, Is.EqualTo("FindHome")); } @@ -1248,7 +1260,7 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); - var excpetion = Assert.Throws(() => { _telescope.GuideRateDeclination = 0; }); + var excpetion = Assert.Throws(() => _telescope.GuideRateDeclination = 0); Assert.That(excpetion.Property, Is.EqualTo("GuideRateDeclination")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1281,7 +1293,7 @@ namespace Meade.net.Telescope.UnitTests { _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); - var excpetion = Assert.Throws(() => { _telescope.GuideRateRightAscension = 0; }); + var excpetion = Assert.Throws(() => _telescope.GuideRateRightAscension = 0); Assert.That(excpetion.Property, Is.EqualTo("GuideRateRightAscension")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1313,7 +1325,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void MoveAxis_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: MoveAxis")); } @@ -1396,7 +1408,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate)); Assert.That(exception.Message, Is.EqualTo($"Rate {testRate} not supported")); } @@ -1408,7 +1420,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate); }); + var exception = Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisTertiary, testRate)); Assert.That(exception.Message, Is.EqualTo("Can not move this axis.")); } @@ -1416,7 +1428,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Park_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.Park(); }); + var exception = Assert.Throws(() => _telescope.Park()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: Park")); } @@ -1455,7 +1467,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void PulseGuide_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(GuideDirections.guideEast, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: PulseGuide")); } @@ -1502,7 +1514,7 @@ namespace Meade.net.Telescope.UnitTests var duration = 0; ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide whilst slewing to target.")); } @@ -1520,7 +1532,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axes, 1); - var exception = Assert.Throws(() => { _telescope.PulseGuide(direction, duration); }); + var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide while moving same axis.")); } @@ -1702,7 +1714,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void RightAscensionRate_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.RightAscensionRate = 1; }); + var excpetion = Assert.Throws(() => _telescope.RightAscensionRate = 1); Assert.That(excpetion.Property, Is.EqualTo("RightAscensionRate")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1711,7 +1723,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetPark_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SetPark(); }); + var excpetion = Assert.Throws(() => _telescope.SetPark()); Assert.That(excpetion.Method, Is.EqualTo("SetPark")); } @@ -1732,7 +1744,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SideOfPier_Set_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SideOfPier = 0; }); + var excpetion = Assert.Throws(() => _telescope.SideOfPier = 0); Assert.That(excpetion.Property, Is.EqualTo("SideOfPier")); Assert.That(excpetion.AccessorSet, Is.True); @@ -1866,7 +1878,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLatitude_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SiteLatitude = 123.45; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = 123.45); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiteLatitude Set")); } @@ -1875,7 +1887,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = 90.01; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = 90.01); Assert.That(exception.Message, Is.EqualTo("Latitude cannot be greater than 90 degrees.")); } @@ -1884,7 +1896,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = -90.01; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = -90.01); Assert.That(exception.Message, Is.EqualTo("Latitude cannot be less than -90 degrees.")); } @@ -1896,7 +1908,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLatitude = siteLatitude; }); + var exception = Assert.Throws(() => _telescope.SiteLatitude = siteLatitude); Assert.That(exception.Message, Is.EqualTo("Failed to set site latitude.")); } @@ -1947,7 +1959,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SiteLongitude_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 123.45; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 123.45); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiteLongitude Set")); } @@ -1956,7 +1968,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 180.1; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 180.1); Assert.That(exception.Message, Is.EqualTo("Longitude cannot be greater than 180 degrees.")); } @@ -1965,7 +1977,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = -180.1; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = -180.1); Assert.That(exception.Message, Is.EqualTo("Longitude cannot be lower than -180 degrees.")); } @@ -1977,7 +1989,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SiteLongitude = 10; }); + var exception = Assert.Throws(() => _telescope.SiteLongitude = 10); Assert.That(exception.Message, Is.EqualTo("Failed to set site longitude.")); } @@ -1998,7 +2010,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToAltAz(0, 0); }); + var exception = Assert.Throws(() => _telescope.SyncToAltAz(0, 0)); Assert.That(exception.Message, Is.EqualTo("Method SyncToAltAz is not implemented in this driver.")); } @@ -2006,7 +2018,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SyncToTarget(); }); + var exception = Assert.Throws(() => _telescope.SyncToTarget()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SyncToTarget")); } @@ -2017,7 +2029,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SyncToTarget(); }); + var exception = Assert.Throws(() => _telescope.SyncToTarget()); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); @@ -2030,7 +2042,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); + Assert.DoesNotThrow(() => _telescope.SyncToTarget()); _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } @@ -2038,7 +2050,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetDeclination_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 0; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 0); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TargetDeclination Set")); } @@ -2047,7 +2059,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 90.1; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 90.1); Assert.That(exception.Message, Is.EqualTo("Declination cannot be greater than 90.")); } @@ -2056,7 +2068,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = -90.1; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = -90.1); Assert.That(exception.Message, Is.EqualTo("Declination cannot be less than -90.")); } @@ -2067,7 +2079,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 50; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 50); Assert.That(exception.Message, Is.EqualTo("Target declination invalid")); } @@ -2125,7 +2137,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TargetRightAscension_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 0; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 0); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TargetRightAscension Set")); } @@ -2134,7 +2146,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 24; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 24); Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be greater than 23:59:59")); } @@ -2143,7 +2155,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = -0.1; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = -0.1); Assert.That(exception.Message, Is.EqualTo("Right ascension value cannot be below 0")); } @@ -2154,7 +2166,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 1); Assert.That(exception.Message, Is.EqualTo("Failed to set TargetRightAscension.")); } @@ -2222,7 +2234,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void TrackingRate_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveSidereal; }); + var exception = Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveSidereal); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: TrackingRate Set")); } @@ -2242,7 +2254,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveKing; }); + var exception = Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveKing); Assert.That(exception.Message, Is.EqualTo("Exception of type 'System.ArgumentOutOfRangeException' was thrown.\r\nParameter name: value\r\nActual value was driveKing.")); } @@ -2295,9 +2307,9 @@ namespace Meade.net.Telescope.UnitTests public void UTCDate_Get_WhenConnected_ThenReturnsUTCDateTime(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns(telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns(telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); + _testProperties.telescopeDate = telescopeDate; + _testProperties.telescopeTime = telescopeTime; + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; ConnectTelescope(); @@ -2317,7 +2329,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void UTCDate_Set_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.UTCDate = new DateTime(2010, 10, 15, 16, 42, 32, DateTimeKind.Utc); }); + var exception = Assert.Throws(() => _telescope.UTCDate = new DateTime(2010, 10, 15, 16, 42, 32, DateTimeKind.Utc)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: UTCDate Set")); } @@ -2335,7 +2347,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; }); + var exception = Assert.Throws(() => _telescope.UTCDate = newDate); Assert.That(exception.Message, Is.EqualTo("Failed to set local time")); } @@ -2344,18 +2356,18 @@ namespace Meade.net.Telescope.UnitTests [TestCase("12/03/15", "21:30:45", "+0.0", 2015, 12, 3, 21, 30, 45)] public void UTCDate_Set_WhenFailsToSetTelescopeDate_ThenThrowsException(string telescopeDate, string telescopeTime, string telescopeUtcCorrection, int year, int month, int day, int hour, int min, int second) { + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; double utcOffsetHours = double.Parse(telescopeUtcCorrection); TimeSpan utcCorrection = TimeSpan.FromHours(utcOffsetHours); var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{newDate:MM/dd/yy}", false)).Returns("0"); ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.UTCDate = newDate; }); + var exception = Assert.Throws(() => _telescope.UTCDate = newDate); Assert.That(exception.Message, Is.EqualTo("Failed to set local date")); } @@ -2369,9 +2381,10 @@ namespace Meade.net.Telescope.UnitTests double utcOffsetHours = double.Parse(telescopeUtcCorrection); TimeSpan utcCorrection = TimeSpan.FromHours(utcOffsetHours); + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; + var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SL{telescopeTime}", false)).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); @@ -2625,7 +2638,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTargetAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToTargetAsync")); } @@ -2636,7 +2649,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Target not set")); } @@ -2647,7 +2660,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Target not set")); } @@ -2659,7 +2672,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("This error should not happen")); } @@ -2690,7 +2703,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Below horizon")); } @@ -2705,7 +2718,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("Above below elevation")); } @@ -2720,14 +2733,14 @@ namespace Meade.net.Telescope.UnitTests _telescope.TargetRightAscension = 2; _telescope.TargetDeclination = 1; - var exception = Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + var exception = Assert.Throws(() => _telescope.SlewToTargetAsync()); Assert.That(exception.Message, Is.EqualTo("the telescope can hit the tripod")); } [Test] public void SlewToTarget_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToTarget(); }); + var exception = Assert.Throws(() => _telescope.SlewToTarget()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToTarget")); } @@ -2759,7 +2772,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinatesAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToCoordinatesAsync(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToCoordinatesAsync")); } @@ -2807,7 +2820,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinates_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToCoordinates(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToCoordinates")); } @@ -2853,7 +2866,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAzAsync_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToAltAzAsync")); } @@ -2862,7 +2875,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 90.1); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 90.1)); Assert.That(exception.Message, Is.EqualTo("Altitude cannot be greater than 90.")); } @@ -2871,7 +2884,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, -0.1); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(0, -0.1)); Assert.That(exception.Message, Is.EqualTo("Altitide cannot be less than 0.")); } @@ -2880,7 +2893,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(360, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(360, 0)); Assert.That(exception.Message, Is.EqualTo("Azimuth cannot be 360 or higher.")); } @@ -2889,7 +2902,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - var exception = Assert.Throws(() => { _telescope.SlewToAltAzAsync(-0.1, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAzAsync(-0.1, 0)); Assert.That(exception.Message, Is.EqualTo("Azimuth cannot be less than 0.")); } @@ -2897,19 +2910,13 @@ namespace Meade.net.Telescope.UnitTests public void SlewToAltAzAsync_WhenAltAndAzValid_ThenConvertsToRADec() { _testProperties.rightAscension = 20; + _testProperties.declination = 10; var altitude = 30; var azimuth = 45; - var declination = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var telescopeRaResult = "HH:MM:SS"; @@ -2920,22 +2927,22 @@ namespace Meade.net.Telescope.UnitTests _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(_testProperties.rightAscension); - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); - _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); + _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", digitsRA)).Returns(telescopeDecResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(_testProperties.declination); ConnectTelescope(); _telescope.SlewToAltAzAsync(azimuth, altitude); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); - Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); } [Test] public void SlewToAltAz_WhenAzimuthLowerThan0_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + var exception = Assert.Throws(() => _telescope.SlewToAltAz(0, 0)); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewToAltAz")); } @@ -2943,23 +2950,17 @@ namespace Meade.net.Telescope.UnitTests public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { _testProperties.rightAscension = 10.0; - var declination = 20; + _testProperties.declination = 20; var azimuth = 30; var altitude = 40; _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.DegreesToDMS(declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); - _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(declination); + _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(_testProperties.declination); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar("Sd+HH:MM:SS", false)).Returns("1"); - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; @@ -2977,7 +2978,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToAltAz(azimuth, altitude); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); - Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); } @@ -2996,29 +2997,24 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Azimuth_WhenConnected_ThenReturnsTelescopeAzumith() { - var expectedAzimuth = 200; - var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - var mockHourAngle = 3; + _testProperties.telescopeAltitude = 45; + _testProperties.telescopeAzimuth = 200; + _testProperties.hourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); - _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - - _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); - - _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); + _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); + ConnectTelescope(); var result = _telescope.Azimuth; - Assert.That(result, Is.EqualTo(expectedAzimuth)); + Assert.That(result, Is.EqualTo(_testProperties.telescopeAzimuth)); } [Test] @@ -3040,17 +3036,13 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - var mockHourAngle = 3; - - _sharedResourcesWrapperMock.Setup(x => x.SendString("GC", false)).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString("GL", false)).Returns("20:15:10"); _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(mockHourAngle); + _astroMathsMock.Setup(x => x.RightAscensionToHourAngle(It.IsAny(), It.IsAny(), It.IsAny())).Returns(_testProperties.hourAngle); - _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); + _astroMathsMock.Setup(x => x.ConvertEqToHoz(_testProperties.hourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = expectedAltitude, Azimuth = 200 }); ConnectTelescope(); @@ -3062,7 +3054,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void AbortSlew_WhenNotConnected_ThenThrowsException() { - var exception = Assert.Throws(() => { _telescope.AbortSlew(); }); + var exception = Assert.Throws(() => _telescope.AbortSlew()); Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: AbortSlew")); } @@ -3087,7 +3079,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.AbortSlew(); }); + Assert.Throws(() => _telescope.AbortSlew()); } [Test] @@ -3096,7 +3088,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0)); } [Test] @@ -3105,7 +3097,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); + Assert.Throws(() => _telescope.PulseGuide(GuideDirections.guideEast, 0)); } [Test] @@ -3114,7 +3106,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAz(0, 0)); } [Test] @@ -3123,7 +3115,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 0)); } [Test] @@ -3132,7 +3124,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinates(0, 0)); } [Test] @@ -3141,7 +3133,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinatesAsync(0, 0)); } [Test] @@ -3150,7 +3142,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTarget(); }); + Assert.Throws(() => _telescope.SlewToTarget()); } [Test] @@ -3159,7 +3151,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + Assert.Throws(() => _telescope.SlewToTargetAsync()); } [Test] @@ -3168,7 +3160,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToCoordinates(0, 0); }); + Assert.Throws(() => _telescope.SyncToCoordinates(0, 0)); } [Test] @@ -3177,7 +3169,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToTarget(); }); + Assert.Throws(() => _telescope.SyncToTarget()); } [Test] @@ -3186,7 +3178,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetDeclination = 1; }); + Assert.Throws(() => _telescope.TargetDeclination = 1); } [Test] @@ -3195,7 +3187,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + Assert.Throws(() => _telescope.TargetRightAscension = 1); } [Test] @@ -3204,7 +3196,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveLunar; }); + Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveLunar); } @@ -3215,7 +3207,7 @@ namespace Meade.net.Telescope.UnitTests { _profileProperties.ParkedBehaviour = behaviour; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); ConnectTelescope(); _telescope.Park(); @@ -3282,13 +3274,9 @@ namespace Meade.net.Telescope.UnitTests _profileProperties.ParkedAz = 180; DateTime testNow = DateTime.ParseExact("2021-10-03T20:36:25", "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); - var declination = 45; + _testProperties.declination = 45; - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); - - _astroMathsMock - .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), - It.IsAny())).Returns(new EquatorialCoordinates { Declination = declination, RightAscension = _testProperties.rightAscension }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); ConnectTelescope(); _telescope.Park(); @@ -3301,7 +3289,7 @@ namespace Meade.net.Telescope.UnitTests break; case ParkedBehaviour.ReportCoordinates: var dec = _telescope.Declination; - Assert.That(dec, Is.EqualTo(declination)); + Assert.That(dec, Is.EqualTo(_testProperties.declination)); break; default: Assert.Throws(() => { var d = _telescope.Declination; }); @@ -3321,7 +3309,7 @@ namespace Meade.net.Telescope.UnitTests var declination = 45; - _clockMock.Setup(x => x.UtcNow).Returns(() => { return testNow; }); + _clockMock.Setup(x => x.UtcNow).Returns(() => testNow); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index 92ec7b9..eb888e5 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -127,6 +127,7 @@ + diff --git a/Meade.net.Telescope/ParkedPosition.cs b/Meade.net.Telescope/ParkedPosition.cs new file mode 100644 index 0000000..29bbb9e --- /dev/null +++ b/Meade.net.Telescope/ParkedPosition.cs @@ -0,0 +1,10 @@ +namespace ASCOM.Meade.net +{ + public class ParkedPosition + { + public double Altitude { get; set; } + public double Azimuth { get; set; } + public double RightAscension { get; set; } + public double Declination { get; set; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 2c0cc16..55e6f00 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -74,6 +74,8 @@ namespace ASCOM.Meade.net private short _settleTime; + private ParkedPosition _parkedPosition; + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -987,23 +989,36 @@ namespace ASCOM.Meade.net get { CheckConnected("Altitude Get"); - + + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + try + { + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! + var result = SharedResourcesWrapper.SendString("GA"); + //:GA# Get Telescope Altitude + //Returns: sDD* MM# or sDD*MM’SS# + //The current scope altitude. The returned format depending on the current precision setting. + + var alt = _utilities.DMSToDegrees(result); + LogMessage("Altitude", $"{alt}"); + return alt; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.NoCoordinates: + throw; + default: + return _parkedPosition.Altitude; + } + } + } + var altAz = CalcAltAzFromTelescopeEqData(); LogMessage("Altitude", $"{altAz.Altitude}"); return altAz.Altitude; - - //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! - //var result = _sharedResourcesWrapper.SendString("GA"); - ////:GA# Get Telescope Altitude - ////Returns: sDD* MM# or sDD*MM’SS# - ////The current scope altitude. The returned format depending on the current precision setting. - - //var alt = utilities.DMSToDegrees(result); - //LogMessage("Altitude", $"{alt}"); - //return alt; - - //LogMessage("Altitude Get", "Not implemented"); - //throw new ASCOM.PropertyNotImplementedException("Altitude", false); } } @@ -1083,15 +1098,31 @@ namespace ASCOM.Meade.net { CheckConnected("Azimuth Get"); - //var result = _sharedResourcesWrapper.SendString("GZ"); - //:GZ# Get telescope azimuth - //Returns: DDD*MM#T or DDD*MM’SS# - //The current telescope Azimuth depending on the selected precision. + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + try + { + var result = SharedResourcesWrapper.SendString("GZ"); + //:GZ# Get telescope azimuth + //Returns: DDD*MM#T or DDD*MM’SS# + //The current telescope Azimuth depending on the selected precision. - //double az = utilities.DMSToDegrees(result); + double az = _utilities.DMSToDegrees(result); - //LogMessage("Azimuth Get", $"{az}"); - //return az; + LogMessage("Azimuth Get", $"{az}"); + return az; + } + catch (ParkedException) + { + switch (ParkedBehaviour) + { + case ParkedBehaviour.NoCoordinates: + throw; + default: + return _parkedPosition.Azimuth; + } + } + } var altAz = CalcAltAzFromTelescopeEqData(); LogMessage("Azimuth Get", $"{altAz.Azimuth}"); @@ -1288,13 +1319,10 @@ namespace ASCOM.Meade.net { switch (ParkedBehaviour) { - case ParkedBehaviour.LastGoodPosition: - return _lastGoodDeclination; - case ParkedBehaviour.ReportCoordinates: - var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); - return raDec.Declination; - default: + case ParkedBehaviour.NoCoordinates: throw; + default: + return _parkedPosition.Declination; } } } @@ -1557,8 +1585,37 @@ namespace ASCOM.Meade.net if (AtPark) return; + switch (ParkedBehaviour) + { + case ParkedBehaviour.LastGoodPosition: + _parkedPosition = new ParkedPosition + { + Altitude = Altitude, + Azimuth = Azimuth, + RightAscension = RightAscension, + Declination = Declination + }; + break; + case ParkedBehaviour.ReportCoordinates: + var utcDateTime = UTCDate; + var latitude = SiteLatitude; + var longitude = SiteLongitude; + var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz); + + _parkedPosition = new ParkedPosition + { + Altitude = ParkedAltAz.Altitude, + Azimuth = ParkedAltAz.Azimuth, + RightAscension = raDec.RightAscension, + Declination = raDec.Declination + }; + break; + } + //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. AtPark = true; + + SharedResourcesWrapper.SendBlind("hP"); //:hP# Autostar, Autostar II and LX 16”Slew to Park Position //Returns: Nothing @@ -1709,13 +1766,10 @@ namespace ASCOM.Meade.net { switch (ParkedBehaviour) { - case ParkedBehaviour.LastGoodPosition: - return _lastGoodRightAsension; - case ParkedBehaviour.ReportCoordinates: - var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); - return raDec.RightAscension; - default: + case ParkedBehaviour.NoCoordinates: throw; + default: + return _parkedPosition.RightAscension; } } @@ -2772,4 +2826,4 @@ namespace ASCOM.Meade.net } #endregion } -} +} \ No newline at end of file From 486a9205ee9b78eff167806fa1bab58581f6b7ab Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 27 Apr 2021 22:08:25 +0100 Subject: [PATCH 03/21] Fixed the defect when one instance of the driver gets parked, the info is shared to the other instances. --- .../TelescopeUnitTests.cs | 14 ++ .../Meade.net.Telescope.csproj | 1 - Meade.net.Telescope/Telescope.cs | 176 ++++++++++-------- Meade.net/Meade.net.csproj | 1 + .../ParkedPosition.cs | 0 Meade.net/SharedResources.cs | 10 + Meade.net/Wrapper/SharedResourcesWrapper.cs | 13 ++ 7 files changed, 133 insertions(+), 82 deletions(-) rename {Meade.net.Telescope => Meade.net}/ParkedPosition.cs (100%) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 893c9b9..c111e34 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -48,9 +48,15 @@ namespace Meade.net.Telescope.UnitTests private TestProperties _testProperties; + private bool _isParked; + private ParkedPosition _parkedPosition; + [SetUp] public void Setup() { + _isParked = false; + _parkedPosition = null; + _testProperties = new TestProperties(); _profileProperties = new ProfileProperties @@ -118,6 +124,14 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => firmwareVersion); + _sharedResourcesWrapperMock.Setup(x => x.SetParked(It.IsAny(), It.IsAny())).Callback((isParked, parkedPostion) => { + _isParked = isParked; + _parkedPosition = parkedPostion; + }); + + _sharedResourcesWrapperMock.SetupGet(x => x.IsParked).Returns(() => _isParked); + _sharedResourcesWrapperMock.SetupGet(x => x.ParkedPosition).Returns(() => _parkedPosition); + _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).Returns(() => new EquatorialCoordinates { Declination = _testProperties.declination, RightAscension = _testProperties.rightAscension }); diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index eb888e5..92ec7b9 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -127,7 +127,6 @@ - diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 55e6f00..c471f58 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -45,12 +45,15 @@ namespace ASCOM.Meade.net /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// //internal static string driverID = "ASCOM.Meade.net.Telescope"; - private static readonly string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? throw new System.InvalidOperationException()); + private static readonly string DriverId = + Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType ?? + throw new System.InvalidOperationException()); /// /// Private variable to hold an ASCOM Utilities object /// private readonly IUtil _utilities; + private readonly IUtilExtra _utilitiesExtra; /// @@ -73,9 +76,7 @@ namespace ASCOM.Meade.net private int _digitsDe = 2; private short _settleTime; - - private ParkedPosition _parkedPosition; - + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -123,7 +124,9 @@ namespace ASCOM.Meade.net sb.AppendLine(); } - public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base(sharedResourcesWrapper) + public Telescope(IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, + ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base( + sharedResourcesWrapper) { _clock = clock; _utilities = util; //Initialise util object @@ -282,6 +285,7 @@ namespace ASCOM.Meade.net $"Site {actionParameters} not allowed, must be between 1 and 4"); } + break; case "getname": switch (parames[1]) @@ -316,6 +320,7 @@ namespace ASCOM.Meade.net $"Site {actionParameters} not allowed, must be between 1 and 4"); } + break; default: throw new InvalidValueException( @@ -398,7 +403,8 @@ namespace ASCOM.Meade.net var connectionInfo = SharedResourcesWrapper.Connect("Serial", DriverId, Tl); try { - LogMessage("Connected Set", $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); + LogMessage("Connected Set", + $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); _targetDeclination = InvalidParameter; @@ -430,19 +436,23 @@ namespace ASCOM.Meade.net { if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) { - LogMessage("Connected Set", $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); + LogMessage("Connected Set", + $"LX200GPS Detecting if daylight savings message on screen: {SendDateTime}"); var displayText = Action("Handbox", "readdisplay"); LogMessage("Connected Set", $"Current Handset display: {displayText}"); if (displayText.Contains("Daylight")) { - LogMessage("Connected Set", $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); + LogMessage("Connected Set", + $"LX200GPS Setting Date time and bypassing settings screens: {SendDateTime}"); BypassHandboxEntryForAutostarII(); } else { - LogMessage("Connected Set", $"LX200GPS Sending current date and time: {SendDateTime}"); + LogMessage("Connected Set", + $"LX200GPS Sending current date and time: {SendDateTime}"); SendCurrentDateTime("Connect"); - LogMessage("Connected Set", $"LX200GPS Attempting manual bypass of prompts: {SendDateTime}"); + LogMessage("Connected Set", + $"LX200GPS Attempting manual bypass of prompts: {SendDateTime}"); ApplySkipAutoStarPrompts("Connect"); } @@ -457,11 +467,13 @@ namespace ASCOM.Meade.net } else { - LogMessage("Connected Set", $"Skipping first connection telescope adjustments (current connections: {connectionInfo.SameDevice})"); + LogMessage("Connected Set", + $"Skipping first connection telescope adjustments (current connections: {connectionInfo.SameDevice})"); } var raAndDec = GetTelescopeRaAndDec(); - LogMessage("Connected Set", $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); + LogMessage("Connected Set", + $"Connected OK. Current RA = {_utilitiesExtra.HoursToHMS(raAndDec.RightAscension)} Dec = {_utilitiesExtra.DegreesToDMS(raAndDec.Declination)}"); } catch (Exception) { @@ -573,6 +585,7 @@ namespace ASCOM.Meade.net { return false; } + return true; } @@ -582,6 +595,7 @@ namespace ASCOM.Meade.net { return true; } + return false; } @@ -608,7 +622,7 @@ namespace ASCOM.Meade.net if (!IsConnected) return true; - if(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) { _isTargetCoordinateInitRequired = false; return _isTargetCoordinateInitRequired; @@ -631,9 +645,9 @@ namespace ASCOM.Meade.net _isTargetCoordinateInitRequired = false; return _isTargetCoordinateInitRequired; } - + //target coordinates are equal current coordinates - if((Math.Abs(RightAscension - rightTargetAscension ) <= eps) && + if ((Math.Abs(RightAscension - rightTargetAscension) <= eps) && (Math.Abs(Declination - targetDeclination) <= eps)) { LogMessage("IsTargetCoordinateInitRequired", "0 diff -> false"); @@ -699,7 +713,7 @@ namespace ASCOM.Meade.net LogMessage("SetLongFormat", $"Get - Azimuth {result}"); if (IsLongFormat == setLongFormat) LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); - } + } else { LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); @@ -807,7 +821,8 @@ namespace ASCOM.Meade.net //1 - Valid break; default: - throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); + throw new ArgumentOutOfRangeException(nameof(site), site, + Resources.Telescope_GetSiteName_Site_out_of_range); } var result = SharedResourcesWrapper.SendChar(command); @@ -825,26 +840,27 @@ namespace ASCOM.Meade.net { case 1: return SharedResourcesWrapper.SendString("GM"); - //:GM# Get Site 1 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //:GM# Get Site 1 Name + //Returns: # + //A ‘#’ terminated string with the name of the requested site. case 2: return SharedResourcesWrapper.SendString("GN"); - //:GN# Get Site 2 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //:GN# Get Site 2 Name + //Returns: # + //A ‘#’ terminated string with the name of the requested site. case 3: return SharedResourcesWrapper.SendString("GO"); - //:GO# Get Site 3 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //:GO# Get Site 3 Name + //Returns: # + //A ‘#’ terminated string with the name of the requested site. case 4: return SharedResourcesWrapper.SendString("GP"); - //:GP# Get Site 4 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //:GP# Get Site 4 Name + //Returns: # + //A ‘#’ terminated string with the name of the requested site. default: - throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); + throw new ArgumentOutOfRangeException(nameof(site), site, + Resources.Telescope_GetSiteName_Site_out_of_range); } } @@ -882,7 +898,7 @@ namespace ASCOM.Meade.net #endregion #region ITelescope Implementation - + public void AbortSlew() { CheckConnected("AbortSlew"); @@ -925,13 +941,13 @@ namespace ASCOM.Meade.net //todo implement GW Command - Supported in Autostar 43Eg and above //if FirmwareIsGreaterThan(TelescopeList.Autostar497_43EG) //{ - //var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); - //:GW# Get Scope Alignment Status - //Returns: # - // where: - //mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial - //tracking: T - tracking, N - not tracking - //alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned. + //var alignmentString = SerialPort.CommandTerminated(":GW#", "#"); + //:GW# Get Scope Alignment Status + //Returns: # + // where: + //mount: A - AzEl mounted, P - Equatorially mounted, G - german mounted equatorial + //tracking: T - tracking, N - not tracking + //alignment: 0 - needs alignment, 1 - one star aligned, 2 - two star aligned, 3 - three star aligned. //} AlignmentModes alignmentMode; @@ -960,7 +976,7 @@ namespace ASCOM.Meade.net //todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly if (!FirmwareIsGreaterThan(TelescopeList.Autostar497_43Eg)) - throw new PropertyNotImplementedException("AlignmentMode",true ); + throw new PropertyNotImplementedException("AlignmentMode", true); switch (value) { @@ -994,6 +1010,8 @@ namespace ASCOM.Meade.net { try { + CheckParked(); + //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! var result = SharedResourcesWrapper.SendString("GA"); //:GA# Get Telescope Altitude @@ -1006,13 +1024,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.NoCoordinates: - throw; - default: - return _parkedPosition.Altitude; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Altitude; + + throw; } } @@ -1032,9 +1048,11 @@ namespace ASCOM.Meade.net EquatorialCoordinates = GetTelescopeRaAndDec() }); - double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, altitudeData.SiteLongitude, + double hourAngle = _astroMaths.RightAscensionToHourAngle(altitudeData.UtcDateTime, + altitudeData.SiteLongitude, altitudeData.EquatorialCoordinates.RightAscension); - var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, altitudeData.EquatorialCoordinates); + var altAz = _astroMaths.ConvertEqToHoz(hourAngle, altitudeData.SiteLatitude, + altitudeData.EquatorialCoordinates); return altAz; } @@ -1073,17 +1091,15 @@ namespace ASCOM.Meade.net return false; } } - - private bool _atPark; - + public bool AtPark { get { - LogMessage("AtPark", "Get - " + _atPark); - return _atPark; + var atPark = SharedResourcesWrapper.IsParked; + LogMessage("AtPark", "Get - " + atPark); + return atPark; } - private set => _atPark = value; } public IAxisRates AxisRates(TelescopeAxes axis) @@ -1102,6 +1118,8 @@ namespace ASCOM.Meade.net { try { + CheckParked(); + var result = SharedResourcesWrapper.SendString("GZ"); //:GZ# Get telescope azimuth //Returns: DDD*MM#T or DDD*MM’SS# @@ -1114,13 +1132,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.NoCoordinates: - throw; - default: - return _parkedPosition.Azimuth; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Azimuth; + + throw; } } @@ -1317,13 +1333,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.NoCoordinates: - throw; - default: - return _parkedPosition.Declination; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Declination; + + throw; } } } @@ -1585,10 +1599,11 @@ namespace ASCOM.Meade.net if (AtPark) return; + ParkedPosition parkedPosition; switch (ParkedBehaviour) { case ParkedBehaviour.LastGoodPosition: - _parkedPosition = new ParkedPosition + parkedPosition = new ParkedPosition { Altitude = Altitude, Azimuth = Azimuth, @@ -1602,7 +1617,7 @@ namespace ASCOM.Meade.net var longitude = SiteLongitude; var raDec = _astroMaths.ConvertHozToEq(utcDateTime, latitude, longitude, ParkedAltAz); - _parkedPosition = new ParkedPosition + parkedPosition = new ParkedPosition { Altitude = ParkedAltAz.Altitude, Azimuth = ParkedAltAz.Azimuth, @@ -1610,12 +1625,13 @@ namespace ASCOM.Meade.net Declination = raDec.Declination }; break; + default: + parkedPosition = null; + break; } //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. - AtPark = true; - - + SharedResourcesWrapper.SetParked(true, parkedPosition); SharedResourcesWrapper.SendBlind("hP"); //:hP# Autostar, Autostar II and LX 16”Slew to Park Position //Returns: Nothing @@ -1764,13 +1780,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.NoCoordinates: - throw; - default: - return _parkedPosition.RightAscension; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.RightAscension; + + throw; } } @@ -2698,7 +2712,7 @@ namespace ASCOM.Meade.net BypassHandboxEntryForAutostarII(); - AtPark = false; + SharedResourcesWrapper.SetParked(false, null); } private bool BypassHandboxEntryForAutostarII() diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index c30849a..4711710 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -141,6 +141,7 @@ + diff --git a/Meade.net.Telescope/ParkedPosition.cs b/Meade.net/ParkedPosition.cs similarity index 100% rename from Meade.net.Telescope/ParkedPosition.cs rename to Meade.net/ParkedPosition.cs diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index ff69268..47730ef 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -493,5 +493,15 @@ namespace ASCOM.Meade.net Count = 0; } } + + public static void SetParked(bool atPark, ParkedPosition parkedPosition) + { + IsParked = atPark; + ParkedPosition = parkedPosition; + } + + public static bool IsParked { get; private set; } + + public static ParkedPosition ParkedPosition { get; private set; } } } \ No newline at end of file diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index c855b6b..d7b078c 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -27,6 +27,10 @@ namespace ASCOM.Meade.net.Wrapper void SetupDialog(); void WriteProfile(ProfileProperties profileProperties); void ReadCharacters(int throwAwayCharacters); + + void SetParked(bool atPark, ParkedPosition parkedPosition); + bool IsParked { get; } + ParkedPosition ParkedPosition { get; } } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -99,5 +103,14 @@ namespace ASCOM.Meade.net.Wrapper { SharedResources.WriteProfile(profileProperties); } + + public void SetParked(bool atPark, ParkedPosition parkedPosition) + { + SharedResources.SetParked(atPark, parkedPosition); + } + + public bool IsParked => SharedResources.IsParked; + + public ParkedPosition ParkedPosition => SharedResources.ParkedPosition; } } From d7637928b7c5c14f13748308eb7bd6ec3406957b Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 27 Apr 2021 22:14:22 +0100 Subject: [PATCH 04/21] Made sure that the telescope doesn't think it's parked for the first Telescope to connect. --- Meade.net.Telescope/Telescope.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c471f58..38fde76 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -416,6 +416,7 @@ namespace ASCOM.Meade.net if (connectionInfo.SameDevice == 1) { + SharedResourcesWrapper.SetParked(false, null); LogMessage("Connected Set", "Making first connection telescope adjustments"); LogMessage("Connected Set", $"Site Longitude: {SiteLongitude}"); @@ -469,6 +470,7 @@ namespace ASCOM.Meade.net { LogMessage("Connected Set", $"Skipping first connection telescope adjustments (current connections: {connectionInfo.SameDevice})"); + CheckParked(); } var raAndDec = GetTelescopeRaAndDec(); From b27e50275dca20df930a254b887bddec78ed5819 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Sun, 9 May 2021 15:20:45 +0100 Subject: [PATCH 05/21] Added extra logging for CommandBlind, CommandBool, and CommandString. --- Meade.net.Telescope/Telescope.cs | 14 ++++++++++---- Meade.net.focuser/Focuser.cs | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 38fde76..137151f 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -339,6 +339,7 @@ namespace ASCOM.Meade.net public void CommandBlind(string command, bool raw) { + LogMessage("CommandBlind", "raw: {0} command {0}", raw, command); CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); @@ -346,14 +347,16 @@ namespace ASCOM.Meade.net // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other + LogMessage("CommandBlind", "Completed"); } public bool CommandBool(string command, bool raw) { + LogMessage("CommandBool", "raw: {0} command {0}", raw, command); CheckConnected("CommandBool"); - //string ret = CommandString(command, raw); - return SharedResourcesWrapper.SendBool(command, raw); - // TODO decode the return string and return true or false + var result = SharedResourcesWrapper.SendBool(command, raw); + LogMessage("CommandBool", "Completed: {0}", result); + return result; // or //throw new MethodNotImplementedException("CommandBool"); // DO NOT have both these sections! One or the other @@ -361,11 +364,14 @@ namespace ASCOM.Meade.net public string CommandString(string command, bool raw) { + LogMessage("CommandString", "raw: {0} command {0}", raw, command); CheckConnected("CommandString"); // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return SharedResourcesWrapper.SendString(command, raw); + var result = SharedResourcesWrapper.SendString(command, raw); + LogMessage("CommandBool", "Completed: {0}", result); + return result; //throw new ASCOM.MethodNotImplementedException("CommandString"); } diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index caa25fc..93e0ca0 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -101,6 +101,7 @@ namespace ASCOM.Meade.net public void CommandBlind(string command, bool raw) { + LogMessage("CommandBlind", "raw: {0} command {0}", raw, command); CheckConnected("CommandBlind"); // Call CommandString and return as soon as it finishes //this.CommandString(command, raw); @@ -108,14 +109,16 @@ namespace ASCOM.Meade.net // or //throw new ASCOM.MethodNotImplementedException("CommandBlind"); // DO NOT have both these sections! One or the other + LogMessage("CommandBlind", "Completed"); } public bool CommandBool(string command, bool raw) { + LogMessage("CommandBool", "raw: {0} command {0}", raw, command); CheckConnected("CommandBool"); - //string ret = CommandString(command, raw); - return SharedResourcesWrapper.SendBool(command, raw); - // decode the return string and return true or false + var result = SharedResourcesWrapper.SendBool(command, raw); + LogMessage("CommandBool", "Completed: {0}", result); + return result; // or //throw new MethodNotImplementedException("CommandBool"); // DO NOT have both these sections! One or the other @@ -123,11 +126,14 @@ namespace ASCOM.Meade.net public string CommandString(string command, bool raw) { + LogMessage("CommandString", "raw: {0} command {0}", raw, command); CheckConnected("CommandString"); // it's a good idea to put all the low level communication with the device here, // then all communication calls this function // you need something to ensure that only one command is in progress at a time - return SharedResourcesWrapper.SendString(command, raw); + var result = SharedResourcesWrapper.SendString(command, raw); + LogMessage("CommandBool", "Completed: {0}", result); + return result; //throw new ASCOM.MethodNotImplementedException("CommandString"); } From 65e06f2d6c3ab4917aef87f978df2e2e58463606 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 6 Jun 2021 17:31:57 +1000 Subject: [PATCH 06/21] Implemented SideOfPier and DestinationSideOfPier For telescopes that automatically perform a meridian flip we can implement the SideOfPier property by updating the current side of pier after a telescope slew (via DestinationSideOfPier) --- .../TelescopeUnitTests.cs | 115 ++++++++++++++++-- Meade.net.Telescope/Telescope.cs | 114 +++++++++++++---- 2 files changed, 192 insertions(+), 37 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index c111e34..e86fd2c 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Reflection; using ASCOM; using ASCOM.Astrometry.AstroUtils; +using ASCOM.Astrometry.NOVAS; using ASCOM.DeviceInterface; using ASCOM.Meade.net; using ASCOM.Meade.net.AstroMaths; @@ -42,6 +43,7 @@ namespace Meade.net.Telescope.UnitTests private Mock _sharedResourcesWrapperMock; private Mock _astroMathsMock; private Mock _clockMock; + private Mock _novasMock; private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; @@ -98,15 +100,17 @@ namespace Meade.net.Telescope.UnitTests }; _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo ); - + _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); _astroMathsMock = new Mock(); _clockMock = new Mock(); + _novasMock = new Mock(); + _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object, _novasMock.Object); } private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) @@ -191,7 +195,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString("ED", false)).Returns(expectedResult); _telescope.Connected = true; - + var actualResult = _telescope.Action("handbox", "readdisplay"); @@ -402,7 +406,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendBool(expectedMessage, raw), Times.Once); Assert.That(result, Is.True); } - + [Test] public void CommandString_WhenNotConnected_ThenThrowsNotConnectedException() { @@ -1199,15 +1203,89 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void DestinationSideOfPier_ThenThrowsException() + public void DestinationSideOfPier_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => + var excpetion = Assert.Throws(() => { var result = _telescope.DestinationSideOfPier(0, 0); Assert.Fail($"{result} should not have returned"); }); - Assert.That(excpetion.Method, Is.EqualTo("DestinationSideOfPier")); + Assert.That(excpetion.Message, Is.EqualTo("Not connected to telescope when trying to execute: DestinationSideOfPier")); + } + + [TestCase(1, 1, 4, PierSide.pierEast)] + [TestCase(1, -1, 4, PierSide.pierEast)] + [TestCase(4, 1, 1, PierSide.pierWest)] + [TestCase(4, -1, 1, PierSide.pierWest)] + [TestCase(0, 0, 0, PierSide.pierUnknown)] + [TestCase(5, 0, 5, PierSide.pierUnknown)] + [TestCase(23.8, 1, 23.9, PierSide.pierEast)] + [TestCase(23.8, -1, 23.9, PierSide.pierEast)] + [TestCase(23.9, 1, 1, PierSide.pierEast)] + [TestCase(23.9, -1, 1, PierSide.pierEast)] + [TestCase(1, 1, 23.9, PierSide.pierWest)] + [TestCase(1, -1, 23.9, PierSide.pierWest)] + public void DestinationSideOfPier_WhenHASiderealTimeDiffIsNotNull_ThenSideOfPierIsCalculated(double ra, double dec, double siderealTime, PierSide expectedDSOP) + { + // given + // SideralTime uses ConditionRA to normalize to 0..24h, so we use it to mock the property + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(siderealTime); + + var ha = siderealTime - ra; + var normalisedHA = ha > 12 ? ha - 24 : ha < -12 ? ha + 24 : ha; + _astroUtilsMock.Setup(x => x.ConditionHA(It.Is(v => v == ha))).Returns(normalisedHA); + + ConnectTelescope(); + + // when + var actualDSOP = _telescope.DestinationSideOfPier(ra, dec); + + // then + Assert.That(siderealTime, Is.InRange(0, 24 + double.Epsilon)); + Assert.That(normalisedHA, Is.InRange(-12, 12 + double.Epsilon)); + Assert.That(actualDSOP, Is.EqualTo(expectedDSOP)); + + _astroUtilsMock.Verify(x => x.ConditionRA(It.IsAny()), Times.Once); + _astroUtilsMock.Verify(x => x.ConditionHA(It.Is(v => v == ha)), Times.Once); + } + + [Test] + public void SiderealTime_Get_WhenNotConnected_ThenThrowsException() + { + // when + var exception = Assert.Throws(() => + { + var result = _telescope.SiderealTime; + Assert.Fail($"{result} should not have returned"); + }); + + // then + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SiderealTime Get")); + } + + [Test] + public void SiderealTime_Get_WhenNOVASErrors_ThenThrowsException() + { + // given + double gst = 0.0; + _novasMock + .Setup(x => x.SiderealTime(It.IsAny(), It.IsAny(), It.IsAny(), ASCOM.Astrometry.GstType.GreenwichApparentSiderealTime, ASCOM.Astrometry.Method.EquinoxBased, ASCOM.Astrometry.Accuracy.Reduced, ref gst)) + .Returns(3) + .Verifiable(); + + ConnectTelescope(); + + // when + var exception = Assert.Throws(() => + { + var result = _telescope.SiderealTime; + Assert.Fail($"{result} should not have returned"); + }); + + // then + Assert.That(exception.Message, Is.EqualTo("NOVAS 3.1 SiderealTime returned: 3 in SiderealTime")); + _novasMock.Verify(); } [Test] @@ -1470,7 +1548,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.AtPark, Is.True); - //act + //act _telescope.Park(); //no change from previous state. @@ -1743,8 +1821,11 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void SideOfPier_Get_ThenThrowsException() + public void SideOfPier_Get_WhenMeridianFlipNotSupported_ThenThrowsException() { + // LX200 classic is a fork mounted scope so it does not support meridian flips + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(TelescopeList.LX200CLASSIC); + var excpetion = Assert.Throws(() => { var result = _telescope.SideOfPier; @@ -2761,6 +2842,9 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() { + // avoid calling SideOfPier because it will call Slewing + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; @@ -2781,6 +2865,7 @@ namespace Meade.net.Telescope.UnitTests _telescope.SlewToTarget(); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] @@ -2841,6 +2926,9 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinates_WhenCalled_ThenSetsTargetAndSlews() { + // avoid calling SideOfPier because it will call Slewing + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); + _testProperties.rightAscension = 1; var declination = 2; @@ -2875,6 +2963,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] @@ -2963,6 +3052,9 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { + // avoid calling SideOfPier because it will call Slewing + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); + _testProperties.rightAscension = 10.0; _testProperties.declination = 20; var azimuth = 30; @@ -2995,6 +3087,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(_telescope.TargetDeclination, Is.EqualTo(_testProperties.declination)); _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); _utilMock.Verify(x => x.WaitForMilliseconds(It.IsAny()), Times.Exactly(iterations)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); } [Test] @@ -3021,8 +3114,8 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(telescopeLongitude); - _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); - + _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); + ConnectTelescope(); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 137151f..c4f65dc 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -57,7 +57,8 @@ namespace ASCOM.Meade.net private readonly IUtilExtra _utilitiesExtra; /// - /// Private variable to hold an ASCOM AstroUtilities object to provide the Range method + /// Private variable to hold an ASCOM AstroUtilities object to provide the method + /// and /// private readonly IAstroUtils _astroUtilities; @@ -65,6 +66,8 @@ namespace ASCOM.Meade.net private readonly IClock _clock; + private readonly INOVAS31 _novas; + /// /// Private variable to hold number of decimals for RA /// @@ -76,7 +79,7 @@ namespace ASCOM.Meade.net private int _digitsDe = 2; private short _settleTime; - + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -92,6 +95,7 @@ namespace ASCOM.Meade.net _astroUtilities = new AstroUtils(); // Initialise astro utilities object _astroMaths = new AstroMaths.AstroMaths(); _clock = new Clock(); + _novas = new NOVAS31(); Initialise(nameof(Telescope)); } @@ -125,7 +129,7 @@ namespace ASCOM.Meade.net } public Telescope(IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, - ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock) : base( + ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths, IClock clock, INOVAS31 novas) : base( sharedResourcesWrapper) { _clock = clock; @@ -133,6 +137,7 @@ namespace ASCOM.Meade.net _utilitiesExtra = utilExtra; //Initialise util object _astroUtilities = astroUtilities; // Initialise astro utilities object _astroMaths = astroMaths; + _novas = novas; Initialise(nameof(Telescope)); } @@ -607,6 +612,18 @@ namespace ASCOM.Meade.net return false; } + // true iff the mount will perform a meridian flip when required + // TODO: Needs checking what mounts actually support this + private bool IsMeridianFlipOnSlewSupported() + { + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200CLASSIC) + { + return false; + } + + return true; + } + private bool FirmwareIsGreaterThan(string minVersion) { var currentVersion = SharedResourcesWrapper.FirmwareVersion; @@ -1099,7 +1116,7 @@ namespace ASCOM.Meade.net return false; } } - + public bool AtPark { get @@ -1368,8 +1385,18 @@ namespace ASCOM.Meade.net public PierSide DestinationSideOfPier(double rightAscension, double declination) { - LogMessage("DestinationSideOfPier Get", "Not implemented"); - throw new MethodNotImplementedException("DestinationSideOfPier"); + CheckConnected("DestinationSideOfPier"); + + double hourAngle = _astroUtilities.ConditionHA(SiderealTime - rightAscension); + + var destinationSOP = hourAngle > 0 + ? PierSide.pierEast : + (hourAngle < 0 ? PierSide.pierWest : SideOfPier); + + LogMessage("DestinationSideOfPier", + $"Destination SOP of RA {rightAscension.ToString(CultureInfo.InvariantCulture)} is {destinationSOP}"); + + return destinationSOP; } public bool DoesRefraction @@ -1433,7 +1460,7 @@ namespace ASCOM.Meade.net //sidereal speed(approx 15.0417”/sec)[Autostar II only] //Returns: Nothing - //info from RickB says that 15.04107 is a better value for + //info from RickB says that 15.04107 is a better value for GuideRate = value; @@ -1464,7 +1491,7 @@ namespace ASCOM.Meade.net SetNewGuideRate(newValue, "GuideRateDeclination"); } } - + public double GuideRateRightAscension { get @@ -1493,7 +1520,7 @@ namespace ASCOM.Meade.net private bool _movingPrimary; private bool _movingSecondary; - + public void MoveAxis(TelescopeAxes axis, double rate) { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); @@ -1555,12 +1582,16 @@ namespace ASCOM.Meade.net //:Me# Move Telescope East at current slew rate //Returns: Nothing _movingPrimary = true; + // in principle we could calculate the current side of pier, but unknown is the safer option. + _pierSide = PierSide.pierUnknown; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind("Mw"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing _movingPrimary = true; + // in principle we could calculate the current side of pier, but unknown is the safer option. + _pierSide = PierSide.pierUnknown; break; } break; @@ -1763,7 +1794,7 @@ namespace ASCOM.Meade.net var hms = $"{token[0]}:{seconds}"; return _utilities.HMSToHours(hms); } - + double _lastGoodRightAsension; public double RightAscension @@ -1792,9 +1823,9 @@ namespace ASCOM.Meade.net if (parkedPosition != null) return parkedPosition.RightAscension; - throw; + throw; } - + } } @@ -1820,10 +1851,25 @@ namespace ASCOM.Meade.net throw new MethodNotImplementedException("SetPark"); } + /// + /// Start with . + /// As we do not know the physical declination axis position, we have to keep track manually. + /// + private PierSide _pierSide = PierSide.pierUnknown; public PierSide SideOfPier { get { + if (IsMeridianFlipOnSlewSupported()) + { + // while mount is slewing return unknown, this is required since + // DoSlewAsync updates _pierSide before slew is finished + var pierSide = Slewing ? PierSide.pierUnknown : _pierSide; + + LogMessage("SideOfPier", "Get - " + pierSide); + return pierSide; + } + LogMessage("SideOfPier Get", "Not implemented"); throw new PropertyNotImplementedException("SideOfPier", false); } @@ -1839,15 +1885,20 @@ namespace ASCOM.Meade.net { get { + CheckConnected("SiderealTime Get"); + // Now using NOVAS 3.1 double siderealTime = 0.0; - using (var novas = new NOVAS31()) + + var jd = _utilities.DateUTCToJulian(_clock.UtcNow); + var siderealTimeResult = _novas.SiderealTime(jd, 0, _novas.DeltaT(jd), + GstType.GreenwichApparentSiderealTime, + Method.EquinoxBased, + Accuracy.Reduced, ref siderealTime); + + if (siderealTimeResult != 0) { - var jd = _utilities.DateUTCToJulian(_clock.UtcNow); - novas.SiderealTime(jd, 0, novas.DeltaT(jd), - GstType.GreenwichApparentSiderealTime, - Method.EquinoxBased, - Accuracy.Reduced, ref siderealTime); + throw new InvalidOperationException($"NOVAS 3.1 SiderealTime returned: {siderealTimeResult} in SiderealTime"); } // Allow for the longitude @@ -1881,7 +1932,7 @@ namespace ASCOM.Meade.net LogMessage("SiteElevation", "Set: no change detected"); return; } - + LogMessage("SiteElevation", $"Set: {value} was {base.SiteElevation}"); base.SiteElevation = value; UpdateSiteElevation(); @@ -2052,7 +2103,7 @@ namespace ASCOM.Meade.net _utilities.WaitForMilliseconds(200); //be responsive to AbortSlew(); } } - + public void SlewToAltAzAsync(double azimuth, double altitude) { CheckConnected("SlewToAltAzAsync"); @@ -2116,15 +2167,23 @@ namespace ASCOM.Meade.net case "0": //We're slewing everything should be working just fine. LogMessage("DoSlewAsync", "Slewing to target"); + + if (IsMeridianFlipOnSlewSupported()) + { + // Update side of pier to destination side of pier + // Assumption: Mount will do meridian flip if required + _pierSide = DestinationSideOfPier(TargetRightAscension, TargetDeclination); + } + SetSlewingMinEndTime(); break; case "1": - //Below Horizon + //Below Horizon string belowHorizonMessage = SharedResourcesWrapper.ReadTerminated(); LogMessage("DoSlewAsync", $"Slew failed \"{belowHorizonMessage}\""); throw new InvalidOperationException(belowHorizonMessage); case "2": - //Below minimum elevation + //Below minimum elevation string belowMinimumElevationMessage = SharedResourcesWrapper.ReadTerminated(); LogMessage("DoSlewAsync", $"Slew failed \"{belowMinimumElevationMessage}\""); throw new InvalidOperationException(belowMinimumElevationMessage); @@ -2362,7 +2421,7 @@ namespace ASCOM.Meade.net LogMessage("SyncToTarget", "Executing"); CheckConnected("SyncToTarget"); CheckParked(); - + var result = SharedResourcesWrapper.SendString("CM"); //:CM# Synchronizes the telescope's position with the currently selected database object's coordinates. //Returns: @@ -2480,7 +2539,7 @@ namespace ASCOM.Meade.net throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); var hms = IsLongFormat ? - _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : + _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); var command = $"Sr{hms}"; @@ -2696,7 +2755,7 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("Failed to set local date"); } - //throwing away these two strings which represent + //throwing away these two strings which represent SharedResourcesWrapper.ReadTerminated(); //Updating Planetary Data# SharedResourcesWrapper.ReadTerminated(); // # }); @@ -2721,6 +2780,9 @@ namespace ASCOM.Meade.net BypassHandboxEntryForAutostarII(); SharedResourcesWrapper.SetParked(false, null); + + // reset side of pier + SideOfPier = PierSide.pierUnknown; } private bool BypassHandboxEntryForAutostarII() @@ -2747,7 +2809,7 @@ namespace ASCOM.Meade.net #region ASCOM Registration // Register or unregister driver for ASCOM. This is harmless if already - // registered or unregistered. + // registered or unregistered. // /// /// Register or unregister the driver with the ASCOM Platform. From fe3c1069542466182a01012753cae01edeca5445 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Mon, 7 Jun 2021 17:58:20 +1000 Subject: [PATCH 07/21] Add unit test around meridian flip detection --- .../TelescopeUnitTests.cs | 135 +++++++++++++++++- 1 file changed, 133 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index e86fd2c..c931d76 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Reflection; using ASCOM; +using ASCOM.Astrometry; using ASCOM.Astrometry.AstroUtils; using ASCOM.Astrometry.NOVAS; using ASCOM.DeviceInterface; @@ -1229,10 +1230,11 @@ namespace Meade.net.Telescope.UnitTests public void DestinationSideOfPier_WhenHASiderealTimeDiffIsNotNull_ThenSideOfPierIsCalculated(double ra, double dec, double siderealTime, PierSide expectedDSOP) { // given - // SideralTime uses ConditionRA to normalize to 0..24h, so we use it to mock the property + // SideralTime uses ConditionRA to normalize to [0..24h), so we use it to mock the property _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(siderealTime); var ha = siderealTime - ra; + // normalized hour angle range is [-12h..12h] var normalisedHA = ha > 12 ? ha - 24 : ha < -12 ? ha + 24 : ha; _astroUtilsMock.Setup(x => x.ConditionHA(It.Is(v => v == ha))).Returns(normalisedHA); @@ -1242,7 +1244,7 @@ namespace Meade.net.Telescope.UnitTests var actualDSOP = _telescope.DestinationSideOfPier(ra, dec); // then - Assert.That(siderealTime, Is.InRange(0, 24 + double.Epsilon)); + Assert.That(siderealTime, Is.InRange(0, 24)); Assert.That(normalisedHA, Is.InRange(-12, 12 + double.Epsilon)); Assert.That(actualDSOP, Is.EqualTo(expectedDSOP)); @@ -1845,6 +1847,135 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.AccessorSet, Is.True); } + delegate void NovasSiderealTimeDelegate(double jdHigh, double jdLow, double jdDelta, GstType gstType, Method method, Accuracy accuracy, ref double sideralTime); + + /// + /// Test cases obtained via .NET telescope simulator + /// + [TestCase(9.4337648353882, -76.7178112042103, "2021-06-07T05:23:41.7610000Z", 8.13556526999591, 145.166333333333, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(10.1581570159006, 11.8639491368916, "2021-06-07T10:59:19.7000000Z", 9.72726050605156, 145.166333333333, 1d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(9.66583199112222, 81.2310578173083, "2021-06-07T11:19:24.5540000Z", 7.73744116673785, 110.285166666667, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(8.32978972808615, -29.816491813155, "2021-06-07T11:29:33.7040000Z", 7.90712206850482, 110.285166666667, 1d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(1.76405553984887, 60.7756226366989, "2021-06-07T11:34:07.5270000Z", 0.214893775091689, -6.24266666666667, 2d, PierSide.pierWest, PierSide.pierEast)] + [TestCase(0.523375885742411, -33.1288722052936, "2021-06-07T11:38:25.1670000Z", 0.286661722506396, -6.24266666666667, 0.5d, PierSide.pierWest, PierSide.pierEast)] + public void SideOfPier_WhenTrackingThroughMeridianAfterSubsequentGoto_ThenAMeridianFlipIsPerformed( + double ra, + double dec, + string jnowTimeStr, /* JNOW of object before transit */ + double jnowSiderealTime, + double siteLongitude, + double trackingTimeHours, + PierSide pierSideBeforeTransit, + PierSide pierSideAfterRetargeting + ) + { + // given + var jnowTime = DateTimeOffset.ParseExact(jnowTimeStr, "o", CultureInfo.InvariantCulture).UtcDateTime; + var trackingTimeDiff = TimeSpan.FromHours(trackingTimeHours); + var timeAfterTracking = jnowTime + trackingTimeDiff; + var raAsHMS = ra + "HMS"; + var decAsDMS = dec + "DMS"; + var currentTime = jnowTime; + + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime); + + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + + // setup for RA + _utilMock.Setup(x => x.HoursToHMS(ra, ":", ":", ":", 2)).Returns(raAsHMS); + _utilMock.Setup(x => x.HMSToHours(raAsHMS)).Returns(ra); + + // setup for DEC + _utilMock.Setup(x => x.DMSToDegrees(decAsDMS)).Returns(dec); + _utilMock.Setup(x => x.DegreesToDMS(dec, "*", ":", ":", 2)).Returns(decAsDMS); + + // setup for SiteLongitude + var siteLongitudeResult = siteLongitude + "Gg"; + _sharedResourcesWrapperMock.Setup(x => x.SendString("Gg", false)).Returns(siteLongitudeResult); + // remember to invert longitude + _utilMock.Setup(x => x.DMSToDegrees(siteLongitudeResult)).Returns(-siteLongitude); + + // setup for SideralTime + var siteLongitudeAdj = siteLongitude / 360.0 * 24.0; + var jnowSiderealTimeWithoutLongAdj = jnowSiderealTime - siteLongitudeAdj; + var afterTrackingSiderealTimeWithoutLongAdj = jnowSiderealTimeWithoutLongAdj + trackingTimeHours; + + _utilMock.Setup(x => x.DateUTCToJulian(It.IsAny())).Returns(pDateTime => pDateTime.Ticks); + + _novasMock + .Setup(x => x.SiderealTime( + It.IsAny(), + 0d, + 0d, + GstType.GreenwichApparentSiderealTime, + Method.EquinoxBased, + Accuracy.Reduced, + ref It.Ref.IsAny)) + .Callback(new NovasSiderealTimeDelegate(NovasSiderealTime)) + .Returns(0); + + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA); + + void NovasSiderealTime(double pJDHigh, double pJDLow, double pJDDelta, GstType pGSTType, Method pMethod, Accuracy pAccuracy, ref double pSideralTime) + { + if (pJDHigh == jnowTime.Ticks) + { + pSideralTime = jnowSiderealTimeWithoutLongAdj; + } + else if (pJDHigh == timeAfterTracking.Ticks) + { + pSideralTime = afterTrackingSiderealTimeWithoutLongAdj; + } + else + { + Assert.Fail($"No sideral time defined for {pJDHigh}"); + } + } + + // Setup DestinationSideOfPier + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA); + + ConnectTelescope(); + + // when + _telescope.SlewToCoordinatesAsync(ra, dec); + var actualSideOfPierAfterSlew = _telescope.SideOfPier; + // simulate tracking time + currentTime += trackingTimeDiff; + var actualSideOfPierAfterTracking = _telescope.SideOfPier; + _telescope.SlewToTargetAsync(); + var actualSideOfPierAfterRetargeting = _telescope.SideOfPier; + + // then + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(ra)); + Assert.That(_telescope.TargetDeclination, Is.EqualTo(dec)); + Assert.That(actualSideOfPierAfterSlew, Is.EqualTo(pierSideBeforeTransit)); + Assert.That(actualSideOfPierAfterTracking, Is.EqualTo(pierSideBeforeTransit)); + Assert.That(actualSideOfPierAfterRetargeting, Is.EqualTo(pierSideAfterRetargeting)); + + _clockMock.Verify(x => x.UtcNow, Times.AtLeast(2)); + + foreach (var time in new[] { jnowTime, timeAfterTracking }) + { + _utilMock.Verify(x => x.DateUTCToJulian(time)); + + _novasMock + .Verify(x => x.SiderealTime( + time.Ticks, + 0d, + 0d, + GstType.GreenwichApparentSiderealTime, + Method.EquinoxBased, + Accuracy.Reduced, + ref It.Ref.IsAny), + Times.Once); + } + + _sharedResourcesWrapperMock.Verify(x => x.SendString("Gg", false), Times.Exactly(3)); + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Exactly(3)); + } + [Test] public void SiteElevation_Get_WhenNotConnectedThrowsException() { From 1684bd60bd49c9317e722b2fcaf5e3b5bcd55f2e Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sat, 12 Jun 2021 15:47:34 +1000 Subject: [PATCH 08/21] Move SideOfPier, TargetRA/DEC properties to SharedResourcesWrapper This change allows several instances of the driver to be in sync w.r.t. TargetRightAscension, TargetDeclination and SideOfPier --- .../TelescopeUnitTests.cs | 11 +- Meade.net.Telescope/Telescope.cs | 135 +++++++++--------- Meade.net/SharedResources.cs | 31 ++-- Meade.net/Wrapper/SharedResourcesWrapper.cs | 25 +++- 4 files changed, 122 insertions(+), 80 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index c931d76..274f6ea 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -100,10 +100,15 @@ namespace Meade.net.Telescope.UnitTests SameDevice = 1 }; - _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo ); + _sharedResourcesWrapperMock.Setup(x => x.Connect("Serial", It.IsAny(), It.IsAny())).Returns( () => _connectionInfo); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(_profileProperties); + _sharedResourcesWrapperMock + .SetupProperty(x => x.SideOfPier) + .SetupProperty(x => x.TargetRightAscension) + .SetupProperty(x => x.TargetDeclination); + _astroMathsMock = new Mock(); _clockMock = new Mock(); @@ -1230,6 +1235,10 @@ namespace Meade.net.Telescope.UnitTests public void DestinationSideOfPier_WhenHASiderealTimeDiffIsNotNull_ThenSideOfPierIsCalculated(double ra, double dec, double siderealTime, PierSide expectedDSOP) { // given + + // deterministic start + _sharedResourcesWrapperMock.Object.SideOfPier = PierSide.pierUnknown; + // SideralTime uses ConditionRA to normalize to [0..24h), so we use it to mock the property _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(siderealTime); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c4f65dc..cfdee7b 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -418,8 +418,6 @@ namespace ASCOM.Meade.net $"Connected to port {ComPort}. Product: {SharedResourcesWrapper.ProductName} Version:{SharedResourcesWrapper.FirmwareVersion}"); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); - _targetDeclination = InvalidParameter; - _targetRightAscension = InvalidParameter; _tracking = true; LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}"); @@ -443,6 +441,11 @@ namespace ASCOM.Meade.net SetTelescopePrecision("Connect"); + // target RA, DEC and SideOfPier are set to default values + SharedResourcesWrapper.SideOfPier = PierSide.pierUnknown; + SharedResourcesWrapper.TargetDeclination = InvalidParameter; + SharedResourcesWrapper.TargetRightAscension = InvalidParameter; + LogMessage("Connected Set", $"SendDateTime: {SendDateTime}"); if (SendDateTime) { @@ -720,7 +723,7 @@ namespace ASCOM.Meade.net var result = SharedResourcesWrapper.SendString("GZ"); LogMessage("SetLongFormat", $"Get - Azimuth {result}"); //:GZ# Get telescope azimuth - //Returns: DDD*MM.T 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; @@ -754,8 +757,8 @@ namespace ASCOM.Meade.net var result = SharedResourcesWrapper.SendChar("P"); //:P# Toggles High Precsion Pointing. When High precision pointing is enabled scope will first allow the operator to center a nearby bright star before moving to the actual target. //Returns: - //“HIGH PRECISION” Current setting after this command. - //“LOW PRECISION” Current setting after this command. + //"HIGH PRECISION" Current setting after this command. + //"LOW PRECISION" Current setting after this command. int throwAwayCharacters = "LOW PRECISION".Length - 1; @@ -816,33 +819,33 @@ namespace ASCOM.Meade.net case 1: command = $"SM{sitename}"; //:SM# - //Set site 1’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. + //Set site 1's name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: - //0 – Invalid + //0 - Invalid //1 - Valid break; case 2: command = $"SN{sitename}"; //:SN# - //Set site 2’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. + //Set site 2's name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: - //0 – Invalid + //0 - Invalid //1 - Valid break; case 3: command = $"SO{sitename}"; //:SO# - //Set site 3’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. + //Set site 3's name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: - //0 – Invalid + //0 - Invalid //1 - Valid break; case 4: command = $"SP{sitename}"; //:SP# - //Set site 4’s name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. + //Set site 4's name to be.LX200s only accept 3 character strings. Other scopes accept up to 15 characters. // Returns: - //0 – Invalid + //0 - Invalid //1 - Valid break; default: @@ -867,22 +870,22 @@ namespace ASCOM.Meade.net return SharedResourcesWrapper.SendString("GM"); //:GM# Get Site 1 Name //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //A '#' terminated string with the name of the requested site. case 2: return SharedResourcesWrapper.SendString("GN"); //:GN# Get Site 2 Name //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //A '#' terminated string with the name of the requested site. case 3: return SharedResourcesWrapper.SendString("GO"); //:GO# Get Site 3 Name //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //A '#' terminated string with the name of the requested site. case 4: return SharedResourcesWrapper.SendString("GP"); //:GP# Get Site 4 Name //Returns: # - //A ‘#’ terminated string with the name of the requested site. + //A '#' terminated string with the name of the requested site. default: throw new ArgumentOutOfRangeException(nameof(site), site, Resources.Telescope_GetSiteName_Site_out_of_range); @@ -1040,7 +1043,7 @@ namespace ASCOM.Meade.net //firmware bug in 44Eg, :GA# is returning the dec, not the altitude! var result = SharedResourcesWrapper.SendString("GA"); //:GA# Get Telescope Altitude - //Returns: sDD* MM# or sDD*MM’SS# + //Returns: sDD* MM# or sDD*MM'SS# //The current scope altitude. The returned format depending on the current precision setting. var alt = _utilities.DMSToDegrees(result); @@ -1147,7 +1150,7 @@ namespace ASCOM.Meade.net var result = SharedResourcesWrapper.SendString("GZ"); //:GZ# Get telescope azimuth - //Returns: DDD*MM#T or DDD*MM’SS# + //Returns: DDD*MM#T or DDD*MM'SS# //The current telescope Azimuth depending on the selected precision. double az = _utilities.DMSToDegrees(result); @@ -1347,7 +1350,7 @@ namespace ASCOM.Meade.net var result = SharedResourcesWrapper.SendString("GD"); //:GD# Get Telescope Declination. - //Returns: sDD*MM# or sDD*MM’SS# + //Returns: sDD*MM# or sDD*MM'SS# //Depending upon the current precision setting for the telescope. double declination = _utilities.DMSToDegrees(result); @@ -1449,7 +1452,7 @@ namespace ASCOM.Meade.net if (!value.InRange(0, 15.0417)) { - throw new InvalidValueException(propertyName, value.ToString(CultureInfo.CurrentCulture), $"{0.ToString(CultureInfo.CurrentCulture)} to {15.0417.ToString(CultureInfo.CurrentCulture)}”/sec"); + throw new InvalidValueException(propertyName, value.ToString(CultureInfo.CurrentCulture), $"{0.ToString(CultureInfo.CurrentCulture)} to {15.0417.ToString(CultureInfo.CurrentCulture)}\"/sec"); } LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)"); @@ -1457,7 +1460,7 @@ namespace ASCOM.Meade.net //:RgSS.S# //Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking //Rates when the CCD guider or handbox guider buttons are pressed when the guide rate is selected.Rate shall not exceed - //sidereal speed(approx 15.0417”/sec)[Autostar II only] + //sidereal speed(approx 15.0417"/sec)[Autostar II only] //Returns: Nothing //info from RickB says that 15.04107 is a better value for @@ -1583,7 +1586,7 @@ namespace ASCOM.Meade.net //Returns: Nothing _movingPrimary = true; // in principle we could calculate the current side of pier, but unknown is the safer option. - _pierSide = PierSide.pierUnknown; + SharedResourcesWrapper.SideOfPier = PierSide.pierUnknown; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind("Mw"); @@ -1591,7 +1594,7 @@ namespace ASCOM.Meade.net //Returns: Nothing _movingPrimary = true; // in principle we could calculate the current side of pier, but unknown is the safer option. - _pierSide = PierSide.pierUnknown; + SharedResourcesWrapper.SideOfPier = PierSide.pierUnknown; break; } break; @@ -1672,7 +1675,7 @@ namespace ASCOM.Meade.net //Setting park to true before sending the park command as the Autostar and Audiostar stop serial communications once the park command has been issued. SharedResourcesWrapper.SetParked(true, parkedPosition); SharedResourcesWrapper.SendBlind("hP"); - //:hP# Autostar, Autostar II and LX 16”Slew to Park Position + //:hP# Autostar, Autostar II and LX 16" Slew to Park Position //Returns: Nothing } @@ -1728,8 +1731,8 @@ namespace ASCOM.Meade.net //:MgwDDDD# //Guide telescope in the commanded direction(nsew) for the number of milliseconds indicated by the unsigned number //passed in the command.These commands support serial port driven guiding. - //Returns – Nothing - //LX200 – Not Supported + //Returns - Nothing + //LX200 - Not Supported _utilities.WaitForMilliseconds(duration); } else @@ -1851,11 +1854,6 @@ namespace ASCOM.Meade.net throw new MethodNotImplementedException("SetPark"); } - /// - /// Start with . - /// As we do not know the physical declination axis position, we have to keep track manually. - /// - private PierSide _pierSide = PierSide.pierUnknown; public PierSide SideOfPier { get @@ -1864,7 +1862,7 @@ namespace ASCOM.Meade.net { // while mount is slewing return unknown, this is required since // DoSlewAsync updates _pierSide before slew is finished - var pierSide = Slewing ? PierSide.pierUnknown : _pierSide; + var pierSide = Slewing ? PierSide.pierUnknown : SharedResourcesWrapper.SideOfPier; LogMessage("SideOfPier", "Get - " + pierSide); return pierSide; @@ -1996,7 +1994,7 @@ namespace ASCOM.Meade.net //:StsDD*MM# //Sets the current site latitude to sDD* MM# //Returns: - //0 – Invalid + //0 - Invalid //1 - Valid if (result != "1") throw new InvalidOperationException("Failed to set site latitude."); @@ -2063,9 +2061,9 @@ namespace ASCOM.Meade.net var result = SharedResourcesWrapper.SendChar(commandstring); //:SgDDD*MM# - //Set current site’s longitude to DDD*MM an ASCII position string + //Set current site's longitude to DDD*MM an ASCII position string //Returns: - //0 – Invalid + //0 - Invalid //1 - Valid if (result != "1") throw new InvalidOperationException("Failed to set site longitude."); @@ -2172,7 +2170,7 @@ namespace ASCOM.Meade.net { // Update side of pier to destination side of pier // Assumption: Mount will do meridian flip if required - _pierSide = DestinationSideOfPier(TargetRightAscension, TargetDeclination); + SharedResourcesWrapper.SideOfPier = DestinationSideOfPier(TargetRightAscension, TargetDeclination); } SetSlewingMinEndTime(); @@ -2201,11 +2199,11 @@ namespace ASCOM.Meade.net break; case false: var maResponse = SharedResourcesWrapper.SendChar("MA"); - //:MA# Autostar, LX 16”, Autostar II – Slew to target Alt and Az + //:MA# Autostar, LX 16", Autostar II - Slew to target Alt and Az //Returns: //0 - No fault - //1 – Fault - // LX200 – Not supported + //1 - Fault + //LX200 - Not supported if (maResponse == "1") { @@ -2345,8 +2343,8 @@ namespace ASCOM.Meade.net } //:D# Requests a string of bars indicating the distance to the current target location. //Returns: - //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. + //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 = false; try @@ -2433,41 +2431,42 @@ namespace ASCOM.Meade.net // 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 targetRA = SharedResourcesWrapper.TargetRightAscension ?? InvalidParameter; double ra = RightAscension; - if (Math.Abs(_targetRightAscension - InvalidParameter) > 0.1 && - _utilities.HoursToHMS(ra, ":", ":", ":", _digitsRa) != _utilities.HoursToHMS(_targetRightAscension, ":", ":", ":", _digitsRa)) + if (Math.Abs(targetRA - InvalidParameter) > 0.1 && + _utilities.HoursToHMS(ra, ":", ":", ":", _digitsRa) != _utilities.HoursToHMS(targetRA, ":", ":", ":", _digitsRa)) { - LogMessage("SyncToTarget", $"differ RA real {ra} targeted {_targetRightAscension}"); - _targetRightAscension = ra; + LogMessage("SyncToTarget", $"differ RA real {ra} targeted {targetRA}"); + SharedResourcesWrapper.TargetRightAscension = ra; } + double targetDEC = SharedResourcesWrapper.TargetDeclination ?? InvalidParameter; double de = Declination; - if (Math.Abs(_targetDeclination - InvalidParameter) > 0.1 && - _utilities.DegreesToDMS(de, "*", ":", ":", _digitsDe) != _utilities.DegreesToDMS(_targetDeclination, "*", ":", ":", _digitsDe)) + if (Math.Abs(targetDEC - InvalidParameter) > 0.1 && + _utilities.DegreesToDMS(de, "*", ":", ":", _digitsDe) != _utilities.DegreesToDMS(targetDEC, "*", ":", ":", _digitsDe)) { - LogMessage("SyncToTarget", $"differ DE real {de} targeted {_targetDeclination}"); - _targetDeclination = de; + LogMessage("SyncToTarget", $"differ DE real {de} targeted {targetDEC}"); + SharedResourcesWrapper.TargetDeclination = de; } } - private double _targetDeclination = InvalidParameter; public double TargetDeclination { get { - if (_targetDeclination.Equals(InvalidParameter)) + var targetDeclination = SharedResourcesWrapper.TargetDeclination ?? InvalidParameter; + if (targetDeclination.Equals(InvalidParameter)) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated(":Gd#", "#"); ////:Gd# Get Currently Selected Object/Target Declination - ////Returns: sDD* MM# or sDD*MM’SS# + ////Returns: sDD* MM# or sDD*MM'SS# ////Depending upon the current precision setting for the telescope. //double targetDec = DmsToDouble(result); //return targetDec; - - LogMessage("TargetDeclination Get", $"{_targetDeclination}"); - return _targetDeclination; + LogMessage("TargetDeclination Get", $"{targetDeclination}"); + return targetDeclination; } set { @@ -2496,23 +2495,23 @@ namespace ASCOM.Meade.net //Set target object declination to sDD*MM or sDD*MM:SS depending on the current precision setting //Returns: //1 - Dec Accepted - //0 – Dec invalid + //0 - Dec invalid if (result == "0") { throw new InvalidOperationException("Target declination invalid"); } - _targetDeclination = _utilities.DMSToDegrees(dms); + SharedResourcesWrapper.TargetDeclination = _utilities.DMSToDegrees(dms); } } - private double _targetRightAscension = InvalidParameter; public double TargetRightAscension { get { - if (_targetRightAscension.Equals(InvalidParameter)) + var targetRightAscension = SharedResourcesWrapper.TargetRightAscension ?? InvalidParameter; + if (targetRightAscension.Equals(InvalidParameter)) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated(":Gr#", "#"); @@ -2523,8 +2522,8 @@ namespace ASCOM.Meade.net //double targetRa = HmsToDouble(result); //return targetRa; - LogMessage("TargetRightAscension Get", $"{_targetRightAscension}"); - return _targetRightAscension; + LogMessage("TargetRightAscension Get", $"{targetRightAscension}"); + return targetRightAscension; } set { @@ -2549,13 +2548,13 @@ namespace ASCOM.Meade.net //:SrHH:MM:SS# //Set target object RA to HH:MM.T or HH: MM: SS depending on the current precision setting. // Returns: - //0 – Invalid + //0 - Invalid //1 - Valid if (response == "0") throw new InvalidOperationException("Failed to set TargetRightAscension."); - _targetRightAscension = _utilities.HMSToHours(hms); + SharedResourcesWrapper.TargetRightAscension = _utilities.HMSToHours(hms); } } @@ -2735,7 +2734,7 @@ namespace ASCOM.Meade.net //:SLHH:MM:SS# //Set the local Time //Returns: - //0 – Invalid + //0 - Invalid //1 - Valid if (timeResult != "1") { @@ -2747,8 +2746,8 @@ namespace ASCOM.Meade.net //:SCMM/DD/YY# //Change Handbox Date to MM/DD/YY //Returns: - //D = ‘0’ if the date is invalid.The string is the null string. - //D = ‘1’ for valid dates and the string is “Updating Planetary Data# #” + //D = '0' if the date is invalid. The string is the null string. + //D = '1' for valid dates and the string is "Updating Planetary Data# #" //Note: For Autostar II this is the UTC data! if (dateResult != "1") { @@ -2796,7 +2795,7 @@ namespace ASCOM.Meade.net //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. + //Returns: 1 - if command was accepted. return result == "1"; } diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 47730ef..bcf1134 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -4,7 +4,7 @@ // ================ // // This class is a container for all shared resources that may be needed -// by the drivers served by the Local Server. +// by the drivers served by the Local Server. // // NOTES: // @@ -20,6 +20,7 @@ using System.Globalization; using System.Runtime.InteropServices; using System.Security.AccessControl; using System.Windows.Forms; +using ASCOM.DeviceInterface; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities; using ASCOM.Utilities.Interfaces; @@ -49,7 +50,7 @@ namespace ASCOM.Meade.net #region single serial port connector // - // this region shows a way that a single serial port could be connected to by multiple + // this region shows a way that a single serial port could be connected to by multiple // drivers. // // Connected is used to handle the connections to the port. @@ -73,7 +74,7 @@ namespace ASCOM.Meade.net public static IProfileFactory ProfileFactory { - get => _profileFactory ?? ( _profileFactory = new ProfileFactory()); + get => _profileFactory ?? (_profileFactory = new ProfileFactory()); set => _profileFactory = value; } @@ -122,7 +123,7 @@ namespace ASCOM.Meade.net public static bool SendBool(string command, bool raw = false) { - + var result = SendChar(command, raw); return result == "1"; @@ -273,7 +274,7 @@ namespace ASCOM.Meade.net profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault)); profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault); profileProperties.SendDateTime = Convert.ToBoolean(driverProfile.GetValue(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault)); - + profileProperties.ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription(driverProfile.GetValue(DriverId, ParkedBehaviourName, string.Empty, ParkedBehaviourDefault)); profileProperties.ParkedAlt = double.Parse(driverProfile.GetValue(DriverId, ParkedAltName, string.Empty, ParkedAltDefault), NumberFormatInfo.InvariantInfo); profileProperties.ParkedAz = double.Parse(driverProfile.GetValue(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault), NumberFormatInfo.InvariantInfo); @@ -311,7 +312,7 @@ namespace ASCOM.Meade.net } #endregion - + #region Multi Driver handling public static string ProductName { get; private set; } = string.Empty; @@ -334,7 +335,7 @@ namespace ASCOM.Meade.net private static readonly Dictionary ConnectedDevices = new Dictionary(); private static readonly Dictionary ConnectedDeviceIds = new Dictionary(); - private static IProfileFactory _profileFactory ; + private static IProfileFactory _profileFactory; /// @@ -350,7 +351,7 @@ namespace ASCOM.Meade.net { if (!ConnectedDevices.ContainsKey(deviceId)) ConnectedDevices.Add(deviceId, new DeviceHardware()); - + if (!ConnectedDeviceIds.ContainsKey(driverId)) ConnectedDeviceIds.Add(driverId, new DeviceHardware()); @@ -363,7 +364,7 @@ namespace ASCOM.Meade.net SharedSerial.DTREnable = profileProperties.RtsDtrEnabled; SharedSerial.RTSEnable = profileProperties.RtsDtrEnabled; SharedSerial.DataBits = profileProperties.DataBits; - SharedSerial.StopBits = (SerialStopBits)Enum.Parse(typeof(SerialStopBits), profileProperties.StopBits ); + SharedSerial.StopBits = (SerialStopBits)Enum.Parse(typeof(SerialStopBits), profileProperties.StopBits); SharedSerial.Parity = (SerialParity)Enum.Parse(typeof(SerialParity), profileProperties.Parity); SharedSerial.Speed = (SerialSpeed)profileProperties.Speed; SharedSerial.Handshake = (SerialHandshake)Enum.Parse(typeof(SerialHandshake), profileProperties.Handshake); @@ -493,7 +494,7 @@ namespace ASCOM.Meade.net Count = 0; } } - + public static void SetParked(bool atPark, ParkedPosition parkedPosition) { IsParked = atPark; @@ -503,5 +504,15 @@ namespace ASCOM.Meade.net public static bool IsParked { get; private set; } public static ParkedPosition ParkedPosition { get; private set; } + + /// + /// 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 double? TargetRightAscension { get; set; } + + public static double? TargetDeclination { get; set; } } } \ No newline at end of file diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index d7b078c..83fe829 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -1,4 +1,5 @@ using System; +using ASCOM.DeviceInterface; using ASCOM.Utilities.Interfaces; namespace ASCOM.Meade.net.Wrapper @@ -31,6 +32,10 @@ namespace ASCOM.Meade.net.Wrapper void SetParked(bool atPark, ParkedPosition parkedPosition); bool IsParked { get; } ParkedPosition ParkedPosition { get; } + + PierSide SideOfPier { get; set; } + double? TargetRightAscension { get; set; } + double? TargetDeclination { get; set; } } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -74,7 +79,7 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.SendBool(command, raw); } - public string SendChar(string message,bool raw = false) + public string SendChar(string message, bool raw = false) { return SharedResources.SendChar(message, raw); } @@ -112,5 +117,23 @@ namespace ASCOM.Meade.net.Wrapper public bool IsParked => SharedResources.IsParked; public ParkedPosition ParkedPosition => SharedResources.ParkedPosition; + + public PierSide SideOfPier + { + get => SharedResources.SideOfPier; + set => SharedResources.SideOfPier = value; + } + + public double? TargetRightAscension + { + get => SharedResources.TargetRightAscension; + set => SharedResources.TargetRightAscension = value; + } + + public double? TargetDeclination + { + get => SharedResources.TargetDeclination; + set => SharedResources.TargetDeclination = value; + } } } From bdbd206a54f11d8e4b9a73ec1343bf77f3ebff2f Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sat, 12 Jun 2021 16:05:56 +1000 Subject: [PATCH 09/21] Avoid possible data race condition when calculating DSOP --- 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 cfdee7b..80a1cf1 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1394,7 +1394,7 @@ namespace ASCOM.Meade.net var destinationSOP = hourAngle > 0 ? PierSide.pierEast : - (hourAngle < 0 ? PierSide.pierWest : SideOfPier); + (hourAngle < 0 ? PierSide.pierWest : SharedResourcesWrapper.SideOfPier); // avoid pierUnknown while Slewing LogMessage("DestinationSideOfPier", $"Destination SOP of RA {rightAscension.ToString(CultureInfo.InvariantCulture)} is {destinationSOP}"); From 6c769f36490dbbe1b2b7b37fbb517f1dc3e33eed Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sat, 12 Jun 2021 20:09:51 +1000 Subject: [PATCH 10/21] Add SlewSettleTime and IsLongFormat to SharedResources interface Also ensure that digit precision is set during initialisation --- .../TelescopeUnitTests.cs | 67 ++++++++++++++++++- Meade.net.Telescope/Telescope.cs | 37 +++++----- Meade.net/MeadeTelescopeBase.cs | 4 +- Meade.net/SharedResources.cs | 10 ++- Meade.net/Wrapper/SharedResourcesWrapper.cs | 16 +++++ 5 files changed, 110 insertions(+), 24 deletions(-) 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; + } } } From 036a9d711648279ef43b0bf354c1bb9783c719d3 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 13 Jun 2021 09:45:07 +1000 Subject: [PATCH 11/21] Add multi-connection test for TargetRightAscension --- .../TelescopeUnitTests.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 9a3adf3..4467bf8 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -2516,6 +2516,44 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(rightAscension)); } + [TestCase(0d)] + [TestCase(6d)] + [TestCase(12d)] + [TestCase(23.599d)] + public void TargetRightAscension_Set_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(double targetRightAscension) + { + var targetRightAscensionHMS = targetRightAscension + "HMS"; + var command = $"Sr{targetRightAscensionHMS}"; + + _utilMock.Setup(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2)).Returns(targetRightAscensionHMS); + _utilMock.Setup(x => x.HMSToHours(targetRightAscensionHMS)).Returns(targetRightAscension); + _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.TargetRightAscension = targetRightAscension; + + Assert.That(_telescope.TargetRightAscension, Is.EqualTo(targetRightAscension)); + + 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.TargetRightAscension, Is.EqualTo(targetRightAscension)); + + _utilMock.Verify(x => x.HoursToHMS(targetRightAscension, ":", ":", ":", 2), Times.Once); + _utilMock.Verify(x => x.HMSToHours(targetRightAscensionHMS), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(command, false), Times.Once); + } + [Test] public void Tracking_Get_WhenDefault_ThenIsTrue() { From 0b75b8d2cd46950955ea0044456cadab069622a2 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 13 Jun 2021 09:49:09 +1000 Subject: [PATCH 12/21] Remove now unneeded Setup for DestinationSideOfPier DestinationSideOfPier will not call Slewing anymore, since it reads the property from SharedResourcesWrapper directly. --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 4467bf8..fd414ae 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -3085,9 +3085,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToTarget_WhenSlewing_ThenWaitsForTheSlewToComplete() { - // avoid calling SideOfPier because it will call Slewing - _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); - _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); var slewCounter = 0; @@ -3169,9 +3166,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToCoordinates_WhenCalled_ThenSetsTargetAndSlews() { - // avoid calling SideOfPier because it will call Slewing - _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); - _testProperties.rightAscension = 1; var declination = 2; @@ -3295,9 +3289,6 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SlewToAltAz_WhenCalled_ThenSetsTargetAndSlews() { - // avoid calling SideOfPier because it will call Slewing - _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(+1); - _testProperties.rightAscension = 10.0; _testProperties.declination = 20; var azimuth = 30; From b23da15022f8a91ce8ecfd5cc85bef79bce889c9 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 13 Jun 2021 16:30:35 +1000 Subject: [PATCH 13/21] Make Focuser.cs ASCII compatible --- Meade.net.focuser/Focuser.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 93e0ca0..8d3ac6c 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -43,7 +43,7 @@ namespace ASCOM.Meade.net /// Private variable to hold an ASCOM Utilities object /// private readonly IUtil _utilities; - + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -304,7 +304,7 @@ namespace ASCOM.Meade.net var backlashCompensationSteps = direction ? Math.Abs(BacklashCompensation) : 0; var steps = Math.Abs(position) + backlashCompensationSteps; - + MoveFocuser(direction, steps); @@ -343,11 +343,11 @@ namespace ASCOM.Meade.net //:FS# Set Focus speed to slowest setting //Returns: Nothing - //:F# Autostar, Autostar II – set focuser speed to where is an ASCII digit 1..4 + //:F# Autostar, Autostar II - set focuser speed to where is an ASCII digit 1..4 //Returns: Nothing - //All others – Not Supported + //All others - Not Supported _utilities.WaitForMilliseconds(100); - + PerformFocuserMove(directionOut); _utilities.WaitForMilliseconds(steps); @@ -418,7 +418,7 @@ namespace ASCOM.Meade.net #region ASCOM Registration // Register or unregister driver for ASCOM. This is harmless if already - // registered or unregistered. + // registered or unregistered. // /// /// Register or unregister the driver with the ASCOM Platform. @@ -488,7 +488,7 @@ namespace ASCOM.Meade.net } #endregion - + /// /// Use this function to throw an exception if we aren't connected to the hardware /// From 2e3572375f5ec8918c814c1dc1589826a513dd8b Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 13 Jun 2021 17:23:15 +1000 Subject: [PATCH 14/21] Test that SideralTime is preserved across connections --- .../TelescopeUnitTests.cs | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index fd414ae..255bc01 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1881,6 +1881,43 @@ namespace Meade.net.Telescope.UnitTests Assert.That(excpetion.AccessorSet, Is.True); } + [TestCase(0, 34, PierSide.pierEast)] + [TestCase(12, 34, PierSide.pierEast)] + [TestCase(23.4, 34, PierSide.pierWest)] + public void SideOfPier_WhenSecondConnectionMade_ThenValueIsPreserved(double ra, double dec, PierSide expectedPierSide) + { + _sharedResourcesWrapperMock.Setup(x => x.SendChar("MS", false)).Returns("0"); + _utilMock.Setup(x => x.HMSToHours(null)).Returns(ra); + _utilMock.Setup(x => x.DMSToDegrees(null)).Returns(dec); + _astroUtilsMock.Setup(x => x.ConditionHA(It.IsAny())).Returns(pHA => pHA < -12 ? pHA + 12 : pHA > 12 ? pHA - 12 : pHA); + _astroUtilsMock.Setup(x => x.ConditionRA(It.IsAny())).Returns(pRA => pRA < 0 ? pRA + 24 : pRA >= 24 ? pRA - 24 : pRA); + + ConnectTelescope(); + Assert.That(_connectionInfo.SameDevice, Is.EqualTo(1)); + + _telescope.SlewToCoordinates(ra, dec); + var sideOfPierAfterSlew = _telescope.SideOfPier; + + Assert.That(sideOfPierAfterSlew, Is.EqualTo(expectedPierSide)); + + 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.SideOfPier, Is.EqualTo(sideOfPierAfterSlew)); + + _sharedResourcesWrapperMock.Verify(x => x.SendChar("MS", false), Times.Once); + _utilMock.Verify(x => x.HMSToHours(null), Times.Once); + _utilMock.Verify(x => x.DMSToDegrees(null), Times.AtLeast(2)); + _astroUtilsMock.Verify(x => x.ConditionHA(It.IsAny()), Times.Once); + _astroUtilsMock.Verify(x => x.ConditionRA(It.IsAny()), Times.Once); + } + delegate void NovasSiderealTimeDelegate(double jdHigh, double jdLow, double jdDelta, GstType gstType, Method method, Accuracy accuracy, ref double sideralTime); /// @@ -2399,7 +2436,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(0d)] [TestCase(45d)] [TestCase(90d)] - public void TargetDeclination_Set_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(double targetDeclination) + public void TargetDeclination_Set_WhenSecondConnectionMade_ThenValueIsPreserved(double targetDeclination) { var targetDeclinationDMS = targetDeclination + "DMS"; var sign = targetDeclination >= 0 ? "+" : string.Empty; @@ -2520,7 +2557,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(6d)] [TestCase(12d)] [TestCase(23.599d)] - public void TargetRightAscension_Set_WhenSecondConnectionMade_ThenSlewSettleTimeIsPreserved(double targetRightAscension) + public void TargetRightAscension_Set_WhenSecondConnectionMade_ThenValueIsPreserved(double targetRightAscension) { var targetRightAscensionHMS = targetRightAscension + "HMS"; var command = $"Sr{targetRightAscensionHMS}"; From af750549fe7ed65eb69f93e43ac09db2ed96deaf Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Sun, 13 Jun 2021 17:36:42 +1000 Subject: [PATCH 15/21] Test that low-precision digit values are preserved across connections --- .../TelescopeUnitTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 255bc01..978e51a 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1020,6 +1020,40 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); } + [Test] + public void IsLongFormat_WhenHighPrecisionNotSupportedAndSecondConnectionMade_ThenDigitPrecisionValuesArePreserved() + { + var ra = 12d; + var dec = 34d; + + _utilMock.Setup(x => x.HoursToHM(ra, ":", "", 1)).Returns(ra + "HM"); + _utilMock.Setup(x => x.DegreesToDM(dec, "*", "", 0)).Returns(dec + "DM"); + + ConnectTelescope(TelescopeList.LX200CLASSIC); + + _telescope.TargetRightAscension = ra; + _telescope.TargetDeclination = dec; + + 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; + + secondTelescopeInstance.TargetRightAscension = ra; + secondTelescopeInstance.TargetDeclination = dec; + + _utilMock.Verify(x => x.HoursToHM(ra, ":", "", 1), Times.Exactly(2)); + _utilMock.Verify(x => x.DegreesToDM(dec, "*", "", 0), Times.Exactly(2)); + _utilMock.Verify(x => x.HoursToHMS(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), 2), Times.Never); + _utilMock.Verify(x => x.DegreesToDMS(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), 2), Times.Never); + } + [TestCase(0)] [TestCase(1)] [TestCase(2)] From 6fc476b031e867c3c31d5137c1bea838d55f4692 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Tue, 22 Jun 2021 17:21:21 +1000 Subject: [PATCH 16/21] Make further properties multi-client and thread-safe Move MovingPrimary, MovingSecondary, EarliestNonSlewingTime to SharedResources, make all new properties thread-safe (atomic) operations. --- .../TelescopeUnitTests.cs | 42 +++++++++-- Meade.net.Telescope/Telescope.cs | 35 ++++----- .../Meade.net.UnitTests.csproj | 6 ++ .../SharedResourcesUnitTests.cs | 12 +-- Meade.net.UnitTests/ThreadSafeBoolTests.cs | 39 ++++++++++ .../ThreadSafeDateTimeTests.cs | 64 ++++++++++++++++ Meade.net.UnitTests/ThreadSafeEnumTests.cs | 51 +++++++++++++ .../ThreadSafeNullableDoubleTests.cs | 45 ++++++++++++ Meade.net.UnitTests/packages.config | 2 + Meade.net/Meade.net.csproj | 4 + Meade.net/SharedResources.cs | 73 +++++++++++++++++-- Meade.net/ThreadSafeBool.cs | 17 +++++ Meade.net/ThreadSafeDateTime.cs | 20 +++++ Meade.net/ThreadSafeEnum.cs | 21 ++++++ Meade.net/ThreadSafeNullableDouble.cs | 24 ++++++ Meade.net/Wrapper/SharedResourcesWrapper.cs | 24 ++++++ 16 files changed, 435 insertions(+), 44 deletions(-) create mode 100644 Meade.net.UnitTests/ThreadSafeBoolTests.cs create mode 100644 Meade.net.UnitTests/ThreadSafeDateTimeTests.cs create mode 100644 Meade.net.UnitTests/ThreadSafeEnumTests.cs create mode 100644 Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs create mode 100644 Meade.net/ThreadSafeBool.cs create mode 100644 Meade.net/ThreadSafeDateTime.cs create mode 100644 Meade.net/ThreadSafeEnum.cs create mode 100644 Meade.net/ThreadSafeNullableDouble.cs diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 978e51a..e5dddec 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1004,20 +1004,28 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.AtLeastOnce); } - [TestCase("High", false, true)] - [TestCase("High", true, true)] - [TestCase("Low", false, false)] - [TestCase("Low", true, false)] - public void Precision_Set_WhenSecondConnectionMade_ThenTelescopePrecisionNotChanged(string desiredPresision, bool telescopePrecision, bool finalPrecision) + [TestCase("High")] + [TestCase("Low")] + public void Precision_Set_WhenSecondConnectionMade_ThenTelescopePrecisionNotChanged(string desiredPresision) { + var isLongFormat = desiredPresision == "High" + || (desiredPresision == "Low" + ? false + : throw new ArgumentOutOfRangeException(nameof(desiredPresision), desiredPresision, "Should be High or Low")); + _sharedResourcesWrapperMock.SetupProperty(x => x.IsLongFormat, isLongFormat); + _sharedResourcesWrapperMock.Setup(x => x.SendString("GR", false)).Returns(() => _testProperties.telescopeRaResult); + _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(() => _testProperties.rightAscension); + _profileProperties.Precision = desiredPresision; _connectionInfo.SameDevice = 2; //_connectionInfo.Connections = 2; + _telescope.Connected = true; _sharedResourcesWrapperMock.Verify(x => x.SendChar("P", false), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.IsLongFormat, Times.Once); } [Test] @@ -1687,6 +1695,9 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) { + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); _sharedResourcesWrapperMock.Setup(x => x.SendString("D", false)).Returns(""); var duration = 0; @@ -1697,6 +1708,8 @@ namespace Meade.net.Telescope.UnitTests var exception = Assert.Throws(() => _telescope.PulseGuide(direction, duration)); Assert.That(exception.Message, Is.EqualTo("Unable to PulseGuide while moving same axis.")); + Assert.That(_sharedResourcesWrapperMock.Object.MovingPrimary, Is.EqualTo(axes == TelescopeAxes.axisPrimary)); + Assert.That(_sharedResourcesWrapperMock.Object.MovingSecondary, Is.EqualTo(axes == TelescopeAxes.axisSecondary)); } [TestCase(GuideDirections.guideEast)] @@ -2909,6 +2922,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(15, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:25", false)] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsExpectedValueForSettleTime(short settleTime, short profileSettleTime, string startSlewing, string endSlewing, bool isSlewing) { + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); _profileProperties.SettleTime = profileSettleTime; var timescalled = 0; @@ -2979,6 +2993,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(-1, TelescopeAxes.axisSecondary)] public void Slewing_WhenTelescopeIsMoving_ThenDoesNotSendCommandAndReturnsTrue(int rate, TelescopeAxes axis) { + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); + ConnectTelescope(); _telescope.MoveAxis(axis, rate); @@ -2986,6 +3004,9 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Slewing; Assert.That(result, Is.True); + Assert.That(_sharedResourcesWrapperMock.Object.MovingPrimary, Is.EqualTo(axis == TelescopeAxes.axisPrimary)); + Assert.That(_sharedResourcesWrapperMock.Object.MovingSecondary, Is.EqualTo(axis == TelescopeAxes.axisSecondary)); + _sharedResourcesWrapperMock.Verify(x => x.SendString("D", false), Times.Never); } @@ -3005,6 +3026,11 @@ namespace Meade.net.Telescope.UnitTests [TestCase(-1, TelescopeAxes.axisSecondary, 10, 20, true, true)] public void Slewing_WhenTelescopeStops_ThenWaitsForSettleTime(int rate, TelescopeAxes axis, short profileSettleTime, short driverSettleTime, bool expectedResultInWaitingPeriod, bool afterProfileSettleTimeUp) { + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingPrimary); + _sharedResourcesWrapperMock.SetupProperty(x => x.MovingSecondary); + _sharedResourcesWrapperMock.SetupProperty(x => x.SlewSettleTime); + _sharedResourcesWrapperMock.SetupProperty(x => x.EarliestNonSlewingTime, DateTime.MinValue); + _profileProperties.SettleTime = profileSettleTime; DateTime currentTime = MakeTime("2021-01-23T22:02:10"); @@ -3022,17 +3048,17 @@ namespace Meade.net.Telescope.UnitTests _telescope.MoveAxis(axis, 0); - currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + currentTime += TimeSpan.FromSeconds(profileSettleTime / 2); result = _telescope.Slewing; Assert.That(result, Is.EqualTo(expectedResultInWaitingPeriod)); - currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + currentTime += TimeSpan.FromSeconds(profileSettleTime / 2); result = _telescope.Slewing; Assert.That(result, Is.EqualTo(afterProfileSettleTimeUp)); - currentTime = currentTime + TimeSpan.FromSeconds(driverSettleTime); + currentTime += TimeSpan.FromSeconds(driverSettleTime); result = _telescope.Slewing; Assert.That(result, Is.False); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 03e9b1b..2980a5c 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -938,8 +938,8 @@ namespace ASCOM.Meade.net //:Q# Halt all current slewing //Returns:Nothing - _movingPrimary = false; - _movingSecondary = false; + SharedResourcesWrapper.MovingPrimary = false; + SharedResourcesWrapper.MovingSecondary = false; SetSlewingMinEndTime(); } @@ -1522,9 +1522,6 @@ namespace ASCOM.Meade.net } } - private bool _movingPrimary; - private bool _movingSecondary; - public void MoveAxis(TelescopeAxes axis, double rate) { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); @@ -1573,7 +1570,7 @@ namespace ASCOM.Meade.net SetSlewingMinEndTime(); } - _movingPrimary = false; + SharedResourcesWrapper.MovingPrimary = false; SharedResourcesWrapper.SendBlind("Qe"); //:Qe# Halt eastward Slews //Returns: Nothing @@ -1585,17 +1582,13 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind("Me"); //:Me# Move Telescope East at current slew rate //Returns: Nothing - _movingPrimary = true; - // in principle we could calculate the current side of pier, but unknown is the safer option. - SharedResourcesWrapper.SideOfPier = PierSide.pierUnknown; + SharedResourcesWrapper.MovingPrimary = true; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind("Mw"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing - _movingPrimary = true; - // in principle we could calculate the current side of pier, but unknown is the safer option. - SharedResourcesWrapper.SideOfPier = PierSide.pierUnknown; + SharedResourcesWrapper.MovingPrimary = true; break; } break; @@ -1607,7 +1600,7 @@ namespace ASCOM.Meade.net { SetSlewingMinEndTime(); } - _movingSecondary = false; + SharedResourcesWrapper.MovingSecondary = false; SharedResourcesWrapper.SendBlind("Qn"); //:Qn# Halt northward Slews //Returns: Nothing @@ -1619,13 +1612,13 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind("Mn"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing - _movingSecondary = true; + SharedResourcesWrapper.MovingSecondary = true; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind("Ms"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing - _movingSecondary = true; + SharedResourcesWrapper.MovingSecondary = true; break; } break; @@ -1695,11 +1688,11 @@ namespace ASCOM.Meade.net _isGuiding = true; try { - if (_movingPrimary && + if (SharedResourcesWrapper.MovingPrimary && (direction == GuideDirections.guideEast || direction == GuideDirections.guideWest)) throw new InvalidOperationException("Unable to PulseGuide while moving same axis."); - if (_movingSecondary && + if (SharedResourcesWrapper.MovingSecondary && (direction == GuideDirections.guideNorth || direction == GuideDirections.guideSouth)) throw new InvalidOperationException("Unable to PulseGuide while moving same axis."); @@ -2279,11 +2272,9 @@ namespace ASCOM.Meade.net if (_isGuiding) return false; - return _movingPrimary || _movingSecondary; + return SharedResourcesWrapper.MovingPrimary || SharedResourcesWrapper.MovingSecondary; } - private DateTime _earliestNonSlewingTime = DateTime.MinValue; - public bool Slewing { get @@ -2292,7 +2283,7 @@ namespace ASCOM.Meade.net if (isSlewing) SetSlewingMinEndTime(); - else if (_clock.UtcNow < _earliestNonSlewingTime) + else if (_clock.UtcNow < SharedResourcesWrapper.EarliestNonSlewingTime) isSlewing = true; LogMessage("Slewing", $"Result = {isSlewing}"); @@ -2302,7 +2293,7 @@ namespace ASCOM.Meade.net private void SetSlewingMinEndTime() { - _earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); + SharedResourcesWrapper.EarliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); } private TimeSpan GetTotalSlewingSettleTime() diff --git a/Meade.net.UnitTests/Meade.net.UnitTests.csproj b/Meade.net.UnitTests/Meade.net.UnitTests.csproj index 636c411..803c477 100644 --- a/Meade.net.UnitTests/Meade.net.UnitTests.csproj +++ b/Meade.net.UnitTests/Meade.net.UnitTests.csproj @@ -1,5 +1,6 @@  + @@ -98,6 +99,10 @@ + + + + @@ -116,5 +121,6 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + \ No newline at end of file diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 0465c34..e936814 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -29,7 +29,7 @@ namespace Meade.net.UnitTests [Test] public void CheckThatSerialPortIsSetToUseMock() { - Assert.That(SharedResources.SharedSerial,Is.EqualTo(_serialMock.Object)); + Assert.That(SharedResources.SharedSerial, Is.EqualTo(_serialMock.Object)); } [TestCase(true, "Test")] @@ -160,7 +160,7 @@ namespace Meade.net.UnitTests string GuideRateProfileNameDefault = "10.077939"; //67% of sidereal rate string PrecisionDefault = "Unchanged"; string GuidingStyleDefault = "Auto"; - + string BacklashCompensationDefault = "3000"; string ReverseFocuserDiectionDefault = "true"; @@ -239,15 +239,15 @@ namespace Meade.net.UnitTests SharedResources.ProfileFactory = profileFactoryMock.Object; var profileProperties = SharedResources.ReadProfile(); - + Assert.That(profeWrapper.DeviceType, Is.EqualTo("Telescope")); Assert.That(profileProperties.TraceLogger, Is.EqualTo(bool.Parse(TraceStateDefault))); Assert.That(profileProperties.ComPort, Is.EqualTo(ComPortDefault)); - + Assert.That(profileProperties.GuideRateArcSecondsPerSecond, - Is.EqualTo(double.Parse(GuideRateProfileNameDefault))); + Is.EqualTo(double.Parse(GuideRateProfileNameDefault))); Assert.That(profileProperties.Precision, Is.EqualTo(PrecisionDefault)); Assert.That(profileProperties.GuidingStyle, Is.EqualTo(GuidingStyleDefault)); @@ -423,7 +423,7 @@ namespace Meade.net.UnitTests string serialPortReturn = string.Empty; - _serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { + _serialMock.Setup(x => x.Transmit("#:GVP#")).Callback(() => { serialPortReturn = string.Empty; throw new Exception("Testerror"); }); diff --git a/Meade.net.UnitTests/ThreadSafeBoolTests.cs b/Meade.net.UnitTests/ThreadSafeBoolTests.cs new file mode 100644 index 0000000..a757fd8 --- /dev/null +++ b/Meade.net.UnitTests/ThreadSafeBoolTests.cs @@ -0,0 +1,39 @@ +using ASCOM.Meade.net; +using NUnit.Framework; + +namespace Meade.net.UnitTests +{ + public class ThreadSafeBoolTests + { + [TestCase(false)] + [TestCase(true)] + public void WhenConvertedValueIsSame(bool value) + { + // given + ThreadSafeBool sut = value; + + // when + bool actual = sut; + + // then + Assert.That(actual, Is.EqualTo(value)); + } + + [TestCase(false, false)] + [TestCase(false, true)] + [TestCase(true, false)] + [TestCase(true, true)] + public void WhenSetValueIsChanged(bool value, bool setValue) + { + // given + ThreadSafeBool sut = value; + + // when + sut.Set(setValue); + bool afterset = sut; + + // then + Assert.That(afterset, Is.EqualTo(setValue)); + } + } +} diff --git a/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs new file mode 100644 index 0000000..5fd619c --- /dev/null +++ b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs @@ -0,0 +1,64 @@ +using ASCOM.Meade.net; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Meade.net.UnitTests +{ + public class ThreadSafeDateTimeTests + { + [TestCaseSource(nameof(DateTimeSource))] + public void WhenConvertedValueIsSame(DateTime value) + { + // given + ThreadSafeDateTime sut = value; + + // when + DateTime actual = sut; + + // then + Assert.That(actual, Is.EqualTo(value)); + } + + [TestCaseSource(nameof(DateTimeSetSource))] + public void WhenSetValueIsChanged(DateTime value, DateTime setValue) + { + // given + ThreadSafeDateTime sut = value; + + // when + sut.Set(setValue); + DateTime afterset = sut; + + // then + Assert.That(afterset, Is.EqualTo(setValue)); + } + + static readonly DateTime Example1 = DateTimeOffset.Parse("2012-05-09T02:10:31.296761Z", CultureInfo.InvariantCulture).UtcDateTime; + static readonly DateTime Example2 = DateTimeOffset.Parse("2051-03-09T23:15:11.556081Z", CultureInfo.InvariantCulture).UtcDateTime; + + static IEnumerable DateTimeSource => new[] + { + DateTime.MinValue, + Example1, + Example2 + }; + + static IEnumerable DateTimeSetSource => new[] + { + new TestCaseData(DateTime.MinValue, Example1), + new TestCaseData(DateTime.MinValue, Example2), + new TestCaseData(DateTime.MinValue, DateTime.MinValue), + new TestCaseData(Example1, Example1), + new TestCaseData(Example1, Example2), + new TestCaseData(Example1, DateTime.MinValue), + new TestCaseData(Example2, Example1), + new TestCaseData(Example2, Example2), + new TestCaseData(Example2, DateTime.MinValue) + }; + } +} diff --git a/Meade.net.UnitTests/ThreadSafeEnumTests.cs b/Meade.net.UnitTests/ThreadSafeEnumTests.cs new file mode 100644 index 0000000..5157cd7 --- /dev/null +++ b/Meade.net.UnitTests/ThreadSafeEnumTests.cs @@ -0,0 +1,51 @@ +using ASCOM.DeviceInterface; +using ASCOM.Meade.net; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Meade.net.UnitTests +{ + public class ThreadSafeEnumTests + { + [TestCase(PierSide.pierUnknown)] + [TestCase(PierSide.pierEast)] + [TestCase(PierSide.pierWest)] + public void WhenConvertedValueIsSame(PierSide value) + { + // given + ThreadSafeEnum sut = value; + + // when + PierSide actual = sut; + + // then + Assert.That(actual, Is.EqualTo(value)); + } + + [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] + [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] + [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] + [TestCase(PierSide.pierEast, PierSide.pierUnknown)] + [TestCase(PierSide.pierEast, PierSide.pierWest)] + [TestCase(PierSide.pierEast, PierSide.pierEast)] + [TestCase(PierSide.pierWest, PierSide.pierUnknown)] + [TestCase(PierSide.pierWest, PierSide.pierWest)] + [TestCase(PierSide.pierWest, PierSide.pierEast)] + public void WhenSetValueIsChanged(PierSide value, PierSide setValue) + { + // given + ThreadSafeEnum sut = value; + + // when + sut.Set(setValue); + PierSide afterset = sut; + + // then + Assert.That(afterset, Is.EqualTo(setValue)); + } + } +} diff --git a/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs new file mode 100644 index 0000000..3537f4e --- /dev/null +++ b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs @@ -0,0 +1,45 @@ +using ASCOM.Meade.net; +using NUnit.Framework; + +namespace Meade.net.UnitTests +{ + public class ThreadSafeNullableDoubleTests + { + [TestCase(0.1d)] + [TestCase(-12.34d)] + [TestCase(0d)] + [TestCase(null)] + public void WhenConvertedValueIsSame(double? value) + { + // given + ThreadSafeNullableDouble sut = value; + + // when + double? actual = sut; + + // then + Assert.That(actual, Is.EqualTo(value)); + } + + [TestCase(0.1d, 0.2d)] + [TestCase(-12.34d, 5d)] + [TestCase(0d, 1d)] + [TestCase(null, 2d)] + [TestCase(0.1d, null)] + [TestCase(-12.34d, null)] + [TestCase(0d, null)] + [TestCase(null, null)] + public void WhenSetValueIsChanged(double? value, double? setValue) + { + // given + ThreadSafeNullableDouble sut = value; + + // when + sut.Set(setValue); + double? afterset = sut; + + // then + Assert.That(afterset, Is.EqualTo(setValue)); + } + } +} diff --git a/Meade.net.UnitTests/packages.config b/Meade.net.UnitTests/packages.config index 507c431..55f7ddc 100644 --- a/Meade.net.UnitTests/packages.config +++ b/Meade.net.UnitTests/packages.config @@ -5,6 +5,8 @@ + + \ No newline at end of file diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index 4711710..1a6b06e 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -146,6 +146,10 @@ + + + + diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 8165e7b..b27a0e6 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Globalization; using System.Runtime.InteropServices; using System.Security.AccessControl; +using System.Threading; using System.Windows.Forms; using ASCOM.DeviceInterface; using ASCOM.Meade.net.Wrapper; @@ -245,7 +246,7 @@ namespace ASCOM.Meade.net private const string HandShakeDefault = "None"; private const string ParityDefault = "None"; private const string SendDateTimeDefault = "false"; - private static string ParkedBehaviourDefault = "No Coordinates"; + private const string ParkedBehaviourDefault = "No Coordinates"; private const string ParkedAltDefault = "0"; private const string ParkedAzimuthDefault = "180"; @@ -501,22 +502,78 @@ namespace ASCOM.Meade.net ParkedPosition = parkedPosition; } - public static bool IsParked { get; private set; } + private static readonly ThreadSafeBool _isParked = false; + public static bool IsParked + { + get => _isParked; + private set => _isParked.Set(value); + } - public static ParkedPosition ParkedPosition { get; private set; } + private static ParkedPosition _parkedPosition; + public static ParkedPosition ParkedPosition + { + get => _parkedPosition; + private set => Interlocked.Exchange(ref _parkedPosition, value); + } + private static readonly ThreadSafeEnum _sideOfPier = PierSide.pierUnknown; /// /// Start with . /// As we do not know the physical declination axis position, we have to keep track manually. /// - public static PierSide SideOfPier { get; internal set; } = PierSide.pierUnknown; + public static PierSide SideOfPier + { + get => _sideOfPier; + internal set => _sideOfPier.Set(value); + } - public static double? TargetRightAscension { get; internal set; } + private static readonly ThreadSafeNullableDouble _targetRightAscension = null as double?; + public static double? TargetRightAscension + { + get => _targetRightAscension; + internal set => _targetRightAscension.Set(value); + } - public static double? TargetDeclination { get; internal set; } + private static readonly ThreadSafeNullableDouble _targetDeclination = null as double?; + public static double? TargetDeclination + { + get => _targetDeclination; + internal set => _targetDeclination.Set(value); + } - public static short SlewSettleTime { get; internal set; } + private static int _slewSettleTime; + public static short SlewSettleTime + { + get => Convert.ToInt16(_slewSettleTime); + internal set => Interlocked.Exchange(ref _slewSettleTime, value); + } - public static bool IsLongFormat { get; internal set; } + private static readonly ThreadSafeBool _isLongFormat = false; + public static bool IsLongFormat + { + get => _isLongFormat; + internal set => _isLongFormat.Set(value); + } + + private static readonly ThreadSafeBool _movingPrimary = false; + public static bool MovingPrimary + { + get => _movingPrimary; + internal set => _movingPrimary.Set(value); + } + + private static readonly ThreadSafeBool _movingSecondary = false; + public static bool MovingSecondary + { + get => _movingSecondary; + internal set => _movingSecondary.Set(value); + } + + private static readonly ThreadSafeDateTime _earliestNonSlewingTime = DateTime.MinValue; + public static DateTime EarliestNonSlewingTime + { + get => _earliestNonSlewingTime; + internal set => _earliestNonSlewingTime.Set(value); + } } } \ No newline at end of file diff --git a/Meade.net/ThreadSafeBool.cs b/Meade.net/ThreadSafeBool.cs new file mode 100644 index 0000000..b60d275 --- /dev/null +++ b/Meade.net/ThreadSafeBool.cs @@ -0,0 +1,17 @@ +using System.Threading; + +namespace ASCOM.Meade.net +{ + public class ThreadSafeBool + { + private object _value; + + public ThreadSafeBool(in bool value) => _value = value; + + public void Set(in bool value) => Interlocked.Exchange(ref _value, value); + + public static implicit operator ThreadSafeBool(in bool value) => new ThreadSafeBool(value); + + public static implicit operator bool(ThreadSafeBool @this) => (bool)@this._value; + } +} \ No newline at end of file diff --git a/Meade.net/ThreadSafeDateTime.cs b/Meade.net/ThreadSafeDateTime.cs new file mode 100644 index 0000000..c336ef2 --- /dev/null +++ b/Meade.net/ThreadSafeDateTime.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading; + +namespace ASCOM.Meade.net +{ + public class ThreadSafeDateTime + { + private long _value; + + public ThreadSafeDateTime(in DateTime value) => _value = DateTimeToLong(value); + + public void Set(in DateTime value) => Interlocked.Exchange(ref _value, DateTimeToLong(value)); + + private static long DateTimeToLong(in DateTime value) => value.ToUniversalTime().Ticks; + + public static implicit operator ThreadSafeDateTime(in DateTime value) => new ThreadSafeDateTime(value); + + public static implicit operator DateTime(ThreadSafeDateTime @this) => new DateTime(Interlocked.Read(ref @this._value), DateTimeKind.Utc); + } +} \ No newline at end of file diff --git a/Meade.net/ThreadSafeEnum.cs b/Meade.net/ThreadSafeEnum.cs new file mode 100644 index 0000000..f942dfc --- /dev/null +++ b/Meade.net/ThreadSafeEnum.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading; + +namespace ASCOM.Meade.net +{ + public class ThreadSafeEnum + where T: struct, Enum + { + private long _value; + + public ThreadSafeEnum(T value) => _value = EnumToLong(value); + + public void Set(T value) => Interlocked.Exchange(ref _value, EnumToLong(value)); + + private static long EnumToLong(T value) => Convert.ToInt64(value); + + public static implicit operator ThreadSafeEnum(T value) => new ThreadSafeEnum(value); + + public static implicit operator T(ThreadSafeEnum @this) => (T) Enum.ToObject(typeof(T), Interlocked.Read(ref @this._value)); + } +} \ No newline at end of file diff --git a/Meade.net/ThreadSafeNullableDouble.cs b/Meade.net/ThreadSafeNullableDouble.cs new file mode 100644 index 0000000..4a8efd1 --- /dev/null +++ b/Meade.net/ThreadSafeNullableDouble.cs @@ -0,0 +1,24 @@ +using System; +using System.Threading; + +namespace ASCOM.Meade.net +{ + public class ThreadSafeNullableDouble + { + private long _value; + + public ThreadSafeNullableDouble(in double? value) => _value = NullableDoubleToLong(value); + + public void Set(in double? value) => Interlocked.Exchange(ref _value, NullableDoubleToLong(value)); + + private static long NullableDoubleToLong(in double? value) => BitConverter.DoubleToInt64Bits(value ?? double.NaN); + + public static implicit operator ThreadSafeNullableDouble(in double? value) => new ThreadSafeNullableDouble(value); + + public static implicit operator double?(ThreadSafeNullableDouble @this) + { + var doubleValue = BitConverter.Int64BitsToDouble(Interlocked.Read(ref @this._value)); + return double.IsNaN(doubleValue) ? null as double? : doubleValue; + } + } +} \ No newline at end of file diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index d123a71..8e91bb7 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -40,6 +40,12 @@ namespace ASCOM.Meade.net.Wrapper short SlewSettleTime { get; set; } bool IsLongFormat { get; set; } + + bool MovingPrimary { get; set; } + + bool MovingSecondary { get; set; } + + DateTime EarliestNonSlewingTime { get; set; } } public class SharedResourcesWrapper : ISharedResourcesWrapper @@ -151,5 +157,23 @@ namespace ASCOM.Meade.net.Wrapper get => SharedResources.IsLongFormat; set => SharedResources.IsLongFormat = value; } + + public bool MovingPrimary + { + get => SharedResources.MovingPrimary; + set => SharedResources.MovingPrimary = value; + } + + public bool MovingSecondary + { + get => SharedResources.MovingSecondary; + set => SharedResources.MovingSecondary = value; + } + + public DateTime EarliestNonSlewingTime + { + get => SharedResources.EarliestNonSlewingTime; + set => SharedResources.EarliestNonSlewingTime = value; + } } } From 7afd364efa3592e915796a88d1d6905f1197273e Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Tue, 22 Jun 2021 17:43:25 +1000 Subject: [PATCH 17/21] Add tests for SharedResources properties Ensure that default values are correct and no error appears --- .../SharedResourcesUnitTests.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index e936814..8c5fb79 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -1,6 +1,7 @@  using System; using System.Globalization; +using ASCOM.DeviceInterface; using ASCOM.Meade.net; using ASCOM.Meade.net.Wrapper; using ASCOM.Utilities.Interfaces; @@ -618,5 +619,35 @@ namespace Meade.net.UnitTests _traceLoggerMock.Verify( x => x.LogIssue("Connect", "Unable to decode response from the telescope, This is likely a hardware serial communications error."), Times.Once); } + + [Test] + public void CheckIsParkedIsFalseByDefault() => Assert.That(SharedResources.IsParked, Is.False); + + [Test] + public void CheckParkedPositionIsNullByDefault() => Assert.That(SharedResources.ParkedPosition, Is.Null); + + [Test] + public void CheckIsLongFormatIsFalseByDefault() => Assert.That(SharedResources.IsLongFormat, Is.False); + + [Test] + public void CheckMovingPrimaryIsFalseBydefault() => Assert.That(SharedResources.MovingPrimary, Is.False); + + [Test] + public void CheckMovingSecondaryIsFalseBydefault() => Assert.That(SharedResources.MovingSecondary, Is.False); + + [Test] + public void CheckSideOfPierIsUnknownByDefault() => Assert.That(SharedResources.SideOfPier, Is.EqualTo(PierSide.pierUnknown)); + + [Test] + public void CheckSlewSettleTimeIsZeroByDefault() => Assert.That(SharedResources.SlewSettleTime, Is.EqualTo((short)0)); + + [Test] + public void CheckEarliestNonNonSlewingTimeIsMinValueByDefault() => Assert.That(SharedResources.EarliestNonSlewingTime, Is.EqualTo(DateTime.MinValue)); + + [Test] + public void CheckTargetDeclinationIsNullByDefault() => Assert.That(SharedResources.TargetDeclination.HasValue, Is.False); + + [Test] + public void CheckTargetRightAscensionIsNullByDefault() => Assert.That(SharedResources.TargetRightAscension.HasValue, Is.False); } } From 6dff32505e3d8ca4582e74defc30c108602d1ef1 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Wed, 23 Jun 2021 11:07:23 +1000 Subject: [PATCH 18/21] Clarify thread-safe value test intention --- Meade.net.UnitTests/ThreadSafeBoolTests.cs | 6 +++--- .../ThreadSafeDateTimeTests.cs | 9 +++------ Meade.net.UnitTests/ThreadSafeEnumTests.cs | 19 +++++++------------ .../ThreadSafeNullableDoubleTests.cs | 6 +++--- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/Meade.net.UnitTests/ThreadSafeBoolTests.cs b/Meade.net.UnitTests/ThreadSafeBoolTests.cs index a757fd8..adeee40 100644 --- a/Meade.net.UnitTests/ThreadSafeBoolTests.cs +++ b/Meade.net.UnitTests/ThreadSafeBoolTests.cs @@ -7,7 +7,7 @@ namespace Meade.net.UnitTests { [TestCase(false)] [TestCase(true)] - public void WhenConvertedValueIsSame(bool value) + public void When_Assigned_ThenValueIsSame(bool value) { // given ThreadSafeBool sut = value; @@ -23,10 +23,10 @@ namespace Meade.net.UnitTests [TestCase(false, true)] [TestCase(true, false)] [TestCase(true, true)] - public void WhenSetValueIsChanged(bool value, bool setValue) + public void When_SetValue_ThenValueIsUpdated(bool initialValue, bool setValue) { // given - ThreadSafeBool sut = value; + ThreadSafeBool sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs index 5fd619c..e20e46a 100644 --- a/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs +++ b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs @@ -3,16 +3,13 @@ using NUnit.Framework; using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Meade.net.UnitTests { public class ThreadSafeDateTimeTests { [TestCaseSource(nameof(DateTimeSource))] - public void WhenConvertedValueIsSame(DateTime value) + public void When_Assigned_ThenValueIsSame(DateTime value) { // given ThreadSafeDateTime sut = value; @@ -25,10 +22,10 @@ namespace Meade.net.UnitTests } [TestCaseSource(nameof(DateTimeSetSource))] - public void WhenSetValueIsChanged(DateTime value, DateTime setValue) + public void When_SetValue_ThenValueIsUpdated(DateTime initialValue, DateTime setValue) { // given - ThreadSafeDateTime sut = value; + ThreadSafeDateTime sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeEnumTests.cs b/Meade.net.UnitTests/ThreadSafeEnumTests.cs index 5157cd7..f542eed 100644 --- a/Meade.net.UnitTests/ThreadSafeEnumTests.cs +++ b/Meade.net.UnitTests/ThreadSafeEnumTests.cs @@ -1,11 +1,6 @@ using ASCOM.DeviceInterface; using ASCOM.Meade.net; using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Meade.net.UnitTests { @@ -14,7 +9,7 @@ namespace Meade.net.UnitTests [TestCase(PierSide.pierUnknown)] [TestCase(PierSide.pierEast)] [TestCase(PierSide.pierWest)] - public void WhenConvertedValueIsSame(PierSide value) + public void When_Assigned_ThenValueIsSame(PierSide value) { // given ThreadSafeEnum sut = value; @@ -27,18 +22,18 @@ namespace Meade.net.UnitTests } [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] - [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] - [TestCase(PierSide.pierUnknown, PierSide.pierUnknown)] + [TestCase(PierSide.pierUnknown, PierSide.pierEast)] + [TestCase(PierSide.pierUnknown, PierSide.pierWest)] [TestCase(PierSide.pierEast, PierSide.pierUnknown)] - [TestCase(PierSide.pierEast, PierSide.pierWest)] [TestCase(PierSide.pierEast, PierSide.pierEast)] + [TestCase(PierSide.pierEast, PierSide.pierWest)] [TestCase(PierSide.pierWest, PierSide.pierUnknown)] - [TestCase(PierSide.pierWest, PierSide.pierWest)] [TestCase(PierSide.pierWest, PierSide.pierEast)] - public void WhenSetValueIsChanged(PierSide value, PierSide setValue) + [TestCase(PierSide.pierWest, PierSide.pierWest)] + public void When_SetValue_ThenValueIsUpdated(PierSide initialValue, PierSide setValue) { // given - ThreadSafeEnum sut = value; + ThreadSafeEnum sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs index 3537f4e..ea7bd78 100644 --- a/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs +++ b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs @@ -9,7 +9,7 @@ namespace Meade.net.UnitTests [TestCase(-12.34d)] [TestCase(0d)] [TestCase(null)] - public void WhenConvertedValueIsSame(double? value) + public void When_Assigned_ThenValueIsSame(double? value) { // given ThreadSafeNullableDouble sut = value; @@ -29,10 +29,10 @@ namespace Meade.net.UnitTests [TestCase(-12.34d, null)] [TestCase(0d, null)] [TestCase(null, null)] - public void WhenSetValueIsChanged(double? value, double? setValue) + public void When_SetValue_ThenValueIsUpdated(double? initialValue, double? setValue) { // given - ThreadSafeNullableDouble sut = value; + ThreadSafeNullableDouble sut = initialValue; // when sut.Set(setValue); From 6c274997692707a2eae4c59b4a89c50d3f5657c4 Mon Sep 17 00:00:00 2001 From: Sebastian Godelet Date: Wed, 23 Jun 2021 16:21:08 +1000 Subject: [PATCH 19/21] Create generic ThreadSafeValue --- Meade.net.UnitTests/ThreadSafeBoolTests.cs | 4 ++-- .../ThreadSafeDateTimeTests.cs | 4 ++-- Meade.net.UnitTests/ThreadSafeEnumTests.cs | 4 ++-- .../ThreadSafeNullableDoubleTests.cs | 4 ++-- Meade.net/Meade.net.csproj | 5 +--- Meade.net/SharedResources.cs | 16 ++++++------- Meade.net/ThreadSafeBool.cs | 17 ------------- Meade.net/ThreadSafeDateTime.cs | 20 ---------------- Meade.net/ThreadSafeEnum.cs | 21 ---------------- Meade.net/ThreadSafeNullableDouble.cs | 24 ------------------- Meade.net/ThreadSafeValue.cs | 18 ++++++++++++++ 11 files changed, 35 insertions(+), 102 deletions(-) delete mode 100644 Meade.net/ThreadSafeBool.cs delete mode 100644 Meade.net/ThreadSafeDateTime.cs delete mode 100644 Meade.net/ThreadSafeEnum.cs delete mode 100644 Meade.net/ThreadSafeNullableDouble.cs create mode 100644 Meade.net/ThreadSafeValue.cs diff --git a/Meade.net.UnitTests/ThreadSafeBoolTests.cs b/Meade.net.UnitTests/ThreadSafeBoolTests.cs index adeee40..beb2ddf 100644 --- a/Meade.net.UnitTests/ThreadSafeBoolTests.cs +++ b/Meade.net.UnitTests/ThreadSafeBoolTests.cs @@ -10,7 +10,7 @@ namespace Meade.net.UnitTests public void When_Assigned_ThenValueIsSame(bool value) { // given - ThreadSafeBool sut = value; + ThreadSafeValue sut = value; // when bool actual = sut; @@ -26,7 +26,7 @@ namespace Meade.net.UnitTests public void When_SetValue_ThenValueIsUpdated(bool initialValue, bool setValue) { // given - ThreadSafeBool sut = initialValue; + ThreadSafeValue sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs index e20e46a..3123a33 100644 --- a/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs +++ b/Meade.net.UnitTests/ThreadSafeDateTimeTests.cs @@ -12,7 +12,7 @@ namespace Meade.net.UnitTests public void When_Assigned_ThenValueIsSame(DateTime value) { // given - ThreadSafeDateTime sut = value; + ThreadSafeValue sut = value; // when DateTime actual = sut; @@ -25,7 +25,7 @@ namespace Meade.net.UnitTests public void When_SetValue_ThenValueIsUpdated(DateTime initialValue, DateTime setValue) { // given - ThreadSafeDateTime sut = initialValue; + ThreadSafeValue sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeEnumTests.cs b/Meade.net.UnitTests/ThreadSafeEnumTests.cs index f542eed..da89b5c 100644 --- a/Meade.net.UnitTests/ThreadSafeEnumTests.cs +++ b/Meade.net.UnitTests/ThreadSafeEnumTests.cs @@ -12,7 +12,7 @@ namespace Meade.net.UnitTests public void When_Assigned_ThenValueIsSame(PierSide value) { // given - ThreadSafeEnum sut = value; + ThreadSafeValue sut = value; // when PierSide actual = sut; @@ -33,7 +33,7 @@ namespace Meade.net.UnitTests public void When_SetValue_ThenValueIsUpdated(PierSide initialValue, PierSide setValue) { // given - ThreadSafeEnum sut = initialValue; + ThreadSafeValue sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs index ea7bd78..492a4e9 100644 --- a/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs +++ b/Meade.net.UnitTests/ThreadSafeNullableDoubleTests.cs @@ -12,7 +12,7 @@ namespace Meade.net.UnitTests public void When_Assigned_ThenValueIsSame(double? value) { // given - ThreadSafeNullableDouble sut = value; + ThreadSafeValue sut = value; // when double? actual = sut; @@ -32,7 +32,7 @@ namespace Meade.net.UnitTests public void When_SetValue_ThenValueIsUpdated(double? initialValue, double? setValue) { // given - ThreadSafeNullableDouble sut = initialValue; + ThreadSafeValue sut = initialValue; // when sut.Set(setValue); diff --git a/Meade.net/Meade.net.csproj b/Meade.net/Meade.net.csproj index 1a6b06e..8681147 100644 --- a/Meade.net/Meade.net.csproj +++ b/Meade.net/Meade.net.csproj @@ -146,10 +146,7 @@ - - - - + diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index b27a0e6..6567a07 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -502,7 +502,7 @@ namespace ASCOM.Meade.net ParkedPosition = parkedPosition; } - private static readonly ThreadSafeBool _isParked = false; + private static readonly ThreadSafeValue _isParked = false; public static bool IsParked { get => _isParked; @@ -516,7 +516,7 @@ namespace ASCOM.Meade.net private set => Interlocked.Exchange(ref _parkedPosition, value); } - private static readonly ThreadSafeEnum _sideOfPier = PierSide.pierUnknown; + private static readonly ThreadSafeValue _sideOfPier = PierSide.pierUnknown; /// /// Start with . /// As we do not know the physical declination axis position, we have to keep track manually. @@ -527,14 +527,14 @@ namespace ASCOM.Meade.net internal set => _sideOfPier.Set(value); } - private static readonly ThreadSafeNullableDouble _targetRightAscension = null as double?; + private static readonly ThreadSafeValue _targetRightAscension = null as double?; public static double? TargetRightAscension { get => _targetRightAscension; internal set => _targetRightAscension.Set(value); } - private static readonly ThreadSafeNullableDouble _targetDeclination = null as double?; + private static readonly ThreadSafeValue _targetDeclination = null as double?; public static double? TargetDeclination { get => _targetDeclination; @@ -548,28 +548,28 @@ namespace ASCOM.Meade.net internal set => Interlocked.Exchange(ref _slewSettleTime, value); } - private static readonly ThreadSafeBool _isLongFormat = false; + private static readonly ThreadSafeValue _isLongFormat = false; public static bool IsLongFormat { get => _isLongFormat; internal set => _isLongFormat.Set(value); } - private static readonly ThreadSafeBool _movingPrimary = false; + private static readonly ThreadSafeValue _movingPrimary = false; public static bool MovingPrimary { get => _movingPrimary; internal set => _movingPrimary.Set(value); } - private static readonly ThreadSafeBool _movingSecondary = false; + private static readonly ThreadSafeValue _movingSecondary = false; public static bool MovingSecondary { get => _movingSecondary; internal set => _movingSecondary.Set(value); } - private static readonly ThreadSafeDateTime _earliestNonSlewingTime = DateTime.MinValue; + private static readonly ThreadSafeValue _earliestNonSlewingTime = DateTime.MinValue; public static DateTime EarliestNonSlewingTime { get => _earliestNonSlewingTime; diff --git a/Meade.net/ThreadSafeBool.cs b/Meade.net/ThreadSafeBool.cs deleted file mode 100644 index b60d275..0000000 --- a/Meade.net/ThreadSafeBool.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Threading; - -namespace ASCOM.Meade.net -{ - public class ThreadSafeBool - { - private object _value; - - public ThreadSafeBool(in bool value) => _value = value; - - public void Set(in bool value) => Interlocked.Exchange(ref _value, value); - - public static implicit operator ThreadSafeBool(in bool value) => new ThreadSafeBool(value); - - public static implicit operator bool(ThreadSafeBool @this) => (bool)@this._value; - } -} \ No newline at end of file diff --git a/Meade.net/ThreadSafeDateTime.cs b/Meade.net/ThreadSafeDateTime.cs deleted file mode 100644 index c336ef2..0000000 --- a/Meade.net/ThreadSafeDateTime.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Threading; - -namespace ASCOM.Meade.net -{ - public class ThreadSafeDateTime - { - private long _value; - - public ThreadSafeDateTime(in DateTime value) => _value = DateTimeToLong(value); - - public void Set(in DateTime value) => Interlocked.Exchange(ref _value, DateTimeToLong(value)); - - private static long DateTimeToLong(in DateTime value) => value.ToUniversalTime().Ticks; - - public static implicit operator ThreadSafeDateTime(in DateTime value) => new ThreadSafeDateTime(value); - - public static implicit operator DateTime(ThreadSafeDateTime @this) => new DateTime(Interlocked.Read(ref @this._value), DateTimeKind.Utc); - } -} \ No newline at end of file diff --git a/Meade.net/ThreadSafeEnum.cs b/Meade.net/ThreadSafeEnum.cs deleted file mode 100644 index f942dfc..0000000 --- a/Meade.net/ThreadSafeEnum.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Threading; - -namespace ASCOM.Meade.net -{ - public class ThreadSafeEnum - where T: struct, Enum - { - private long _value; - - public ThreadSafeEnum(T value) => _value = EnumToLong(value); - - public void Set(T value) => Interlocked.Exchange(ref _value, EnumToLong(value)); - - private static long EnumToLong(T value) => Convert.ToInt64(value); - - public static implicit operator ThreadSafeEnum(T value) => new ThreadSafeEnum(value); - - public static implicit operator T(ThreadSafeEnum @this) => (T) Enum.ToObject(typeof(T), Interlocked.Read(ref @this._value)); - } -} \ No newline at end of file diff --git a/Meade.net/ThreadSafeNullableDouble.cs b/Meade.net/ThreadSafeNullableDouble.cs deleted file mode 100644 index 4a8efd1..0000000 --- a/Meade.net/ThreadSafeNullableDouble.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Threading; - -namespace ASCOM.Meade.net -{ - public class ThreadSafeNullableDouble - { - private long _value; - - public ThreadSafeNullableDouble(in double? value) => _value = NullableDoubleToLong(value); - - public void Set(in double? value) => Interlocked.Exchange(ref _value, NullableDoubleToLong(value)); - - private static long NullableDoubleToLong(in double? value) => BitConverter.DoubleToInt64Bits(value ?? double.NaN); - - public static implicit operator ThreadSafeNullableDouble(in double? value) => new ThreadSafeNullableDouble(value); - - public static implicit operator double?(ThreadSafeNullableDouble @this) - { - var doubleValue = BitConverter.Int64BitsToDouble(Interlocked.Read(ref @this._value)); - return double.IsNaN(doubleValue) ? null as double? : doubleValue; - } - } -} \ No newline at end of file diff --git a/Meade.net/ThreadSafeValue.cs b/Meade.net/ThreadSafeValue.cs new file mode 100644 index 0000000..652fa88 --- /dev/null +++ b/Meade.net/ThreadSafeValue.cs @@ -0,0 +1,18 @@ +using JetBrains.Annotations; +using System.Threading; + +namespace ASCOM.Meade.net +{ + public class ThreadSafeValue + { + private object _value; + + public ThreadSafeValue(in T value) => _value = value; + + public void Set(in T value) => Interlocked.Exchange(ref _value, value); + + public static implicit operator ThreadSafeValue(in T value) => new ThreadSafeValue(value); + + public static implicit operator T([NotNull] ThreadSafeValue @this) => (T)(@this?._value ?? default); + } +} \ No newline at end of file From c6baab2b12ba6e65547dc35bd7ba0b1719bf552f Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 23 Jun 2021 13:11:33 +0100 Subject: [PATCH 20/21] Added tolerance in unit test to allow for rounding error. --- AstroMath.UnitTests/AstroMathsUnitTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index 2e4e37c..c9dc655 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -123,7 +123,8 @@ namespace AstroMath.UnitTests var altAz = _astroMath.ConvertEqToHoz(hourAngle, latitude, equatorialCoordinates); - Assert.That(altAz.Altitude, Is.EqualTo(20.958562421092779)); + Assert.That(altAz.Altitude, Is.GreaterThan(20.958562421092770)); + Assert.That(altAz.Altitude, Is.LessThanOrEqualTo(20.958562421092779)); Assert.That(altAz.Azimuth, Is.EqualTo(281.2728706962269)); } From f1d100892bf0f74c2950087d59cc32f70fba9539 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Wed, 23 Jun 2021 13:18:30 +0100 Subject: [PATCH 21/21] Removed nunit3 Test adapter --- Meade.net.UnitTests/Meade.net.UnitTests.csproj | 2 -- Meade.net.UnitTests/packages.config | 1 - 2 files changed, 3 deletions(-) diff --git a/Meade.net.UnitTests/Meade.net.UnitTests.csproj b/Meade.net.UnitTests/Meade.net.UnitTests.csproj index 803c477..3ab6018 100644 --- a/Meade.net.UnitTests/Meade.net.UnitTests.csproj +++ b/Meade.net.UnitTests/Meade.net.UnitTests.csproj @@ -1,6 +1,5 @@  - @@ -121,6 +120,5 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - \ No newline at end of file diff --git a/Meade.net.UnitTests/packages.config b/Meade.net.UnitTests/packages.config index 55f7ddc..ad73520 100644 --- a/Meade.net.UnitTests/packages.config +++ b/Meade.net.UnitTests/packages.config @@ -6,7 +6,6 @@ - \ No newline at end of file