From db06002ebf44d462169452e32b2a32c578bd1e16 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 26 Feb 2021 00:11:44 +0000 Subject: [PATCH 01/12] Added support for SlewSettleTime --- .../TelescopeUnitTests.cs | 48 +++++-- Meade.net.Telescope/Telescope.cs | 10 +- Meade.net/MeadeTelescopeBase.cs | 3 + Meade.net/ProfileProperties.cs | 1 + Meade.net/SetupDialogForm.cs | 6 +- Meade.net/SetupDialogForm.designer.cs | 31 +++++ Meade.net/SetupDialogForm.resx | 127 ++++++++++++++---- Meade.net/SharedResources.cs | 4 + 8 files changed, 189 insertions(+), 41 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 1afc3e7..7989e84 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1633,25 +1633,55 @@ namespace Meade.net.Telescope.UnitTests } [Test] - public void SlewSettleTime_Get_ThenThrowsException() + public void SlewSettleTime_Get_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => + var exception = Assert.Throws(() => { var result = _telescope.SlewSettleTime; Assert.Fail($"{result} should not have returned"); }); - - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.False); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Get")); } [Test] - public void SlewSettleTime_Set_ThenThrowsException() + public void SlewSettleTime_Set_WhenNotConnected_ThenThrowsException() { - var excpetion = Assert.Throws(() => { _telescope.SlewSettleTime = 0; }); + var exception = Assert.Throws(() => + { + _telescope.SlewSettleTime = 13; + Assert.Fail($"should not have returned"); + }); + Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set")); + } - Assert.That(excpetion.Property, Is.EqualTo("SlewSettleTime")); - Assert.That(excpetion.AccessorSet, Is.True); + [TestCase(5)] + [TestCase(10)] + [TestCase(2)] + public void SlewSettleTime_Get_ReturnsExpectedValue(short settleTime) + { + _profileProperties.SettleTime = settleTime; + + ConnectTelescope(); + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(settleTime)); + } + + [TestCase(8)] + [TestCase(12)] + [TestCase(3)] + public void SlewSettleTime_Set_ThenReturnsNewSettleTime(short settleTime) + { + _profileProperties.SettleTime = 0; + + ConnectTelescope(); + + _telescope.SlewSettleTime = settleTime; + + var result = _telescope.SlewSettleTime; + + Assert.That(result, Is.EqualTo(settleTime)); } [Test] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index bf06b16..b1fe144 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1774,14 +1774,16 @@ namespace ASCOM.Meade.net { get { - LogMessage("SlewSettleTime Get", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", false); + CheckConnected("SlewSettleTime Get"); + LogMessage("SlewSettleTime Get", $"{SettleTime} Seconds"); + return SettleTime; } // ReSharper disable once ValueParameterNotUsed set { - LogMessage("SlewSettleTime Set", "Not implemented"); - throw new PropertyNotImplementedException("SlewSettleTime", true); + CheckConnected("SlewSettleTime Set"); + LogMessage("SlewSettleTime Set", $"Setting from {SettleTime} to {value}"); + SettleTime = value; } } diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 1250461..6fd1d53 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -27,6 +27,7 @@ namespace ASCOM.Meade.net protected string Precision; protected string GuidingStyle; protected double SiteElevation; + protected short SettleTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -67,6 +68,7 @@ namespace ASCOM.Meade.net Precision = profileProperties.Precision; GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; + SettleTime = profileProperties.SettleTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -76,6 +78,7 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Precision: {Precision}"); LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); + LogMessage("ReadProfile", $"Settle Time after slew: {SettleTime}"); } /// diff --git a/Meade.net/ProfileProperties.cs b/Meade.net/ProfileProperties.cs index f5155c4..b4f11cc 100644 --- a/Meade.net/ProfileProperties.cs +++ b/Meade.net/ProfileProperties.cs @@ -13,5 +13,6 @@ namespace ASCOM.Meade.net public bool DynamicBreaking { get; set; } public bool RtsDtrEnabled { get; set; } public double SiteElevation { get; set; } + public short SettleTime { get; set; } } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index b6a7208..52d1e90 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -88,6 +88,7 @@ namespace ASCOM.Meade.net cbxReverseDirection.Checked = profileProperties.ReverseFocusDirection; cbxDynamicBreaking.Checked = profileProperties.DynamicBreaking; + nudSettleTime.Value = profileProperties.SettleTime; } public ProfileProperties GetProfile() @@ -103,8 +104,9 @@ namespace ASCOM.Meade.net BacklashCompensation = int.Parse(txtBacklashSteps.Text), ReverseFocusDirection = cbxReverseDirection.Checked, DynamicBreaking = cbxDynamicBreaking.Checked, - SiteElevation = double.Parse(txtElevation.Text) - }; + SiteElevation = double.Parse(txtElevation.Text), + SettleTime = Convert.ToInt16(nudSettleTime.Value) + }; return profileProperties; } diff --git a/Meade.net/SetupDialogForm.designer.cs b/Meade.net/SetupDialogForm.designer.cs index 4d23524..d0858bd 100644 --- a/Meade.net/SetupDialogForm.designer.cs +++ b/Meade.net/SetupDialogForm.designer.cs @@ -61,7 +61,11 @@ namespace ASCOM.Meade.net this.label12 = new System.Windows.Forms.Label(); this.txtElevation = new System.Windows.Forms.TextBox(); this.label13 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.nudSettleTime = new System.Windows.Forms.NumericUpDown(); + this.label15 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).BeginInit(); this.SuspendLayout(); // // cmdOK @@ -231,10 +235,33 @@ namespace ASCOM.Meade.net resources.ApplyResources(this.label13, "label13"); this.label13.Name = "label13"; // + // label14 + // + resources.ApplyResources(this.label14, "label14"); + this.label14.Name = "label14"; + // + // nudSettleTime + // + resources.ApplyResources(this.nudSettleTime, "nudSettleTime"); + this.nudSettleTime.Maximum = new decimal(new int[] { + 32767, + 0, + 0, + 0}); + this.nudSettleTime.Name = "nudSettleTime"; + // + // label15 + // + resources.ApplyResources(this.label15, "label15"); + this.label15.Name = "label15"; + // // SetupDialogForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label15); + this.Controls.Add(this.nudSettleTime); + this.Controls.Add(this.label14); this.Controls.Add(this.label13); this.Controls.Add(this.txtElevation); this.Controls.Add(this.label12); @@ -270,6 +297,7 @@ namespace ASCOM.Meade.net this.TopMost = true; this.Shown += new System.EventHandler(this.SetupDialogForm_Shown); ((System.ComponentModel.ISupportInitialize)(this.picASCOM)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.nudSettleTime)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -305,5 +333,8 @@ namespace ASCOM.Meade.net private Label label12; private TextBox txtElevation; private Label label13; + private Label label14; + private NumericUpDown nudSettleTime; + private Label label15; } } \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.resx b/Meade.net/SetupDialogForm.resx index a71d20e..73de650 100644 --- a/Meade.net/SetupDialogForm.resx +++ b/Meade.net/SetupDialogForm.resx @@ -145,7 +145,7 @@ $this - 26 + 29 Bottom, Right @@ -172,7 +172,7 @@ $this - 25 + 28 12, 9 @@ -196,7 +196,7 @@ $this - 24 + 27 Top, Right @@ -223,7 +223,7 @@ $this - 23 + 26 True @@ -250,7 +250,7 @@ $this - 22 + 25 True @@ -277,7 +277,7 @@ $this - 21 + 24 97, 87 @@ -298,7 +298,7 @@ $this - 20 + 23 True @@ -325,7 +325,7 @@ $this - 19 + 22 97, 275 @@ -349,7 +349,7 @@ $this - 18 + 21 True @@ -376,7 +376,7 @@ $this - 17 + 20 True @@ -403,7 +403,7 @@ $this - 16 + 19 True @@ -430,7 +430,7 @@ $this - 15 + 18 Unchanged @@ -460,7 +460,7 @@ $this - 14 + 17 True @@ -490,7 +490,7 @@ $this - 13 + 16 Auto @@ -520,7 +520,7 @@ $this - 12 + 15 True @@ -550,7 +550,7 @@ $this - 11 + 14 True @@ -583,7 +583,7 @@ $this - 10 + 13 97, 411 @@ -607,7 +607,7 @@ $this - 8 + 11 True @@ -637,7 +637,7 @@ $this - 9 + 12 True @@ -667,7 +667,7 @@ $this - 7 + 10 True @@ -700,7 +700,7 @@ $this - 6 + 9 True @@ -727,7 +727,7 @@ $this - 5 + 8 True @@ -754,7 +754,7 @@ $this - 4 + 7 17, 17 @@ -790,7 +790,7 @@ $this - 3 + 6 17, 17 @@ -820,7 +820,7 @@ $this - 2 + 5 97, 202 @@ -841,7 +841,7 @@ $this - 1 + 4 True @@ -868,6 +868,81 @@ $this + 3 + + + True + + + 12, 236 + + + 56, 13 + + + 25 + + + Settle time + + + label14 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 97, 234 + + + 120, 20 + + + 26 + + + nudSettleTime + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 223, 236 + + + 47, 13 + + + 27 + + + seconds + + + label15 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + 0 diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 625e9ed..691e28d 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -146,6 +146,7 @@ namespace ASCOM.Meade.net private const string ReverseFocusDirectionName = "Reverse Focuser Direction"; private const string DynamicBreakingName = "Dynamic Breaking"; private const string SiteElevationName = "Site Elevation"; + private const string SettleTimeName = "Settle Time"; public static void WriteProfile(ProfileProperties profileProperties) { @@ -164,6 +165,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, ReverseFocusDirectionName, profileProperties.ReverseFocusDirection.ToString()); driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString()); + driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); } } } @@ -178,6 +180,7 @@ namespace ASCOM.Meade.net private const string ReverseFocuserDiectionDefault = "true"; private const string DynamicBreakingDefault = "true"; private const string SiteElevationDefault = "0"; + private const string SettleTimeDefault = "2"; public static ProfileProperties ReadProfile() { @@ -197,6 +200,7 @@ namespace ASCOM.Meade.net profileProperties.ReverseFocusDirection = Convert.ToBoolean(driverProfile.GetValue(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault)); profileProperties.DynamicBreaking = Convert.ToBoolean(driverProfile.GetValue(DriverId, DynamicBreakingName, string.Empty, DynamicBreakingDefault)); profileProperties.SiteElevation = Convert.ToInt32(driverProfile.GetValue(DriverId, SiteElevationName, string.Empty, SiteElevationDefault)); + profileProperties.SettleTime = Convert.ToInt16(driverProfile.GetValue(DriverId, SettleTimeName, string.Empty, SettleTimeDefault)); } return profileProperties; From e9491da70771b88822e7c2986ccdc9946b0c3af1 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 27 Feb 2021 21:20:06 +0000 Subject: [PATCH 02/12] Seperated the SlewSettleTime property from the ProfileSettle time, and implemented a delay on IsSlewing to use the combined SettleTimes --- .../TelescopeUnitTests.cs | 74 +++++++++++++++++-- Meade.net.Telescope/Clock.cs | 9 +++ Meade.net.Telescope/IClock.cs | 9 +++ .../Meade.net.Telescope.csproj | 2 + Meade.net.Telescope/Telescope.cs | 34 +++++++-- Meade.net/MeadeTelescopeBase.cs | 6 +- 6 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 Meade.net.Telescope/Clock.cs create mode 100644 Meade.net.Telescope/IClock.cs diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 7989e84..62c63ef 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Reflection; using ASCOM; using ASCOM.Astrometry.AstroUtils; @@ -22,6 +23,7 @@ namespace Meade.net.Telescope.UnitTests private Mock _astroUtilsMock; private Mock _sharedResourcesWrapperMock; private Mock _astroMathsMock; + private Mock _clockMock; private ProfileProperties _profileProperties; private ConnectionInfo _connectionInfo; @@ -63,8 +65,10 @@ namespace Meade.net.Telescope.UnitTests _astroMathsMock = new Mock(); + _clockMock = new Mock(); + _telescope = new ASCOM.Meade.net.Telescope(_utilMock.Object, _utilExtraMock.Object, _astroUtilsMock.Object, - _sharedResourcesWrapperMock.Object, _astroMathsMock.Object); + _sharedResourcesWrapperMock.Object, _astroMathsMock.Object, _clockMock.Object); } private void ConnectTelescope(string productName = TelescopeList.Autostar497, string firmwareVersion = TelescopeList.Autostar497_31Ee) @@ -1654,18 +1658,14 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo("Not connected to telescope when trying to execute: SlewSettleTime Set")); } - [TestCase(5)] - [TestCase(10)] - [TestCase(2)] - public void SlewSettleTime_Get_ReturnsExpectedValue(short settleTime) + [Test] + public void SlewSettleTime_Get_ReturnsExpectedValue() { - _profileProperties.SettleTime = settleTime; - ConnectTelescope(); var result = _telescope.SlewSettleTime; - Assert.That(result, Is.EqualTo(settleTime)); + Assert.That(result, Is.EqualTo(0)); } [TestCase(8)] @@ -2339,6 +2339,64 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"),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)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:06", true)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:09", true)] + [TestCase(10, 0, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)] + [TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:01", true)] + [TestCase(0, 5, "2021-10-03T20:36:00", "2021-10-03T20:36:05", false)] + [TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:05", true)] + [TestCase(0, 10, "2021-10-03T20:36:00", "2021-10-03T20:36:10", false)] + [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) + { + _profileProperties.SettleTime = profileSettleTime; + + var timescalled = 0; + DateTime startSlewingDateTime = DateTime.ParseExact(startSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + DateTime endSlewingDatetime = DateTime.ParseExact(endSlewing, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + + _clockMock.Setup(x => x.UtcNow).Returns(() => + { + if (timescalled == 0) + { + timescalled++; + return startSlewingDateTime; + } + + return endSlewingDatetime; + }); + + var slewingText = "|"; + var notSlewingText = String.Empty; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":D#")).Returns( () => + { + if (timescalled == 0) + { + return slewingText; + } + + return notSlewingText; + }); + + ConnectTelescope(); + + _telescope.SlewSettleTime = settleTime; + + var result = _telescope.Slewing; + + Assert.That(result, Is.EqualTo(true)); + + result = _telescope.Slewing; + + Assert.That(result, Is.EqualTo(isSlewing)); + } [TestCase(TelescopeList.LX200CLASSIC,"","|", true)] [TestCase(TelescopeList.LX200CLASSIC, "", "||||||||", true)] diff --git a/Meade.net.Telescope/Clock.cs b/Meade.net.Telescope/Clock.cs new file mode 100644 index 0000000..745e9a7 --- /dev/null +++ b/Meade.net.Telescope/Clock.cs @@ -0,0 +1,9 @@ +using System; + +namespace ASCOM.Meade.net +{ + public class Clock : IClock + { + public DateTime UtcNow => DateTime.UtcNow; + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/IClock.cs b/Meade.net.Telescope/IClock.cs new file mode 100644 index 0000000..2745543 --- /dev/null +++ b/Meade.net.Telescope/IClock.cs @@ -0,0 +1,9 @@ +using System; + +namespace ASCOM.Meade.net +{ + public interface IClock + { + DateTime UtcNow { get; } + } +} \ No newline at end of file diff --git a/Meade.net.Telescope/Meade.net.Telescope.csproj b/Meade.net.Telescope/Meade.net.Telescope.csproj index af7987b..cfae8a4 100644 --- a/Meade.net.Telescope/Meade.net.Telescope.csproj +++ b/Meade.net.Telescope/Meade.net.Telescope.csproj @@ -124,8 +124,10 @@ + + diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index b1fe144..8524fac 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -60,16 +60,20 @@ namespace ASCOM.Meade.net private readonly IAstroMaths _astroMaths; + private readonly IClock _clock; + /// /// Private variable to hold number of decimals for RA /// private int _digitsRa = 2; /// - /// Private variable to hold number of decimals for DE + /// Private variable to hold number of decimals for Dec /// private int _digitsDe = 2; + private short _settleTime; + /// /// Initializes a new instance of the class. /// Must be public for COM registration. @@ -84,6 +88,7 @@ namespace ASCOM.Meade.net _utilitiesExtra = util; //Initialise util object _astroUtilities = new AstroUtils(); // Initialise astro utilities object _astroMaths = new AstroMaths.AstroMaths(); + _clock = new Clock(); Initialise(nameof(Telescope)); } @@ -116,8 +121,9 @@ namespace ASCOM.Meade.net sb.AppendLine(); } - public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths) : 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 _utilitiesExtra = utilExtra; //Initialise util object _astroUtilities = astroUtilities; // Initialise astro utilities object @@ -1775,15 +1781,14 @@ namespace ASCOM.Meade.net get { CheckConnected("SlewSettleTime Get"); - LogMessage("SlewSettleTime Get", $"{SettleTime} Seconds"); - return SettleTime; + LogMessage("SlewSettleTime Get", $"{_settleTime} Seconds"); + return _settleTime; } - // ReSharper disable once ValueParameterNotUsed set { CheckConnected("SlewSettleTime Set"); - LogMessage("SlewSettleTime Set", $"Setting from {SettleTime} to {value}"); - SettleTime = value; + LogMessage("SlewSettleTime Set", $"Setting from {_settleTime} to {value}"); + _settleTime = value; } } @@ -1964,16 +1969,29 @@ namespace ASCOM.Meade.net return _movingPrimary || _movingSecondary; } + private DateTime _earliestNonSlewingTime = DateTime.MinValue; + public bool Slewing { get { var isSlewing = GetSlewing(); + + if (isSlewing) + _earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); + else if (_clock.UtcNow < _earliestNonSlewingTime) + isSlewing = true; + LogMessage("Slewing", $"Result = {isSlewing}"); return isSlewing; } } + private TimeSpan GetTotalSlewingSettleTime() + { + return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime ); + } + private bool GetSlewing() { if (!Connected) return false; @@ -2001,7 +2019,7 @@ namespace ASCOM.Meade.net bool isSlewing = false; try { - if (string.IsNullOrWhiteSpace(result)) + if (string.IsNullOrEmpty(result)) { isSlewing = false; return isSlewing; diff --git a/Meade.net/MeadeTelescopeBase.cs b/Meade.net/MeadeTelescopeBase.cs index 6fd1d53..51e0892 100644 --- a/Meade.net/MeadeTelescopeBase.cs +++ b/Meade.net/MeadeTelescopeBase.cs @@ -27,7 +27,7 @@ namespace ASCOM.Meade.net protected string Precision; protected string GuidingStyle; protected double SiteElevation; - protected short SettleTime; + protected short ProfileSettleTime; protected readonly ISharedResourcesWrapper SharedResourcesWrapper; @@ -68,7 +68,7 @@ namespace ASCOM.Meade.net Precision = profileProperties.Precision; GuidingStyle = profileProperties.GuidingStyle.ToLower(); SiteElevation = profileProperties.SiteElevation; - SettleTime = profileProperties.SettleTime; + ProfileSettleTime = profileProperties.SettleTime; LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}"); LogMessage("ReadProfile", $"Com Port: {ComPort}"); @@ -78,7 +78,7 @@ namespace ASCOM.Meade.net LogMessage("ReadProfile", $"Precision: {Precision}"); LogMessage("ReadProfile", $"Guiding Style: {GuidingStyle}"); LogMessage("ReadProfile", $"Site Elevation: {SiteElevation}"); - LogMessage("ReadProfile", $"Settle Time after slew: {SettleTime}"); + LogMessage("ReadProfile", $"Settle Time after slew: {ProfileSettleTime}"); } /// From 136ccc8fa95a15a2846593633c85053e4b94650f Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 28 Feb 2021 20:03:19 +0000 Subject: [PATCH 03/12] Added more places to initialise the slewing settle delay --- Meade.net.Telescope/Telescope.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 8524fac..4b75b6b 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1866,6 +1866,7 @@ namespace ASCOM.Meade.net case "0": //We're slewing everything should be working just fine. LogMessage("DoSlewAsync", "Slewing to target"); + SetSlewingMinEndTime(); break; case "1": //Below Horizon @@ -1901,7 +1902,7 @@ namespace ASCOM.Meade.net { throw new InvalidOperationException("fault"); } - + SetSlewingMinEndTime(); break; } }); @@ -1978,7 +1979,7 @@ namespace ASCOM.Meade.net var isSlewing = GetSlewing(); if (isSlewing) - _earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); + SetSlewingMinEndTime(); else if (_clock.UtcNow < _earliestNonSlewingTime) isSlewing = true; @@ -1987,6 +1988,11 @@ namespace ASCOM.Meade.net } } + private void SetSlewingMinEndTime() + { + _earliestNonSlewingTime = _clock.UtcNow + GetTotalSlewingSettleTime(); + } + private TimeSpan GetTotalSlewingSettleTime() { return TimeSpan.FromSeconds( SlewSettleTime + ProfileSettleTime ); From b0ef75ae66f566d2de0fab811828a9951fc91fa6 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 1 Mar 2021 09:55:07 +0000 Subject: [PATCH 04/12] Added code to include the settle time in the Moving Axis commands (except when moving at Guide Rate) --- Meade.net.Telescope/Telescope.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 4b75b6b..9a8c074 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -819,6 +819,7 @@ namespace ASCOM.Meade.net _movingPrimary = false; _movingSecondary = false; + SetSlewingMinEndTime(); } public AlignmentModes AlignmentMode @@ -1341,6 +1342,9 @@ namespace ASCOM.Meade.net private bool _movingPrimary; private bool _movingSecondary; + private double _primaryRate; + private double _secondaryRate; + public void MoveAxis(TelescopeAxes axis, double rate) { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); @@ -1383,6 +1387,11 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: + if (_primaryRate > 1) + { + //We're going faster than Guide speed, so need to wait for the scope to settle. + SetSlewingMinEndTime(); + } _movingPrimary = false; SharedResourcesWrapper.SendBlind(":Qe#"); //:Qe# Halt eastward Slews @@ -1390,19 +1399,21 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind(":Qw#"); //:Qw# Halt westward Slews //Returns: Nothing + _primaryRate = 0; break; case ComparisonResult.Greater: - SharedResourcesWrapper.SendBlind(":Me#"); //:Me# Move Telescope East at current slew rate //Returns: Nothing _movingPrimary = true; + _primaryRate = absRate; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind(":Mw#"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing _movingPrimary = true; + _primaryRate = absRate; break; } break; @@ -1410,6 +1421,11 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: + if (_secondaryRate > 1) + { + //We're going faster than Guide speed, so need to wait for the scope to settle. + SetSlewingMinEndTime(); + } _movingSecondary = false; SharedResourcesWrapper.SendBlind(":Qn#"); //:Qn# Halt northward Slews @@ -1417,18 +1433,22 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind(":Qs#"); //:Qs# Halt southward Slews //Returns: Nothing + + _secondaryRate = 0; break; case ComparisonResult.Greater: SharedResourcesWrapper.SendBlind(":Mn#"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing _movingSecondary = true; + _secondaryRate = absRate; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind(":Ms#"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing _movingSecondary = true; + _secondaryRate = absRate; break; } From f57a73843a3d55aee04178bee48fa3b2ff328060 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 1 Mar 2021 11:19:27 +0000 Subject: [PATCH 05/12] Fixed a few code inspections --- Meade.net.Telescope/Telescope.cs | 18 +++++++++--------- Meade.net/LocalServer.cs | 27 ++++++++++++++++----------- Meade.net/SharedResources.cs | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 9a8c074..167d64a 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1392,6 +1392,7 @@ namespace ASCOM.Meade.net //We're going faster than Guide speed, so need to wait for the scope to settle. SetSlewingMinEndTime(); } + _movingPrimary = false; SharedResourcesWrapper.SendBlind(":Qe#"); //:Qe# Halt eastward Slews @@ -1580,7 +1581,7 @@ namespace ASCOM.Meade.net /// /// convert a HH:MM.T (classic LX200 RA Notation) string to a double hours. T is the decimal part of minutes which is converted into seconds /// - public double HMToHours(string hm) + public double HmToHours(string hm) { var token = hm.Split('.'); if (token.Length != 2) @@ -1601,7 +1602,7 @@ namespace ASCOM.Meade.net //Returns: HH:MM.T# or HH:MM:SS# //Depending which precision is set for the telescope - double rightAscension = HMToHours(result); + double rightAscension = HmToHours(result); LogMessage("RightAscension", $"Get - {result} convert to {rightAscension} {_utilitiesExtra.HoursToHMS(rightAscension)}"); return rightAscension; @@ -1686,7 +1687,7 @@ namespace ASCOM.Meade.net CheckConnected("SiteElevation Set"); LogMessage("SiteElevation", $"Set: {value}"); - if (value == base.SiteElevation) + if (Math.Abs(value - base.SiteElevation) < 0.1) { LogMessage("SiteElevation", $"Set: no change detected"); return; @@ -2119,14 +2120,14 @@ namespace ASCOM.Meade.net // At least the classic LX200 low precision might not slew to the exact target position // This Requires to retrieve the aimed target ra de from the telescope double ra = RightAscension; - if (_targetRightAscension != InvalidParameter && + if (Math.Abs(_targetRightAscension - InvalidParameter) > 0.1 && _utilities.HoursToHMS(ra, ":", ":", ":", _digitsRa) != _utilities.HoursToHMS(_targetRightAscension, ":", ":", ":", _digitsRa)) { LogMessage("SyncToTarget", $"differ RA real {ra} targeted {_targetRightAscension}"); _targetRightAscension = ra; } double de = Declination; - if (_targetDeclination != InvalidParameter && + if (Math.Abs(_targetDeclination - InvalidParameter) > 0.1 && _utilities.DegreesToDMS(de, "*", ":", ":", _digitsDe) != _utilities.DegreesToDMS(_targetDeclination, "*", ":", ":", _digitsDe)) { LogMessage("SyncToTarget", $"differ DE real {de} targeted {_targetDeclination}"); @@ -2167,10 +2168,9 @@ namespace ASCOM.Meade.net throw new InvalidValueException("Declination cannot be less than -90."); var dms = ""; - if (IsLongFormat) - dms = _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe); - else - dms = _utilities.DegreesToDM(value, "*", "", _digitsDe); + dms = IsLongFormat ? + _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe) : + _utilities.DegreesToDM(value, "*", "", _digitsDe); var s = value < 0 ? string.Empty : "+"; diff --git a/Meade.net/LocalServer.cs b/Meade.net/LocalServer.cs index 2a719af..dcd3c4e 100644 --- a/Meade.net/LocalServer.cs +++ b/Meade.net/LocalServer.cs @@ -337,18 +337,23 @@ namespace ASCOM.Meade.net { key?.SetValue(null, progid); // Could be assyTitle/Desc??, but .NET components show ProgId here key?.SetValue("AppId", _sAppId); - using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) + if (key != null) { - key2?.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); - } - using (RegistryKey key2 = key.CreateSubKey("ProgId")) - { - key2?.SetValue(null, progid); - } - key.CreateSubKey("Programmable"); - using (RegistryKey key2 = key.CreateSubKey("LocalServer32")) - { - key2?.SetValue(null, Application.ExecutablePath); + using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) + { + key2?.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); + } + + using (RegistryKey key2 = key.CreateSubKey("ProgId")) + { + key2?.SetValue(null, progid); + } + + key.CreateSubKey("Programmable"); + using (RegistryKey key2 = key.CreateSubKey("LocalServer32")) + { + key2?.SetValue(null, Application.ExecutablePath); + } } } // diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 691e28d..1aae39b 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -164,7 +164,7 @@ namespace ASCOM.Meade.net driverProfile.WriteValue(DriverId, BacklashCompensationName, profileProperties.BacklashCompensation.ToString()); driverProfile.WriteValue(DriverId, ReverseFocusDirectionName, profileProperties.ReverseFocusDirection.ToString()); driverProfile.WriteValue(DriverId, DynamicBreakingName, profileProperties.DynamicBreaking.ToString()); - driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString()); + driverProfile.WriteValue(DriverId, SiteElevationName, profileProperties.SiteElevation.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, SettleTimeName, profileProperties.SettleTime.ToString()); } } From cdf1066e4e09e67dbda6800d973df119b77fabc9 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 12:54:47 +0000 Subject: [PATCH 06/12] Fixed a few more code inspections --- Meade.net.Telescope/Telescope.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 167d64a..d0ebdd7 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -2048,6 +2048,7 @@ namespace ASCOM.Meade.net { if (string.IsNullOrEmpty(result)) { + // ReSharper disable once RedundantAssignment isSlewing = false; return isSlewing; } @@ -2167,8 +2168,7 @@ namespace ASCOM.Meade.net if (value < -90) throw new InvalidValueException("Declination cannot be less than -90."); - var dms = ""; - dms = IsLongFormat ? + var dms = IsLongFormat ? _utilities.DegreesToDMS(value, "*", ":", ":", _digitsDe) : _utilities.DegreesToDM(value, "*", "", _digitsDe); @@ -2223,12 +2223,9 @@ namespace ASCOM.Meade.net if (value >= 24) throw new InvalidValueException("Right ascension value cannot be greater than 23:59:59"); - var hms = ""; - if(IsLongFormat) - hms = _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa); - else - //meade protocol defines H:MM.T format - hms = _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); + var hms = IsLongFormat ? + _utilities.HoursToHMS(value, ":", ":", ":", _digitsRa) : + _utilities.HoursToHM(value, ":", "", _digitsRa).Replace(',','.'); var command = $":Sr{hms}#"; LogMessage("TargetRightAscension Set", $"{command}"); From acc935248b876ddfda14dbb182d684ff3d9d00bc Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 13:07:21 +0000 Subject: [PATCH 07/12] Couple more code inspections, and changes the MoveAxis so that it will apply the settle time delay when not guiding. --- Meade.net.Telescope/Telescope.cs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index d0ebdd7..ada8098 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -1341,10 +1341,7 @@ namespace ASCOM.Meade.net private bool _movingPrimary; private bool _movingSecondary; - - private double _primaryRate; - private double _secondaryRate; - + public void MoveAxis(TelescopeAxes axis, double rate) { LogMessage("MoveAxis", $"Axis={axis} rate={rate}"); @@ -1387,9 +1384,8 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: - if (_primaryRate > 1) + if (!_isGuiding) { - //We're going faster than Guide speed, so need to wait for the scope to settle. SetSlewingMinEndTime(); } @@ -1400,21 +1396,18 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind(":Qw#"); //:Qw# Halt westward Slews //Returns: Nothing - _primaryRate = 0; break; case ComparisonResult.Greater: SharedResourcesWrapper.SendBlind(":Me#"); //:Me# Move Telescope East at current slew rate //Returns: Nothing _movingPrimary = true; - _primaryRate = absRate; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind(":Mw#"); //:Mw# Move Telescope West at current slew rate //Returns: Nothing _movingPrimary = true; - _primaryRate = absRate; break; } break; @@ -1422,9 +1415,8 @@ namespace ASCOM.Meade.net switch (rate.Compare(0)) { case ComparisonResult.Equals: - if (_secondaryRate > 1) + if (!_isGuiding) { - //We're going faster than Guide speed, so need to wait for the scope to settle. SetSlewingMinEndTime(); } _movingSecondary = false; @@ -1434,26 +1426,20 @@ namespace ASCOM.Meade.net SharedResourcesWrapper.SendBlind(":Qs#"); //:Qs# Halt southward Slews //Returns: Nothing - - _secondaryRate = 0; break; case ComparisonResult.Greater: SharedResourcesWrapper.SendBlind(":Mn#"); //:Mn# Move Telescope North at current slew rate //Returns: Nothing _movingSecondary = true; - _secondaryRate = absRate; break; case ComparisonResult.Lower: SharedResourcesWrapper.SendBlind(":Ms#"); //:Ms# Move Telescope South at current slew rate //Returns: Nothing _movingSecondary = true; - _secondaryRate = absRate; break; - } - break; default: throw new InvalidValueException("Can not move this axis."); From 9dde0d9e81a5a8d84b0892f270e0d33f96640b2a Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 13:49:02 +0000 Subject: [PATCH 08/12] Another code inspection. --- Meade.net/Properties/Resources.Designer.cs | 9 +++++++++ Meade.net/Properties/Resources.resx | 3 +++ Meade.net/SetupDialogForm.cs | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Meade.net/Properties/Resources.Designer.cs b/Meade.net/Properties/Resources.Designer.cs index 1f4ff11..c735eec 100644 --- a/Meade.net/Properties/Resources.Designer.cs +++ b/Meade.net/Properties/Resources.Designer.cs @@ -135,5 +135,14 @@ namespace ASCOM.Meade.net.Properties { return ResourceManager.GetString("SetupDialogForm_TextBox1_TextChanged___0_00_0___of_sidereal_rate_", resourceCulture); } } + + /// + /// Looks up a localized string similar to Please enter only numbers.. + /// + internal static string SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_ { + get { + return ResourceManager.GetString("SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_", resourceCulture); + } + } } } diff --git a/Meade.net/Properties/Resources.resx b/Meade.net/Properties/Resources.resx index 67a3869..9de5db4 100644 --- a/Meade.net/Properties/Resources.resx +++ b/Meade.net/Properties/Resources.resx @@ -144,4 +144,7 @@ Valid are : -register, -unregister and -embedding {0} Settings ({1}) + + Please enter only numbers. + \ No newline at end of file diff --git a/Meade.net/SetupDialogForm.cs b/Meade.net/SetupDialogForm.cs index 52d1e90..d56b963 100644 --- a/Meade.net/SetupDialogForm.cs +++ b/Meade.net/SetupDialogForm.cs @@ -169,7 +169,7 @@ namespace ASCOM.Meade.net { if (System.Text.RegularExpressions.Regex.IsMatch(txtElevation.Text, "[^0-9]")) { - MessageBox.Show("Please enter only numbers."); + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); txtElevation.Text = txtElevation.Text.Remove(txtElevation.Text.Length - 1); } } @@ -178,7 +178,7 @@ namespace ASCOM.Meade.net { if (System.Text.RegularExpressions.Regex.IsMatch(txtBacklashSteps.Text, "[^0-9]")) { - MessageBox.Show("Please enter only numbers."); + MessageBox.Show(Resources.SetupDialogForm_txtElevation_TextChanged_1_Please_enter_only_numbers_); txtBacklashSteps.Text = txtElevation.Text.Remove(txtBacklashSteps.Text.Length - 1); } } From f88ad13f0d0027bdf4b3a7479ae81dc277f7b1fa Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 14:02:12 +0000 Subject: [PATCH 09/12] Testing to ignore unit tests from code inspections. --- .gitignore | 1 - Meade.net.sln.DotSettings | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Meade.net.sln.DotSettings diff --git a/.gitignore b/.gitignore index a6bb49f..f2ba386 100644 --- a/.gitignore +++ b/.gitignore @@ -218,5 +218,4 @@ _Pvt_Extensions # nCrunch items *.ncrunchsolution -*.DotSettings *.ncrunchproject diff --git a/Meade.net.sln.DotSettings b/Meade.net.sln.DotSettings new file mode 100644 index 0000000..7f8d523 --- /dev/null +++ b/Meade.net.sln.DotSettings @@ -0,0 +1,4 @@ + + True + True + True \ No newline at end of file From a5773aaaa9637a9a40ee02a0ccca37515b724ad5 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 14:23:42 +0000 Subject: [PATCH 10/12] Trying to change the inspections again --- Meade.net.sln.DotSettings | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Meade.net.sln.DotSettings b/Meade.net.sln.DotSettings index 7f8d523..a89188a 100644 --- a/Meade.net.sln.DotSettings +++ b/Meade.net.sln.DotSettings @@ -1,4 +1,6 @@  - True + False + True + True True True \ No newline at end of file From 032fb2e8a81b35ff504d81d0c7a824d4d13a126e Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 20:24:13 +0000 Subject: [PATCH 11/12] Code inspection --- Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs b/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs index 9254007..183700e 100644 --- a/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs +++ b/Meade.net.Telescope/AstroMaths/AstroMathExtensions.cs @@ -58,7 +58,7 @@ namespace ASCOM.Meade.net.AstroMaths t0 -= 24; } - var ut = DateTimeToDecimalHours(utcDateTime); + var ut = utcDateTime.DateTimeToDecimalHours(); var a = ut * 1.002737909; var t1 = t0 + a; From 75b6f0b4b41a2cfbef411fbb796846d8f72779c9 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 2 Mar 2021 20:24:43 +0000 Subject: [PATCH 12/12] Added unit testing for the settle time delay on MoveAxis. --- .../TelescopeUnitTests.cs | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 62c63ef..16b330d 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -1463,6 +1463,53 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendBlind($":Q{d}#")); } + [TestCase(GuideDirections.guideEast)] + [TestCase(GuideDirections.guideWest)] + [TestCase(GuideDirections.guideNorth)] + [TestCase(GuideDirections.guideSouth)] + public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndDoesNotWaitForExtraSettleTime(GuideDirections direction) + { + short slewSettleTime = 10; + _profileProperties.SettleTime = slewSettleTime; + + var telescopeDecResult = "s12*34’56"; + var dmsResult = 1.2; + var telescopeRaResult = "HH:MM:SS"; + var hmsResult = 1.3; + + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GD#")).Returns(telescopeDecResult); + _sharedResourcesWrapperMock.Setup(x => x.SendString(":GR#")).Returns(telescopeRaResult); + _utilMock.Setup(x => x.DMSToDegrees(telescopeDecResult)).Returns(dmsResult); + _utilMock.Setup(x => x.HMSToHours(telescopeRaResult)).Returns(hmsResult); + + var duration = 0; + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => TelescopeList.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => TelescopeList.Autostar497_30Ee); + + _telescope.Connected = true; + + _telescope.PulseGuide(direction, duration); + + string d = string.Empty; + switch (direction) + { + case GuideDirections.guideEast: + d = "e"; + break; + case GuideDirections.guideWest: + d = "w"; + break; + case GuideDirections.guideNorth: + d = "n"; + break; + case GuideDirections.guideSouth: + d = "s"; + break; + } + + _clockMock.Verify(x => x.UtcNow, Times.Never); + } + [TestCase(GuideDirections.guideEast)] [TestCase(GuideDirections.guideWest)] [TestCase(GuideDirections.guideNorth)] @@ -2439,6 +2486,60 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock.Verify(x => x.SendString(":D#"), Times.Never); } + [TestCase(1, TelescopeAxes.axisPrimary, 0, 0, false, false)] + [TestCase(-1, TelescopeAxes.axisPrimary, 0, 0, false, false)] + [TestCase(1, TelescopeAxes.axisSecondary, 0, 0, false, false)] + [TestCase(-1, TelescopeAxes.axisSecondary, 0, 0, false, false)] + + [TestCase(1, TelescopeAxes.axisPrimary, 10, 0, true, false)] + [TestCase(-1, TelescopeAxes.axisPrimary, 10, 0, true, false)] + [TestCase(1, TelescopeAxes.axisSecondary, 10, 0, true, false)] + [TestCase(-1, TelescopeAxes.axisSecondary, 10, 0, true, false)] + + [TestCase(1, TelescopeAxes.axisPrimary, 10, 20, true, true)] + [TestCase(-1, TelescopeAxes.axisPrimary, 10, 20, true, true)] + [TestCase(1, TelescopeAxes.axisSecondary, 10, 20, true, true)] + [TestCase(-1, TelescopeAxes.axisSecondary, 10, 20, true, true)] + public void Slewing_WhenTelescopeStops_ThenWaitsForSettleTime(int rate, TelescopeAxes axis, short profileSettleTime, short driverSettleTime, bool expectedResultInWaitingPeriod, bool afterProfileSettleTimeUp) + { + _profileProperties.SettleTime = profileSettleTime; + + DateTime currentTime = MakeTime("2021-01-23T22:02:10"); + + _clockMock.Setup(x => x.UtcNow).Returns(() => currentTime ); + + ConnectTelescope(); + + _telescope.SlewSettleTime = driverSettleTime; + + _telescope.MoveAxis(axis, rate); + + var result = _telescope.Slewing; + Assert.That(result, Is.True); + + _telescope.MoveAxis(axis, 0); + + currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + + result = _telescope.Slewing; + Assert.That(result, Is.EqualTo(expectedResultInWaitingPeriod)); + + currentTime = currentTime + TimeSpan.FromSeconds(profileSettleTime / 2); + + result = _telescope.Slewing; + Assert.That(result, Is.EqualTo(afterProfileSettleTimeUp)); + + currentTime = currentTime + TimeSpan.FromSeconds(driverSettleTime); + + result = _telescope.Slewing; + Assert.That(result, Is.False); + } + + private DateTime MakeTime( string dateTimeString ) + { + return DateTime.ParseExact(dateTimeString, "yyyy-MM-dd'T'HH:mm:ss", CultureInfo.InvariantCulture); + } + [Test] public void SlewToTargetAsync_WhenNotConnected_ThenThrowsException()