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..c111e34 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] @@ -40,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 @@ -70,7 +84,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(); }); @@ -84,8 +98,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 +111,35 @@ 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); - _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#", true)).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); + + _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 }); + + _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 +180,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")); } @@ -157,43 +188,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 +238,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")] @@ -217,25 +248,25 @@ 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")); } - [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)); } @@ -246,7 +277,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")); } @@ -262,21 +293,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")] @@ -286,7 +317,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 +328,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 +340,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 +351,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,66 +360,72 @@ 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")); } - [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] 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")); } - [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() { 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")); } - [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,46 +438,45 @@ 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] 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 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.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] @@ -450,26 +486,22 @@ 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 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.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SC{telescopeDate}#")).Returns("1"); - ConnectTelescope(TelescopeList.LX200GPS, string.Empty); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendChar(setDateCommand, false), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.ReadTerminated(), Times.Exactly(2)); } @@ -480,6 +512,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(() => @@ -487,19 +520,18 @@ 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.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 +546,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 +555,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 +593,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,43 +619,43 @@ 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] 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")); } @@ -633,7 +665,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}.")); } @@ -644,7 +676,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}.")); } @@ -659,7 +691,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 +763,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 +787,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,17 +802,17 @@ 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); _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); @@ -901,7 +933,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 +961,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 +973,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 +989,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 +1005,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] @@ -1096,10 +1128,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")); } @@ -1121,7 +1153,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 +1167,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,14 +1185,14 @@ namespace Meade.net.Telescope.UnitTests public void DeclinationRate_Get_ThenReturns0() { var actualResult = _telescope.DeclinationRate; - + Assert.That(actualResult, Is.EqualTo(0)); } [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); @@ -1171,7 +1203,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"); }); @@ -1194,7 +1226,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); @@ -1211,7 +1243,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")); } @@ -1242,7 +1274,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); @@ -1257,7 +1289,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)); } @@ -1275,7 +1307,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); @@ -1290,7 +1322,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)); } @@ -1307,28 +1339,28 @@ 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")); } - [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 +1368,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 +1383,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 +1398,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 +1422,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")); } @@ -1402,7 +1434,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.")); } @@ -1410,7 +1442,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")); } @@ -1419,11 +1451,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 +1466,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 +1474,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 +1513,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,12 +1523,12 @@ 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(); - 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.")); } @@ -1507,14 +1539,14 @@ 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(); _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.")); } @@ -1530,7 +1562,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 +1578,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.PulseGuide(direction, duration); - + Assert.That(isSlewing, Is.False); } @@ -1560,7 +1592,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 +1616,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 +1635,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 +1690,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 +1711,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] @@ -1696,7 +1728,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); @@ -1705,7 +1737,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")); } @@ -1726,7 +1758,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); @@ -1782,7 +1814,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,16 +1883,16 @@ 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] 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")); } @@ -1869,7 +1901,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.")); } @@ -1878,7 +1910,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.")); } @@ -1886,26 +1918,26 @@ 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(); - 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.")); } - [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 +1960,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(); @@ -1941,7 +1973,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")); } @@ -1950,7 +1982,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.")); } @@ -1959,32 +1991,32 @@ 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.")); } [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(); - 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.")); } - [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 +2024,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.")); } @@ -2000,39 +2032,39 @@ 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")); } [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); + Assert.DoesNotThrow(() => _telescope.SyncToTarget()); + + _sharedResourcesWrapperMock.Verify(x => x.SendString("CM", false), Times.Once); } [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")); } @@ -2041,7 +2073,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.")); } @@ -2050,36 +2082,36 @@ 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.")); } [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(); - var exception = Assert.Throws(() => { _telescope.TargetDeclination = 50; }); + var exception = Assert.Throws(() => _telescope.TargetDeclination = 50); 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 +2127,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 +2137,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(); @@ -2119,7 +2151,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")); } @@ -2128,7 +2160,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")); } @@ -2137,33 +2169,33 @@ 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")); } [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(); - var exception = Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + var exception = Assert.Throws(() => _telescope.TargetRightAscension = 1); 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 +2211,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 +2219,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,25 +2242,25 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Tracking = tracking; - Assert.That(_telescope.Tracking, Is.EqualTo( tracking)); + Assert.That(_telescope.Tracking, Is.EqualTo(tracking)); } [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")); } - [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 +2268,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 +2321,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); + _testProperties.telescopeDate = telescopeDate; + _testProperties.telescopeTime = telescopeTime; + _testProperties.telescopeUtcCorrection = telescopeUtcCorrection; ConnectTelescope(); @@ -2311,7 +2343,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 +2356,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")); } @@ -2338,18 +2370,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#", 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.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")); } @@ -2363,11 +2395,12 @@ 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#", 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.SendChar($"SL{telescopeTime}", false)).Returns("1"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar($"SC{telescopeDate}", false)).Returns("1"); ConnectTelescope(); @@ -2381,12 +2414,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 +2436,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 +2447,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 +2470,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 +2482,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 +2496,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 +2512,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 +2527,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 +2557,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 +2567,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 +2575,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 +2591,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 +2614,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 +2643,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); } @@ -2619,7 +2652,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")); } @@ -2630,7 +2663,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")); } @@ -2641,7 +2674,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")); } @@ -2653,14 +2686,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("This error should not happen")); } [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 +2703,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(); @@ -2684,14 +2717,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("Below horizon")); } [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(); @@ -2699,14 +2732,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("Above below elevation")); } [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(); @@ -2714,25 +2747,25 @@ 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")); } [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 +2780,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 +2801,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 +2812,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,13 +2828,13 @@ 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] 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")); } @@ -2815,18 +2848,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 +2872,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)); } @@ -2847,7 +2880,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")); } @@ -2856,7 +2889,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.")); } @@ -2865,7 +2898,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.")); } @@ -2874,7 +2907,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.")); } @@ -2883,7 +2916,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.")); } @@ -2891,45 +2924,39 @@ 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#", 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("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); - _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)); - _sharedResourcesWrapperMock.Verify(x => x.SendChar(":MS#"), Times.Once); + 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")); } @@ -2937,28 +2964,22 @@ 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); - - _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"); + _utilMock.Setup(x => x.DegreesToDMS(_testProperties.declination, "*", ":", ":", 2)).Returns(_testProperties.telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(_testProperties.telescopeRaResult)).Returns(_testProperties.declination); - _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.SendString("GG", false)).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.SendChar("Sd+HH:MM:SS", false)).Returns("1"); - _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 +2988,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); + 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)); } @@ -2990,29 +3011,24 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Azimuth_WhenConnected_ThenReturnsTelescopeAzumith() { - var expectedAzimuth = 200; - var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; + + _testProperties.telescopeAltitude = 45; + _testProperties.telescopeAzimuth = 200; + _testProperties.hourAngle = 3; + + _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); - 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(":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); - - _astroMathsMock.Setup(x => x.ConvertEqToHoz(mockHourAngle, It.IsAny(), It.IsAny())).Returns(new HorizonCoordinates { Altitude = 45, Azimuth = expectedAzimuth }); ConnectTelescope(); var result = _telescope.Azimuth; - Assert.That(result,Is.EqualTo(expectedAzimuth)); + Assert.That(result, Is.EqualTo(_testProperties.telescopeAzimuth)); } [Test] @@ -3034,18 +3050,13 @@ namespace Meade.net.Telescope.UnitTests var telescopeLongitude = "350"; var telescopeLongitudeValue = 350; - var mockHourAngle = 3; + _sharedResourcesWrapperMock.Setup(x => x.SendString("GG", false)).Returns("-1.0"); - _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(":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); + _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(); @@ -3057,7 +3068,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")); } @@ -3068,12 +3079,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] @@ -3082,7 +3093,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.AbortSlew(); }); + Assert.Throws(() => _telescope.AbortSlew()); } [Test] @@ -3091,7 +3102,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0); }); + Assert.Throws(() => _telescope.MoveAxis(TelescopeAxes.axisPrimary, 0)); } [Test] @@ -3100,7 +3111,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.PulseGuide(GuideDirections.guideEast, 0); }); + Assert.Throws(() => _telescope.PulseGuide(GuideDirections.guideEast, 0)); } [Test] @@ -3109,7 +3120,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAz(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAz(0, 0)); } [Test] @@ -3118,7 +3129,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToAltAzAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToAltAzAsync(0, 0)); } [Test] @@ -3127,7 +3138,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinates(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinates(0, 0)); } [Test] @@ -3136,7 +3147,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToCoordinatesAsync(0, 0); }); + Assert.Throws(() => _telescope.SlewToCoordinatesAsync(0, 0)); } [Test] @@ -3145,7 +3156,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTarget(); }); + Assert.Throws(() => _telescope.SlewToTarget()); } [Test] @@ -3154,7 +3165,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SlewToTargetAsync(); }); + Assert.Throws(() => _telescope.SlewToTargetAsync()); } [Test] @@ -3163,7 +3174,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToCoordinates(0,0); }); + Assert.Throws(() => _telescope.SyncToCoordinates(0, 0)); } [Test] @@ -3172,7 +3183,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.SyncToTarget(); }); + Assert.Throws(() => _telescope.SyncToTarget()); } [Test] @@ -3181,7 +3192,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetDeclination = 1; }); + Assert.Throws(() => _telescope.TargetDeclination = 1); } [Test] @@ -3190,7 +3201,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TargetRightAscension = 1; }); + Assert.Throws(() => _telescope.TargetRightAscension = 1); } [Test] @@ -3199,7 +3210,7 @@ namespace Meade.net.Telescope.UnitTests ConnectTelescope(); _telescope.Park(); - Assert.Throws(() => { _telescope.TrackingRate = DriveRates.driveLunar; }); + Assert.Throws(() => _telescope.TrackingRate = DriveRates.driveLunar); } @@ -3210,7 +3221,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(); @@ -3264,7 +3275,7 @@ namespace Meade.net.Telescope.UnitTests var l = _telescope.SiteLongitude; Assert.That(l, Is.EqualTo(siteLongitude)); } - + } [TestCase(ParkedBehaviour.NoCoordinates)] @@ -3277,13 +3288,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(); @@ -3296,7 +3303,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; }); @@ -3316,7 +3323,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/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 81605b3..38fde76 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,7 +76,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. @@ -121,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 @@ -189,68 +194,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); @@ -280,6 +285,7 @@ namespace ASCOM.Meade.net $"Site {actionParameters} not allowed, must be between 1 and 4"); } + break; case "getname": switch (parames[1]) @@ -314,6 +320,7 @@ namespace ASCOM.Meade.net $"Site {actionParameters} not allowed, must be between 1 and 4"); } + break; default: throw new InvalidValueException( @@ -335,7 +342,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 +352,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 } @@ -395,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; @@ -407,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}"); @@ -427,19 +437,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"); } @@ -454,11 +468,14 @@ 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})"); + CheckParked(); } 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) { @@ -570,6 +587,7 @@ namespace ASCOM.Meade.net { return false; } + return true; } @@ -579,6 +597,7 @@ namespace ASCOM.Meade.net { return true; } + return false; } @@ -605,7 +624,7 @@ namespace ASCOM.Meade.net if (!IsConnected) return true; - if(SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) + if (SharedResourcesWrapper.ProductName != TelescopeList.LX200CLASSIC) { _isTargetCoordinateInitRequired = false; return _isTargetCoordinateInitRequired; @@ -628,9 +647,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"); @@ -675,7 +694,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,17 +705,17 @@ 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) LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); - } + } else { LogMessage("SetLongFormat", $"Long coordinate format: {setLongFormat} "); @@ -709,7 +728,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 +748,6 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.ReadCharacters(throwAwayCharacters); - //Make sure that the buffers are cleared out. - SharedResourcesWrapper.SendBlind("#"); - return highPrecision; } @@ -749,7 +765,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 +791,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 +799,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 +807,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 +815,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: @@ -807,7 +823,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); @@ -824,27 +841,28 @@ namespace ASCOM.Meade.net switch (site) { case 1: - return SharedResourcesWrapper.SendString(":GM#"); - //:GM# Get Site 1 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + 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#"); - //:GN# Get Site 2 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + 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#"); - //:GO# Get Site 3 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + 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#"); - //:GP# Get Site 4 Name - //Returns: # - //A ‘#’ terminated string with the name of the requested site. + return SharedResourcesWrapper.SendString("GP"); + //: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); } } @@ -864,11 +882,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# @@ -882,14 +900,14 @@ namespace ASCOM.Meade.net #endregion #region ITelescope Implementation - + public void AbortSlew() { CheckConnected("AbortSlew"); CheckParked(); LogMessage("AbortSlew", "Aborting slew"); - SharedResourcesWrapper.SendBlind(":Q#"); + SharedResourcesWrapper.SendBlind("Q"); //:Q# Halt all current slewing //Returns:Nothing @@ -914,7 +932,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 @@ -925,13 +943,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,18 +978,18 @@ 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) { 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; @@ -989,23 +1007,36 @@ namespace ASCOM.Meade.net get { CheckConnected("Altitude Get"); - + + if (SharedResourcesWrapper.ProductName == TelescopeList.LX200GPS) + { + try + { + CheckParked(); + + //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) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Altitude; + + throw; + } + } + 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); } } @@ -1019,9 +1050,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; } @@ -1060,17 +1093,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) @@ -1085,15 +1116,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 + { + CheckParked(); - //double az = utilities.DMSToDegrees(result); + 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. - //LogMessage("Azimuth Get", $"{az}"); - //return az; + double az = _utilities.DMSToDegrees(result); + + LogMessage("Azimuth Get", $"{az}"); + return az; + } + catch (ParkedException) + { + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Azimuth; + + throw; + } + } var altAz = CalcAltAzFromTelescopeEqData(); LogMessage("Azimuth Get", $"{altAz.Azimuth}"); @@ -1275,7 +1322,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. @@ -1288,16 +1335,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.LastGoodPosition: - return _lastGoodDeclination; - case ParkedBehaviour.ReportCoordinates: - var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); - return raDec.Declination; - default: - throw; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.Declination; + + throw; } } } @@ -1378,7 +1420,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 +1502,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 +1537,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 +1567,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; @@ -1559,9 +1601,40 @@ namespace ASCOM.Meade.net if (AtPark) return; + ParkedPosition parkedPosition; + 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; + 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.SendBlind(":hP#"); + SharedResourcesWrapper.SetParked(true, parkedPosition); + SharedResourcesWrapper.SendBlind("hP"); //:hP# Autostar, Autostar II and LX 16”Slew to Park Position //Returns: Nothing } @@ -1611,7 +1684,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 +1769,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 @@ -1709,16 +1782,11 @@ namespace ASCOM.Meade.net } catch (ParkedException) { - switch (ParkedBehaviour) - { - case ParkedBehaviour.LastGoodPosition: - return _lastGoodRightAsension; - case ParkedBehaviour.ReportCoordinates: - var raDec = _astroMaths.ConvertHozToEq(UTCDate, SiteLatitude, SiteLongitude, ParkedAltAz); - return raDec.RightAscension; - default: - throw; - } + var parkedPosition = SharedResourcesWrapper.ParkedPosition; + if (parkedPosition != null) + return parkedPosition.RightAscension; + + throw; } } @@ -1824,7 +1892,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 +1933,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 +1959,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 +2002,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 +2098,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 +2135,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 +2272,7 @@ namespace ASCOM.Meade.net string result; try { - result = SharedResourcesWrapper.SendString(":D#"); + result = SharedResourcesWrapper.SendString("D"); } catch (TimeoutException) { @@ -2289,7 +2357,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 +2423,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 +2477,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 +2539,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 +2581,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 +2612,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 +2665,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 +2677,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,13 +2708,13 @@ 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 BypassHandboxEntryForAutostarII(); - AtPark = false; + SharedResourcesWrapper.SetParked(false, null); } private bool BypassHandboxEntryForAutostarII() @@ -2655,7 +2723,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 @@ -2774,4 +2842,4 @@ namespace ASCOM.Meade.net } #endregion } -} +} \ No newline at end of file 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/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/ParkedPosition.cs b/Meade.net/ParkedPosition.cs new file mode 100644 index 0000000..29bbb9e --- /dev/null +++ b/Meade.net/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/SharedResources.cs b/Meade.net/SharedResources.cs index 61a6249..47730ef 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 @@ -479,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 82e24e0..d7b078c 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(); @@ -26,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 @@ -54,19 +59,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() @@ -93,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; } }