From aca01de4eeb356cbbe3f8526da2fe355a89bb499 Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Fri, 23 Apr 2021 19:45:10 +0100 Subject: [PATCH] Added a # prefix before the commands. --- .../FocuserUnitTests.cs | 4 +- .../TelescopeUnitTests.cs | 140 +++++++++--------- Meade.net.Telescope/Telescope.cs | 18 +-- .../SharedResourcesUnitTests.cs | 9 +- Meade.net/SharedResources.cs | 15 +- Meade.net/Wrapper/SharedResourcesWrapper.cs | 6 +- 6 files changed, 92 insertions(+), 100 deletions(-) diff --git a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs index ca09d30..9f945d2 100644 --- a/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs +++ b/Meade.net.Focuser.UnitTests/FocuserUnitTests.cs @@ -159,11 +159,11 @@ namespace Meade.net.Focuser.UnitTests ConnectFocuser(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); var actualMessage = _focuser.CommandString(sendMessage, true); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 04e538a..1a2c74a 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -61,7 +61,7 @@ namespace Meade.net.Telescope.UnitTests _astroUtilsMock = new Mock(); _sharedResourcesWrapperMock = new Mock(); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _sharedResourcesWrapperMock.Setup(x => x.ReadProfile()).Returns(() =>_profileProperties); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); @@ -89,7 +89,7 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(_testProperties.telescopeRaResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#", true)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.HMSToHours(_testProperties.telescopeRaResult)).Returns(_testProperties.rightAscension); _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => productName); @@ -145,14 +145,14 @@ namespace Meade.net.Telescope.UnitTests public void Action_Handbox_ReadDisplay() { string expectedResult = "test result string"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#")).Returns(expectedResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":ED#", true)).Returns(expectedResult); _telescope.Connected = true; var actualResult = _telescope.Action("handbox", "readdisplay"); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":ED#", true), Times.Once); Assert.That(actualResult, Is.EqualTo(expectedResult)); } @@ -216,14 +216,14 @@ namespace Meade.net.Telescope.UnitTests [TestCase("4", ":GP#", "Parents")] public void Action_Site_GetName_WhenCallingWithValidValues_ThenSelectsCorrectSite(string site, string telescopeCommand, string siteName) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand)).Returns(siteName); + _sharedResourcesWrapperMock.Setup(x => x.SendString(telescopeCommand, true)).Returns(siteName); ConnectTelescope(); string parameters = $"GetName {site}"; var result = _telescope.Action("site", parameters); - _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(telescopeCommand, true), Times.Once); Assert.That(result, Is.EqualTo(siteName)); } @@ -370,13 +370,13 @@ namespace Meade.net.Telescope.UnitTests string expectedMessage = "expected result message"; string sendMessage = "test blind Message"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage)).Returns(() => expectedMessage); + _sharedResourcesWrapperMock.Setup(x => x.SendString(sendMessage, true)).Returns(() => expectedMessage); ConnectTelescope(); var actualMessage = _telescope.CommandString(sendMessage, true); - _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(sendMessage, true), Times.Once); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); } @@ -392,7 +392,7 @@ namespace Meade.net.Telescope.UnitTests if (expectedConnected) { - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); } } @@ -408,7 +408,7 @@ 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#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Once); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"),Times.Once); } @@ -424,7 +424,7 @@ 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#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GZ#", true), Times.Never); _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Rg{_profileProperties.GuideRateArcSecondsPerSecond:00.0}#"), Times.Never); } @@ -461,7 +461,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_31Ee); - _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny())).Throws(new Exception("TestFailed")); + _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny(), It.IsAny())).Throws(new Exception("TestFailed")); //act _telescope.Connected = true; @@ -496,7 +496,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsShortFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); _telescope.SetLongFormat(false); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"),Times.Never); @@ -505,7 +505,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatFalse_WhenTelescopeReturnsLongFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(false); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); @@ -514,7 +514,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatTrue_WhenTelescopeReturnsLongFormat_ThenDoesNothing() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM’SS"); _telescope.SetLongFormat(true); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Never); @@ -523,7 +523,7 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SetLongFormatTrue_WhenTelescopeReturnsShortFormat_ThenTogglesPrecision() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#", true)).Returns("DDD*MM"); _telescope.SetLongFormat(true); _sharedResourcesWrapperMock.Verify(x => x.SendBlind(":U#"), Times.Once); @@ -838,7 +838,7 @@ namespace Meade.net.Telescope.UnitTests { _telescope.Connected = true; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#"), Times.Never); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":P#", true), Times.Never); } [TestCase("High", false, true)] @@ -989,7 +989,7 @@ namespace Meade.net.Telescope.UnitTests public void Declination_Get_WhenConnected_ThenReadsValueFromScope(string declincationString) { var expectedResult = 12.34; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(declincationString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(declincationString); _utilMock.Setup(x => x.DMSToDegrees(declincationString)).Returns(expectedResult); ConnectTelescope(); @@ -1004,14 +1004,14 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(); var result = _telescope.Declination; - _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#"), Times.Exactly(2)); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":GD#", true), Times.Exactly(2)); _utilMock.Verify(x => x.DMSToDegrees(telescopeDecResult), Times.Exactly(2)); Assert.That(result, Is.EqualTo(dmsResult)); @@ -1359,7 +1359,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth)] public void PulseGuide_WhenSlewingAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); var duration = 0; ConnectTelescope(); @@ -1375,7 +1375,7 @@ namespace Meade.net.Telescope.UnitTests [TestCase(GuideDirections.guideSouth, TelescopeAxes.axisSecondary)] public void PulseGuide_WhenMovingAxisAndPulseGuideAttempted_ThenThrowsExpectedException(GuideDirections direction, TelescopeAxes axes) { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns(""); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(""); var duration = 0; ConnectTelescope(); @@ -1398,7 +1398,7 @@ namespace Meade.net.Telescope.UnitTests _testProperties.rightAscension = 1.3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); var duration = 0; @@ -1428,7 +1428,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1471,7 +1471,7 @@ namespace Meade.net.Telescope.UnitTests var telescopeDecResult = "s12*34’56"; var dmsResult = 1.2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); ConnectTelescope(TelescopeList.Autostar497, TelescopeList.Autostar497_30Ee); @@ -1725,14 +1725,14 @@ namespace Meade.net.Telescope.UnitTests var siteLatitudeString = "testLatString"; var siteLatitudeValue = 123.45; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#")).Returns(siteLatitudeString); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gt#", true)).Returns(siteLatitudeString); _utilMock.Setup(x => x.DMSToDegrees(siteLatitudeString)).Returns(siteLatitudeValue); ConnectTelescope(); var result = _telescope.SiteLatitude; - _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#"), Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":Gt#", true), Times.Once); Assert.That(result,Is.EqualTo(siteLatitudeValue)); } @@ -1808,7 +1808,7 @@ namespace Meade.net.Telescope.UnitTests { var telescopeLongitude = "testLongitude"; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#")).Returns(telescopeLongitude); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":Gg#", true)).Returns(telescopeLongitude); _utilMock.Setup(x => x.DMSToDegrees(telescopeLongitude)).Returns(telescopeLongitudeValue); ConnectTelescope(); @@ -1887,26 +1887,26 @@ namespace Meade.net.Telescope.UnitTests [Test] public void SyncToTarget_WhenSyncToTargetFails_ThenThrowsException() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(string.Empty); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(string.Empty); ConnectTelescope(); var exception = Assert.Throws(() => { _telescope.SyncToTarget(); } ); Assert.That(exception.Message, Is.EqualTo("Unable to perform sync")); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); } [Test] public void SyncToTarget_WhenSyncToTargetWorks_ThennoExceptionThrown() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#")).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":CM#", true)).Returns(" M31 EX GAL MAG 3.5 SZ178.0'#"); ConnectTelescope(); Assert.DoesNotThrow(() => { _telescope.SyncToTarget(); }); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); } [Test] @@ -2169,9 +2169,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#")).Returns(telescopeDate); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns(telescopeTime); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _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); ConnectTelescope(); @@ -2204,7 +2204,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#", true)).Returns(telescopeUtcCorrection); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":SL{telescopeTime}#")).Returns("0"); ConnectTelescope(); @@ -2223,7 +2223,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _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"); @@ -2245,7 +2245,7 @@ namespace Meade.net.Telescope.UnitTests var newDate = new DateTime(year, month, day, hour, min, second, DateTimeKind.Local) + utcCorrection; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns(telescopeUtcCorrection); + _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"); @@ -2297,15 +2297,15 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{hms}#")).Returns("1"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sd{dec}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#")).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); + _sharedResourcesWrapperMock.Setup(x => x.SendString($":CM#", true)).Returns("M31 EX GAL MAG 3.5 SZ178.0'#"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); ConnectTelescope(); _telescope.SyncToCoordinates(_testProperties.rightAscension, declination); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":CM#", true), Times.Once); Assert.That(_telescope.TargetRightAscension, Is.EqualTo(_testProperties.rightAscension)); Assert.That(_telescope.TargetDeclination, Is.EqualTo(declination)); } @@ -2317,7 +2317,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); } [Test] @@ -2329,13 +2329,13 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.False); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); } [Test] public void Slewing_WhenTelescopeIsSlewing_ThenReturnsTrue() { - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns("|"); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns("|"); ConnectTelescope(); @@ -2343,7 +2343,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true),Times.Once); } [TestCase(0, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:01", false)] @@ -2381,7 +2381,7 @@ namespace Meade.net.Telescope.UnitTests var slewingText = "|"; var notSlewingText = String.Empty; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns( () => + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns( () => { if (timescalled == 0) { @@ -2410,12 +2410,10 @@ namespace Meade.net.Telescope.UnitTests [TestCase(TelescopeList.LX200CLASSIC, "", "[FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF][FF] [FF][FF][FF][FF][FF][FF]", false)] //The test case below is this same string encoded to return exactly what the telescope will return. [TestCase(TelescopeList.LX200CLASSIC, "", "\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff\x00ff \x00ff\x00ff\x00ff\x00ff\x00ff\x00ff", false)] [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "|", true)] - [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "[7F]", true)] - [TestCase(TelescopeList.Autostar497, TelescopeList.Autostar497_43Eg, "\x00ff", true)] [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#")).Returns(response); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#", true)).Returns(response); ConnectTelescope(productName, firmwareVersion); @@ -2423,7 +2421,7 @@ namespace Meade.net.Telescope.UnitTests Assert.That(result, Is.EqualTo(isSlewing)); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Once); } [TestCase(1, TelescopeAxes.axisPrimary)] @@ -2439,7 +2437,7 @@ namespace Meade.net.Telescope.UnitTests var result = _telescope.Slewing; Assert.That(result, Is.True); - _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); + _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#", true), Times.Never); } [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] @@ -2613,7 +2611,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#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2652,7 +2650,7 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Setup(x => x.SendChar(":MS#")).Returns("0"); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(declination); @@ -2696,7 +2694,7 @@ namespace Meade.net.Telescope.UnitTests var dmsResult = 1.2; var digitsRA = 2; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#", true)).Returns(telescopeDecResult); _sharedResourcesWrapperMock.Setup(x => x.SendChar($":Sr{_testProperties.telescopeRaResult}#")).Returns("1"); _utilMock.Setup(x => x.HoursToHMS(_testProperties.rightAscension, ":", ":", ":", digitsRA)).Returns(_testProperties.telescopeRaResult); @@ -2707,7 +2705,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#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2777,9 +2775,9 @@ namespace Meade.net.Telescope.UnitTests var azimuth = 45; var declination = 10; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.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"); _astroMathsMock .Setup(x => x.ConvertHozToEq(It.IsAny(), It.IsAny(), It.IsAny(), @@ -2826,9 +2824,9 @@ namespace Meade.net.Telescope.UnitTests _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#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.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"); _astroMathsMock @@ -2839,7 +2837,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#", true)).Returns(() => { slewCounter++; if (slewCounter <= iterations) @@ -2878,11 +2876,11 @@ namespace Meade.net.Telescope.UnitTests var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.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#")).Returns(telescopeLongitude); + _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); @@ -2917,11 +2915,11 @@ namespace Meade.net.Telescope.UnitTests var mockHourAngle = 3; - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GC#")).Returns("10/15/20"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GL#")).Returns("20:15:10"); - _sharedResourcesWrapperMock.Setup(x => x.SendString(":GG#")).Returns("-1.0"); + _sharedResourcesWrapperMock.Setup(x => x.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#")).Returns(telescopeLongitude); + _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); @@ -2954,7 +2952,7 @@ namespace Meade.net.Telescope.UnitTests var isSloSlewing = _telescope.Slewing; Assert.That(isSloSlewing, Is.False); - _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#"), Times.Once); + _sharedResourcesWrapperMock.Verify( x => x.SendString(":D#", true), Times.Once); } } } \ No newline at end of file diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 5183e95..1cb7ec9 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -357,7 +357,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"); } @@ -2107,18 +2107,6 @@ namespace ASCOM.Meade.net return isSlewing; } - if (result.Equals("[7F]")) - { - isSlewing = true; - return isSlewing; - } - - if (result.Equals("\x00ff")) - { - isSlewing = true; - return isSlewing; - } - ////classic LX200 return bar with 32 chars. FF is contained from left to right when slewing //byte[] ba = Encoding.Default.GetBytes(result); ////replace fill chars not belonging to a slew bar. Are there others? The bar character is a FF in hex. @@ -2134,13 +2122,13 @@ namespace ASCOM.Meade.net ////a 0 movement will solved that lock if the target coordinates are set to the current coordinates. //if (IsTargetCoordinateInitRequired()) // InitTargetCoordinates(); - - return isSlewing; } finally { LogMessage("IsSlewingToTarget", $"IsSlewing = {isSlewing} : result = {result ?? ""}"); } + + return isSlewing; } public void SyncToAltAz(double azimuth, double altitude) diff --git a/Meade.net.UnitTests/SharedResourcesUnitTests.cs b/Meade.net.UnitTests/SharedResourcesUnitTests.cs index 414d327..ec88158 100644 --- a/Meade.net.UnitTests/SharedResourcesUnitTests.cs +++ b/Meade.net.UnitTests/SharedResourcesUnitTests.cs @@ -59,15 +59,16 @@ namespace Meade.net.UnitTests Assert.That(result, Is.EqualTo(expectedResult)); } - [Test] - public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound() + [TestCase(false, "Test")] + [TestCase(true, "#Test")] + public void SendString_WhenCalled_ThenSendsMessageAndReadsResultUntilTerminatorFound(bool includePrefix, string expectedMessage) { - var expectedMessage = "Test"; + var transmitMessage = "Test"; var expectedResult = "TestMessage#"; _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(expectedResult); - var result = SharedResources.SendString(expectedMessage); + var result = SharedResources.SendString(transmitMessage, includePrefix); _serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 1d07e15..f84a243 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -93,12 +93,17 @@ namespace ASCOM.Meade.net /// /// /// - public static string SendString(string message) + public static string SendString(string message, bool includePrefix = true) { lock (LockObject) { SharedSerial.ClearBuffers(); - SharedSerial.Transmit(message); + + if (includePrefix) + SharedSerial.Transmit( $"#{message}"); + else + SharedSerial.Transmit(message); + return SharedSerial.ReceiveTerminated("#").TrimEnd('#'); } } @@ -324,8 +329,8 @@ namespace ASCOM.Meade.net try { - ProductName = SendString("#:GVP#"); - FirmwareVersion = SendString("#:GVN#"); + ProductName = SendString(":GVP#"); + FirmwareVersion = SendString(":GVN#"); } catch (Exception ex) { @@ -345,7 +350,7 @@ namespace ASCOM.Meade.net try { - string utcOffSet = SendString("#:GG#"); + string utcOffSet = SendString(":GG#"); //:GG# Get UTC offset time //Returns: sHH# or sHH.H# //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index b9fa801..82e24e0 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -15,7 +15,7 @@ namespace ASCOM.Meade.net.Wrapper void Lock(Action action); T Lock(Func func); - string SendString(string message); + string SendString(string message, bool includePrefix = true); void SendBlind(string message); string SendChar(string message); @@ -54,9 +54,9 @@ namespace ASCOM.Meade.net.Wrapper return SharedResources.Lock(func); } - public string SendString(string message) + public string SendString(string message, bool includePrefix = true) { - return SharedResources.SendString(message); + return SharedResources.SendString(message, includePrefix); } public void SendBlind(string message)